@@ -27,7 +27,7 @@ define(function (require, exports, module) {
2727 return ;
2828 }
2929
30- let $ , __PR , testWindow , ExtensionLoader , Menus , Commands , CommandManager , EditorManager ,
30+ let $ , __PR , testWindow , ExtensionLoader , Menus , Commands , CommandManager , EditorManager , MainViewManager ,
3131 SpecRunnerUtils = require ( "spec/SpecRunnerUtils" ) ,
3232 nonGitReadOnlyTestFolder = SpecRunnerUtils . getTestPath ( "/spec/LowLevelFileIO-test-files" ) ;
3333
@@ -61,6 +61,7 @@ define(function (require, exports, module) {
6161 Commands = testWindow . brackets . test . Commands ;
6262 CommandManager = testWindow . brackets . test . CommandManager ;
6363 EditorManager = testWindow . brackets . test . EditorManager ;
64+ MainViewManager = testWindow . brackets . test . MainViewManager ;
6465 testPathGit = await SpecRunnerUtils . getTempTestDirectory ( "/spec/EditorCommandHandlers-test-files" ) ;
6566
6667 await SpecRunnerUtils . loadProjectInTestWindow ( testPathGit ) ;
@@ -507,6 +508,70 @@ define(function (require, exports, module) {
507508 $ ( ".switch-branch" ) . click ( ) ;
508509 await waitForBranchNameDropdown ( defaultBranch ) ;
509510 } ) ;
511+
512+ function workingSetHas ( fileName ) {
513+ const workingSet = MainViewManager . getWorkingSet ( MainViewManager . ALL_PANES ) ;
514+ return workingSet . some ( ( file ) => file . fullPath . endsWith ( "/" + fileName ) ) ;
515+ }
516+
517+ function viewedFileIs ( fileName ) {
518+ const viewedPath = MainViewManager . getCurrentlyViewedPath ( MainViewManager . ACTIVE_PANE ) ;
519+ return ! ! viewedPath && viewedPath . endsWith ( "/" + fileName ) ;
520+ }
521+
522+ async function makeFilesChanged ( fileNames ) {
523+ await showGitPanel ( ) ;
524+ await __PR . closeAll ( ) ;
525+ await awaitsFor ( ( ) => {
526+ return MainViewManager . getWorkingSetSize ( MainViewManager . ALL_PANES ) === 0 ;
527+ } , "working set to be empty" ) ;
528+
529+ for ( const fileName of fileNames ) {
530+ await __PR . writeTextFile ( fileName , `/* changed ${ fileName } */\n` , true ) ;
531+ }
532+ await __PR . execCommand ( Commands . CMD_GIT_REFRESH ) ;
533+ await awaitsFor ( ( ) => {
534+ return $gitPanel . find ( ".modified-file" ) . length === fileNames . length ;
535+ } , `${ fileNames . length } files to be in modified files list` , 10000 ) ;
536+ }
537+
538+ it ( "should open all changed files add them to the working set" , async ( ) => {
539+ await makeFilesChanged ( [ "test.css" , "test.js" ] ) ;
540+
541+ await __PR . execCommand ( Commands . CMD_GIT_OPEN_CHANGED_FILES ) ;
542+ await awaitsFor ( ( ) => {
543+ return workingSetHas ( "test.css" ) && workingSetHas ( "test.js" ) ;
544+ } , "changed files to be added to the working set" , 10000 ) ;
545+
546+ // only the changed files are opened, test.html was left untouched
547+ expect ( MainViewManager . getWorkingSetSize ( MainViewManager . ALL_PANES ) ) . toBe ( 2 ) ;
548+ expect ( workingSetHas ( "test.html" ) ) . toBeFalse ( ) ;
549+
550+ // nothing was open, so one of the changed files is brought into view
551+ await awaitsFor ( ( ) => {
552+ return viewedFileIs ( "test.css" ) || viewedFileIs ( "test.js" ) ;
553+ } , "a changed file to be viewed" , 10000 ) ;
554+ } ) ;
555+
556+ it ( "should not switch the viewed file when opening all changed files" , async ( ) => {
557+ await makeFilesChanged ( [ "test.css" , "test.js" ] ) ;
558+
559+ // test.html has no changes, so it must stay in view after the command
560+ await __PR . openFile ( "test.html" ) ;
561+ await awaitsFor ( ( ) => {
562+ return viewedFileIs ( "test.html" ) ;
563+ } , "test.html to be the viewed file" ) ;
564+
565+ await __PR . execCommand ( Commands . CMD_GIT_OPEN_CHANGED_FILES ) ;
566+ await awaitsFor ( ( ) => {
567+ return workingSetHas ( "test.css" ) && workingSetHas ( "test.js" ) ;
568+ } , "changed files to be added to the working set" , 10000 ) ;
569+
570+ // a git refresh round trip gives any stray file open enough time to land
571+ await __PR . execCommand ( Commands . CMD_GIT_REFRESH ) ;
572+ expect ( viewedFileIs ( "test.html" ) ) . toBeTrue ( ) ;
573+ expect ( MainViewManager . getWorkingSetSize ( MainViewManager . ALL_PANES ) ) . toBe ( 3 ) ;
574+ } ) ;
510575 } ) ;
511576 } ) ;
512577} ) ;
0 commit comments