fix bugs & tests

pull/2257/head^2
filip mertens 3 years ago committed by yann300
parent 9524c22d26
commit beb47308ff
  1. 387
      apps/remix-ide-e2e/src/tests/search.test.ts
  2. 13
      libs/remix-ui/search/src/lib/components/Exclude.tsx
  3. 6
      libs/remix-ui/search/src/lib/components/Find.tsx
  4. 7
      libs/remix-ui/search/src/lib/components/Include.tsx
  5. 8
      libs/remix-ui/search/src/lib/context/context.tsx
  6. 10
      libs/remix-ui/search/src/lib/reducers/Reducer.ts

@ -9,229 +9,228 @@ module.exports = {
}, },
'Should find text': function (browser: NightwatchBrowser) { 'Should find text': function (browser: NightwatchBrowser) {
browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]') browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]')
.click('*[plugin="search"]').waitForElementVisible('*[id="search_input"]') .click('*[plugin="search"]').waitForElementVisible('*[id="search_input"]')
.setValue('*[id="search_input"]', 'read').pause(1000) .waitForElementVisible('*[id="search_include"]')
.waitForElementContainsText('*[data-id="search_results"]', '3_BALLOT.SOL', 60000) .setValue('*[id="search_include"]', ', *.txt').pause(2000)
.waitForElementContainsText('*[data-id="search_results"]', 'contracts', 60000) .setValue('*[id="search_input"]', 'read').sendKeys('*[id="search_input"]', browser.Keys.ENTER)
.waitForElementContainsText('*[data-id="search_results"]', 'README.TXT', 60000) .pause(1000)
.waitForElementContainsText('*[data-id="search_results"]', 'file must') .waitForElementContainsText('*[data-id="search_results"]', '3_BALLOT.SOL', 60000)
.waitForElementContainsText('*[data-id="search_results"]', 'be compiled') .waitForElementContainsText('*[data-id="search_results"]', 'contracts', 60000)
.waitForElementContainsText('*[data-id="search_results"]', 'that person al') .waitForElementContainsText('*[data-id="search_results"]', 'README.TXT', 60000)
.waitForElementContainsText('*[data-id="search_results"]', 'sender.voted') .waitForElementContainsText('*[data-id="search_results"]', 'file must')
.waitForElementContainsText('*[data-id="search_results"]', 'read') .waitForElementContainsText('*[data-id="search_results"]', 'be compiled')
.elements('css selector','.search_plugin_search_line', (res) => { .waitForElementContainsText('*[data-id="search_results"]', 'that person al')
Array.isArray(res.value) && browser.assert.equal(res.value.length, 6) .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': 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, 45)
})
.setValue('*[id="search_exclude"]', ',contracts/**').sendKeys('*[id="search_exclude"]', browser.Keys.ENTER).pause(4000)
.elements('css selector', '.search_plugin_search_line', (res) => {
Array.isArray(res.value) && browser.assert.equal(res.value.length, 40)
})
.clearValue('*[id="search_include"]').setValue('*[id="search_include"]', '*.sol, *.js, *.txt')
.clearValue('*[id="search_exclude"]').setValue('*[id="search_exclude"]', '.*/**/*')
}, },
'Should find regex': function (browser: NightwatchBrowser) { 'Should find regex': function (browser: NightwatchBrowser) {
browser browser
.waitForElementVisible('*[data-id="search_use_regex"]').click('*[data-id="search_use_regex"]') .waitForElementVisible('*[data-id="search_use_regex"]').click('*[data-id="search_use_regex"]')
.waitForElementVisible('*[id="search_input"]') .waitForElementVisible('*[id="search_input"]')
.clearValue('*[id="search_input"]') .clearValue('*[id="search_input"]')
.setValue('*[id="search_input"]', '^contract').pause(1000) .setValue('*[id="search_input"]', '^contract').sendKeys('*[id="search_input"]', browser.Keys.ENTER)
.waitForElementContainsText('*[data-id="search_results"]', '3_BALLOT.SOL', 60000) .waitForElementContainsText('*[data-id="search_results"]', '3_BALLOT.SOL', 60000)
.waitForElementContainsText('*[data-id="search_results"]', '2_OWNER.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"]', '1_STORAGE.SOL', 60000)
.waitForElementContainsText('*[data-id="search_results"]', 'BALLOT_TEST.SOL', 60000) .waitForElementContainsText('*[data-id="search_results"]', '4_BALLOT_TEST.SOL', 60000)
.waitForElementContainsText('*[data-id="search_results"]', 'tests', 60000) .waitForElementContainsText('*[data-id="search_results"]', 'tests', 60000)
.elements('css selector','.search_plugin_search_line', (res) => { .elements('css selector', '.search_plugin_search_line', (res) => {
Array.isArray(res.value) && browser.assert.equal(res.value.length, 4) Array.isArray(res.value) && browser.assert.equal(res.value.length, 4)
}) })
}, },
'Should find matchcase': function (browser: NightwatchBrowser) { 'Should find matchcase': function (browser: NightwatchBrowser) {
browser browser
.waitForElementVisible('*[data-id="search_use_regex"]').click('*[data-id="search_use_regex"]') .waitForElementVisible('*[data-id="search_use_regex"]').click('*[data-id="search_use_regex"]')
.waitForElementVisible('*[data-id="search_case_sensitive"]').click('*[data-id="search_case_sensitive"]') .waitForElementVisible('*[data-id="search_case_sensitive"]').click('*[data-id="search_case_sensitive"]').pause(4000)
.elements('css selector','.search_plugin_search_line', (res) => { .elements('css selector', '.search_plugin_search_line', (res) => {
Array.isArray(res.value) && browser.assert.equal(res.value.length, 0) Array.isArray(res.value) && browser.assert.equal(res.value.length, 0)
}) })
.clearValue('*[id="search_input"]') .clearValue('*[id="search_input"]')
.setValue('*[id="search_input"]', 'Contract').pause(1000) .setValue('*[id="search_input"]', 'Contract').sendKeys('*[id="search_input"]', browser.Keys.ENTER).pause(1000)
.elements('css selector','.search_plugin_search_line', (res) => { .elements('css selector', '.search_plugin_search_line', (res) => {
Array.isArray(res.value) && browser.assert.equal(res.value.length, 9) Array.isArray(res.value) && browser.assert.equal(res.value.length, 9)
}) })
.waitForElementContainsText('*[data-id="search_results"]', 'DEPLOY_ETHERS.JS', 60000) .waitForElementContainsText('*[data-id="search_results"]', 'DEPLOY_ETHERS.JS', 60000)
.waitForElementContainsText('*[data-id="search_results"]', 'DEPLOY_WEB3.JS', 60000) .waitForElementContainsText('*[data-id="search_results"]', 'DEPLOY_WEB3.JS', 60000)
.waitForElementContainsText('*[data-id="search_results"]', 'STORAGE.TEST.JS', 60000) .waitForElementContainsText('*[data-id="search_results"]', 'STORAGE.TEST.JS', 60000)
.waitForElementContainsText('*[data-id="search_results"]', 'scripts', 60000) .waitForElementContainsText('*[data-id="search_results"]', 'scripts', 60000)
}, },
'Should find matchword': function (browser: NightwatchBrowser) { 'Should find matchword': function (browser: NightwatchBrowser) {
browser browser
.waitForElementVisible('*[data-id="search_case_sensitive"]').click('*[data-id="search_case_sensitive"]') .waitForElementVisible('*[data-id="search_case_sensitive"]').click('*[data-id="search_case_sensitive"]')
.waitForElementVisible('*[data-id="search_whole_word"]').click('*[data-id="search_whole_word"]') .waitForElementVisible('*[data-id="search_whole_word"]').click('*[data-id="search_whole_word"]').pause(2000)
.clearValue('*[id="search_input"]') .clearValue('*[id="search_input"]')
.setValue('*[id="search_input"]', 'contract').pause(1000) .setValue('*[id="search_input"]', 'contract').sendKeys('*[id="search_input"]', browser.Keys.ENTER).pause(4000)
.elements('css selector','.search_plugin_search_line', (res) => { .elements('css selector', '.search_plugin_search_line', (res) => {
Array.isArray(res.value) && browser.assert.equal(res.value.length, 29) Array.isArray(res.value) && browser.assert.equal(res.value.length, 29)
}) })
}, },
'Should replace text': function (browser: NightwatchBrowser) { 'Should replace text': function (browser: NightwatchBrowser) {
browser browser
.waitForElementVisible('*[data-id="toggle_replace"]').click('*[data-id="toggle_replace"]') .waitForElementVisible('*[data-id="toggle_replace"]').click('*[data-id="toggle_replace"]')
.waitForElementVisible('*[id="search_replace"]') .waitForElementVisible('*[id="search_replace"]')
.setValue('*[id="search_replace"]', 'replacing').pause(1000) .setValue('*[id="search_replace"]', 'replacing').pause(1000)
.waitForElementVisible('*[data-id="contracts/2_Owner.sol-30-71"]') .waitForElementVisible('*[data-id="contracts/2_Owner.sol-30-71"]')
.moveToElement('*[data-id="contracts/2_Owner.sol-30-71"]', 10, 10) .moveToElement('*[data-id="contracts/2_Owner.sol-30-71"]', 10, 10)
.waitForElementVisible('*[data-id="replace-contracts/2_Owner.sol-30-71"]') .waitForElementVisible('*[data-id="replace-contracts/2_Owner.sol-30-71"]')
.click('*[data-id="replace-contracts/2_Owner.sol-30-71"]').pause(2000). .click('*[data-id="replace-contracts/2_Owner.sol-30-71"]').pause(2000).
modalFooterOKClick('confirmreplace').pause(2000). modalFooterOKClick('confirmreplace').pause(2000).
getEditorValue((content) => { getEditorValue((content) => {
browser.assert.ok(content.includes('replacing deployer for a constructor'), 'should replace text ok') browser.assert.ok(content.includes('replacing deployer for a constructor'), 'should replace text ok')
}) })
}, },
'Should replace text without confirmation': function (browser: NightwatchBrowser) { 'Should replace text without confirmation': function (browser: NightwatchBrowser) {
browser.click('*[data-id="confirm_replace_label"]').pause(500) browser.click('*[data-id="confirm_replace_label"]').pause(500)
.clearValue('*[id="search_input"]') .clearValue('*[id="search_input"]')
.setValue('*[id="search_input"]', 'replacing').pause(1000) .setValue('*[id="search_input"]', 'replacing').sendKeys('*[id="search_input"]', browser.Keys.ENTER).pause(1000)
.setValue('*[id="search_replace"]', '2').pause(1000) .setValue('*[id="search_replace"]', '2').pause(1000)
.waitForElementVisible('*[data-id="contracts/2_Owner.sol-30-71"]') .waitForElementVisible('*[data-id="contracts/2_Owner.sol-30-71"]')
.moveToElement('*[data-id="contracts/2_Owner.sol-30-71"]', 10, 10) .moveToElement('*[data-id="contracts/2_Owner.sol-30-71"]', 10, 10)
.waitForElementVisible('*[data-id="replace-contracts/2_Owner.sol-30-71"]') .waitForElementVisible('*[data-id="replace-contracts/2_Owner.sol-30-71"]')
.click('*[data-id="replace-contracts/2_Owner.sol-30-71"]').pause(2000). .click('*[data-id="replace-contracts/2_Owner.sol-30-71"]').pause(2000).
getEditorValue((content) => { getEditorValue((content) => {
browser.assert.ok(content.includes('replacing2 deployer for a constructor'), 'should replace text ok') browser.assert.ok(content.includes('replacing2 deployer for a constructor'), 'should replace text ok')
}) })
}, },
'Should replace all & undo': function (browser: NightwatchBrowser) { 'Should replace all & undo': function (browser: NightwatchBrowser) {
browser browser
.clearValue('*[id="search_input"]') .clearValue('*[id="search_input"]')
.setValue('*[id="search_input"]', 'storage') .setValue('*[id="search_input"]', 'storage').sendKeys('*[id="search_input"]', browser.Keys.ENTER)
.clearValue('*[id="search_replace"]') .clearValue('*[id="search_replace"]')
.setValue('*[id="search_replace"]', '123test').pause(1000) .setValue('*[id="search_replace"]', '123test').pause(1000)
.waitForElementVisible('*[data-id="replace-all-contracts/1_Storage.sol"]') .waitForElementVisible('*[data-id="replace-all-contracts/1_Storage.sol"]')
.click('*[data-id="replace-all-contracts/1_Storage.sol"]').pause(2000) .click('*[data-id="replace-all-contracts/1_Storage.sol"]').pause(2000)
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes('contract 123test'), 'should replace text ok') browser.assert.ok(content.includes('contract 123test'), 'should replace text ok')
browser.assert.ok(content.includes('title 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"]') .waitForElementVisible('*[data-id="undo-replace-contracts/1_Storage.sol"]')
.click('*[data-id="undo-replace-contracts/1_Storage.sol"]').pause(2000) .click('*[data-id="undo-replace-contracts/1_Storage.sol"]').pause(2000)
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes('contract Storage'), 'should undo text ok') browser.assert.ok(content.includes('contract Storage'), 'should undo text ok')
browser.assert.ok(content.includes('title Storage'), 'should undo text ok') browser.assert.ok(content.includes('title Storage'), 'should undo text ok')
}) })
}, },
'Should replace all & undo & switch between files': function (browser: NightwatchBrowser) { 'Should replace all & undo & switch between files': function (browser: NightwatchBrowser) {
browser.waitForElementVisible('*[id="search_input"]') browser.waitForElementVisible('*[id="search_input"]')
.clearValue('*[id="search_input"]') .clearValue('*[id="search_input"]')
.setValue('*[id="search_input"]', 'storage') .setValue('*[id="search_input"]', 'storage').sendKeys('*[id="search_input"]', browser.Keys.ENTER)
.clearValue('*[id="search_replace"]') .clearValue('*[id="search_replace"]')
.setValue('*[id="search_replace"]', '123test').pause(1000) .setValue('*[id="search_replace"]', '123test').pause(1000)
.waitForElementVisible('*[data-id="replace-all-contracts/1_Storage.sol"]') .waitForElementVisible('*[data-id="replace-all-contracts/1_Storage.sol"]')
.click('*[data-id="replace-all-contracts/1_Storage.sol"]').pause(2000) .click('*[data-id="replace-all-contracts/1_Storage.sol"]').pause(2000)
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes('contract 123test'), 'should replace text ok') browser.assert.ok(content.includes('contract 123test'), 'should replace text ok')
browser.assert.ok(content.includes('title 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"]') .waitForElementVisible('*[data-id="undo-replace-contracts/1_Storage.sol"]')
.openFile('README.txt') .openFile('README.txt')
.click('*[plugin="search"]').pause(2000) .click('*[plugin="search"]').pause(2000)
.waitForElementNotPresent('*[data-id="undo-replace-contracts/1_Storage.sol"]') .waitForElementNotPresent('*[data-id="undo-replace-contracts/1_Storage.sol"]')
.waitForElementVisible('*[data-id="replace-all-README.txt"]') .waitForElementVisible('*[data-id="replace-all-README.txt"]')
.click('*[data-id="replace-all-README.txt"]').pause(2000) .click('*[data-id="replace-all-README.txt"]').pause(2000)
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes("123test' contract"), 'should replace text ok') browser.assert.ok(content.includes("123test' contract"), 'should replace text ok')
}) })
.waitForElementVisible('*[data-id="undo-replace-README.txt"]') .waitForElementVisible('*[data-id="undo-replace-README.txt"]')
.click('div[title="default_workspace/contracts/1_Storage.sol"]').pause(2000) .click('div[title="default_workspace/contracts/1_Storage.sol"]').pause(2000)
.waitForElementVisible('*[data-id="undo-replace-contracts/1_Storage.sol"]') .waitForElementVisible('*[data-id="undo-replace-contracts/1_Storage.sol"]')
.click('*[data-id="undo-replace-contracts/1_Storage.sol"]').pause(2000) .click('*[data-id="undo-replace-contracts/1_Storage.sol"]').pause(2000)
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes('contract Storage'), 'should undo text ok') browser.assert.ok(content.includes('contract Storage'), 'should undo text ok')
browser.assert.ok(content.includes('title Storage'), 'should undo text ok') browser.assert.ok(content.includes('title Storage'), 'should undo text ok')
}) })
.click('div[title="default_workspace/README.txt"]').pause(2000) .click('div[title="default_workspace/README.txt"]').pause(2000)
.waitForElementVisible('*[data-id="undo-replace-README.txt"]') .waitForElementVisible('*[data-id="undo-replace-README.txt"]')
.click('*[data-id="undo-replace-README.txt"]').pause(2000) .click('*[data-id="undo-replace-README.txt"]').pause(2000)
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes("Storage' contract"), 'should replace text ok') browser.assert.ok(content.includes("Storage' contract"), 'should replace text ok')
}) })
}, },
'Should hide button when edited content is the same': function (browser: NightwatchBrowser) { 'Should hide button when edited content is the same': function (browser: NightwatchBrowser) {
browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]') browser.waitForElementVisible('*[data-id="remixIdeSidePanel"]')
.addFile('test.sol', { content: '123'}) .addFile('test.sol', { content: '123' })
.click('*[plugin="search"]').waitForElementVisible('*[id="search_input"]') .click('*[plugin="search"]').waitForElementVisible('*[id="search_input"]')
.clearValue('*[id="search_input"]') .clearValue('*[id="search_input"]')
.setValue('*[id="search_input"]', '123') .setValue('*[id="search_input"]', '123').sendKeys('*[id="search_input"]', browser.Keys.ENTER)
.clearValue('*[id="search_replace"]') .clearValue('*[id="search_replace"]')
.setValue('*[id="search_replace"]', '456').pause(1000) .setValue('*[id="search_replace"]', '456').pause(1000)
.waitForElementVisible('*[data-id="replace-all-test.sol"]') .waitForElementVisible('*[data-id="replace-all-test.sol"]')
.click('*[data-id="replace-all-test.sol"]').pause(2000) .click('*[data-id="replace-all-test.sol"]').pause(2000)
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes('456'), 'should replace text ok') browser.assert.ok(content.includes('456'), 'should replace text ok')
} }
) )
.setEditorValue('123') .setEditorValue('123')
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes('123'), 'should have text ok') browser.assert.ok(content.includes('123'), 'should have text ok')
} }
).pause(1000) ).pause(1000)
.waitForElementNotPresent('*[data-id="undo-replace-test.sol"]') .waitForElementNotPresent('*[data-id="undo-replace-test.sol"]')
}, },
'Should disable/enable button when edited content changed': function (browser: NightwatchBrowser) { 'Should disable/enable button when edited content changed': function (browser: NightwatchBrowser) {
browser browser
.waitForElementVisible('*[id="search_input"]') .waitForElementVisible('*[id="search_input"]')
.clearValue('*[id="search_input"]') .clearValue('*[id="search_input"]')
.setValue('*[id="search_input"]', '123') .setValue('*[id="search_input"]', '123').sendKeys('*[id="search_input"]', browser.Keys.ENTER)
.clearValue('*[id="search_replace"]') .clearValue('*[id="search_replace"]')
.setValue('*[id="search_replace"]', 'replaced').pause(1000) .setValue('*[id="search_replace"]', 'replaced').pause(1000)
.waitForElementVisible('*[data-id="replace-all-test.sol"]') .waitForElementVisible('*[data-id="replace-all-test.sol"]')
.click('*[data-id="replace-all-test.sol"]').pause(2000) .click('*[data-id="replace-all-test.sol"]').pause(2000)
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes('replaced'), 'should replace text ok') browser.assert.ok(content.includes('replaced'), 'should replace text ok')
} }
) )
.setEditorValue('changed') .setEditorValue('changed')
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes('changed'), 'should have text ok') browser.assert.ok(content.includes('changed'), 'should have text ok')
} }
).pause(1000) ).pause(1000)
.waitForElementVisible('*[data-id="undo-replace-test.sol"]') .waitForElementVisible('*[data-id="undo-replace-test.sol"]')
.getAttribute('[data-id="undo-replace-test.sol"]', 'disabled', (result) => { .getAttribute('[data-id="undo-replace-test.sol"]', 'disabled', (result) => {
browser.assert.equal(result.value, 'true', 'should be disabled') browser.assert.equal(result.value, 'true', 'should be disabled')
}) })
.setEditorValue('replaced') .setEditorValue('replaced')
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes('replaced'), 'should have text ok') browser.assert.ok(content.includes('replaced'), 'should have text ok')
} }
).pause(1000) ).pause(1000)
.waitForElementVisible('*[data-id="undo-replace-test.sol"]') .waitForElementVisible('*[data-id="undo-replace-test.sol"]')
.getAttribute('[data-id="undo-replace-test.sol"]', 'disabled', (result) => { .getAttribute('[data-id="undo-replace-test.sol"]', 'disabled', (result) => {
browser.assert.equal(result.value, null, 'should not be disabled') browser.assert.equal(result.value, null, 'should not be disabled')
}) })
.click('*[data-id="undo-replace-test.sol"]').pause(2000) .click('*[data-id="undo-replace-test.sol"]').pause(2000)
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.includes('123'), 'should have text ok') browser.assert.ok(content.includes('123'), 'should have text ok')
}) })
.waitForElementNotPresent('*[data-id="undo-replace-test.sol"]') .waitForElementNotPresent('*[data-id="undo-replace-test.sol"]')
},
'Should find text with include': function (browser: NightwatchBrowser) {
browser
.clearValue('*[id="search_input"]')
.setValue('*[id="search_input"]', 'contract').pause(1000)
.setValue('*[id="search_include"]', 'contracts/**').pause(2000)
.elements('css selector','.search_plugin_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_plugin_search_line', (res) => {
Array.isArray(res.value) && browser.assert.equal(res.value.length, 28)
})
.setValue('*[id="search_exclude"]', ',contracts/**').pause(2000)
.elements('css selector','.search_plugin_search_line', (res) => {
Array.isArray(res.value) && browser.assert.equal(res.value.length, 24)
})
}, },
'should clear search': function (browser: NightwatchBrowser) { 'should clear search': function (browser: NightwatchBrowser) {
browser browser
.waitForElementVisible('*[id="search_input"]') .waitForElementVisible('*[id="search_input"]')
.setValue('*[id="search_input"]', 'nodata').pause(1000) .setValue('*[id="search_input"]', 'nodata').sendKeys('*[id="search_input"]', browser.Keys.ENTER).pause(1000)
.elements('css selector','.search_plugin_search_line', (res) => { .elements('css selector', '.search_plugin_search_line', (res) => {
Array.isArray(res.value) && browser.assert.equal(res.value.length, 0) Array.isArray(res.value) && browser.assert.equal(res.value.length, 0)
}) })
} }
} }

