From 01290d390b494d150308b36386c95b021bbbe40f Mon Sep 17 00:00:00 2001 From: filip mertens Date: Fri, 22 Jul 2022 11:53:33 +0200 Subject: [PATCH] updates --- .../src/tests/file_decorator.test.ts | 96 ++++++++++++------- .../src/app/plugins/file-decorator.ts | 39 ++++---- .../file-decorators/src/lib/types/index.ts | 2 +- 3 files changed, 86 insertions(+), 51 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/file_decorator.test.ts b/apps/remix-ide-e2e/src/tests/file_decorator.test.ts index 2aa226397c..9b47bbc61f 100644 --- a/apps/remix-ide-e2e/src/tests/file_decorator.test.ts +++ b/apps/remix-ide-e2e/src/tests/file_decorator.test.ts @@ -11,31 +11,50 @@ module.exports = { 'Test decorators with script': function (browser: NightwatchBrowser) { browser - .openFile('contracts') - .openFile('contracts/2_Owner.sol') - .openFile('contracts/1_Storage.sol') - .openFile('contracts/3_Ballot.sol') - .addFile('scripts/decorators.ts', { content: testScript }) - .pause(2000) - .executeScript('remix.exeCurrent()') - .pause(4000) - .useXpath() - .waitForElementContainsText('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-error-contracts/2_Owner.sol"]', '2') - .waitForElementContainsText('//*[@class="mainview"]//*[@data-id="file-decoration-error-contracts/2_Owner.sol"]', '2') - .waitForElementContainsText('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-custom-contracts/2_Owner.sol"]', 'U') - .waitForElementContainsText('//*[@class="mainview"]//*[@data-id="file-decoration-custom-contracts/2_Owner.sol"]', 'U') - .waitForElementContainsText('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-warning-contracts/1_Storage.sol"]', '2') - .waitForElementContainsText('//*[@class="mainview"]//*[@data-id="file-decoration-warning-contracts/1_Storage.sol"]', '2') - .useCss() - .waitForElementNotPresent('[data-id="file-decoration-custom-contracts/3_Ballot.sol"]', 10000) - .useXpath() - .moveToElement('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-error-contracts/2_Owner.sol"]', 0,0) - .waitForElementVisible('//*[@id="error-tooltip-contracts/2_Owner.sol"]') - .waitForElementContainsText('//*[@id="error-tooltip-contracts/2_Owner.sol"]', 'error on owner') + .openFile('contracts') + .openFile('contracts/2_Owner.sol') + .openFile('contracts/1_Storage.sol') + .openFile('contracts/3_Ballot.sol') + .addFile('scripts/decorators.ts', { content: testScriptSet }) + .pause(2000) + .executeScript('remix.exeCurrent()') + .pause(4000) + .useXpath() + .waitForElementContainsText('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-error-contracts/2_Owner.sol"]', '2') + .waitForElementContainsText('//*[@class="mainview"]//*[@data-id="file-decoration-error-contracts/2_Owner.sol"]', '2') + .waitForElementContainsText('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-custom-contracts/2_Owner.sol"]', 'U') + .waitForElementContainsText('//*[@class="mainview"]//*[@data-id="file-decoration-custom-contracts/2_Owner.sol"]', 'U') + .waitForElementContainsText('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-warning-contracts/1_Storage.sol"]', '2') + .waitForElementContainsText('//*[@class="mainview"]//*[@data-id="file-decoration-warning-contracts/1_Storage.sol"]', '2') + .waitForElementContainsText('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-custom-contracts/3_Ballot.sol"]', 'customtext') + .waitForElementContainsText('//*[@class="mainview"]//*[@data-id="file-decoration-custom-contracts/3_Ballot.sol"]', 'customtext') + .moveToElement('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-error-contracts/2_Owner.sol"]', 0, 0) + .waitForElementVisible('//*[@id="error-tooltip-contracts/2_Owner.sol"]') + .waitForElementContainsText('//*[@id="error-tooltip-contracts/2_Owner.sol"]', 'error on owner') + }, + + 'clear ballot decorator': function (browser: NightwatchBrowser) { + browser + .useCss() + .addFile('scripts/clearballot.ts', { content: testScriptClearBallot }) + .pause(2000) + .executeScript('remix.exeCurrent()') + .pause(4000) + .waitForElementNotPresent('[data-id="file-decoration-custom-contracts/3_Ballot.sol"]', 10000) + }, + 'clear all decorators': function (browser: NightwatchBrowser) { + browser + .addFile('scripts/clearall.ts', { content: testScriptClear }) + .pause(2000) + .executeScript('remix.exeCurrent()') + .pause(4000) + .waitForElementNotPresent('[data-id="file-decoration-error-contracts/2_Owner.sol"]', 10000) + .waitForElementNotPresent('[data-id="file-decoration-warning-contracts/1_Storage.sol"]', 10000) } + } -const testScript = ` +const testScriptSet = ` (async () => { remix.call('fileDecorator' as any, 'clearFileDecorators') let decorator: any = { @@ -46,7 +65,6 @@ const testScript = ` fileStateIconClass: '', fileStateIcon: '', text: '2', - owner: 'code-parser', bubble: true, comment: 'error on owner', } @@ -58,11 +76,10 @@ const testScript = ` fileStateIconClass: 'text-success', fileStateIcon: 'U', text: '', - owner: 'code-parser', bubble: true, comment: 'modified', } - remix.call('fileDecorator' as any, 'setFileDecorators', [decorator, decorator2]) + await remix.call('fileDecorator' as any, 'setFileDecorators', [decorator, decorator2]) decorator = { path: 'contracts/1_Storage.sol', @@ -72,11 +89,10 @@ const testScript = ` fileStateIconClass: '', fileStateIcon: '', text: '2', - owner: 'code-parser', bubble: true, comment: 'warning on storage', } - remix.call('fileDecorator' as any, 'setFileDecorators', decorator) + await remix.call('fileDecorator' as any, 'setFileDecorators', decorator) decorator = { path: 'contracts/3_Ballot.sol', @@ -85,13 +101,25 @@ const testScript = ` fileStateLabelClass: '', fileStateIconClass: '', fileStateIcon: 'customtext', - text: 'w', - owner: 'dgit', + text: 'with text', bubble: true, - comment: '', + comment: 'custom comment', } - remix.call('fileDecorator' as any, 'setFileDecorators', decorator) - - remix.call('fileDecorator' as any, 'clearFileDecorators', 'dgit') + await remix.call('fileDecorator' as any, 'setFileDecorators', decorator) - })()` \ No newline at end of file + })()` + + +const testScriptClearBallot = ` + (async () => { + + await remix.call('fileDecorator' as any, 'clearFileDecorators', 'contracts/3_Ballot.sol') + + })()` + +const testScriptClear = ` + (async () => { + await remix.call('fileDecorator' as any, 'clearAllFileDecorators') + + + })()` \ No newline at end of file diff --git a/apps/remix-ide/src/app/plugins/file-decorator.ts b/apps/remix-ide/src/app/plugins/file-decorator.ts index 5332db1508..5fc495bcf1 100644 --- a/apps/remix-ide/src/app/plugins/file-decorator.ts +++ b/apps/remix-ide/src/app/plugins/file-decorator.ts @@ -8,7 +8,7 @@ import { fileDecoration } from '@remix-ui/file-decorators' const profile = { name: 'fileDecorator', desciption: 'Keeps decorators of the files', - methods: ['setFileDecorators', 'clearFileDecorators'], + methods: ['setFileDecorators', 'clearFileDecorators', 'clearAllFileDecorators'], events: ['fileDecoratorsChanged'], version: '0.0.1' } @@ -25,15 +25,17 @@ export class FileDecorator extends Plugin { * @param fileStates Array of file states */ async setFileDecorators(fileStates: fileDecoration[] | fileDecoration) { + const { from } = this.currentRequest const workspace = await this.call('filePanel', 'getCurrentWorkspace') const fileStatesPayload = Array.isArray(fileStates) ? fileStates : [fileStates] // clear all file states in the previous state of this owner on the files called fileStatesPayload.forEach((state) => { state.workspace = workspace + state.owner = from }) const filteredState = this._fileStates.filter((state) => { const index = fileStatesPayload.findIndex((payloadFileState: fileDecoration) => { - return payloadFileState.owner == state.owner && payloadFileState.path == state.path + return from == state.owner && payloadFileState.path == state.path }) return index == -1 }) @@ -45,21 +47,26 @@ export class FileDecorator extends Plugin { } } - async clearFileDecorators(owner? : string) { - if(!owner) { - this._fileStates = [] - this.emit('fileDecoratorsChanged', []) - } else { - const filteredState = this._fileStates.filter((state) => { - return state.owner != owner - }) - const newState = [...filteredState].sort(sortByPath) - - if (!deepequal(newState, this._fileStates)) { - this._fileStates = newState - this.emit('fileDecoratorsChanged', this._fileStates) - } + async clearFileDecorators(path?: string) { + const { from } = this.currentRequest + if (!from) return + + const filteredState = this._fileStates.filter((state) => { + if(state.owner != from) return true + if(path && state.path != path) return true + }) + const newState = [...filteredState].sort(sortByPath) + + if (!deepequal(newState, this._fileStates)) { + this._fileStates = newState + this.emit('fileDecoratorsChanged', this._fileStates) } + + } + + async clearAllFileDecorators() { + this._fileStates = [] + this.emit('fileDecoratorsChanged', []) } } diff --git a/libs/remix-ui/file-decorators/src/lib/types/index.ts b/libs/remix-ui/file-decorators/src/lib/types/index.ts index ef6620434a..fa783ec6e5 100644 --- a/libs/remix-ui/file-decorators/src/lib/types/index.ts +++ b/libs/remix-ui/file-decorators/src/lib/types/index.ts @@ -14,7 +14,7 @@ export enum fileDecorationType { fileStateIcon: string | HTMLDivElement | JSX.Element, bubble: boolean, text?: string, - owner: string, + owner?: string, workspace?: any tooltip?: string comment?: string[] | string