solidityUnitTesting intl

pull/5370/head
drafish 2 years ago committed by Aniket
parent 87e15ab922
commit 0edf83d4e0
  1. 2
      apps/remix-ide/src/app/tabs/locales/en/index.js
  2. 35
      apps/remix-ide/src/app/tabs/locales/en/solidityUnitTesting.json
  3. 2
      apps/remix-ide/src/app/tabs/locales/zh/index.js
  4. 35
      apps/remix-ide/src/app/tabs/locales/zh/solidityUnitTesting.json
  5. 71
      libs/remix-ui/solidity-unit-testing/src/lib/solidity-unit-testing.tsx

@ -8,6 +8,7 @@ import settingsJson from './settings.json';
import solidityJson from './solidity.json'; import solidityJson from './solidity.json';
import terminalJson from './terminal.json'; import terminalJson from './terminal.json';
import udappJson from './udapp.json'; import udappJson from './udapp.json';
import solidityUnitTestingJson from './solidityUnitTesting.json';
export default { export default {
...debuggerJson, ...debuggerJson,
@ -20,4 +21,5 @@ export default {
...solidityJson, ...solidityJson,
...terminalJson, ...terminalJson,
...udappJson, ...udappJson,
...solidityUnitTestingJson,
} }

@ -0,0 +1,35 @@
{
"solidityUnitTesting.displayName": "Solidity unit testing",
"solidityUnitTesting.testDirectory": "Test directory",
"solidityUnitTesting.testYourSmartContract": "Test your smart contract in Solidity.",
"solidityUnitTesting.selectDirectory": "Select directory to load and generate test files.",
"solidityUnitTesting.uiPathInputTooltip": "Press 'Enter' to change the path for test files.",
"solidityUnitTesting.uiPathInputButtonTooltip": "Create a test folder",
"solidityUnitTesting.create": "Create",
"solidityUnitTesting.generateTestsButtonTooltip": "Generate a sample test file",
"solidityUnitTesting.generate": "Generate",
"solidityUnitTesting.generateTestsLinkTooltip": "Check out documentation.",
"solidityUnitTesting.howToUse": "How to use...",
"solidityUnitTesting.runButtonTitle1": "Run tests",
"solidityUnitTesting.runButtonTitle2": "Please select Solidity compiler version greater than 0.4.12.",
"solidityUnitTesting.runButtonTitle3": "No solidity file selected",
"solidityUnitTesting.runButtonTitle4": "The \"Solidity Plugin\" should be activated",
"solidityUnitTesting.runButtonTitle5": "No test file selected",
"solidityUnitTesting.stopButtonLabel1": "Stop",
"solidityUnitTesting.stopButtonLabel2": "Stopping",
"solidityUnitTesting.run": "Run",
"solidityUnitTesting.runTestsTabStopActionTooltip": "Stop running tests",
"solidityUnitTesting.selectAll": "Select all",
"solidityUnitTesting.testTabTestsExecutionStopped": "The test execution has been stopped",
"solidityUnitTesting.testTabTestsExecutionStoppedError": "The test execution has been stopped because of error(s) in your test file",
"solidityUnitTesting.progress": "Progress: {readyTestsNumber} finished (of {runningTestsNumber})",
"solidityUnitTesting.resultFor": "Result for",
"solidityUnitTesting.passed": "Passed",
"solidityUnitTesting.failed": "Failed",
"solidityUnitTesting.timeTaken": "Time Taken",
"solidityUnitTesting.errorMessage": "Error Message",
"solidityUnitTesting.assertion": "Assertion",
"solidityUnitTesting.expectedValueShouldBe": "Expected value should be",
"solidityUnitTesting.receivedValue": "Received value",
"solidityUnitTesting.skippingTheRemainingTests": "Skipping the remaining tests of the function."
}

@ -8,6 +8,7 @@ import settingsJson from './settings.json';
import solidityJson from './solidity.json'; import solidityJson from './solidity.json';
import terminalJson from './terminal.json'; import terminalJson from './terminal.json';
import udappJson from './udapp.json'; import udappJson from './udapp.json';
import solidityUnitTestingJson from './solidityUnitTesting.json';
import enJson from '../en'; import enJson from '../en';
// There may have some un-translated content. Always fill in the gaps with EN JSON. // There may have some un-translated content. Always fill in the gaps with EN JSON.
@ -23,4 +24,5 @@ export default Object.assign({}, enJson, {
...solidityJson, ...solidityJson,
...terminalJson, ...terminalJson,
...udappJson, ...udappJson,
...solidityUnitTestingJson,
}) })

