From a39c6358c1dc00ad298008f93e3dd8f0316e6c4c Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 24 Mar 2021 15:26:35 +0530 Subject: [PATCH] trim input --- apps/remix-ide/src/app/tabs/test-tab.js | 42 +++++++++++++++---------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/test-tab.js b/apps/remix-ide/src/app/tabs/test-tab.js index ceb2cd095e..b554fc0e29 100644 --- a/apps/remix-ide/src/app/tabs/test-tab.js +++ b/apps/remix-ide/src/app/tabs/test-tab.js @@ -556,24 +556,33 @@ module.exports = class TestTab extends ViewPlugin { }) } + trimTestDirInput (input) { + if(input.includes('/')) return input.split('/').map(e => e.trim()).join('/') + else return input.trim() + } + handleTestDirInput () { - if (this.inputPath.value && this.inputPath.value.endsWith('/')) { - this.updateDirList(this.inputPath.value) - } else { - let matchFound = false - for (const option of this.uiPathList.querySelectorAll('option')) { - if (option.innerHTML === this.inputPath.value) matchFound = true - } - // If there is no matching folder in the workspace with entered text, enable Create button - if (!matchFound) { - // Enable Create button - this.createTestFolder.disabled = false - // Disable Generate button because dir is not existing - this.updateGenerateFileAction().disabled = true - } else { - this.createTestFolder.disabled = true - this.updateGenerateFileAction().disabled = false + const testDirInput = this.trimTestDirInput(this.inputPath.value) + if (testDirInput) { + if (testDirInput.endsWith('/')) this.updateDirList(testDirInput) + else { + let matchFound = false + for (const option of this.uiPathList.querySelectorAll('option')) { + if (option.innerHTML === testDirInput) matchFound = true + } + // If there is no matching folder in the workspace with entered text, enable Create button + if (!matchFound) { + // Enable Create button + this.createTestFolder.disabled = false + // Disable Generate button because dir is not existing + this.updateGenerateFileAction().disabled = true + } else { + this.createTestFolder.disabled = true + this.updateGenerateFileAction().disabled = false + } } + } else { + this.updateDirList('/') } } @@ -600,6 +609,7 @@ module.exports = class TestTab extends ViewPlugin { title="Create a test folder" disabled=true onclick=${(e) => { + this.inputPath.value = this.trimTestDirInput(this.inputPath.value) this.testTabLogic.generateTestFolder(this.inputPath.value) this.createTestFolder.disabled = true this.updateGenerateFileAction().disabled = false