@@ -111,12 +111,14 @@ define(function (require, exports, module) {
111111 return false ;
112112 }
113113
114- async function initFileRestorer ( fileToOpen ) {
114+ async function initFileRestorer ( fileToOpen , scanInterval = 100 ) {
115+ await deletePath ( tempRestorePath ) ;
116+ await SpecRunnerUtils . waitTillPathNotExists ( tempRestorePath ) ;
115117 await openFile ( fileToOpen ) ;
116118 expect ( isFileOpen ( fileToOpen ) ) . toBeTrue ( ) ;
117119 expect ( testWindow . _FileRecoveryExtensionForTests ) . exists ;
118120 expect ( await SpecRunnerUtils . pathExists ( tempRestorePath , true ) ) . toBeFalse ( ) ;
119- testWindow . _FileRecoveryExtensionForTests . initWith ( 100 ,
121+ testWindow . _FileRecoveryExtensionForTests . initWith ( scanInterval ,
120122 FileSystem . getDirectoryForPath ( tempRestorePath ) ) ;
121123 await SpecRunnerUtils . waitTillPathExists ( tempRestorePath ) ;
122124
@@ -175,5 +177,40 @@ define(function (require, exports, module) {
175177 } , "waiting for restore notification" , 5000 ) ;
176178 await closeSession ( ) ;
177179 } , 10000 ) ;
180+
181+ // below project switch test case is flakey. need to fix. disable for now.
182+ // it("Should show restore on project switch", async function () {
183+ // const readOnlyProject = SpecRunnerUtils.getTestPath("/spec/ProjectManager-test-files");
184+ // await initFileRestorer("toDelete1/file.js", 1000);
185+ // let projectRestorePath = testWindow._FileRecoveryExtensionForTests.getProjectRestoreRoot(testPath);
186+ //
187+ // // now edit a file so that its backup is created
188+ // const unsavedText = "hello" + Math.random();
189+ // let editor = EditorManager.getActiveEditor();
190+ // editor.document.setText(unsavedText);
191+ // await SpecRunnerUtils.waitTillPathExists(projectRestorePath.fullPath + "toDelete1/file.js", false);
192+ //
193+ // // backup is now present, switch to another project
194+ // let loadPromise = SpecRunnerUtils.loadProjectInTestWindow(readOnlyProject);
195+ // await awaitsFor(()=>{
196+ // return $('button[data-button-id=dontsave]').length >= 1;
197+ // }, "waiting for save changes dialogue", 5000);
198+ // $('button[data-button-id=dontsave]')[0].click();
199+ // await loadPromise;
200+ // await SpecRunnerUtils.loadProjectInTestWindow(testPath);
201+ // await awaits(3000);
202+ // await awaitsFor(()=>{
203+ // return $(".file-recovery-button").length === 1;
204+ // }, "waiting for restore notification", 5000);
205+ //
206+ // // now press the recover button to start the recovery
207+ // $(".file-recovery-button").click();
208+ // // check if the file is recovered
209+ // await awaitsFor(()=>{
210+ // editor = EditorManager.getActiveEditor();
211+ // return editor && editor.document.getText() === unsavedText;
212+ // }, "waiting for restore notification", 5000);
213+ // await closeSession();
214+ // }, 1000000);
178215 } ) ;
179216} ) ;
0 commit comments