77
88import * as assert from 'assert' ;
99import URI from 'vs/base/common/uri' ;
10+ import paths = require( 'vs/base/common/paths' ) ;
1011import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
1112import { createInstantiationService } from 'vs/platform/instantiation/common/instantiationService' ;
1213import { TestFileService , TestLifecycleService , TestPartService , TestEditorService , TestConfigurationService , TestUntitledEditorService , TestStorageService , TestTelemetryService , TestContextService , TestMessageService , TestEventService } from 'vs/workbench/test/browser/servicesTestUtils' ;
1314import { WorkingFileEntry , WorkingFilesModel } from 'vs/workbench/parts/files/common/workingFilesModel' ;
1415import { TextFileService } from 'vs/workbench/parts/files/browser/textFileServices' ;
1516import { createMockModelService , createMockModeService } from 'vs/editor/test/common/servicesTestUtils' ;
17+ import { EditorInput } from 'vs/workbench/common/editor' ;
18+ import { FileEditorInput } from 'vs/workbench/parts/files/browser/editors/fileEditorInput' ;
19+
20+ function toResource ( path ) {
21+ return URI . file ( paths . join ( 'C:\\' , path ) ) ;
22+ }
1623
1724let baseInstantiationService : IInstantiationService ;
25+ let editorService : TestEditorService ;
1826let eventService : TestEventService ;
1927let textFileService : TextFileService ;
2028
2129suite ( 'Files - WorkingFilesModel' , ( ) => {
2230
2331 setup ( ( ) => {
32+ editorService = new TestEditorService ( ) ;
2433 eventService = new TestEventService ( ) ;
2534
2635 baseInstantiationService = createInstantiationService ( {
@@ -31,7 +40,7 @@ suite('Files - WorkingFilesModel', () => {
3140 telemetryService : new TestTelemetryService ( ) ,
3241 storageService : new TestStorageService ( ) ,
3342 untitledEditorService : new TestUntitledEditorService ( ) ,
34- editorService : new TestEditorService ( ) ,
43+ editorService : editorService ,
3544 partService : new TestPartService ( ) ,
3645 modeService : createMockModeService ( ) ,
3746 modelService : createMockModelService ( ) ,
@@ -103,4 +112,30 @@ suite('Files - WorkingFilesModel', () => {
103112
104113 assert . equal ( model . popLastClosedEntry ( ) , null ) ;
105114 } ) ;
115+
116+ test ( "Reopening multiple files will open the editor in the previously opened file" , function ( ) {
117+ let model = baseInstantiationService . createInstance ( WorkingFilesModel ) ;
118+
119+ // Open /foo then /bar, set /foo as active input
120+ let fooEntry = model . addEntry ( URI . create ( 'file' , null , '/foo' ) ) ;
121+ editorService . getActiveEditorInput = ( ) => {
122+ return baseInstantiationService . createInstance ( FileEditorInput , fooEntry . resource , 'text/javascript' , void 0 ) ;
123+ } ;
124+ model . addEntry ( URI . create ( 'file' , null , '/bar' ) ) ;
125+ model . clear ( ) ;
126+
127+ let lastClosedEntry : WorkingFileEntry [ ] = model . popLastClosedEntry ( ) ;
128+ assert . equal ( lastClosedEntry [ 0 ] . resource . path , '/foo' ) ;
129+
130+ // Open /bar then /foo, set /foo as active input
131+ model . addEntry ( URI . create ( 'file' , null , '/bar' ) ) ;
132+ fooEntry = model . addEntry ( URI . create ( 'file' , null , '/foo' ) ) ;
133+ editorService . getActiveEditorInput = ( ) => {
134+ return baseInstantiationService . createInstance ( FileEditorInput , fooEntry . resource , 'text/javascript' , void 0 ) ;
135+ } ;
136+ model . clear ( ) ;
137+
138+ lastClosedEntry = model . popLastClosedEntry ( ) ;
139+ assert . equal ( lastClosedEntry [ 0 ] . resource . path , '/foo' ) ;
140+ } ) ;
106141} ) ;
0 commit comments