From 6147ef036919bda06ed3a95120b0d5cdccad593f Mon Sep 17 00:00:00 2001 From: filip mertens Date: Mon, 21 Feb 2022 18:11:08 +0100 Subject: [PATCH] e2e --- apps/remix-ide-e2e/src/tests/search.test.ts | 103 ++++++++++++++++++ .../search/src/lib/components/Exclude.tsx | 1 + .../search/src/lib/components/Find.tsx | 4 + .../search/src/lib/components/Include.tsx | 6 +- .../search/src/lib/components/Replace.tsx | 1 + .../lib/components/results/ResultSummary.tsx | 4 +- .../src/lib/components/results/Results.tsx | 4 +- .../search/src/lib/context/context.tsx | 2 +- package.json | 3 +- 9 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 apps/remix-ide-e2e/src/tests/search.test.ts diff --git a/apps/remix-ide-e2e/src/tests/search.test.ts b/apps/remix-ide-e2e/src/tests/search.test.ts new file mode 100644 index 0000000000..626778851d --- /dev/null +++ b/apps/remix-ide-e2e/src/tests/search.test.ts @@ -0,0 +1,103 @@ +'use strict' + +import { NightwatchBrowser } from 'nightwatch' +import init from '../helpers/init' + +module.exports = { + + before: function (browser: NightwatchBrowser, done: VoidFunction) { + init(browser, done, 'http://127.0.0.1:8080', true) + }, + 'Should find text': function (browser: NightwatchBrowser) { + browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]') + .click('*[plugin="search"]').waitForElementVisible('*[id="search_input"]') + .setValue('*[id="search_input"]', 'read').pause(1000) + .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/3_BALLOT.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'README.TXT', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'file must') + .waitForElementContainsText('*[data-id="search_results"]', 'be compiled') + .waitForElementContainsText('*[data-id="search_results"]', 'that person al') + .waitForElementContainsText('*[data-id="search_results"]', 'sender.voted') + .waitForElementContainsText('*[data-id="search_results"]', 'read') + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 6) + }) + }, + 'Should find regex': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="search_use_regex"]').click('*[data-id="search_use_regex"]') + .waitForElementVisible('*[id="search_input"]') + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', '^contract').pause(1000) + .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/3_BALLOT.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/2_OWNER.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'CONTRACTS/1_STORAGE.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'TESTS/4_BALLOT_TEST.SOL', 60000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 4) + }) + }, + 'Should find matchcase': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="search_use_regex"]').click('*[data-id="search_use_regex"]') + .waitForElementVisible('*[data-id="search_case_sensitive"]').click('*[data-id="search_case_sensitive"]') + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 0) + }) + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'Contract').pause(1000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 6) + }) + .waitForElementContainsText('*[data-id="search_results"]', 'SCRIPTS/DEPLOY_ETHERS.JS', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'SCRIPTS/DEPLOY_WEB3.JS', 60000) + }, + 'Should find matchword': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="search_case_sensitive"]').click('*[data-id="search_case_sensitive"]') + .waitForElementVisible('*[data-id="search_whole_word"]').click('*[data-id="search_whole_word"]') + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'contract').pause(1000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 27) + }) + }, + 'Should replace text': function (browser: NightwatchBrowser) { + browser + .setValue('*[id="search_replace"]', 'replacing').pause(1000) + .waitForElementVisible('*[data-id="contracts/2_Owner.sol-30-71"]') + .moveToElement('*[data-id="contracts/2_Owner.sol-30-71"]', 10, 10) + .waitForElementVisible('*[data-id="replace-contracts/2_Owner.sol-30-71"]') + .click('*[data-id="replace-contracts/2_Owner.sol-30-71"]').pause(2000). + getEditorValue((content) => { + browser.assert.ok(content.includes('replacing deployer for a constructor'), 'should replace text ok') + }) + }, + 'Should find text with include': function (browser: NightwatchBrowser) { + browser + .setValue('*[id="search_include"]', 'contracts/**').pause(2000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 4) + }) + }, + 'Should find text with exclude': function (browser: NightwatchBrowser) { + browser + .clearValue('*[id="search_include"]').pause(2000) + .setValue('*[id="search_include"]', '**').pause(2000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 26) + }) + .setValue('*[id="search_exclude"]', ',contracts/**').pause(2000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 22) + }) + }, + 'should clear search': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[id="search_input"]') + .setValue('*[id="search_input"]', 'nodata').pause(1000) + .elements('css selector','.search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 0) + }) + } +} \ No newline at end of file diff --git a/libs/remix-ui/search/src/lib/components/Exclude.tsx b/libs/remix-ui/search/src/lib/components/Exclude.tsx index c6bdef48e2..4de9a0f30a 100644 --- a/libs/remix-ui/search/src/lib/components/Exclude.tsx +++ b/libs/remix-ui/search/src/lib/components/Exclude.tsx @@ -20,6 +20,7 @@ export const Exclude = props => {
{
{ }} >
{ }} >
{ const { setInclude } = useContext(SearchContext) + const [str, setStr] = useState('') let timeOutId: any = null const change = e => { + setStr(e.target.value) clearTimeout(timeOutId) timeOutId = setTimeout(() => setInclude(e.target.value), 500) } @@ -14,9 +16,11 @@ export const Include = props => {
diff --git a/libs/remix-ui/search/src/lib/components/Replace.tsx b/libs/remix-ui/search/src/lib/components/Replace.tsx index 33b9ba2539..a6ecf39887 100644 --- a/libs/remix-ui/search/src/lib/components/Replace.tsx +++ b/libs/remix-ui/search/src/lib/components/Replace.tsx @@ -14,6 +14,7 @@ export const Replace = props => {
{ const { hightLightInPath, replaceText, state } = useContext(SearchContext) - const selectLine = async (line: SearchResultLineLine) => { await hightLightInPath(props.searchResult, line) } @@ -32,6 +31,7 @@ export const ResultSummary = (props: ResultSummaryProps) => { onClick={async () => { selectLine(lineItem) }} + data-id={`${props.searchResult.filename}-${lineItem.position.start.line}-${lineItem.position.start.column}`} key={props.searchResult.filename} className='search_line pb-1' > @@ -41,7 +41,7 @@ export const ResultSummary = (props: ResultSummaryProps) => {
{lineItem.right.substring(0, 100)}
-
{ +
{ replace(lineItem) }} className="codicon codicon-find-replace" role="button" aria-label="Replace" aria-disabled="false">
diff --git a/libs/remix-ui/search/src/lib/components/results/Results.tsx b/libs/remix-ui/search/src/lib/components/results/Results.tsx index abb8d8ac1b..9a1b717cca 100644 --- a/libs/remix-ui/search/src/lib/components/results/Results.tsx +++ b/libs/remix-ui/search/src/lib/components/results/Results.tsx @@ -6,11 +6,11 @@ export const Results = () => { const { state } = useContext(SearchContext) return ( - <> +
{state.searchResults && state.searchResults.map((result, index) => { return })} - +
) } diff --git a/libs/remix-ui/search/src/lib/context/context.tsx b/libs/remix-ui/search/src/lib/context/context.tsx index 6ba9ba86c1..7ae00dc66e 100644 --- a/libs/remix-ui/search/src/lib/context/context.tsx +++ b/libs/remix-ui/search/src/lib/context/context.tsx @@ -128,8 +128,8 @@ export const SearchProvider = ({ let flags = 'g' let find = state.find if (!state.casesensitive) flags += 'i' - if (state.matchWord) find = `\\b${find}\\b` if (!state.useRegExp) find = escapeRegExp(find) + if (state.matchWord) find = `\\b${find}\\b` const re = new RegExp(find, flags) const result: SearchResultLine[] = findLinesInStringWithMatch(text, re) return result diff --git a/package.json b/package.json index a38866094a..6abfafa406 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "workspace-schematic": "nx workspace-schematic", "dep-graph": "nx dep-graph", "help": "nx help", - "lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd,remix-ui-tree-view,remix-ui-modal-dialog,remix-ui-toaster,remix-ui-helper,remix-ui-debugger-ui,remix-ui-workspace,remix-ui-static-analyser,remix-ui-checkbox,remix-ui-settings,remix-core-plugin,remix-ui-renderer,remix-ui-publish-to-storage,remix-ui-solidity-compiler,solidity-unit-testing,remix-ui-plugin-manager,remix-ui-terminal,remix-ui-editor,remix-ui-app,remix-ui-tabs,remix-ui-panel,remix-ui-run-tab,remix-ui-permission-handler", + "lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd,remix-ui-tree-view,remix-ui-modal-dialog,remix-ui-toaster,remix-ui-helper,remix-ui-debugger-ui,remix-ui-workspace,remix-ui-static-analyser,remix-ui-checkbox,remix-ui-settings,remix-core-plugin,remix-ui-renderer,remix-ui-publish-to-storage,remix-ui-solidity-compiler,solidity-unit-testing,remix-ui-plugin-manager,remix-ui-terminal,remix-ui-editor,remix-ui-app,remix-ui-tabs,remix-ui-panel,remix-ui-run-tab,remix-ui-permission-handler,remix-ui-search", "build:libs": "nx run-many --target=build --parallel=false --with-deps=true --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd", "test:libs": "nx run-many --target=test --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd", "publish:libs": "npm run build:libs && lerna publish --skip-git && npm run bumpVersion:libs", @@ -97,6 +97,7 @@ "nightwatch_local_pluginApi": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/plugin_api_*.js --env=chrome", "nightwatch_local_migrate_filesystem": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/migrateFileSystem.test.js --env=chrome", "nightwatch_local_stress_editor": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/stress.editor.js --env=chromeDesktop", + "nightwatch_local_search": "npm run build:e2e && nightwatch --config dist/apps/remix-ide-e2e/nightwatch.js dist/apps/remix-ide-e2e/src/tests/search.test.js --env=chromeDesktop", "onchange": "onchange apps/remix-ide/build/app.js -- npm-run-all lint", "remixd": "nx build remixd && chmod +x dist/libs/remixd/src/bin/remixd.js && dist/libs/remixd/src/bin/remixd.js -s ./apps/remix-ide/contracts --remix-ide http://127.0.0.1:8080", "selenium": "selenium-standalone start",