@@ -34,6 +34,7 @@ define(function (require, exports, module) {
3434 DocumentCommandHandlers , // loaded from brackets.test
3535 DocumentManager , // loaded from brackets.test
3636 Dialogs , // loaded from brackets.test
37+ FileViewController , // loaded from brackets.test
3738 SpecRunnerUtils = require ( "spec/SpecRunnerUtils" ) ,
3839 NativeFileSystem = require ( "file/NativeFileSystem" ) . NativeFileSystem ,
3940 FileUtils = require ( "file/FileUtils" ) ,
@@ -59,6 +60,7 @@ define(function (require, exports, module) {
5960 DocumentCommandHandlers = testWindow . brackets . test . DocumentCommandHandlers ;
6061 DocumentManager = testWindow . brackets . test . DocumentManager ;
6162 Dialogs = testWindow . brackets . test . Dialogs ;
63+ FileViewController = testWindow . brackets . test . FileViewController ;
6264 } ) ;
6365 } ) ;
6466
@@ -146,7 +148,7 @@ define(function (require, exports, module) {
146148 } ) ;
147149 } ) ;
148150
149- it ( "should keep untitled document in the Working Set after saving with new name" , function ( ) {
151+ it ( "should swap out untitled document in the Working Set after saving with new name" , function ( ) {
150152 var newFilename = "testname.js" ,
151153 newFilePath = testPath + "/" + newFilename ,
152154 promise ;
@@ -173,12 +175,53 @@ define(function (require, exports, module) {
173175 expect ( noLongerUntitledDocument . isUntitled ( ) ) . toBe ( false ) ;
174176 expect ( noLongerUntitledDocument . file . fullPath ) . toEqual ( newFilePath ) ;
175177 expect ( DocumentManager . findInWorkingSet ( newFilePath ) ) . toBeGreaterThan ( - 1 ) ;
178+ expect ( DocumentManager . getWorkingSet ( ) . length ) . toEqual ( 1 ) ; // no remnant of untitled doc left
176179
177180 // Verify file exists, & clean up
178181 expectAndDelete ( newFilePath ) ;
179182 } ) ;
180183 } ) ;
181184
185+ it ( "should swap out untitled document from working set even when not current" , function ( ) {
186+ var newFilePath = testPath + "/testname.js" ,
187+ promise ;
188+
189+ runs ( function ( ) {
190+ promise = CommandManager . execute ( Commands . FILE_NEW_UNTITLED ) ;
191+
192+ waitsForDone ( promise , "FILE_NEW_UNTITLED" ) ;
193+ } ) ;
194+
195+ runs ( function ( ) {
196+ // Select test.js in the project tree (so nothing is selected in the working set)
197+ promise = FileViewController . openAndSelectDocument ( testPath + "/test.js" , FileViewController . PROJECT_MANAGER ) ;
198+
199+ waitsForDone ( promise , "openAndSelectDocument" ) ;
200+ } ) ;
201+
202+ runs ( function ( ) {
203+ spyOn ( testWindow . brackets . fs , 'showSaveDialog' ) . andCallFake ( function ( dialogTitle , initialPath , proposedNewName , callback ) {
204+ callback ( undefined , newFilePath ) ;
205+ } ) ;
206+
207+ var promise = CommandManager . execute ( Commands . FILE_SAVE_ALL ) ;
208+ waitsForDone ( promise , "FILE_SAVE_ALL" ) ;
209+ } ) ;
210+
211+ runs ( function ( ) {
212+ var noLongerUntitledDocument = DocumentManager . getCurrentDocument ( ) ;
213+
214+ expect ( noLongerUntitledDocument . isDirty ) . toBe ( false ) ;
215+ expect ( noLongerUntitledDocument . isUntitled ( ) ) . toBe ( false ) ;
216+ expect ( noLongerUntitledDocument . file . fullPath ) . toEqual ( newFilePath ) ;
217+ expect ( DocumentManager . findInWorkingSet ( newFilePath ) ) . toBeGreaterThan ( - 1 ) ;
218+ expect ( DocumentManager . getWorkingSet ( ) . length ) . toEqual ( 1 ) ; // no remnant of untitled doc left
219+
220+ // Verify file exists, & clean up
221+ expectAndDelete ( newFilePath ) ;
222+ } ) ;
223+ } ) ;
224+
182225 it ( "should ask to save untitled document upon closing" , function ( ) {
183226 var newFilename = "testname2.js" ,
184227 newFilePath = testPath + "/" + newFilename ,
0 commit comments