@ -0,0 +1,35 @@
{
"solidityUnitTesting.displayName": "Solidity 单元测试",
"solidityUnitTesting.testDirectory": "测试目录",
"solidityUnitTesting.testYourSmartContract": "在 Solidity 中测试您的智能合约。",
"solidityUnitTesting.selectDirectory": "选择要加载和生成测试文件的目录。",
"solidityUnitTesting.uiPathInputTooltip": "按 \"Enter\" 键更改测试文件的路径。",
"solidityUnitTesting.uiPathInputButtonTooltip": "创建一个测试目录",
"solidityUnitTesting.create": "创建",
"solidityUnitTesting.generateTestsButtonTooltip": "生成示例测试文件",
"solidityUnitTesting.generate": "生成",
"solidityUnitTesting.generateTestsLinkTooltip": "查看文档。",
"solidityUnitTesting.howToUse": "如何使用...",
"solidityUnitTesting.runButtonTitle1": "运行测试",
"solidityUnitTesting.runButtonTitle2": "请选择大于 0.4.12 的 Solidity 编译器版本。",
"solidityUnitTesting.runButtonTitle3": "未选择 solidity 文件",
"solidityUnitTesting.runButtonTitle4": "应该激活 \"Solidity Plugin\"",
"solidityUnitTesting.runButtonTitle5": "未选择测试文件",
"solidityUnitTesting.stopButtonLabel1": "停止",
"solidityUnitTesting.stopButtonLabel2": "正在停止",
"solidityUnitTesting.run": "执行",
"solidityUnitTesting.runTestsTabStopActionTooltip": "停止运行测试",
"solidityUnitTesting.selectAll": "全选",
"solidityUnitTesting.testTabTestsExecutionStopped": "测试执行已停止",
"solidityUnitTesting.testTabTestsExecutionStoppedError": "由于测试文件中的错误,测试执行已停止",
"solidityUnitTesting.progress": "进度:{readyTestsNumber} 已完成(共 {runningTestsNumber})",
"solidityUnitTesting.resultFor": "测试结果",
"solidityUnitTesting.passed": "通过",
"solidityUnitTesting.failed": "失败",
"solidityUnitTesting.timeTaken": "耗时",
"solidityUnitTesting.errorMessage": "错误信息",
"solidityUnitTesting.assertion": "断言",
"solidityUnitTesting.expectedValueShouldBe": "期望值应该是",
"solidityUnitTesting.receivedValue": "实际值",
"solidityUnitTesting.skippingTheRemainingTests": "跳过该方法的其余测试。"
}

