From fb1e83500c55426f2bbb087be089e3af10881aad Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Tue, 28 Sep 2021 02:40:09 +0100 Subject: [PATCH] Fixed workspace test, ensure open files are closed before workspace creation --- .../remix-ide-e2e/src/tests/workspace.test.ts | 23 +++++++------------ apps/remix-ide/src/app/files/fileManager.js | 13 +++++++---- .../workspace/src/lib/actions/workspace.ts | 2 +- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/workspace.test.ts b/apps/remix-ide-e2e/src/tests/workspace.test.ts index 204b8e7c31..470c0b4b6f 100644 --- a/apps/remix-ide-e2e/src/tests/workspace.test.ts +++ b/apps/remix-ide-e2e/src/tests/workspace.test.ts @@ -38,8 +38,8 @@ module.exports = { .waitForElementVisible('[data-id="workspacesModalDialogModalDialogModalFooter-react"] > span') // eslint-disable-next-line dot-notation .execute(function () { document.querySelector('*[data-id="modalDialogCustomPromptTextCreate"]')['value'] = 'workspace_name' }) - .pause(1000) - .click('span[data-id="workspacesModalDialog-modal-footer-ok-react"]') + .waitForElementVisible('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') + .click('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') .waitForElementVisible('*[data-id="treeViewLitreeViewItemtests"]') .pause(1000) .addFile('test.sol', { content: 'test' }) @@ -48,11 +48,8 @@ module.exports = { .waitForElementVisible('*[data-id="modalDialogCustomPromptTextCreate"]') // eslint-disable-next-line dot-notation .execute(function () { document.querySelector('*[data-id="modalDialogCustomPromptTextCreate"]')['value'] = 'workspace_name_1' }) - .waitForElementVisible('span[data-id="workspacesModalDialog-modal-footer-ok-react"]') - // eslint-disable-next-line dot-notation - .execute(function () { document.querySelector('span[data-id="workspacesModalDialog-modal-footer-ok-react"]') }) - .pause(2000) - .click('span[data-id="workspacesModalDialog-modal-footer-ok-react"]') + .waitForElementVisible('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok]') + .click('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') .waitForElementVisible('*[data-id="treeViewLitreeViewItemtests"]') .pause(2000) .waitForElementNotPresent('*[data-id="treeViewLitreeViewItemtest.sol"]') @@ -68,10 +65,8 @@ module.exports = { .waitForElementVisible('*[data-id="modalDialogCustomPromptTextRename"]') // eslint-disable-next-line dot-notation .execute(function () { document.querySelector('*[data-id="modalDialogCustomPromptTextRename"]')['value'] = 'workspace_name_renamed' }) - .pause(2000) - .waitForElementPresent('span[data-id="workspacesModalDialog-modal-footer-ok-react"]') - .click('span[data-id="workspacesModalDialog-modal-footer-ok-react"]') - .pause(2000) + .waitForElementPresent('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') + .click('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') .click('*[data-id="workspacesSelect"] option[value="workspace_name_1"]') .pause(2000) .waitForElementNotPresent('*[data-id="treeViewLitreeViewItemtest.sol"]') @@ -84,10 +79,8 @@ module.exports = { browser .click('*[data-id="workspacesSelect"] option[value="workspace_name_1"]') .click('*[data-id="workspaceDelete"]') // delete workspace_name_1 - .waitForElementVisible('[data-id="workspacesModalDialogModalDialogModalFooter-react"] > span') - .pause(2000) - .click('[data-id="workspacesModalDialogModalDialogModalFooter-react"] > span') - .pause(2000) + .waitForElementVisible('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') + .click('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') .waitForElementNotPresent('*[data-id="workspacesSelect"] option[value="workspace_name_1"]') .end() }, diff --git a/apps/remix-ide/src/app/files/fileManager.js b/apps/remix-ide/src/app/files/fileManager.js index 478a2ddc32..fa919a03f3 100644 --- a/apps/remix-ide/src/app/files/fileManager.js +++ b/apps/remix-ide/src/app/files/fileManager.js @@ -458,11 +458,14 @@ class FileManager extends Plugin { closeAllFiles () { // TODO: Only keep `this.emit` (issue#2210) - this.emit('filesAllClosed') - this.events.emit('filesAllClosed') - for (const file in this.openedFiles) { - this.closeFile(file) - } + return new Promise((resolve) => { + this.emit('filesAllClosed') + this.events.emit('filesAllClosed') + for (const file in this.openedFiles) { + this.closeFile(file) + } + resolve(true) + }) } closeFile (name) { diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 48f32cbd3e..89a53e62e8 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -35,11 +35,11 @@ export const addInputField = async (type: 'file' | 'folder', path: string) => { } export const createWorkspace = async (workspaceName: string) => { + await plugin.fileManager.closeAllFiles() const promise = createWorkspaceTemplate(workspaceName, 'default-template') dispatch(createWorkspaceRequest(promise)) promise.then(async () => { - await plugin.fileManager.closeAllFiles() dispatch(createWorkspaceSuccess(workspaceName)) await loadWorkspacePreset('default-template') // await switchToWorkspace(workspaceName)