Commit dd427660 authored by LianaHus's avatar LianaHus Committed by Aniket

implemented Stop

parent 3e614224
...@@ -29,6 +29,7 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -29,6 +29,7 @@ module.exports = class TestTab extends ViewPlugin {
this.data = {} this.data = {}
this.appManager = appManager this.appManager = appManager
this.renderer = renderer this.renderer = renderer
this.hasBeenStoped = false
this.baseurl = 'https://solc-bin.ethereum.org/bin' this.baseurl = 'https://solc-bin.ethereum.org/bin'
appManager.event.on('activate', (name) => { appManager.event.on('activate', (name) => {
if (name === 'solidity') this.updateRunAction(fileManager.currentFile()) if (name === 'solidity') this.updateRunAction(fileManager.currentFile())
...@@ -158,6 +159,9 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -158,6 +159,9 @@ module.exports = class TestTab extends ViewPlugin {
this.testsSummary.appendChild(yo`<div class="${css.testFailureSummary} text-danger" >${error.message}</div>`) this.testsSummary.appendChild(yo`<div class="${css.testFailureSummary} text-danger" >${error.message}</div>`)
this.testsSummary.appendChild(yo`<br>`) this.testsSummary.appendChild(yo`<br>`)
}) })
if (this.hasBeenStoped) {
this.testsSummary.appendChild(yo`<label class="text-warning h5">The test execution has been stopped</label>`)
}
} }
async testFromPath (path) { async testFromPath (path) {
...@@ -190,6 +194,10 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -190,6 +194,10 @@ module.exports = class TestTab extends ViewPlugin {
} }
runTest (testFilePath, callback) { runTest (testFilePath, callback) {
if (this.hasBeenStoped) {
this.updateFinalResult()
return
}
this.loading.hidden = false this.loading.hidden = false
this.fileManager.getFile(testFilePath).then((content) => { this.fileManager.getFile(testFilePath).then((content) => {
const runningTest = {} const runningTest = {}
...@@ -224,12 +232,16 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -224,12 +232,16 @@ module.exports = class TestTab extends ViewPlugin {
this.call('editor', 'clearAnnotations') this.call('editor', 'clearAnnotations')
this.testsOutput.innerHTML = '' this.testsOutput.innerHTML = ''
this.testsSummary.innerHTML = '' this.testsSummary.innerHTML = ''
var tests = this.data.selectedTests const tests = this.data.selectedTests
if (!tests) return if (!tests) return
this.loading.hidden = tests.length === 0 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) })
} }
stopTests () {
this.hasBeenStoped = true
}
updateGenerateFileAction (currentFile) { updateGenerateFileAction (currentFile) {
let el = yo`<button class="btn border w-50" data-id="testTabGenerateTestFile" title="Generate sample test file." onclick="${this.testTabLogic.generateTestFile.bind(this.testTabLogic)}">Generate</button>` let el = yo`<button class="btn border w-50" data-id="testTabGenerateTestFile" title="Generate sample test file." onclick="${this.testTabLogic.generateTestFile.bind(this.testTabLogic)}">Generate</button>`
if (!currentFile) { if (!currentFile) {
...@@ -246,17 +258,18 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -246,17 +258,18 @@ module.exports = class TestTab extends ViewPlugin {
updateRunAction (currentFile) { updateRunAction (currentFile) {
let el = yo` let el = yo`
<div id="runTestsTabRunAction" data-id="testTabRunTestsTabRunAction" class="w-50 btn btn-primary" onclick="${this.runTests.bind(this)}"> <button id="runTestsTabRunAction" data-id="testTabRunTestsTabRunAction" class="w-50 btn btn-primary" onclick="${() => { this.hasBeenStoped = false; this.runTests() }}">
<span class="fas fa-play ml-2"></span> <span class="fas fa-play ml-2"></span>
<label class="btn p-1 ml-2 m-0">Run</label> <label class="btn p-1 ml-2 m-0">Run</label>
</div> </button>
` `
const isSolidityActive = this.appManager.actives.includes('solidity') const isSolidityActive = this.appManager.actives.includes('solidity')
if (!currentFile || !isSolidityActive) { if (!currentFile || !isSolidityActive) {
el.setAttribute('disabled', 'disabled') el.setAttribute('disabled', 'disabled')
if (!currentFile) { if (!currentFile) {
el.setAttribute('title', 'No file selected') el.setAttribute('title', 'No file selected')
} else if (!isSolidityActive) el.setAttribute('title', 'The solidity module should be activated') } else if (!isSolidityActive) el.setAttribute('title', 'The "Solidity Plugin" should be activated')
// @todo(#2747) we can activate the plugin here
} }
if (!this.runActionElement) { if (!this.runActionElement) {
...@@ -268,12 +281,17 @@ module.exports = class TestTab extends ViewPlugin { ...@@ -268,12 +281,17 @@ module.exports = class TestTab extends ViewPlugin {
} }
updateStopAction () { updateStopAction () {
return yo` const runBtn = document.getElementById('runTestsTabRunAction')
<div id="runTestsTabStopAction" class="w-50 pl-2 ml-2 btn btn-secondary" title="Stop running tests" onclick="${this.runTests.bind(this)}"> const stopBtn = yo`
<span class="fas fa-stop ml-2"></span> <button id="runTestsTabStopAction" class="w-50 pl-2 ml-2 btn btn-secondary" title="Stop running tests" onclick=${() => this.stopTests()}">
<label class="btn p-1 ml-2 m-0">Stop</label> <span class="fas fa-stop ml-2"></span>
</div> <label class="btn p-1 ml-2 m-0">Stop</label>
</button>
` `
if (runBtn && runBtn.getAttribute('disabled')) {
runBtn.setAttribute('disabled', 'disabled')
}
return stopBtn
} }
updateTestFileList (tests) { updateTestFileList (tests) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment