pull/5370/head
filip mertens 2 years ago
parent cb124717a7
commit 01290d390b
  1. 94
      apps/remix-ide-e2e/src/tests/file_decorator.test.ts
  2. 37
      apps/remix-ide/src/app/plugins/file-decorator.ts
  3. 2
      libs/remix-ui/file-decorators/src/lib/types/index.ts

@ -11,31 +11,50 @@ module.exports = {
'Test decorators with script': function (browser: NightwatchBrowser) { 'Test decorators with script': function (browser: NightwatchBrowser) {
browser browser
.openFile('contracts') .openFile('contracts')
.openFile('contracts/2_Owner.sol') .openFile('contracts/2_Owner.sol')
.openFile('contracts/1_Storage.sol') .openFile('contracts/1_Storage.sol')
.openFile('contracts/3_Ballot.sol') .openFile('contracts/3_Ballot.sol')
.addFile('scripts/decorators.ts', { content: testScript }) .addFile('scripts/decorators.ts', { content: testScriptSet })
.pause(2000) .pause(2000)
.executeScript('remix.exeCurrent()') .executeScript('remix.exeCurrent()')
.pause(4000) .pause(4000)
.useXpath() .useXpath()
.waitForElementContainsText('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-error-contracts/2_Owner.sol"]', '2') .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('//*[@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('//*[@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('//*[@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('//*[@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('//*[@class="mainview"]//*[@data-id="file-decoration-warning-contracts/1_Storage.sol"]', '2')
.useCss() .waitForElementContainsText('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-custom-contracts/3_Ballot.sol"]', 'customtext')
.waitForElementNotPresent('[data-id="file-decoration-custom-contracts/3_Ballot.sol"]', 10000) .waitForElementContainsText('//*[@class="mainview"]//*[@data-id="file-decoration-custom-contracts/3_Ballot.sol"]', 'customtext')
.useXpath() .moveToElement('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-error-contracts/2_Owner.sol"]', 0, 0)
.moveToElement('//*[@id="fileExplorerView"]//*[@data-id="file-decoration-error-contracts/2_Owner.sol"]', 0,0) .waitForElementVisible('//*[@id="error-tooltip-contracts/2_Owner.sol"]')
.waitForElementVisible('//*[@id="error-tooltip-contracts/2_Owner.sol"]') .waitForElementContainsText('//*[@id="error-tooltip-contracts/2_Owner.sol"]', 'error on owner')
.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 () => { (async () => {
remix.call('fileDecorator' as any, 'clearFileDecorators') remix.call('fileDecorator' as any, 'clearFileDecorators')
let decorator: any = { let decorator: any = {
@ -46,7 +65,6 @@ const testScript = `
fileStateIconClass: '', fileStateIconClass: '',
fileStateIcon: '', fileStateIcon: '',
text: '2', text: '2',
owner: 'code-parser',
bubble: true, bubble: true,
comment: 'error on owner', comment: 'error on owner',
} }
@ -58,11 +76,10 @@ const testScript = `
fileStateIconClass: 'text-success', fileStateIconClass: 'text-success',
fileStateIcon: 'U', fileStateIcon: 'U',
text: '', text: '',
owner: 'code-parser',
bubble: true, bubble: true,
comment: 'modified', comment: 'modified',
} }
remix.call('fileDecorator' as any, 'setFileDecorators', [decorator, decorator2]) await remix.call('fileDecorator' as any, 'setFileDecorators', [decorator, decorator2])
decorator = { decorator = {
path: 'contracts/1_Storage.sol', path: 'contracts/1_Storage.sol',
@ -72,11 +89,10 @@ const testScript = `
fileStateIconClass: '', fileStateIconClass: '',
fileStateIcon: '', fileStateIcon: '',
text: '2', text: '2',
owner: 'code-parser',
bubble: true, bubble: true,
comment: 'warning on storage', comment: 'warning on storage',
} }
remix.call('fileDecorator' as any, 'setFileDecorators', decorator) await remix.call('fileDecorator' as any, 'setFileDecorators', decorator)
decorator = { decorator = {
path: 'contracts/3_Ballot.sol', path: 'contracts/3_Ballot.sol',
@ -85,13 +101,25 @@ const testScript = `
fileStateLabelClass: '', fileStateLabelClass: '',
fileStateIconClass: '', fileStateIconClass: '',
fileStateIcon: 'customtext', fileStateIcon: 'customtext',
text: 'w', text: 'with text',
owner: 'dgit',
bubble: true, bubble: true,
comment: '', comment: 'custom comment',
} }
remix.call('fileDecorator' as any, 'setFileDecorators', decorator) await remix.call('fileDecorator' as any, 'setFileDecorators', decorator)
remix.call('fileDecorator' as any, 'clearFileDecorators', 'dgit')
})()` })()`
const testScriptClearBallot = `
(async () => {
await remix.call('fileDecorator' as any, 'clearFileDecorators', 'contracts/3_Ballot.sol')
})()`
const testScriptClear = `
(async () => {
await remix.call('fileDecorator' as any, 'clearAllFileDecorators')
})()`

@ -8,7 +8,7 @@ import { fileDecoration } from '@remix-ui/file-decorators'
const profile = { const profile = {
name: 'fileDecorator', name: 'fileDecorator',
desciption: 'Keeps decorators of the files', desciption: 'Keeps decorators of the files',
methods: ['setFileDecorators', 'clearFileDecorators'], methods: ['setFileDecorators', 'clearFileDecorators', 'clearAllFileDecorators'],
events: ['fileDecoratorsChanged'], events: ['fileDecoratorsChanged'],
version: '0.0.1' version: '0.0.1'
} }
@ -25,15 +25,17 @@ export class FileDecorator extends Plugin {
* @param fileStates Array of file states * @param fileStates Array of file states
*/ */
async setFileDecorators(fileStates: fileDecoration[] | fileDecoration) { async setFileDecorators(fileStates: fileDecoration[] | fileDecoration) {
const { from } = this.currentRequest
const workspace = await this.call('filePanel', 'getCurrentWorkspace') const workspace = await this.call('filePanel', 'getCurrentWorkspace')
const fileStatesPayload = Array.isArray(fileStates) ? fileStates : [fileStates] const fileStatesPayload = Array.isArray(fileStates) ? fileStates : [fileStates]
// clear all file states in the previous state of this owner on the files called // clear all file states in the previous state of this owner on the files called
fileStatesPayload.forEach((state) => { fileStatesPayload.forEach((state) => {
state.workspace = workspace state.workspace = workspace
state.owner = from
}) })
const filteredState = this._fileStates.filter((state) => { const filteredState = this._fileStates.filter((state) => {
const index = fileStatesPayload.findIndex((payloadFileState: fileDecoration) => { 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 return index == -1
}) })
@ -45,21 +47,26 @@ export class FileDecorator extends Plugin {
} }
} }
async clearFileDecorators(owner? : string) { async clearFileDecorators(path?: string) {
if(!owner) { const { from } = this.currentRequest
this._fileStates = [] if (!from) return
this.emit('fileDecoratorsChanged', [])
} else {
const filteredState = this._fileStates.filter((state) => {
return state.owner != owner
})
const newState = [...filteredState].sort(sortByPath)
if (!deepequal(newState, this._fileStates)) { const filteredState = this._fileStates.filter((state) => {
this._fileStates = newState if(state.owner != from) return true
this.emit('fileDecoratorsChanged', this._fileStates) 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', [])
} }
} }

@ -14,7 +14,7 @@ export enum fileDecorationType {
fileStateIcon: string | HTMLDivElement | JSX.Element, fileStateIcon: string | HTMLDivElement | JSX.Element,
bubble: boolean, bubble: boolean,
text?: string, text?: string,
owner: string, owner?: string,
workspace?: any workspace?: any
tooltip?: string tooltip?: string
comment?: string[] | string comment?: string[] | string

Loading…
Cancel
Save