From fc40e5f90997c57dae91d4068e1bc2bd01688d5b Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 15 Feb 2019 17:40:21 -0500 Subject: [PATCH] move test tab logic to its own file --- src/app/tabs/test-tab.js | 66 +------------------------------- src/app/tabs/testTab/testTab.js | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 65 deletions(-) create mode 100644 src/app/tabs/testTab/testTab.js diff --git a/src/app/tabs/test-tab.js b/src/app/tabs/test-tab.js index 8c5f7e23f5..bd626ad892 100644 --- a/src/app/tabs/test-tab.js +++ b/src/app/tabs/test-tab.js @@ -1,75 +1,11 @@ var yo = require('yo-yo') var async = require('async') -var helper = require('../../lib/helper.js') var tooltip = require('../ui/tooltip') -var modalDialogCustom = require('../ui/modal-dialog-custom') var css = require('./styles/test-tab-styles') 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; - } - }` - } - -} +const TestTabLogic = require('./testTab/testTab') module.exports = class TestTab extends ApiFactory { constructor (fileManager, filePanel, compileTab) { diff --git a/src/app/tabs/testTab/testTab.js b/src/app/tabs/testTab/testTab.js new file mode 100644 index 0000000000..e1d41a544e --- /dev/null +++ b/src/app/tabs/testTab/testTab.js @@ -0,0 +1,67 @@ +var helper = require('../../../lib/helper.js') +var modalDialogCustom = require('../../ui/modal-dialog-custom') + +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 = TestTabLogic