Merge pull request #2057 from ethereum/FixTestTabUx

UX test module: Disable actions if necessary
pull/1/head
yann300 6 years ago committed by GitHub
commit 86569f7848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/app.js
  2. 73
      src/app/tabs/test-tab.js
  3. 2
      src/app/tabs/testTab/testTab.js

@ -412,7 +412,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
let test = new TestTab( let test = new TestTab(
registry.get('filemanager').api, registry.get('filemanager').api,
registry.get('filepanel').api, registry.get('filepanel').api,
compileTab compileTab,
appStore
) )
let sourceHighlighters = registry.get('editor').api.sourceHighlighters let sourceHighlighters = registry.get('editor').api.sourceHighlighters

@ -19,16 +19,22 @@ const profile = {
} }
module.exports = class TestTab extends BaseApi { module.exports = class TestTab extends BaseApi {
constructor (fileManager, filePanel, compileTab) { constructor (fileManager, filePanel, compileTab, appStore) {
super(profile) super(profile)
this.compileTab = compileTab this.compileTab = compileTab
this._view = { el: null } this._view = { el: null }
this.compileTab = compileTab this.compileTab = compileTab
this.fileManager = fileManager this.fileManager = fileManager
this.filePanel = filePanel this.filePanel = filePanel
this.appStore = appStore
this.testTabLogic = new TestTabLogic(fileManager) this.testTabLogic = new TestTabLogic(fileManager)
this.data = {} this.data = {}
this.testList = yo`<div class=${css.testList}></div>` 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 () { activate () {
@ -47,15 +53,20 @@ module.exports = class TestTab extends BaseApi {
this.data.selectedTests.push(file) this.data.selectedTests.push(file)
}) })
this.fileManager.events.on('noFileSelected', () => {
this.updateGenerateFileAction()
this.updateRunAction()
this.updateTestFileList()
})
this.fileManager.events.on('currentFileChanged', (file, provider) => { this.fileManager.events.on('currentFileChanged', (file, provider) => {
this.updateGenerateFileAction(file)
this.updateRunAction(file)
this.testTabLogic.getTests((error, tests) => { this.testTabLogic.getTests((error, tests) => {
if (error) return tooltip(error) if (error) return tooltip(error)
this.data.allTests = tests this.data.allTests = tests
this.data.selectedTests = [...this.data.allTests] this.data.selectedTests = [...this.data.allTests]
this.updateTestFileList(tests)
const testsMessage = (tests.length ? this.listTests() : 'No test file available')
yo.update(this.testList, yo`<div class=${css.testList}>${testsMessage}</div>`)
if (!this.testsOutput || !this.testsSummary) return if (!this.testsOutput || !this.testsSummary) return
}) })
}) })
@ -148,13 +159,55 @@ module.exports = class TestTab extends BaseApi {
} }
runTests () { runTests () {
this.loading.hidden = false
this.testsOutput.innerHTML = '' this.testsOutput.innerHTML = ''
this.testsSummary.innerHTML = '' this.testsSummary.innerHTML = ''
var tests = this.data.selectedTests var tests = this.data.selectedTests
if (!tests) return
this.loading.hidden = tests.length === 0
async.eachOfSeries(tests, (value, key, callback) => { this.runTest(value, callback) }) async.eachOfSeries(tests, (value, key, callback) => { this.runTest(value, callback) })
} }
updateGenerateFileAction (currentFile) {
let el = yo`<button class="${css.generateTestFile} btn btn-primary" onclick="${this.testTabLogic.generateTestFile.bind(this.testTabLogic)}">Generate test file</button>`
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`<button class="${css.runButton} btn btn-primary" onclick="${this.runTests.bind(this)}">Run Tests</button>`
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`<div class=${css.testList}>${testsMessage}</div>`
if (!this.testFilesListElement) {
this.testFilesListElement = el
} else {
yo.update(this.testFilesListElement, el)
}
return this.testFilesListElement
}
render () { render () {
this.testsOutput = yo`<div class="${css.container} m-3 border border-primary border-right-0 border-left-0 border-bottom-0" hidden='true' id="tests"></div>` this.testsOutput = yo`<div class="${css.container} m-3 border border-primary border-right-0 border-left-0 border-bottom-0" hidden='true' id="tests"></div>`
this.testsSummary = yo`<div class="${css.container} border border-primary border-right-0 border-left-0 border-bottom-0" hidden='true' id="tests"></div>` this.testsSummary = yo`<div class="${css.container} border border-primary border-right-0 border-left-0 border-bottom-0" hidden='true' id="tests"></div>`
@ -172,11 +225,11 @@ module.exports = class TestTab extends BaseApi {
For more details, see For more details, see
How to test smart contracts guide in our documentation. How to test smart contracts guide in our documentation.
<br/> <br/>
<div class="${css.generateTestFile} btn btn-secondary" onclick="${this.testTabLogic.generateTestFile.bind(this.testTabLogic)}">Generate test file</div> ${this.updateGenerateFileAction()}
</div> </div>
<div class="${css.tests}"> <div class="${css.tests}">
<div class="${css.buttons}"> <div class="${css.buttons}">
<div class="${css.runButton} btn btn-primary" onclick="${this.runTests.bind(this)}">Run Tests</div> ${this.updateRunAction()}
<label class="${css.label} mx-4 m-2" for="checkAllTests"> <label class="${css.label} mx-4 m-2" for="checkAllTests">
<input id="checkAllTests" <input id="checkAllTests"
type="checkbox" type="checkbox"
@ -186,7 +239,7 @@ module.exports = class TestTab extends BaseApi {
Check/Uncheck all Check/Uncheck all
</label> </label>
</div> </div>
${this.testList} ${this.updateTestFileList()}
<hr> <hr>
<div class="${css.buttons}" ><h6>Results:${this.loading}</h6></div> <div class="${css.buttons}" ><h6>Results:${this.loading}</h6></div>
${this.testsOutput} ${this.testsOutput}

@ -33,7 +33,7 @@ class TestTabLogic {
for (var file in files) { for (var file in files) {
if (/.(_test.sol)$/.exec(file)) tests.push(provider.type + '/' + file) if (/.(_test.sol)$/.exec(file)) tests.push(provider.type + '/' + file)
} }
cb(null, tests) cb(null, tests, path)
} }
generateTestContractSample () { generateTestContractSample () {

Loading…
Cancel
Save