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

@ -15,7 +15,7 @@ module.exports = {
.openFile('contracts/2_Owner.sol')
.openFile('contracts/1_Storage.sol')
.openFile('contracts/3_Ballot.sol')
.addFile('scripts/decorators.ts', { content: testScript })
.addFile('scripts/decorators.ts', { content: testScriptSet })
.pause(2000)
.executeScript('remix.exeCurrent()')
.pause(4000)
@ -26,16 +26,35 @@ module.exports = {
.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)
.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)
await remix.call('fileDecorator' as any, 'setFileDecorators', decorator)
})()`
const testScriptClearBallot = `
(async () => {
await remix.call('fileDecorator' as any, 'clearFileDecorators', 'contracts/3_Ballot.sol')
})()`
const testScriptClear = `
(async () => {
await remix.call('fileDecorator' as any, 'clearAllFileDecorators')
remix.call('fileDecorator' as any, 'clearFileDecorators', 'dgit')
})()`

@ -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,13 +47,13 @@ export class FileDecorator extends Plugin {
}
}
async clearFileDecorators(owner? : string) {
if(!owner) {
this._fileStates = []
this.emit('fileDecoratorsChanged', [])
} else {
async clearFileDecorators(path?: string) {
const { from } = this.currentRequest
if (!from) return
const filteredState = this._fileStates.filter((state) => {
return state.owner != owner
if(state.owner != from) return true
if(path && state.path != path) return true
})
const newState = [...filteredState].sort(sortByPath)
@ -59,7 +61,12 @@ export class FileDecorator extends Plugin {
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,
bubble: boolean,
text?: string,
owner: string,
owner?: string,
workspace?: any
tooltip?: string
comment?: string[] | string

Loading…
Cancel
Save