improved unit testing plugin path

pull/1271/head
lianahus 4 years ago committed by Liana Husikyan
parent a6704d4427
commit 102be89099
  1. 81
      apps/remix-ide/src/app/tabs/test-tab.js
  2. 1
      apps/remix-ide/src/app/tabs/testTab/testTab.js
  3. 8
      apps/remix-ide/src/lib/helper.js

@ -1,5 +1,7 @@
import { ViewPlugin } from '@remixproject/engine-web' import { ViewPlugin } from '@remixproject/engine-web'
import { canUseWorker, urlFromVersion } from '../compiler/compiler-utils' import { canUseWorker, urlFromVersion } from '../compiler/compiler-utils'
import * as helper from '../../lib/helper'
var yo = require('yo-yo') var yo = require('yo-yo')
var async = require('async') var async = require('async')
var tooltip = require('../ui/tooltip') var tooltip = require('../ui/tooltip')
@ -52,18 +54,26 @@ module.exports = class TestTab extends ViewPlugin {
} }
listenToEvents () { listenToEvents () {
this.on('filePanel', 'newTestFileCreated', file => { this.on('filePanel', 'newTestFileCreated', async file => {
var testList = this._view.el.querySelector("[class^='testList']") try {
var test = this.createSingleTest(file) await this.testTabLogic.getTests((error, tests) => {
testList.appendChild(test) 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)
}
this.data.allTests.push(file) this.data.allTests.push(file)
this.data.selectedTests.push(file) this.data.selectedTests.push(file)
}) })
this.on('filePanel', 'setWorkspace', () => { this.on('filePanel', 'setWorkspace', async () => {
this.testTabLogic.setCurrentPath(this.defaultPath) this.testTabLogic.setCurrentPath(this.defaultPath)
this.inputPath.value = this.defaultPath this.inputPath.value = this.defaultPath
this.updateForNewCurrent() await this.updateForNewCurrent()
}) })
this.fileManager.events.on('noFileSelected', () => { this.fileManager.events.on('noFileSelected', () => {
@ -72,18 +82,23 @@ 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))
} }
updateForNewCurrent (file) { async updateForNewCurrent (file) {
this.updateGenerateFileAction() this.data.allTests = []
if (!this.areTestsRunning) this.updateRunAction(file)
this.updateTestFileList() this.updateTestFileList()
this.clearResults() this.clearResults()
this.testTabLogic.getTests((error, tests) => { this.updateGenerateFileAction()
if (error) return tooltip(error) if (!this.areTestsRunning) this.updateRunAction(file)
this.data.allTests = tests try {
this.data.selectedTests = [...this.data.allTests] await this.testTabLogic.getTests((error, tests) => {
this.updateTestFileList(tests) if (error) return tooltip(error)
if (!this.testsOutput) return // eslint-disable-line 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)
}
} }
createSingleTest (testFile) { createSingleTest (testFile) {
@ -96,7 +111,7 @@ module.exports = class TestTab extends ViewPlugin {
} }
listTests () { listTests () {
if (!this.data.allTests) return [] if (!this.data.allTests || !this.data.allTests.length) return []
return this.data.allTests.map( return this.data.allTests.map(
testFile => this.createSingleTest(testFile) testFile => this.createSingleTest(testFile)
) )
@ -587,9 +602,10 @@ module.exports = class TestTab extends ViewPlugin {
} }
async handleTestDirInput (e) { async handleTestDirInput (e) {
const testDirInput = this.trimTestDirInput(this.inputPath.value) let testDirInput = this.trimTestDirInput(this.inputPath.value)
testDirInput = helper.removeMultipleSlashes(testDirInput)
if (e.key === 'Enter') { if (e.key === 'Enter') {
this.inputPath.value = this.trimTestDirInput(testDirInput) this.inputPath.value = testDirInput
if (await this.testTabLogic.pathExists(testDirInput)) { if (await this.testTabLogic.pathExists(testDirInput)) {
this.testTabLogic.setCurrentPath(testDirInput) this.testTabLogic.setCurrentPath(testDirInput)
this.updateForNewCurrent() this.updateForNewCurrent()
@ -599,6 +615,7 @@ module.exports = class TestTab extends ViewPlugin {
if (testDirInput) { if (testDirInput) {
if (testDirInput.endsWith('/')) { if (testDirInput.endsWith('/')) {
testDirInput = helper.removeTrailingSlashes(testDirInput)
if (this.testTabLogic.currentPath === testDirInput.substr(0, testDirInput.length - 1)) { if (this.testTabLogic.currentPath === testDirInput.substr(0, testDirInput.length - 1)) {
this.createTestFolder.disabled = true this.createTestFolder.disabled = true
this.updateGenerateFileAction().disabled = true this.updateGenerateFileAction().disabled = true
@ -612,7 +629,7 @@ module.exports = class TestTab extends ViewPlugin {
} else { } else {
// Enable Create button // Enable Create button
this.createTestFolder.disabled = false this.createTestFolder.disabled = false
// Disable Generate button because dir is not existing // Disable Generate button because dir does not exist
this.updateGenerateFileAction().disabled = true this.updateGenerateFileAction().disabled = true
} }
} }
@ -621,6 +638,16 @@ module.exports = class TestTab extends ViewPlugin {
} }
} }
async handleEnter (e) {
this.inputPath.value = helper.removeMultipleSlashes(this.trimTestDirInput(this.inputPath.value))
if (this.createTestFolder.disabled) {
if (await this.testTabLogic.pathExists(this.inputPath.value)) {
this.testTabLogic.setCurrentPath(this.inputPath.value)
this.updateForNewCurrent()
}
}
}
render () { render () {
this.onActivationInternal() this.onActivationInternal()
this.testsOutput = yo`<div class="mx-3 mb-2 pb-4 border-top border-primary" hidden='true' id="solidityUnittestsOutput" data-id="testTabSolidityUnitTestsOutput"></a>` this.testsOutput = yo`<div class="mx-3 mb-2 pb-4 border-top border-primary" hidden='true' id="solidityUnittestsOutput" data-id="testTabSolidityUnitTestsOutput"></a>`
@ -636,16 +663,7 @@ module.exports = class TestTab extends ViewPlugin {
name="utPath" name="utPath"
style="background-image: var(--primary);" style="background-image: var(--primary);"
onkeyup=${(e) => this.handleTestDirInput(e)} onkeyup=${(e) => this.handleTestDirInput(e)}
onchange=${async (e) => { onchange=${async (e) => this.handleEnter(e)}
if (this.createTestFolder.disabled) {
this.inputPath.value = this.trimTestDirInput(this.inputPath.value)
if (await this.testTabLogic.pathExists(this.inputPath.value)) {
this.inputPath.value = this.trimTestDirInput(this.inputPath.value)
this.testTabLogic.setCurrentPath(this.inputPath.value)
this.updateForNewCurrent()
}
}
}}
/>` />`
this.createTestFolder = yo` this.createTestFolder = yo`
@ -654,7 +672,8 @@ module.exports = class TestTab extends ViewPlugin {
data-id="testTabGenerateTestFolder" data-id="testTabGenerateTestFolder"
title="Create a test folder" title="Create a test folder"
disabled=true disabled=true
onclick=${(e) => this.handleCreateFolder()}> onclick=${(e) => this.handleCreateFolder()}
>
Create Create
</button> </button>
` `

@ -17,6 +17,7 @@ class TestTabLogic {
// Todo move this check to File Manager after refactoring // Todo move this check to File Manager after refactoring
// Checking to ignore the value which contains only whitespaces // Checking to ignore the value which contains only whitespaces
if (!path || !(/\S/.test(path))) return if (!path || !(/\S/.test(path))) return
path = helper.removeMultipleSlashes(path)
const fileProvider = this.fileManager.fileProviderOf(path.split('/')[0]) const fileProvider = this.fileManager.fileProviderOf(path.split('/')[0])
fileProvider.exists(path).then(res => { fileProvider.exists(path).then(res => {
if (!res) fileProvider.createDir(path) if (!res) fileProvider.createDir(path)

@ -104,6 +104,14 @@ module.exports = {
const hexValue = hash.slice(2, hash.length) const hexValue = hash.slice(2, hash.length)
return this.is0XPrefixed(hash) && /^[0-9a-fA-F]{64}$/.test(hexValue) return this.is0XPrefixed(hash) && /^[0-9a-fA-F]{64}$/.test(hexValue)
}, },
removeTrailingSlashes (text) {
// Single or consecutive leading slashes:
return text.replace(/^\/+/g, '')
},
removeMultipleSlashes (text) {
// Replace consecutive slashes with '/'
return text.replace(/\/+/g, '/')
},
find: find, find: find,
getPathIcon (path) { getPathIcon (path) {
return path.endsWith('.txt') return path.endsWith('.txt')

Loading…
Cancel
Save