From 882a79ef8ceaaedaaeb8c26617b3cf7ee026ea95 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 3 Jun 2019 10:35:03 +0200 Subject: [PATCH] fix test tab ux --- src/app.js | 3 +- src/app/tabs/test-tab.js | 73 ++++++++++++++++++++++++++++----- src/app/tabs/testTab/testTab.js | 2 +- 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/app.js b/src/app.js index a21b9b047f..013530ea6e 100644 --- a/src/app.js +++ b/src/app.js @@ -412,7 +412,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org let test = new TestTab( registry.get('filemanager').api, registry.get('filepanel').api, - compileTab + compileTab, + appStore ) let sourceHighlighters = registry.get('editor').api.sourceHighlighters diff --git a/src/app/tabs/test-tab.js b/src/app/tabs/test-tab.js index a1e7b160d7..51e2c96929 100644 --- a/src/app/tabs/test-tab.js +++ b/src/app/tabs/test-tab.js @@ -19,16 +19,22 @@ const profile = { } module.exports = class TestTab extends BaseApi { - constructor (fileManager, filePanel, compileTab) { + constructor (fileManager, filePanel, compileTab, appStore) { super(profile) this.compileTab = compileTab this._view = { el: null } this.compileTab = compileTab this.fileManager = fileManager this.filePanel = filePanel + this.appStore = appStore this.testTabLogic = new TestTabLogic(fileManager) this.data = {} - this.testList = yo`
` + this.appStore.event.on('activate', (name) => { + if (name === 'solidity') this.updateRunAction(fileManager.currentFile()) + }) + this.appStore.event.on('deactivate', (name) => { + if (name === 'solidity') this.updateRunAction(fileManager.currentFile()) + }) } activate () { @@ -47,15 +53,20 @@ module.exports = class TestTab extends BaseApi { this.data.selectedTests.push(file) }) + this.fileManager.events.on('noFileSelected', () => { + this.updateGenerateFileAction() + this.updateRunAction() + this.updateTestFileList() + }) + this.fileManager.events.on('currentFileChanged', (file, provider) => { + this.updateGenerateFileAction(file) + this.updateRunAction(file) this.testTabLogic.getTests((error, tests) => { if (error) return tooltip(error) this.data.allTests = tests this.data.selectedTests = [...this.data.allTests] - - const testsMessage = (tests.length ? this.listTests() : 'No test file available') - yo.update(this.testList, yo`
${testsMessage}
`) - + this.updateTestFileList(tests) if (!this.testsOutput || !this.testsSummary) return }) }) @@ -148,13 +159,55 @@ module.exports = class TestTab extends BaseApi { } runTests () { - this.loading.hidden = false this.testsOutput.innerHTML = '' this.testsSummary.innerHTML = '' var tests = this.data.selectedTests + if (!tests) return + this.loading.hidden = tests.length === 0 async.eachOfSeries(tests, (value, key, callback) => { this.runTest(value, callback) }) } + updateGenerateFileAction (currentFile) { + let el = yo`` + if (!currentFile) { + el.setAttribute('disabled', 'disabled') + el.setAttribute('title', 'No file selected') + } + if (!this.generateFileActionElement) { + this.generateFileActionElement = el + } else { + yo.update(this.generateFileActionElement, el) + } + return this.generateFileActionElement + } + + updateRunAction (currentFile) { + let el = yo`` + const isSolidityActive = this.appStore.isActive('solidity') + if (!currentFile || !isSolidityActive) { + el.setAttribute('disabled', 'disabled') + if (!currentFile) el.setAttribute('title', 'No file selected') + if (!isSolidityActive) el.setAttribute('title', 'The solidity module should be activated') + } + + if (!this.runActionElement) { + this.runActionElement = el + } else { + yo.update(this.runActionElement, el) + } + return this.runActionElement + } + + updateTestFileList (tests) { + const testsMessage = (tests && tests.length ? this.listTests() : 'No test file available') + let el = yo`
${testsMessage}
` + if (!this.testFilesListElement) { + this.testFilesListElement = el + } else { + yo.update(this.testFilesListElement, el) + } + return this.testFilesListElement + } render () { this.testsOutput = yo`` this.testsSummary = yo`` @@ -172,11 +225,11 @@ module.exports = class TestTab extends BaseApi { For more details, see How to test smart contracts guide in our documentation.
-
Generate test file
+ ${this.updateGenerateFileAction()}
-
Run Tests
+ ${this.updateRunAction()}
- ${this.testList} + ${this.updateTestFileList()}
Results:${this.loading}
${this.testsOutput} diff --git a/src/app/tabs/testTab/testTab.js b/src/app/tabs/testTab/testTab.js index 620b40aa57..f630632634 100644 --- a/src/app/tabs/testTab/testTab.js +++ b/src/app/tabs/testTab/testTab.js @@ -33,7 +33,7 @@ class TestTabLogic { for (var file in files) { if (/.(_test.sol)$/.exec(file)) tests.push(provider.type + '/' + file) } - cb(null, tests) + cb(null, tests, path) } generateTestContractSample () {