Skip to content

Commit 37de803

Browse files
committed
test: more integration test for file recovery
1 parent 44bcfa1 commit 37de803

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/extensions/default/NavigationAndHistory/FileRecovery.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ define(function (require, exports, module) {
188188
Strings: Strings,
189189
PROJECT_TO_RECOVER: projectRootPath
190190
});
191+
if(project.restoreNotification){
192+
project.restoreNotification.close();
193+
project.restoreNotification = null;
194+
}
191195
project.restoreNotification = NotificationUI.createToastFromTemplate( Strings.RECOVER_UNSAVED_FILES_TITLE,
192196
notificationHTML, {
193197
dismissOnClick: false,
@@ -332,6 +336,7 @@ define(function (require, exports, module) {
332336
const project = trackedProjects[currentProjectRoot.fullPath];
333337
if(project.restoreNotification) {
334338
project.restoreNotification.close();
339+
project.restoreNotification = null;
335340
}
336341
changeScanner().catch(err=>{
337342
console.error("[recovery] beforeProjectClosed failed which scanning for changes to backup", err);

src/extensions/default/NavigationAndHistory/integ-tests.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)