@@ -10,7 +10,7 @@ import GithubPackage from '../lib/github-package';
1010describe ( 'GithubPackage' , function ( ) {
1111
1212 async function buildAtomEnvironmentAndGithubPackage ( buildAtomEnvironment , options = { } ) {
13- const atomEnv = global . buildAtomEnvironment ( ) ;
13+ const atomEnv = buildAtomEnvironment ( ) ;
1414 await disableFilesystemWatchers ( atomEnv ) ;
1515
1616 const packageOptions = {
@@ -147,7 +147,7 @@ describe('GithubPackage', function() {
147147 ( {
148148 atomEnv, githubPackage,
149149 project, config, configDirPath, contextPool,
150- } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironmentAndGithubPackage ) ) ;
150+ } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironment ) ) ;
151151 } ) ;
152152
153153 afterEach ( async function ( ) {
@@ -237,6 +237,105 @@ describe('GithubPackage', function() {
237237 } ) ;
238238 } ) ;
239239
240+ describe ( 'with 3 projects and unactivated' , function ( ) {
241+ let workdirPath1 , workdirPath2 , workdirPath3 ;
242+ beforeEach ( async function ( ) {
243+ ( [ workdirPath1 , workdirPath2 , workdirPath3 ] = await Promise . all ( [
244+ cloneRepository ( 'three-files' ) ,
245+ cloneRepository ( 'three-files' ) ,
246+ cloneRepository ( 'three-files' ) ,
247+ ] ) ) ;
248+ project . setPaths ( [ workdirPath1 , workdirPath2 , workdirPath3 ] ) ;
249+ } ) ;
250+
251+ describe ( 'with useProjectFromActivePanel config enabled' , function ( ) {
252+ beforeEach ( async function ( ) {
253+ atomEnv . config . set ( 'github.useProjectFromActivePanel' , true ) ;
254+ await contextUpdateAfter ( githubPackage , ( ) => githubPackage . activate ( { } ) ) ;
255+ } ) ;
256+
257+ it ( 'changes repository when active panel is changed' , async function ( ) {
258+ await Promise . all ( [
259+ atomEnv . workspace . open ( path . join ( workdirPath1 , 'a.txt' ) ) ,
260+ new Promise ( ( resolve , reject ) => {
261+ githubPackage . scheduleActiveContextUpdate = ( { activeRepositoryPath} ) => {
262+ try {
263+ assert . strictEqual ( activeRepositoryPath , workdirPath1 ) ;
264+ resolve ( ) ;
265+ } catch ( e ) { reject ( e ) ; }
266+ } ;
267+ } ) ,
268+ ] ) ;
269+
270+ await Promise . all ( [
271+ atomEnv . workspace . open ( path . join ( workdirPath2 , 'b.txt' ) ) ,
272+ new Promise ( ( resolve , reject ) => {
273+ githubPackage . scheduleActiveContextUpdate = ( { activeRepositoryPath} ) => {
274+ try {
275+ assert . strictEqual ( activeRepositoryPath , workdirPath2 ) ;
276+ resolve ( ) ;
277+ } catch ( e ) { reject ( e ) ; }
278+ } ;
279+ } ) ,
280+ ] ) ;
281+
282+ await Promise . all ( [
283+ atomEnv . workspace . open ( path . join ( workdirPath3 , 'c.txt' ) ) ,
284+ new Promise ( ( resolve , reject ) => {
285+ githubPackage . scheduleActiveContextUpdate = ( { activeRepositoryPath} ) => {
286+ try {
287+ assert . strictEqual ( activeRepositoryPath , workdirPath3 ) ;
288+ resolve ( ) ;
289+ } catch ( e ) { reject ( e ) ; }
290+ } ;
291+ } ) ,
292+ ] ) ;
293+ } ) ;
294+
295+ it ( 'subscribes to changes in the configuration value' , async function ( ) {
296+ const scheduleActiveContextUpdate = githubPackage . scheduleActiveContextUpdate = sinon . stub ( ) ;
297+
298+ await Promise . all ( [
299+ atomEnv . workspace . open ( path . join ( workdirPath1 , 'a.txt' ) ) ,
300+ new Promise ( ( resolve , reject ) => {
301+ scheduleActiveContextUpdate . callsFake ( ( { activeRepositoryPath} ) => {
302+ try {
303+ assert . strictEqual ( activeRepositoryPath , workdirPath1 ) ;
304+ resolve ( ) ;
305+ } catch ( e ) { reject ( e ) ; }
306+ } ) ;
307+ } ) ,
308+ ] ) ;
309+
310+ atomEnv . config . set ( 'github.useProjectFromActivePanel' , false ) ;
311+ await Promise . all ( [
312+ atomEnv . workspace . open ( path . join ( workdirPath2 , 'b.txt' ) ) ,
313+ new Promise ( resolve => {
314+ const disposable = atomEnv . workspace . getCenter ( ) . onDidStopChangingActivePaneItem ( ( ) => {
315+ disposable . dispose ( ) ;
316+ resolve ( ) ;
317+ } ) ;
318+ } ) ,
319+ ] ) ;
320+
321+ atomEnv . config . set ( 'github.useProjectFromActivePanel' , true ) ;
322+ await Promise . all ( [
323+ atomEnv . workspace . open ( path . join ( workdirPath3 , 'c.txt' ) ) ,
324+ new Promise ( ( resolve , reject ) => {
325+ scheduleActiveContextUpdate . callsFake ( ( { activeRepositoryPath} ) => {
326+ try {
327+ assert . strictEqual ( activeRepositoryPath , workdirPath3 ) ;
328+ resolve ( ) ;
329+ } catch ( e ) { reject ( e ) ; }
330+ } ) ;
331+ } ) ,
332+ ] ) ;
333+
334+ assert . strictEqual ( scheduleActiveContextUpdate . callCount , 2 ) ;
335+ } ) ;
336+ } ) ;
337+ } ) ;
338+
240339 describe ( 'with 1 project and absent state' , function ( ) {
241340 let workdirPath1 , workdirPath2 , context1 ;
242341 beforeEach ( async function ( ) {
@@ -357,7 +456,7 @@ describe('GithubPackage', function() {
357456 ( {
358457 atomEnv, githubPackage,
359458 project, contextPool,
360- } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironmentAndGithubPackage ) ) ;
459+ } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironment ) ) ;
361460 } ) ;
362461
363462 afterEach ( async function ( ) {
@@ -664,7 +763,7 @@ describe('GithubPackage', function() {
664763 ( {
665764 atomEnv, githubPackage,
666765 project, contextPool,
667- } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironmentAndGithubPackage ) ) ;
766+ } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironment ) ) ;
668767 } ) ;
669768
670769 afterEach ( async function ( ) {
@@ -706,7 +805,7 @@ describe('GithubPackage', function() {
706805 ( {
707806 atomEnv, githubPackage,
708807 project,
709- } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironmentAndGithubPackage ) ) ;
808+ } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironment ) ) ;
710809 } ) ;
711810
712811 afterEach ( async function ( ) {
@@ -774,7 +873,7 @@ describe('GithubPackage', function() {
774873 beforeEach ( async function ( ) {
775874 ( {
776875 atomEnv, githubPackage,
777- } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironmentAndGithubPackage ) ) ;
876+ } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironment ) ) ;
778877
779878 sinon . spy ( githubPackage , 'rerender' ) ;
780879 } ) ;
@@ -825,7 +924,7 @@ describe('GithubPackage', function() {
825924 beforeEach ( async function ( ) {
826925 ( {
827926 atomEnv, githubPackage,
828- } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironmentAndGithubPackage ) ) ;
927+ } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironment ) ) ;
829928
830929 sinon . spy ( githubPackage , 'rerender' ) ;
831930 } ) ;
@@ -879,7 +978,7 @@ describe('GithubPackage', function() {
879978 ( {
880979 atomEnv, githubPackage,
881980 project, contextPool,
882- } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironmentAndGithubPackage ) ) ;
981+ } = await buildAtomEnvironmentAndGithubPackage ( global . buildAtomEnvironment ) ) ;
883982 } ) ;
884983
885984 let workdirPath1 , atomGitRepository1 , repository1 ;
0 commit comments