handleTestDirInput

pull/5370/head
Aniket-Engg 3 years ago committed by Aniket
parent 80a75b96a0
commit 01b0c9df49
  1. 4
      apps/remix-ide/src/app/tabs/test-tab.js
  2. 110
      libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx

@ -4,7 +4,7 @@ import ReactDOM from 'react-dom'
import { SolidityUnitTesting } from '@remix-ui/solidity-unit-testing' // eslint-disable-line import { SolidityUnitTesting } from '@remix-ui/solidity-unit-testing' // eslint-disable-line
import { ViewPlugin } from '@remixproject/engine-web' import { ViewPlugin } from '@remixproject/engine-web'
import { removeMultipleSlashes, removeTrailingSlashes } from '../../lib/helper' import helper, { removeMultipleSlashes, removeTrailingSlashes } from '../../lib/helper'
import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity' import { canUseWorker, urlFromVersion } from '@remix-project/remix-solidity'
import { format } from 'util' import { format } from 'util'
var yo = require('yo-yo') var yo = require('yo-yo')
@ -811,7 +811,7 @@ module.exports = class TestTab extends ViewPlugin {
renderComponent () { renderComponent () {
console.log('renderComponent-start-->') console.log('renderComponent-start-->')
ReactDOM.render( ReactDOM.render(
<SolidityUnitTesting testTab={this}/> <SolidityUnitTesting testTab={this} testTabLogic={this.testTabLogic} helper={helper} />
, this.element) , this.element)
console.log('renderComponent-end-->') console.log('renderComponent-end-->')
} }

@ -5,7 +5,9 @@ import './css/style.css'
/* eslint-disable-next-line */ /* eslint-disable-next-line */
export interface SolidityUnitTestingProps {} export interface SolidityUnitTestingProps {}
export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => { export const SolidityUnitTesting = (props: any) => {
const {helper, testTab, testTabLogic} = props
const [defaultPath, setDefaultPath] = useState('tests') const [defaultPath, setDefaultPath] = useState('tests')
const [disableCreateButton, setDisableCreateButton] = useState(true) const [disableCreateButton, setDisableCreateButton] = useState(true)
@ -14,45 +16,88 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => {
const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true) const [testsExecutionStoppedHidden, setTestsExecutionStoppedHidden] = useState(true)
const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true) const [testsExecutionStoppedErrorHidden, setTestsExecutionStoppedErrorHidden] = useState(true)
const [inputPathValue, setInputPathValue] = useState('')
const handleTestDirInput = async (e:any) => { const trimTestDirInput = (input:string) => {
console.log('handleTestDirInput--e-->', e) if (input.includes('/')) return input.split('/').map(e => e.trim()).join('/')
else return input.trim()
}
// let testDirInput = this.trimTestDirInput(this.inputPath.value) const updateForNewCurrent = async (file = null) => {
// testDirInput = removeMultipleSlashes(testDirInput) // Ensure that when someone clicks on compilation error and that opens a new file
// if (testDirInput !== '/') testDirInput = removeTrailingSlashes(testDirInput) // Test result, which is compilation error in this case, is not cleared
// if (e.key === 'Enter') { // if (this.currentErrors) {
// this.inputPath.value = testDirInput // if (Array.isArray(this.currentErrors) && this.currentErrors.length > 0) {
// if (await this.testTabLogic.pathExists(testDirInput)) { // const errFiles = this.currentErrors.map(err => { if (err.sourceLocation && err.sourceLocation.file) return err.sourceLocation.file })
// this.testTabLogic.setCurrentPath(testDirInput) // if (errFiles.includes(file)) return
// this.updateForNewCurrent() // } else if (this.currentErrors.sourceLocation && this.currentErrors.sourceLocation.file && this.currentErrors.sourceLocation.file === file) return
// return
// } // }
// // if current file is changed while debugging and one of the files imported in test file are opened
// // do not clear the test results in SUT plugin
// if (this.isDebugging && this.allFilesInvolved.includes(file)) return
// this.data.allTests = []
// this.updateTestFileList()
// this.clearResults()
// this.updateGenerateFileAction()
// if (!this.areTestsRunning) this.updateRunAction(file)
// try {
// await this.testTabLogic.getTests((error, tests) => {
// if (error) return tooltip(error)
// this.data.allTests = tests
// this.data.selectedTests = [...this.data.allTests]
// this.updateTestFileList(tests)
// if (!this.testsOutput) return // eslint-disable-line
// })
// } catch (e) {
// console.log(e)
// } // }
}
// if (testDirInput) { const updateDirList = (path: string) => {
// if (testDirInput.endsWith('/') && testDirInput !== '/') { // for (const o of this.uiPathList.querySelectorAll('option')) o.remove()
// testDirInput = removeTrailingSlashes(testDirInput) // testTabLogic.dirList(path).then((options) => {
// if (this.testTabLogic.currentPath === testDirInput.substr(0, testDirInput.length - 1)) { // options.forEach((path) => this.uiPathList.appendChild(yo`<option>${path}</option>`))
// this.createTestFolder.disabled = true // })
}
const handleTestDirInput = async (e:any) => {
console.log('handleTestDirInput--e-->', e)
let testDirInput = trimTestDirInput(inputPathValue)
testDirInput = helper.removeMultipleSlashes(testDirInput)
if (testDirInput !== '/') testDirInput = helper.removeTrailingSlashes(testDirInput)
if (e.key === 'Enter') {
setInputPathValue(testDirInput)
if (await testTabLogic.pathExists(testDirInput)) {
testTabLogic.setCurrentPath(testDirInput)
updateForNewCurrent()
return
}
}
if (testDirInput) {
if (testDirInput.endsWith('/') && testDirInput !== '/') {
testDirInput = helper.removeTrailingSlashes(testDirInput)
if (testTabLogic.currentPath === testDirInput.substr(0, testDirInput.length - 1)) {
setDisableCreateButton(true)
// this.updateGenerateFileAction().disabled = true // this.updateGenerateFileAction().disabled = true
// } }
// this.updateDirList(testDirInput) updateDirList(testDirInput)
// } else { } else {
// // If there is no matching folder in the workspace with entered text, enable Create button // If there is no matching folder in the workspace with entered text, enable Create button
// if (await this.testTabLogic.pathExists(testDirInput)) { if (await testTabLogic.pathExists(testDirInput)) {
// this.createTestFolder.disabled = true setDisableCreateButton(true)
// this.updateGenerateFileAction().disabled = false // this.updateGenerateFileAction().disabled = false
// } else { } else {
// // Enable Create button // Enable Create button
// this.createTestFolder.disabled = false setDisableCreateButton(false)
// // Disable Generate button because dir does not exist // Disable Generate button because dir does not exist
// this.updateGenerateFileAction().disabled = true // this.updateGenerateFileAction().disabled = true
// } }
// } }
// } else { } else {
// this.updateDirList('/') updateDirList('/')
// } }
} }
const handleEnter = async(e:any) => { const handleEnter = async(e:any) => {
@ -207,6 +252,7 @@ export const SolidityUnitTesting = (props: SolidityUnitTestingProps) => {
id="utPath" id="utPath"
data-id="uiPathInput" data-id="uiPathInput"
name="utPath" name="utPath"
value={inputPathValue}
title="Press 'Enter' to change the path for test files." title="Press 'Enter' to change the path for test files."
style= {{ backgroundImage: "var(--primary)"}} style= {{ backgroundImage: "var(--primary)"}}
onKeyUp= {handleTestDirInput} onKeyUp= {handleTestDirInput}

Loading…
Cancel
Save