From 017e446ce51a1a9eef772a2f07f44f6f63c58a30 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Fri, 22 Mar 2024 10:29:01 +0100 Subject: [PATCH] search test --- .../remixdesktop/src/plugins/ripgrepPlugin.ts | 19 +- .../test/tests/app/search.test.ts | 188 ++++++++++++++++++ 2 files changed, 199 insertions(+), 8 deletions(-) create mode 100644 apps/remixdesktop/test/tests/app/search.test.ts diff --git a/apps/remixdesktop/src/plugins/ripgrepPlugin.ts b/apps/remixdesktop/src/plugins/ripgrepPlugin.ts index 4b620bb596..c53084a566 100644 --- a/apps/remixdesktop/src/plugins/ripgrepPlugin.ts +++ b/apps/remixdesktop/src/plugins/ripgrepPlugin.ts @@ -1,10 +1,9 @@ -import {PluginClient} from '@remixproject/plugin' -import {Profile} from '@remixproject/plugin-utils' -import {ElectronBasePlugin, ElectronBasePluginClient} from '@remixproject/plugin-electron' +import { Profile } from '@remixproject/plugin-utils' +import { ElectronBasePlugin, ElectronBasePluginClient } from '@remixproject/plugin-electron' import path from 'path' -import {rgPath} from '@vscode/ripgrep' +import { rgPath } from '@vscode/ripgrep' import byline from 'byline' -import {spawn} from 'child_process' +import { spawn } from 'child_process' import { SearchInWorkspaceOptions } from '../lib' const profile: Profile = { @@ -69,14 +68,14 @@ export class RipgrepPluginClient extends ElectronBasePluginClient { if (opts && opts.include) { for (const include of opts.include) { if (include !== '') { - globs.push('--glob=' + include) + globs.push('--glob=' + include + '') } } } if (opts && opts.exclude) { for (const exclude of opts.exclude) { if (exclude !== '') { - globs.push('--glob=!=' + exclude) + globs.push('--glob=!' + exclude + '') } } } @@ -85,13 +84,17 @@ export class RipgrepPluginClient extends ElectronBasePluginClient { // replace packed app path with unpacked app path for release on windows const customRgPath = rgPath.includes('app.asar.unpacked') ? rgPath : rgPath.replace('app.asar', 'app.asar.unpacked') + console.log('customRgPath', [...globs, ...args, opts.pattern, '.'], path) + const rg = spawn(customRgPath, [...globs, ...args, opts.pattern, '.'], { + cwd: path + }); - const rg = spawn(customRgPath, [...globs, ...args, opts.pattern, path]) const resultrg: any[] = [] const stream = byline(rg.stdout.setEncoding('utf8')) stream.on('data', (rgresult: string) => { + console.log('rgresult', rgresult) let pathWithoutWorkingDir = rgresult.replace(convertPathToPosix(this.workingDir), '') if (pathWithoutWorkingDir.endsWith('/')) { pathWithoutWorkingDir = pathWithoutWorkingDir.slice(0, -1) diff --git a/apps/remixdesktop/test/tests/app/search.test.ts b/apps/remixdesktop/test/tests/app/search.test.ts new file mode 100644 index 0000000000..f36ab6a584 --- /dev/null +++ b/apps/remixdesktop/test/tests/app/search.test.ts @@ -0,0 +1,188 @@ +import { NightwatchBrowser } from 'nightwatch' + + +module.exports = { + before: function (browser: NightwatchBrowser, done: VoidFunction) { + done() + }, + 'open default template': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="remixIdeIconPanel"]', 10000) + .waitForElementVisible('button[data-id="landingPageImportFromTemplate"]') + .click('button[data-id="landingPageImportFromTemplate"]') + .waitForElementVisible('*[data-id="modalDialogCustomPromptTextCreate"]') + .waitForElementPresent('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') + .click('[data-id="fileSystemModalDialogModalFooter-react"] .modal-ok') + .pause(3000) + .windowHandles(function (result) { + console.log(result.value) + browser.switchWindow(result.value[1]) + .waitForElementVisible('*[data-id="treeViewLitreeViewItemtests"]') + .click('*[data-id="treeViewLitreeViewItemtests"]') + .waitForElementVisible('*[data-id="treeViewLitreeViewItemcontracts"]') + .click('*[data-id="treeViewLitreeViewItemcontracts"]') + .waitForElementVisible('[data-id="treeViewLitreeViewItemcontracts/1_Storage.sol"]') + .openFile('contracts/1_Storage.sol') + .waitForElementVisible('*[id="editorView"]', 10000) + .getEditorValue((content) => { + browser.assert.ok(content.includes('function retrieve() public view returns (uint256){')) + }) + }) + }, + 'Should find text #group1': function (browser: NightwatchBrowser) { + browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]') + .click('*[plugin="search"]').waitForElementVisible('*[id="search_input"]') + .waitForElementVisible('*[id="search_include"]') + .setValue('*[id="search_include"]', ', *.*').pause(2000) + .setValue('*[id="search_input"]', 'read').sendKeys('*[id="search_input"]', browser.Keys.ENTER) + .pause(1000) + .waitForElementContainsText('*[data-id="search_results"]', '3_BALLOT.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'contracts', 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_plugin_search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 6) + }) + }, 'Should find text with exclude #group1': function (browser: NightwatchBrowser) { + browser + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'contract').pause(1000) + .clearValue('*[id="search_include"]').pause(2000) + .setValue('*[id="search_include"]', '**').sendKeys('*[id="search_include"]', browser.Keys.ENTER).pause(4000) + .elements('css selector', '.search_plugin_search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 62) + }) + .setValue('*[id="search_exclude"]', ',contracts/**').sendKeys('*[id="search_exclude"]', browser.Keys.ENTER).pause(4000) + .pause() + .elements('css selector', '.search_plugin_search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 56) + }) + .clearValue('*[id="search_include"]').setValue('*[id="search_include"]', '*.sol, *.js, *.txt') + .clearValue('*[id="search_exclude"]').setValue('*[id="search_exclude"]', '.*/**/*') + }, + 'Should find regex #group1': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[id="search_input"]') + .clearValue('*[id="search_input"]').pause(2000) + .setValue('*[id="search_input"]', '^contract').sendKeys('*[id="search_input"]', browser.Keys.ENTER).pause(3000) + .waitForElementVisible('*[data-id="search_use_regex"]').click('*[data-id="search_use_regex"]').pause(3000) + .waitForElementContainsText('*[data-id="search_results"]', '3_BALLOT.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', '2_OWNER.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', '1_STORAGE.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'BALLOT_TEST.SOL', 60000) + .waitForElementContainsText('*[data-id="search_results"]', 'tests', 60000) + .elements('css selector', '.search_plugin_search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 4) + }) + }, + 'Should find matchcase #group1': 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"]').pause(4000) + .elements('css selector', '.search_plugin_search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 0) + }) + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'Contract').sendKeys('*[id="search_input"]', browser.Keys.ENTER).pause(3000) + .elements('css selector', '.search_plugin_search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 3) + }) + .waitForElementContainsText('*[data-id="search_results"]', 'STORAGE.TEST.JS', 60000) + }, + 'Should find matchword #group1': 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"]').pause(2000) + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'contract').sendKeys('*[id="search_input"]', browser.Keys.ENTER).pause(4000) + .elements('css selector', '.search_plugin_search_line', (res) => { + Array.isArray(res.value) && browser.assert.equal(res.value.length, 15) + }) + }, + 'Should replace text #group1': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="toggle_replace"]').click('*[data-id="toggle_replace"]') + .waitForElementVisible('*[id="search_replace"]') + .setValue('*[id="search_replace"]', 'replacing').sendKeys('*[id="search_replace"]', browser.Keys.ENTER).pause(1000) + .waitForElementVisible('*[data-id="contracts/2_Owner.sol-33-71"]') + .moveToElement('*[data-id="contracts/2_Owner.sol-33-71"]', 10, 10) + .waitForElementVisible('*[data-id="replace-contracts/2_Owner.sol-33-71"]') + .click('*[data-id="replace-contracts/2_Owner.sol-33-71"]').pause(2000). + modalFooterOKClick('confirmreplace').pause(2000). + getEditorValue((content) => { + browser.assert.ok(content.includes('replacing deployer for a constructor'), 'should replace text ok') + }) + }, + 'Should replace text without confirmation #group1': function (browser: NightwatchBrowser) { + browser.click('*[data-id="confirm_replace_label"]').pause(500) + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'replacing').sendKeys('*[id="search_input"]', browser.Keys.ENTER).pause(1000) + .setValue('*[id="search_replace"]', 'replacing2').pause(1000) + .waitForElementVisible('*[data-id="contracts/2_Owner.sol-33-71"]') + .moveToElement('*[data-id="contracts/2_Owner.sol-33-71"]', 10, 10) + .waitForElementVisible('*[data-id="replace-contracts/2_Owner.sol-33-71"]') + .click('*[data-id="replace-contracts/2_Owner.sol-33-71"]').pause(2000). + getEditorValue((content) => { + browser.assert.ok(content.includes('replacing2 deployer for a constructor'), 'should replace text ok') + }) + }, + 'Should replace all & undo #group1': function (browser: NightwatchBrowser) { + browser + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'storage').sendKeys('*[id="search_input"]', browser.Keys.ENTER) + .clearValue('*[id="search_replace"]') + .setValue('*[id="search_replace"]', '123test').pause(1000) + .waitForElementVisible('*[data-id="replace-all-contracts/1_Storage.sol"]') + .click('*[data-id="replace-all-contracts/1_Storage.sol"]').pause(2000) + .getEditorValue((content) => { + browser.assert.ok(content.includes('contract 123test'), 'should replace text ok') + browser.assert.ok(content.includes('title 123test'), 'should replace text ok') + }) + .waitForElementVisible('*[data-id="undo-replace-contracts/1_Storage.sol"]') + .click('*[data-id="undo-replace-contracts/1_Storage.sol"]').pause(2000) + .getEditorValue((content) => { + browser.assert.ok(content.includes('contract Storage'), 'should undo text ok') + browser.assert.ok(content.includes('title Storage'), 'should undo text ok') + }) + }, + 'Should replace all & undo & switch between files #group1': function (browser: NightwatchBrowser) { + browser.waitForElementVisible('*[id="search_input"]') + .clearValue('*[id="search_input"]') + .setValue('*[id="search_input"]', 'storage').sendKeys('*[id="search_input"]', browser.Keys.ENTER) + .clearValue('*[id="search_replace"]') + .setValue('*[id="search_replace"]', '123test').pause(1000) + .waitForElementVisible('*[data-id="replace-all-contracts/1_Storage.sol"]') + .click('*[data-id="replace-all-contracts/1_Storage.sol"]').pause(2000) + .getEditorValue((content) => { + browser.assert.ok(content.includes('contract 123test'), 'should replace text ok') + browser.assert.ok(content.includes('title 123test'), 'should replace text ok') + }) + .waitForElementVisible('*[data-id="undo-replace-contracts/1_Storage.sol"]') + .openFile('README.txt') + .click('*[plugin="search"]').pause(2000) + .waitForElementNotPresent('*[data-id="undo-replace-contracts/1_Storage.sol"]') + .waitForElementVisible('*[data-id="replace-all-README.txt"]') + .click('*[data-id="replace-all-README.txt"]').pause(2000) + .getEditorValue((content) => { + browser.assert.ok(content.includes("123test' contract"), 'should replace text ok') + }) + .waitForElementVisible('*[data-id="undo-replace-README.txt"]') + .click('div[data-path="default_workspace/contracts/1_Storage.sol"]').pause(2000) + .waitForElementVisible('*[data-id="undo-replace-contracts/1_Storage.sol"]') + .click('*[data-id="undo-replace-contracts/1_Storage.sol"]').pause(2000) + .getEditorValue((content) => { + browser.assert.ok(content.includes('contract Storage'), 'should undo text ok') + browser.assert.ok(content.includes('title Storage'), 'should undo text ok') + }) + .click('div[data-path="default_workspace/README.txt"]').pause(2000) + .waitForElementVisible('*[data-id="undo-replace-README.txt"]') + .click('*[data-id="undo-replace-README.txt"]').pause(2000) + .getEditorValue((content) => { + browser.assert.ok(content.includes("Storage' contract"), 'should replace text ok') + }) + } +} \ No newline at end of file