@ -2,7 +2,7 @@ import React, { useContext, useEffect, useRef, useState } from 'react'
import { SearchContext } from '../context/context' import { SearchContext } from '../context/context'
export const Exclude = props => { export const Exclude = props => {
const { setExclude, cancelSearch } = useContext(SearchContext) const { setExclude, cancelSearch, startSearch } = useContext(SearchContext)
const [excludeInput, setExcludeInput] = useState<string>('.*/**/*') const [excludeInput, setExcludeInput] = useState<string>('.*/**/*')
const change = async e => { const change = async e => {
@ -11,8 +11,9 @@ export const Exclude = props => {
} }
const handleKeypress = async e => { const handleKeypress = async e => {
await setExclude(excludeInput)
if (e.charCode === 13 || e.keyCode === 13) { if (e.charCode === 13 || e.keyCode === 13) {
await setExclude(excludeInput) startSearch()
} }
} }
@ -25,11 +26,11 @@ export const Exclude = props => {
<div className="search_plugin_find-part pl-3"> <div className="search_plugin_find-part pl-3">
<label className='mt-2'>Files to exclude</label> <label className='mt-2'>Files to exclude</label>
<input <input
id='search_exclude ( Enter to exclude )' id='search_exclude'
placeholder="Exclude ie .git/**/*" placeholder="Exclude ie .git/**/* ( Enter to exclude )"
className="form-control" className="form-control"
onKeyPress={handleKeypress} onKeyUp={handleKeypress}
onChange={async(e) => change(e)} onChange={async (e) => change(e)}
value={excludeInput} value={excludeInput}
></input> ></input>
</div> </div>

@ -5,6 +5,7 @@ export const Find = () => {
const { const {
setFind, setFind,
cancelSearch, cancelSearch,
startSearch,
state, state,
toggleCaseSensitive, toggleCaseSensitive,
toggleMatchWholeWord, toggleMatchWholeWord,
@ -19,8 +20,9 @@ export const Find = () => {
const handleKeypress = async e => { const handleKeypress = async e => {
if (e.charCode === 13 || e.keyCode === 13) { if (e.charCode === 13 || e.keyCode === 13) {
await setFind(inputValue) startSearch()
} }
await setFind(inputValue)
} }
useEffect(() => { useEffect(() => {
@ -37,7 +39,7 @@ export const Find = () => {
className="form-control" className="form-control"
value={inputValue} value={inputValue}
onChange={async e => await change(e)} onChange={async e => await change(e)}
onKeyPress={handleKeypress} onKeyUp={handleKeypress}
></input> ></input>
<div className="search_plugin_controls"> <div className="search_plugin_controls">
<div <div

@ -2,15 +2,16 @@ import React, { useContext, useEffect, useRef, useState } from 'react'
import { SearchContext } from '../context/context' import { SearchContext } from '../context/context'
export const Include = props => { export const Include = props => {
const { setInclude, cancelSearch } = useContext(SearchContext) const { setInclude, cancelSearch, startSearch } = useContext(SearchContext)
const [includeInput, setIncludeInput] = useState<string>('*.sol, *.js') const [includeInput, setIncludeInput] = useState<string>('*.sol, *.js')
const change = async e => { const change = async e => {
setIncludeInput(e.target.value) setIncludeInput(e.target.value)
await cancelSearch() await cancelSearch()
} }
const handleKeypress = async e => { const handleKeypress = async e => {
await setInclude(includeInput)
if (e.charCode === 13 || e.keyCode === 13) { if (e.charCode === 13 || e.keyCode === 13) {
await setInclude(includeInput) startSearch()
} }
} }
@ -27,7 +28,7 @@ export const Include = props => {
placeholder="Include ie *.sol ( Enter to include )" placeholder="Include ie *.sol ( Enter to include )"
className="form-control" className="form-control"
onChange={async(e) => change(e)} onChange={async(e) => change(e)}
onKeyPress={handleKeypress} onKeyUp={handleKeypress}
value={includeInput} value={includeInput}
></input> ></input>
</div> </div>

@ -46,6 +46,7 @@ export interface SearchingStateInterface {
undoReplace: (buffer: undoBufferRecord) => Promise<void> undoReplace: (buffer: undoBufferRecord) => Promise<void>
clearUndo: () => void clearUndo: () => void
cancelSearch: (clearResults?:boolean) => Promise<void> cancelSearch: (clearResults?:boolean) => Promise<void>
startSearch: () => void
} }
export const SearchContext = createContext<SearchingStateInterface>(null) export const SearchContext = createContext<SearchingStateInterface>(null)
@ -177,6 +178,13 @@ export const SearchProvider = ({
}) })
}, },
startSearch: () => {
dispatch({
type: 'START_SEARCH',
payload: undefined
})
},
setRun(value: boolean) { setRun(value: boolean) {
dispatch({ dispatch({
type: 'SET_RUN', type: 'SET_RUN',

@ -2,12 +2,16 @@ import { Action, SearchingInitialState, SearchState, undoBufferRecord } from "..
export const SearchReducer = (state: SearchState = SearchingInitialState, action: Action) => { export const SearchReducer = (state: SearchState = SearchingInitialState, action: Action) => {
switch (action.type) { switch (action.type) {
case 'START_SEARCH':
return {
...state,
timeStamp: Date.now()
}
case 'SET_FIND': case 'SET_FIND':
return { return {
...state, ...state,
searchResults: null, searchResults: null,
find: action.payload, find: action.payload
timeStamp: Date.now()
} }
case 'SET_REPLACE': case 'SET_REPLACE':
@ -26,14 +30,12 @@ export const SearchReducer = (state: SearchState = SearchingInitialState, action
return { return {
...state, ...state,
include: action.payload, include: action.payload,
timeStamp: Date.now()
} }
case 'SET_EXCLUDE': case 'SET_EXCLUDE':
return { return {
...state, ...state,
exclude: action.payload, exclude: action.payload,
timeStamp: Date.now()
} }
case 'SET_SEARCH_RESULTS': case 'SET_SEARCH_RESULTS':

Loading…
Cancel
Save