@ -1,4 +1,5 @@
import React, { useState, useRef, useEffect, ReactElement } from 'react' // eslint-disable-line import React, { useState, useRef, useEffect, ReactElement } from 'react' // eslint-disable-line
import { FormattedMessage, useIntl } from 'react-intl'
import * as semver from 'semver' import * as semver from 'semver'
import { eachOfSeries } from 'async' // eslint-disable-line import { eachOfSeries } from 'async' // eslint-disable-line
import type Web3 from 'web3' import type Web3 from 'web3'
@ -45,14 +46,16 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
const { helper, testTab, initialPath } = props const { helper, testTab, initialPath } = props
const { testTabLogic } = testTab const { testTabLogic } = testTab
const intl = useIntl()
const [toasterMsg, setToasterMsg] = useState<string>('') const [toasterMsg, setToasterMsg] = useState<string>('')
const [disableCreateButton, setDisableCreateButton] = useState<boolean>(true) const [disableCreateButton, setDisableCreateButton] = useState<boolean>(true)
const [disableGenerateButton, setDisableGenerateButton] = useState<boolean>(false) const [disableGenerateButton, setDisableGenerateButton] = useState<boolean>(false)
const [disableStopButton, setDisableStopButton] = useState<boolean>(true) const [disableStopButton, setDisableStopButton] = useState<boolean>(true)
const [disableRunButton, setDisableRunButton] = useState<boolean>(false) const [disableRunButton, setDisableRunButton] = useState<boolean>(false)
const [runButtonTitle, setRunButtonTitle] = useState<string>('Run tests') const [runButtonTitle, setRunButtonTitle] = useState<string>(intl.formatMessage({ id: 'solidityUnitTesting.runButtonTitle1' }))
const [stopButtonLabel, setStopButtonLabel] = useState<string>('Stop') const [stopButtonLabel, setStopButtonLabel] = useState<string>(intl.formatMessage({ id: 'solidityUnitTesting.stopButtonLabel1' }))
const [checkSelectAll, setCheckSelectAll] = useState<boolean>(true) const [checkSelectAll, setCheckSelectAll] = useState<boolean>(true)
const [testsOutput, setTestsOutput] = useState<ReactElement[]>([]) const [testsOutput, setTestsOutput] = useState<ReactElement[]>([])
@ -170,7 +173,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
if (!semver.gt(truncateVersion(currentVersion), '0.4.12')) { if (!semver.gt(truncateVersion(currentVersion), '0.4.12')) {
setDisableRunButton(true) setDisableRunButton(true)
setRunButtonTitle('Please select Solidity compiler version greater than 0.4.12.') setRunButtonTitle(intl.formatMessage({ id: 'solidityUnitTesting.runButtonTitle2' }))
} }
}) })
@ -395,17 +398,17 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
<span> {test.value}</span> <span> {test.value}</span>
{debugBtn} {debugBtn}
</div> </div>
<span className="text-dark">Error Message:</span> <span className="text-dark"><FormattedMessage id='solidityUnitTesting.errorMessage' />:</span>
<span className="pb-2 text-break">"{test.errMsg}"</span> <span className="pb-2 text-break">"{test.errMsg}"</span>
<span className="text-dark">Assertion:</span> <span className="text-dark"><FormattedMessage id='solidityUnitTesting.assertion' />:</span>
<div className="d-flex flex-wrap"> <div className="d-flex flex-wrap">
<span>Expected value should be</span> <span><FormattedMessage id='solidityUnitTesting.expectedValueShouldBe' /></span>
<div className="mx-1 font-weight-bold">{method}</div> <div className="mx-1 font-weight-bold">{method}</div>
<div>{preposition} {expected}</div> <div>{preposition} {expected}</div>
</div> </div>
<span className="text-dark">Received value:</span> <span className="text-dark"><FormattedMessage id='solidityUnitTesting.receivedValue' />:</span>
<span>{test.returned}</span> <span>{test.returned}</span>
<span className="text-dark text-sm pb-2">Skipping the remaining tests of the function.</span> <span className="text-dark text-sm pb-2"><FormattedMessage id='solidityUnitTesting.skippingTheRemainingTests' /></span>
</div>) </div>)
setTestsOutput(prevCards => ([...prevCards, testFailCard2])) setTestsOutput(prevCards => ([...prevCards, testFailCard2]))
} }
@ -457,10 +460,10 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
const testSummary = fileTestsResult['summary'] const testSummary = fileTestsResult['summary']
if (testSummary && testSummary.filename && !testSummary.rendered) { if (testSummary && testSummary.filename && !testSummary.rendered) {
const summaryCard: ReactElement = (<div className="d-flex alert-secondary mb-3 p-3 flex-column"> const summaryCard: ReactElement = (<div className="d-flex alert-secondary mb-3 p-3 flex-column">
<span className="font-weight-bold">Result for {testSummary.filename}</span> <span className="font-weight-bold"><FormattedMessage id='solidityUnitTesting.resultFor' /> {testSummary.filename}</span>
<span className="text-success">Passed: {testSummary.passed}</span> <span className="text-success"><FormattedMessage id='solidityUnitTesting.passed' />: {testSummary.passed}</span>
<span className="text-danger">Failed: {testSummary.failed}</span> <span className="text-danger"><FormattedMessage id='solidityUnitTesting.failed' />: {testSummary.failed}</span>
<span>Time Taken: {testSummary.timeTaken}s</span> <span><FormattedMessage id='solidityUnitTesting.timeTaken' />: {testSummary.timeTaken}s</span>
</div>) </div>)
setTestsOutput(prevCards => ([...prevCards, summaryCard])) setTestsOutput(prevCards => ([...prevCards, summaryCard]))
fileTestsResult['summary']['rendered'] = true fileTestsResult['summary']['rendered'] = true
@ -523,7 +526,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
if (_errors || hasBeenStopped.current || readyTestsNumber === runningTestsNumber) { if (_errors || hasBeenStopped.current || readyTestsNumber === runningTestsNumber) {
// All tests are ready or the operation has been canceled or there was a compilation error in one of the test files. // All tests are ready or the operation has been canceled or there was a compilation error in one of the test files.
setDisableStopButton(true) setDisableStopButton(true)
setStopButtonLabel('Stop') setStopButtonLabel(intl.formatMessage({ id: 'solidityUnitTesting.stopButtonLabel1' }))
if (selectedTests.current?.length !== 0) { if (selectedTests.current?.length !== 0) {
setDisableRunButton(false) setDisableRunButton(false)
} }
@ -598,16 +601,16 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
if (!isSolidityActive || !selectedTests.current.length) { if (!isSolidityActive || !selectedTests.current.length) {
setDisableRunButton(true) setDisableRunButton(true)
if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) { if (!currentFile || (currentFile && currentFile.split('.').pop().toLowerCase() !== 'sol')) {
setRunButtonTitle('No solidity file selected') setRunButtonTitle(intl.formatMessage({ id: 'solidityUnitTesting.runButtonTitle3' }))
} else { } else {
setRunButtonTitle('The "Solidity Plugin" should be activated') setRunButtonTitle(intl.formatMessage({ id: 'solidityUnitTesting.runButtonTitle4' }))
} }
} else setDisableRunButton(false) } else setDisableRunButton(false)
} }
const stopTests = () => { const stopTests = () => {
hasBeenStopped.current = true hasBeenStopped.current = true
setStopButtonLabel('Stopping') setStopButtonLabel(intl.formatMessage({ id: 'solidityUnitTesting.stopButtonLabel2' }))
setDisableStopButton(true) setDisableStopButton(true)
setDisableRunButton(true) setDisableRunButton(true)
} }
@ -625,12 +628,12 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
setCheckSelectAll(true) setCheckSelectAll(true)
setDisableRunButton(false) setDisableRunButton(false)
if ((readyTestsNumber === runningTestsNumber || hasBeenStopped.current) && stopButtonLabel.trim() === 'Stop') { if ((readyTestsNumber === runningTestsNumber || hasBeenStopped.current) && stopButtonLabel.trim() === 'Stop') {
setRunButtonTitle('Run tests') setRunButtonTitle(intl.formatMessage({ id: 'solidityUnitTesting.runButtonTitle1' }))
} }
} else if (!selectedTests.current.length) { } else if (!selectedTests.current.length) {
setCheckSelectAll(false) setCheckSelectAll(false)
setDisableRunButton(true) setDisableRunButton(true)
setRunButtonTitle('No test file selected') setRunButtonTitle(intl.formatMessage({ id: 'solidityUnitTesting.runButtonTitle5' }))
} else setCheckSelectAll(false) } else setCheckSelectAll(false)
} }
@ -661,9 +664,9 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
<div className="px-2" id="testView"> <div className="px-2" id="testView">
<Toaster message={toasterMsg} /> <Toaster message={toasterMsg} />
<div className="infoBox"> <div className="infoBox">
<p className="text-lg"> Test your smart contract in Solidity.</p> <p className="text-lg"> <FormattedMessage id='solidityUnitTesting.testYourSmartContract' /></p>
<p> Select directory to load and generate test files.</p> <p> <FormattedMessage id='solidityUnitTesting.selectDirectory' /></p>
<label>Test directory:</label> <label><FormattedMessage id='solidityUnitTesting.testDirectory' />:</label>
<div> <div>
<div className="d-flex p-2"> <div className="d-flex p-2">
<datalist id="utPathList">{ <datalist id="utPathList">{
@ -676,7 +679,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
placement="top-end" placement="top-end"
tooltipClasses="text-nowrap" tooltipClasses="text-nowrap"
tooltipId="uiPathInputtooltip" tooltipId="uiPathInputtooltip"
tooltipText={"Press 'Enter' to change the path for test files."} tooltipText={<FormattedMessage id='solidityUnitTesting.uiPathInputTooltip' />}
> >
<input <input
list="utPathList" list="utPathList"
@ -695,7 +698,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
placement="top-end" placement="top-end"
tooltipClasses="text-nowrap" tooltipClasses="text-nowrap"
tooltipId="uiPathInputButtontooltip" tooltipId="uiPathInputButtontooltip"
tooltipText="Create a test folder" tooltipText={<FormattedMessage id='solidityUnitTesting.uiPathInputButtonTooltip' />}
> >
<button <button
className="btn border ml-2" className="btn border ml-2"
@ -703,7 +706,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
disabled={disableCreateButton} disabled={disableCreateButton}
onClick={handleCreateFolder} onClick={handleCreateFolder}
> >
Create <FormattedMessage id='solidityUnitTesting.create' />
</button> </button>
</CustomTooltip> </CustomTooltip>
</div> </div>
@ -714,7 +717,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
<CustomTooltip <CustomTooltip
tooltipId="generateTestsButtontooltip" tooltipId="generateTestsButtontooltip"
tooltipClasses="text-nowrap" tooltipClasses="text-nowrap"
tooltipText="Generate a sample test file" tooltipText={<FormattedMessage id='solidityUnitTesting.generateTestsButtonTooltip' />}
placement={'bottom-start'} placement={'bottom-start'}
> >
<button <button
@ -726,17 +729,17 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
await updateForNewCurrent() await updateForNewCurrent()
}} }}
> >
Generate <FormattedMessage id='solidityUnitTesting.generate' />
</button> </button>
</CustomTooltip> </CustomTooltip>
<CustomTooltip <CustomTooltip
tooltipId="generateTestsLinktooltip" tooltipId="generateTestsLinktooltip"
tooltipClasses="text-nowrap" tooltipClasses="text-nowrap"
tooltipText="Check out documentation." tooltipText={<FormattedMessage id='solidityUnitTesting.generateTestsLinkTooltip' />}
placement={'bottom-start'} placement={'bottom-start'}
> >
<a className="btn border text-decoration-none pr-0 d-flex w-50 ml-2" target="__blank" href="https://remix-ide.readthedocs.io/en/latest/unittesting.html#test-directory"> <a className="btn border text-decoration-none pr-0 d-flex w-50 ml-2" target="__blank" href="https://remix-ide.readthedocs.io/en/latest/unittesting.html#test-directory">
<label className="btn p-1 ml-2 m-0">How to use...</label> <label className="btn p-1 ml-2 m-0"><FormattedMessage id='solidityUnitTesting.howToUse' /></label>
</a> </a>
</CustomTooltip> </CustomTooltip>
</div> </div>
@ -749,7 +752,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
> >
<button id="runTestsTabRunAction"data-id="testTabRunTestsTabRunAction" className="w-50 btn btn-primary" disabled={disableRunButton} onClick={runTests}> <button id="runTestsTabRunAction"data-id="testTabRunTestsTabRunAction" className="w-50 btn btn-primary" disabled={disableRunButton} onClick={runTests}>
<span className="fas fa-play ml-2"></span> <span className="fas fa-play ml-2"></span>
<label className="labelOnBtn btn btn-primary p-1 ml-2 m-0">Run</label> <label className="labelOnBtn btn btn-primary p-1 ml-2 m-0"><FormattedMessage id='solidityUnitTesting.run' /></label>
</button> </button>
</CustomTooltip> </CustomTooltip>
<button id="runTestsTabStopAction" data-id="testTabRunTestsTabStopAction" className="w-50 pl-2 ml-2 btn btn-secondary" disabled={disableStopButton} onClick={stopTests}> <button id="runTestsTabStopAction" data-id="testTabRunTestsTabStopAction" className="w-50 pl-2 ml-2 btn btn-secondary" disabled={disableStopButton} onClick={stopTests}>
@ -757,7 +760,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
placement={'top-start'} placement={'top-start'}
tooltipClasses="text-nowrap" tooltipClasses="text-nowrap"
tooltipId="info-recorder" tooltipId="info-recorder"
tooltipText="Stop running tests" tooltipText={<FormattedMessage id='solidityUnitTesting.runTestsTabStopActionTooltip' />}
> >
<span> <span>
<span className="fas fa-stop ml-2"></span> <span className="fas fa-stop ml-2"></span>
@ -774,7 +777,7 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
checked={checkSelectAll} checked={checkSelectAll}
onChange={() => { }} // eslint-disable-line onChange={() => { }} // eslint-disable-line
/> />
<label className="text-nowrap pl-2 mb-0" htmlFor="checkAllTests"> Select all </label> <label className="text-nowrap pl-2 mb-0" htmlFor="checkAllTests"> <FormattedMessage id='solidityUnitTesting.selectAll' /> </label>
</div> </div>
<div className="testList py-2 mt-0 border-bottom">{testFiles.length ? testFiles.map((testFileObj: TestObject, index) => { <div className="testList py-2 mt-0 border-bottom">{testFiles.length ? testFiles.map((testFileObj: TestObject, index) => {
const elemId = `singleTest${testFileObj.fileName}` const elemId = `singleTest${testFileObj.fileName}`
@ -787,9 +790,9 @@ export const SolidityUnitTesting = (props: Record<string, any>) => { // eslint-d
}) })
: "No test file available"} </div> : "No test file available"} </div>
<div className="align-items-start flex-column mt-2 mx-3 mb-0"> <div className="align-items-start flex-column mt-2 mx-3 mb-0">
<span className='text-info h6' hidden={progressBarHidden}>Progress: {readyTestsNumber} finished (of {runningTestsNumber})</span> <span className='text-info h6' hidden={progressBarHidden}><FormattedMessage id='solidityUnitTesting.progress' values={{ readyTestsNumber, runningTestsNumber }} /></span>
<label className="text-warning h6" data-id="testTabTestsExecutionStopped" hidden={testsExecutionStoppedHidden}>The test execution has been stopped</label> <label className="text-warning h6" data-id="testTabTestsExecutionStopped" hidden={testsExecutionStoppedHidden}><FormattedMessage id='solidityUnitTesting.testTabTestsExecutionStopped' /></label>
<label className="text-danger h6" data-id="testTabTestsExecutionStoppedError" hidden={testsExecutionStoppedErrorHidden}>The test execution has been stopped because of error(s) in your test file</label> <label className="text-danger h6" data-id="testTabTestsExecutionStoppedError" hidden={testsExecutionStoppedErrorHidden}><FormattedMessage id='solidityUnitTesting.testTabTestsExecutionStoppedError' /></label>
</div> </div>
<div className="mx-3 mb-2 pb-4 border-primary" id="solidityUnittestsOutput" data-id="testTabSolidityUnitTestsOutput">{testsOutput}</div> <div className="mx-3 mb-2 pb-4 border-primary" id="solidityUnittestsOutput" data-id="testTabSolidityUnitTestsOutput">{testsOutput}</div>
</div> </div>

Loading…
Cancel
Save