diff --git a/apps/remix-ide-e2e/src/commands/currentWorkspaceIs.ts b/apps/remix-ide-e2e/src/commands/currentWorkspaceIs.ts new file mode 100644 index 0000000000..a090735f45 --- /dev/null +++ b/apps/remix-ide-e2e/src/commands/currentWorkspaceIs.ts @@ -0,0 +1,19 @@ +import { NightwatchBrowser } from 'nightwatch' +import EventEmitter from 'events' + +class CurrentWorkspaceIs extends EventEmitter { + command (this: NightwatchBrowser, name: string): NightwatchBrowser { + this.api + .execute(function () { + const el = document.querySelector('select[data-id="workspacesSelect"]') as HTMLSelectElement + return el.value + }, [], (result) => { + console.log(result) + this.api.assert.equal(result.value, name) + this.emit('complete') + }) + return this + } +} + +module.exports = CurrentWorkspaceIs diff --git a/apps/remix-ide-e2e/src/tests/url.spec.ts b/apps/remix-ide-e2e/src/tests/url.spec.ts index c1714b01bf..a2abb2cba2 100644 --- a/apps/remix-ide-e2e/src/tests/url.spec.ts +++ b/apps/remix-ide-e2e/src/tests/url.spec.ts @@ -10,7 +10,7 @@ const sources = [ module.exports = { before: function (browser: NightwatchBrowser, done: VoidFunction) { - init(browser, done, 'http://127.0.0.1:8080/#optimize=true&runs=300&evmVersion=istanbul&version=soljson-v0.7.4+commit.3f05b770.js&code=cHJhZ21hIHNvbGlkaXR5ID49MC42LjAgPDAuNy4wOwoKaW1wb3J0ICJodHRwczovL2dpdGh1Yi5jb20vT3BlblplcHBlbGluL29wZW56ZXBwZWxpbi1jb250cmFjdHMvYmxvYi9tYXN0ZXIvY29udHJhY3RzL2FjY2Vzcy9Pd25hYmxlLnNvbCI7Cgpjb250cmFjdCBHZXRQYWlkIGlzIE93bmFibGUgewogIGZ1bmN0aW9uIHdpdGhkcmF3KCkgZXh0ZXJuYWwgb25seU93bmVyIHsKICB9Cn0', true) + init(browser, done, 'http://127.0.0.1:8080/#optimize=true&runs=300&evmVersion=istanbul&version=soljson-v0.7.4+commit.3f05b770.js', true) }, '@sources': function () { @@ -19,6 +19,11 @@ module.exports = { 'Should load the code from URL params': function (browser: NightwatchBrowser) { browser + .pause(5000) + .url('http://127.0.0.1:8080/#optimize=true&runs=300&evmVersion=istanbul&version=soljson-v0.7.4+commit.3f05b770.js&code=cHJhZ21hIHNvbGlkaXR5ID49MC42LjAgPDAuNy4wOwoKaW1wb3J0ICJodHRwczovL2dpdGh1Yi5jb20vT3BlblplcHBlbGluL29wZW56ZXBwZWxpbi1jb250cmFjdHMvYmxvYi9tYXN0ZXIvY29udHJhY3RzL2FjY2Vzcy9Pd25hYmxlLnNvbCI7Cgpjb250cmFjdCBHZXRQYWlkIGlzIE93bmFibGUgewogIGZ1bmN0aW9uIHdpdGhkcmF3KCkgZXh0ZXJuYWwgb25seU93bmVyIHsKICB9Cn0') + .refresh() // we do one reload for making sure we already have the default workspace + .pause(5000) + .currentWorkspaceIs('code-sample') .getEditorValue((content) => { browser.assert.ok(content.indexOf( 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol') !== -1, @@ -28,6 +33,11 @@ module.exports = { 'Should load using URL compiler params': function (browser: NightwatchBrowser) { browser + .pause(5000) + .url('http://127.0.0.1:8080/#optimize=true&runs=300&evmVersion=istanbul&version=soljson-v0.7.4+commit.3f05b770.js') + .refresh() + .pause(5000) + .clickLaunchIcon('solidity') .assert.containsText('#versionSelector option[selected="selected"]', '0.7.4+commit.3f05b770') .assert.containsText('#evmVersionSelector option[selected="selected"]', 'istanbul') .verify.elementPresent('#optimize:checked') diff --git a/apps/remix-ide-e2e/src/types/index.d.ts b/apps/remix-ide-e2e/src/types/index.d.ts index 140b3ee089..d195c8cf2a 100644 --- a/apps/remix-ide-e2e/src/types/index.d.ts +++ b/apps/remix-ide-e2e/src/types/index.d.ts @@ -56,6 +56,7 @@ declare module "nightwatch" { checkAnnotations(type: string, line: number): NightwatchBrowser checkAnnotationsNotPresent(type: string): NightwatchBrowser getLastTransactionHash(callback: (hash: string) => void) + currentWorkspaceIs(name: string): NightwatchBrowser } export interface NightwatchBrowser { diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index cbb10f79eb..6a85a0febf 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -74,9 +74,10 @@ export const Workspace = (props: WorkspaceProps) => { let getWorkspaces = async () => { if (props.workspaces && Array.isArray(props.workspaces)) { if (props.workspaces.length > 0 && state.currentWorkspace === NO_WORKSPACE) { - await props.workspace.setWorkspace(props.workspaces[0]) + const currentWorkspace = props.workspace.getWorkspace() ? props.workspace.getWorkspace() : props.workspaces[0] + await props.workspace.setWorkspace(currentWorkspace) setState(prevState => { - return { ...prevState, workspaces: props.workspaces, currentWorkspace: props.workspaces[0] } + return { ...prevState, workspaces: props.workspaces, currentWorkspace } }) } else { setState(prevState => {