listing test files

pull/1862/head
Aniket-Engg 3 years ago committed by Aniket
parent 5f26f845de
commit f89c204761
  1. 9
      apps/remix-ide/src/app/tabs/test-tab.js
  2. 1
      libs/remix-ui/solidity-unit-testing/src/lib/logic/testTabLogic.ts
  3. 81
      libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx

@ -61,7 +61,6 @@ module.exports = class TestTab extends ViewPlugin {
} }
onActivationInternal () { onActivationInternal () {
console.log('onActivationInternal---start->')
this.testTabLogic = new TestTabLogic(this.fileManager) this.testTabLogic = new TestTabLogic(this.fileManager)
this.listenToEvents() this.listenToEvents()
this.call('filePanel', 'registerContextMenuItem', { this.call('filePanel', 'registerContextMenuItem', {
@ -73,7 +72,6 @@ module.exports = class TestTab extends ViewPlugin {
path: [], path: [],
pattern: [] pattern: []
}) })
console.log('onActivationInternal---end->')
} }
async setTestFolderPath (event) { async setTestFolderPath (event) {
@ -95,7 +93,6 @@ module.exports = class TestTab extends ViewPlugin {
} }
async onActivation () { async onActivation () {
console.log('onActivation--->')
const isSolidityActive = await this.call('manager', 'isActive', 'solidity') const isSolidityActive = await this.call('manager', 'isActive', 'solidity')
if (!isSolidityActive) { if (!isSolidityActive) {
await this.call('manager', 'activatePlugin', 'solidity') await this.call('manager', 'activatePlugin', 'solidity')
@ -106,7 +103,6 @@ module.exports = class TestTab extends ViewPlugin {
} }
onDeactivation () { onDeactivation () {
console.log('onDeactivation--->')
this.off('filePanel', 'newTestFileCreated') this.off('filePanel', 'newTestFileCreated')
this.off('filePanel', 'setWorkspace') this.off('filePanel', 'setWorkspace')
// 'currentFileChanged' event is added more than once // 'currentFileChanged' event is added more than once
@ -114,7 +110,6 @@ module.exports = class TestTab extends ViewPlugin {
} }
listenToEvents () { listenToEvents () {
console.log('listenToEvents--start-->')
this.on('filePanel', 'newTestFileCreated', async file => { this.on('filePanel', 'newTestFileCreated', async file => {
try { try {
await this.testTabLogic.getTests((error, tests) => { await this.testTabLogic.getTests((error, tests) => {
@ -152,7 +147,6 @@ module.exports = class TestTab extends ViewPlugin {
}) })
this.fileManager.events.on('currentFileChanged', (file, provider) => this.updateForNewCurrent(file)) this.fileManager.events.on('currentFileChanged', (file, provider) => this.updateForNewCurrent(file))
console.log('listenToEvents--end-->')
} }
async updateForNewCurrent (file) { async updateForNewCurrent (file) {
@ -709,18 +703,15 @@ module.exports = class TestTab extends ViewPlugin {
} }
render () { render () {
console.log('render--->')
this.onActivationInternal() this.onActivationInternal()
this.renderComponent() this.renderComponent()
return this.element return this.element
} }
renderComponent () { renderComponent () {
console.log('renderComponent-start-->')
ReactDOM.render( ReactDOM.render(
<SolidityUnitTesting testTab={this} helper={helper} /> <SolidityUnitTesting testTab={this} helper={helper} />
, this.element) , this.element)
console.log('renderComponent-end-->')
} }
render2 () { render2 () {

@ -39,7 +39,6 @@ export class TestTabLogic {
generateTestFile () { generateTestFile () {
console.log('Inside generateTestFile-1SUT-') console.log('Inside generateTestFile-1SUT-')
console.log('Inside generateTestFile---fileManager-SUT-->', this.fileManager)
let fileName = this.fileManager.currentFile() let fileName = this.fileManager.currentFile()
const hasCurrent = !!fileName && this.fileManager.currentFile().split('.').pop().toLowerCase() === 'sol' const hasCurrent = !!fileName && this.fileManager.currentFile().split('.').pop().toLowerCase() === 'sol'
if (!hasCurrent) fileName = this.currentPath + '/newFile.sol' if (!hasCurrent) fileName = this.currentPath + '/newFile.sol'

@ -21,7 +21,7 @@ export const SolidityUnitTesting = (props: any) => {
const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true)
const [testsMessage, setTestsMessage] = useState('No test file available') const [testsMessage, setTestsMessage] = useState('No test file available')
const [pathOptions, setPathOptions] = useState(['']) const [pathOptions, setPathOptions] = useState([''])
const [allTests, setAllTests] = useState([]) let [allTests, setAllTests] = useState([])
const [selectedTests, setSelectedTests] = useState([]) const [selectedTests, setSelectedTests] = useState([])
const [inputPathValue, setInputPathValue] = useState('tests') const [inputPathValue, setInputPathValue] = useState('tests')
@ -48,9 +48,10 @@ export const SolidityUnitTesting = (props: any) => {
// this.clearResults() // this.clearResults()
// if (!this.areTestsRunning) this.updateRunAction(file) // if (!this.areTestsRunning) this.updateRunAction(file)
try { try {
await testTabLogic.getTests((error: any, tests: any) => { testTabLogic.getTests((error: any, tests: any) => {
// if (error) return tooltip(error) // if (error) return tooltip(error)
setAllTests(tests) console.log('tests in updateForNewCurrent testTabLogic.getTests', tests)
allTests = tests
setSelectedTests(tests) setSelectedTests(tests)
updateTestFileList(tests) updateTestFileList(tests)
// if (!this.testsOutput) return // eslint-disable-line // if (!this.testsOutput) return // eslint-disable-line
@ -84,7 +85,6 @@ export const SolidityUnitTesting = (props: any) => {
return return
} }
} }
if (testDirInput) { if (testDirInput) {
if (testDirInput.endsWith('/') && testDirInput !== '/') { if (testDirInput.endsWith('/') && testDirInput !== '/') {
testDirInput = helper.removeTrailingSlashes(testDirInput) testDirInput = helper.removeTrailingSlashes(testDirInput)
@ -98,6 +98,8 @@ export const SolidityUnitTesting = (props: any) => {
if (await testTabLogic.pathExists(testDirInput)) { if (await testTabLogic.pathExists(testDirInput)) {
setDisableCreateButton(true) setDisableCreateButton(true)
setDisableGenerateButton(false) setDisableGenerateButton(false)
testTabLogic.setCurrentPath(testDirInput)
updateForNewCurrent()
} else { } else {
// Enable Create button // Enable Create button
setDisableCreateButton(false) setDisableCreateButton(false)
@ -118,7 +120,7 @@ export const SolidityUnitTesting = (props: any) => {
if (disableCreateButton) { if (disableCreateButton) {
if (await testTabLogic.pathExists(inputPath)) { if (await testTabLogic.pathExists(inputPath)) {
testTabLogic.setCurrentPath(inputPath) testTabLogic.setCurrentPath(inputPath)
// this.updateForNewCurrent() updateForNewCurrent()
} }
} }
} }
@ -136,39 +138,11 @@ export const SolidityUnitTesting = (props: any) => {
console.log('path-->', path) console.log('path-->', path)
console.log('inputPath-->', inputPath) console.log('inputPath-->', inputPath)
// this.updateRunAction() // this.updateRunAction()
// this.updateForNewCurrent() updateForNewCurrent()
pathOptions.push(inputPath) pathOptions.push(inputPath)
setPathOptions(pathOptions) setPathOptions(pathOptions)
} }
// const updateGenerateFileAction = () => {
// console.log('updateGenerateFileAction')
// return (
// <button
// className="btn border w-50"
// data-id="testTabGenerateTestFile"
// title="Generate sample test file."
// >
// Generate
// </button>)
// const 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 (!this.generateFileActionElement) {
// this.generateFileActionElement = el
// } else {
// yo.update(this.generateFileActionElement, el)
// }
// return this.generateFileActionElement
// }
const updateRunAction = (currentFile = null) => { const updateRunAction = (currentFile = null) => {
console.log('updateRunAction --currentFile-->', currentFile) console.log('updateRunAction --currentFile-->', currentFile)
@ -214,6 +188,31 @@ export const SolidityUnitTesting = (props: any) => {
// runBtn.setAttribute('disabled', 'disabled') // runBtn.setAttribute('disabled', 'disabled')
} }
const toggleCheckbox = (eChecked: any, test:any) => {
console.log('toggleCheckbox--->', test)
// if (!this.data.selectedTests) {
// this.data.selectedTests = this._view.el.querySelectorAll('.singleTest:checked')
// }
// let selectedTests = this.data.selectedTests
// selectedTests = eChecked ? [...selectedTests, test] : selectedTests.filter(el => el !== test)
// this.data.selectedTests = selectedTests
// const checkAll = this._view.el.querySelector('[id="checkAllTests"]')
// const runBtn = document.getElementById('runTestsTabRunAction')
// if (eChecked) {
// checkAll.checked = true
// const stopBtnInnerText = document.getElementById('runTestsTabStopAction').innerText
// if ((this.readyTestsNumber === this.runningTestsNumber || this.hasBeenStopped) && stopBtnInnerText.trim() === 'Stop') {
// runBtn.removeAttribute('disabled')
// runBtn.setAttribute('title', 'Run tests')
// }
// } else if (!selectedTests.length) {
// checkAll.checked = false
// runBtn.setAttribute('disabled', 'disabled')
// runBtn.setAttribute('title', 'No test file selected')
// }
}
const checkAll = (event: any) => { const checkAll = (event: any) => {
console.log('checkAll --event-->', event) console.log('checkAll --event-->', event)
@ -226,13 +225,13 @@ export const SolidityUnitTesting = (props: any) => {
// } // }
} }
const createSingleTest = (testFile) => { const createSingleTest = (testFile: string) => {
return yo` return (
<div class="d-flex align-items-center py-1"> <div className="d-flex align-items-center py-1">
<input class="singleTest" id="singleTest${testFile}" onchange=${(e) => this.toggleCheckbox(e.target.checked, testFile)} type="checkbox" checked="true"> <input className="singleTest" id="singleTest${testFile}" onChange={(e) => toggleCheckbox(e.target.checked, testFile)} type="checkbox"/>
<label class="singleTestLabel text-nowrap pl-2 mb-0" for="singleTest${testFile}">${testFile}</label> <label className="singleTestLabel text-nowrap pl-2 mb-0" htmlFor="singleTest${testFile}">{testFile}</label>
</div> </div>
` )
} }
const listTests = () => { const listTests = () => {
@ -244,6 +243,7 @@ export const SolidityUnitTesting = (props: any) => {
} }
const updateTestFileList = (tests = []) => { const updateTestFileList = (tests = []) => {
console.log('updateTestFileList--tests->', tests)
const testsMsg: any = (tests && tests.length) ? listTests() : 'No test file available' const testsMsg: any = (tests && tests.length) ? listTests() : 'No test file available'
setTestsMessage(testsMsg) setTestsMessage(testsMsg)
} }
@ -257,7 +257,6 @@ export const SolidityUnitTesting = (props: any) => {
const [resultStatistics] = useState(createResultLabel()) const [resultStatistics] = useState(createResultLabel())
console.log('props---->', props)
return ( return (
<div className="px-2" id="testView"> <div className="px-2" id="testView">
<div className="infoBox"> <div className="infoBox">

Loading…
Cancel
Save