diff --git a/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx b/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx index 2acb1ee4e4..9f9da608f9 100644 --- a/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx +++ b/libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx @@ -67,6 +67,7 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d let [readyTestsNumber, setReadyTestsNumber] = useState(0) // eslint-disable-line let [runningTestsNumber, setRunningTestsNumber] = useState(0) // eslint-disable-line + const areTestsRunning = useRef(false) const hasBeenStopped = useRef(false) const isDebugging = useRef(false) const allTests = useRef([]) @@ -74,7 +75,6 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d const currentErrors:any = useRef([]) // eslint-disable-line @typescript-eslint/no-explicit-any const defaultPath = 'tests' - let areTestsRunning = false let runningTestFileName: string const filesContent: Record> = {} @@ -113,7 +113,7 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d allTests.current = tests selectedTests.current = [...allTests.current] updateTestFileList() - if (!areTestsRunning) await updateRunAction(file) + if (!areTestsRunning.current) await updateRunAction(file) } catch (e: any) { // eslint-disable-line @typescript-eslint/no-explicit-any console.log(e) setToasterMsg(e) @@ -153,7 +153,7 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d await setCurrentPath(defaultPath) }) - testTab.fileManager.events.on('noFileSelected', () => { }) // eslint-disable-line + testTab.fileManager.events.on('noFileSelected', async () => { await updateForNewCurrent() }) testTab.fileManager.events.on('currentFileChanged', async (file: string) => await updateForNewCurrent(file)) }, []) // eslint-disable-line @@ -167,15 +167,7 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d const handleTestDirInput = async (e: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any let testDirInput = trimTestDirInput(e.target.value) testDirInput = helper.removeMultipleSlashes(testDirInput) - if (testDirInput !== '/') testDirInput = helper.removeTrailingSlashes(testDirInput) setInputPathValue(testDirInput) - if (e.key === 'Enter') { - if (await testTabLogic.pathExists(testDirInput)) { - testTabLogic.setCurrentPath(testDirInput) - await updateForNewCurrent() - return - } - } if (testDirInput) { if (testDirInput.endsWith('/') && testDirInput !== '/') { testDirInput = helper.removeTrailingSlashes(testDirInput) @@ -205,17 +197,6 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d } } - const handleEnter = async (e: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any - let inputPath = e.target.value - inputPath = helper.removeMultipleSlashes(trimTestDirInput(inputPath)) - setInputPathValue(inputPath) - if (disableCreateButton) { - if (await testTabLogic.pathExists(inputPath)) { - await setCurrentPath(inputPath) - } - } - } - const handleCreateFolder = async () => { let inputPath = trimTestDirInput(inputPathValue) let path = helper.removeMultipleSlashes(inputPath) @@ -519,7 +500,7 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d if (selectedTests.current?.length !== 0) { setDisableRunButton(false) } - areTestsRunning = false + areTestsRunning.current = false } } @@ -566,7 +547,7 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d } const runTests = () => { - areTestsRunning = true + areTestsRunning.current = true hasBeenStopped.current = false readyTestsNumber = 0 setReadyTestsNumber(readyTestsNumber) @@ -587,14 +568,14 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d const updateRunAction = async (currentFile: any = null) => { // eslint-disable-line @typescript-eslint/no-explicit-any const isSolidityActive = await testTab.appManager.isActive('solidity') - if (!isSolidityActive || !selectedTests.current?.length) { - // setDisableRunButton(true) + if (!isSolidityActive || !selectedTests.current.length) { + setDisableRunButton(true) if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { setRunButtonTitle('No solidity file selected') } else { setRunButtonTitle('The "Solidity Plugin" should be activated') } - } + } else setDisableRunButton(false) } const stopTests = () => { @@ -611,7 +592,7 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d const toggleCheckbox = (eChecked: boolean, index: number) => { testFiles[index].checked = eChecked - setTestFiles(testFiles) + setTestFiles([...testFiles]) selectedTests.current = getCurrentSelectedTests() if (eChecked) { setCheckSelectAll(true) @@ -628,7 +609,7 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d const checkAll = (event: any) => { // eslint-disable-line @typescript-eslint/no-explicit-any testFiles.forEach((testFileObj) => testFileObj.checked = event.target.checked) - setTestFiles(testFiles) + setTestFiles([...testFiles]) setCheckSelectAll(event.target.checked) if (event.target.checked) { selectedTests.current = getCurrentSelectedTests() @@ -646,7 +627,7 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d } else testFiles = [] - setTestFiles(testFiles) + setTestFiles([...testFiles]) } return ( @@ -674,8 +655,7 @@ export const SolidityUnitTesting = (props: Record) => { // eslint-d title="Press 'Enter' to change the path for test files." style={{ backgroundImage: "var(--primary)" }} onKeyDown={() => { if (inputPathValue === '/') setInputPathValue('')} } - onKeyUp={handleTestDirInput} - onChange={handleEnter} + onChange={handleTestDirInput} onClick = {() => { if (inputPathValue === '/') setInputPathValue('')} } />