create initial class to hold test tab logic

pull/3094/head
Iuri Matias 6 years ago committed by yann300
parent 1bba536d25
commit f94f767ca6
  1. 119
      src/app/tabs/test-tab.js

@ -8,6 +8,69 @@ var remixTests = require('remix-tests')
import { ApiFactory } from 'remix-plugin'
class TestTabLogic {
constructor (fileManager) {
this.fileManager = fileManager
}
generateTestFile () {
var path = this.fileManager.currentPath()
var fileProvider = this.fileManager.fileProviderOf(path)
if (!fileProvider) return
helper.createNonClashingNameWithPrefix(path + '/test.sol', fileProvider, '_test', (error, newFile) => {
if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error)
if (!fileProvider.set(newFile, this.generateTestContractSample())) return modalDialogCustom.alert('Failed to create test file ' + newFile)
this.fileManager.switchFile(newFile)
})
}
generateTestContractSample () {
return `pragma solidity >=0.4.0 <0.6.0;
import "remix_tests.sol"; // this import is automatically injected by Remix.
// file name has to end with '_test.sol'
contract test_1 {
function beforeAll() public {
// here should instantiate tested contract
Assert.equal(uint(4), uint(3), "error in before all function");
}
function check1() public {
// use 'Assert' to test the contract
Assert.equal(uint(2), uint(1), "error message");
Assert.equal(uint(2), uint(2), "error message");
}
function check2() public view returns (bool) {
// use the return value (true or false) to test the contract
return true;
}
}
contract test_2 {
function beforeAll() public {
// here should instantiate tested contract
Assert.equal(uint(4), uint(3), "error in before all function");
}
function check1() public {
// use 'Assert' to test the contract
Assert.equal(uint(2), uint(1), "error message");
Assert.equal(uint(2), uint(2), "error message");
}
function check2() public view returns (bool) {
// use the return value (true or false) to test the contract
return true;
}
}`
}
}
module.exports = class TestTab extends ApiFactory {
constructor (fileManager, filePanel, compileTab) {
super()
@ -15,6 +78,7 @@ module.exports = class TestTab extends ApiFactory {
this._view = { el: null }
this.fileManager = fileManager
this.filePanel = filePanel
this.testTabLogic = new TestTabLogic(fileManager)
this.data = {}
this.testList = yo`<div class=${css.testList}></div>`
this.listenToEvents()
@ -165,17 +229,6 @@ module.exports = class TestTab extends ApiFactory {
async.eachOfSeries(tests, (value, key, callback) => { this.runTest(value, callback) })
}
generateTestFile () {
var path = this.fileManager.currentPath()
var fileProvider = this.fileManager.fileProviderOf(path)
if (!fileProvider) return
helper.createNonClashingNameWithPrefix(path + '/test.sol', fileProvider, '_test', (error, newFile) => {
if (error) return modalDialogCustom.alert('Failed to create file. ' + newFile + ' ' + error)
if (!fileProvider.set(newFile, testContractSample)) return modalDialogCustom.alert('Failed to create test file ' + newFile)
this.fileManager.switchFile(newFile)
})
}
render () {
this.testsOutput = yo`<div class=${css.container} hidden='true' id="tests"></div>`
this.testsSummary = yo`<div class=${css.container} hidden='true' id="tests"></div>`
@ -191,7 +244,7 @@ module.exports = class TestTab extends ApiFactory {
<br/>
For more details, see
How to test smart contracts guide in our documentation.
<div class="${css.generateTestFile}" onclick="${this.generateTestFile(this)}">Generate test file</div>
<div class="${css.generateTestFile}" onclick="${this.testTabLogic.generateTestFile(this)}">Generate test file</div>
</div>
<div class="${css.tests}">
${this.testList}
@ -216,45 +269,3 @@ module.exports = class TestTab extends ApiFactory {
}
}
var testContractSample = `pragma solidity >=0.4.0 <0.6.0;
import "remix_tests.sol"; // this import is automatically injected by Remix.
// file name has to end with '_test.sol'
contract test_1 {
function beforeAll() public {
// here should instantiate tested contract
Assert.equal(uint(4), uint(3), "error in before all function");
}
function check1() public {
// use 'Assert' to test the contract
Assert.equal(uint(2), uint(1), "error message");
Assert.equal(uint(2), uint(2), "error message");
}
function check2() public view returns (bool) {
// use the return value (true or false) to test the contract
return true;
}
}
contract test_2 {
function beforeAll() public {
// here should instantiate tested contract
Assert.equal(uint(4), uint(3), "error in before all function");
}
function check1() public {
// use 'Assert' to test the contract
Assert.equal(uint(2), uint(1), "error message");
Assert.equal(uint(2), uint(2), "error message");
}
function check2() public view returns (bool) {
// use the return value (true or false) to test the contract
return true;
}
}`

Loading…
Cancel
Save