pull/5370/head
filip mertens 3 years ago
parent 28b9586be2
commit 138cd2f589
  1. 103
      apps/remix-ide-e2e/src/tests/search.test.ts
  2. 1
      libs/remix-ui/search/src/lib/components/Exclude.tsx
  3. 4
      libs/remix-ui/search/src/lib/components/Find.tsx
  4. 6
      libs/remix-ui/search/src/lib/components/Include.tsx
  5. 1
      libs/remix-ui/search/src/lib/components/Replace.tsx
  6. 4
      libs/remix-ui/search/src/lib/components/results/ResultSummary.tsx
  7. 4
      libs/remix-ui/search/src/lib/components/results/Results.tsx
  8. 2
      libs/remix-ui/search/src/lib/context/context.tsx
  9. 3
      package.json

@ -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)
})
}
}

@ -20,6 +20,7 @@ export const Exclude = props => {
<div className="find-part">
<label>exclude</label>
<input
id='search_exclude'
placeholder="Exclude ie .git/**/*"
className="form-control"
onChange={change}

@ -21,12 +21,14 @@ export const Find = props => {
<label>search</label>
<div className="search-input">
<input
id='search_input'
placeholder="Search"
className="form-control"
onChange={change}
></input>
<div className="controls">
<div
data-id='search_case_sensitive'
title="Match Case"
className={`monaco-custom-checkbox codicon codicon-case-sensitive ${
state.casesensitive ? 'checked' : ''
@ -40,6 +42,7 @@ export const Find = props => {
}}
></div>
<div
data-id='search_whole_word'
title="Match Whole Word"
className={`monaco-custom-checkbox codicon codicon-whole-word ${
state.matchWord ? 'checked' : ''
@ -53,6 +56,7 @@ export const Find = props => {
}}
></div>
<div
data-id='search_use_regex'
title="Use Regular Expression"
className={`monaco-custom-checkbox codicon codicon-regex ${
state.useRegExp ? 'checked' : ''

@ -1,10 +1,12 @@
import React, { useContext } from 'react'
import React, { useContext, useState } from 'react'
import { SearchContext } from '../context/context'
export const Include = props => {
const { setInclude } = useContext(SearchContext)
const [str, setStr] = useState<string>('')
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 => {
<div className="find-part">
<label>include</label>
<input
id='search_include'
placeholder="Include ie contracts/**/*.sol"
className="form-control"
onChange={change}
value={str}
></input>
</div>
</>

@ -14,6 +14,7 @@ export const Replace = props => {
<div className="find-part">
<label>replace</label>
<input
id='search_replace'
placeholder="Replace"
className="form-control"
onChange={change}

@ -10,7 +10,6 @@ interface ResultSummaryProps {
export const ResultSummary = (props: ResultSummaryProps) => {
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) => {
<div className='summary_right'>{lineItem.right.substring(0, 100)}</div>
</div>
<div className='search_control'>
<div title="Replace" onClick={async () => {
<div title="Replace" data-id={`replace-${props.searchResult.filename}-${lineItem.position.start.line}-${lineItem.position.start.column}`} onClick={async () => {
replace(lineItem)
}} className="codicon codicon-find-replace" role="button" aria-label="Replace" aria-disabled="false"></div>
</div>

@ -6,11 +6,11 @@ export const Results = () => {
const { state } = useContext(SearchContext)
return (
<>
<div data-id='search_results'>
{state.searchResults &&
state.searchResults.map((result, index) => {
return <ResultItem key={index} file={result} />
})}
</>
</div>
)
}

@ -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

@ -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",

Loading…
Cancel
Save