Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadow roots #104

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/background/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function getDefaultStorage(): SearchReplacePopupStorage {
replaceTerm: '',
options: {
matchCase: false,
inputFieldsOnly: false,
inputFieldsOnly: true,
hiddenContent: false,
wholeWord: false,
isRegex: false,
Expand Down
94 changes: 94 additions & 0 deletions src/cypress/e2e/amazon.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/// <reference types="cypress" />

import { ELEMENT_FILTER } from '../../constants'
import { isBlobIframe } from '../../elements'
import { searchReplace } from '../../searchreplace'

const SEARCHTERM = 'Chris'
const REPLACETERM = 'Something else'
const BASEURL = 'http://localhost:9000'
describe('Search Replace WordPress', { baseUrl: BASEURL, responseTimeout: 120e3 }, () => {
beforeEach(() => {
cy.visit('http://localhost:9000/tests/amazon_seller/test.html')
})

it('counts the correct number of occurrences', () => {
cy.window().then((window) => {
console.log(window.location.host)
const iframes = Array.from(
<NodeListOf<HTMLIFrameElement>>window.document.querySelectorAll('iframe')
).filter((iframe) => !isBlobIframe(iframe))
cy.wrap(
searchReplace(
'count',
window,
SEARCHTERM,
REPLACETERM,
false,
false,
true,
false,
false,
false,
true,
false,
iframes,
ELEMENT_FILTER
).then((result) => {
console.log(`result`, result)
expect(result.searchReplaceResult.count.original).to.equal(1)
})
).then(() => {
console.log('done')
})
})
})
it('replaces the search term and then replaces it again', () => {
cy.window().then((window) => {
console.log(window.location.host)
const iframes = Array.from(
<NodeListOf<HTMLIFrameElement>>window.document.querySelectorAll('iframe')
).filter((iframe) => !isBlobIframe(iframe))
cy.wrap(
searchReplace(
'searchReplace',
window,
SEARCHTERM,
REPLACETERM,
false,
false,
true,
false,
false,
false,
true,
false,
iframes,
ELEMENT_FILTER
).then((result1) => {
expect(result1.searchReplaceResult.count.replaced).to.equal(1)
searchReplace(
'searchReplace',
window,
REPLACETERM,
SEARCHTERM,
false,
false,
true,
false,
false,
false,
true,
false,
iframes,
ELEMENT_FILTER
).then((result2) => {
expect(result2.searchReplaceResult.count.replaced).to.equal(1)
})
})
).then(() => {
console.log('done')
})
})
})
})
94 changes: 94 additions & 0 deletions src/cypress/e2e/outlook.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/// <reference types="cypress" />

import { ELEMENT_FILTER } from '../../constants'
import { isBlobIframe } from '../../elements'
import { searchReplace } from '../../searchreplace'

const SEARCHTERM = 'Something else'
const REPLACETERM = 'The replacement'
const BASEURL = 'http://localhost:9000'
describe('Search Replace WordPress', { baseUrl: BASEURL, responseTimeout: 120e3 }, () => {
beforeEach(() => {
cy.visit('http://localhost:9000/tests/outlook/test.html')
})

it('counts the correct number of occurrences', () => {
cy.window().then((window) => {
console.log(window.location.host)
const iframes = Array.from(
<NodeListOf<HTMLIFrameElement>>window.document.querySelectorAll('iframe')
).filter((iframe) => !isBlobIframe(iframe))
cy.wrap(
searchReplace(
'count',
window,
SEARCHTERM,
REPLACETERM,
true,
false,
false,
false,
false,
false,
true,
false,
iframes,
ELEMENT_FILTER
).then((result) => {
console.log(`result`, result)
expect(result.searchReplaceResult.count.original).to.equal(1)
})
).then(() => {
console.log('done')
})
})
})
it('replaces the search term and then replaces it again', () => {
cy.window().then((window) => {
console.log(window.location.host)
const iframes = Array.from(
<NodeListOf<HTMLIFrameElement>>window.document.querySelectorAll('iframe')
).filter((iframe) => !isBlobIframe(iframe))
cy.wrap(
searchReplace(
'searchReplace',
window,
SEARCHTERM,
REPLACETERM,
true,
false,
false,
false,
false,
false,
true,
false,
iframes,
ELEMENT_FILTER
).then((result1) => {
expect(result1.searchReplaceResult.count.replaced).to.equal(1)
searchReplace(
'searchReplace',
window,
REPLACETERM,
SEARCHTERM,
true,
false,
false,
false,
false,
false,
true,
false,
iframes,
ELEMENT_FILTER
).then((result2) => {
expect(result2.searchReplaceResult.count.replaced).to.equal(1)
})
})
).then(() => {
console.log('done')
})
})
})
})
7 changes: 2 additions & 5 deletions src/cypress/e2e/searchreplace.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ describe('Search Replace ', () => {
})
})

// TODO add visibilty test for divs contained within hidden parent divs that are multiple levels deep
// it('counts the correct number of visible occurrences for nested hidden items', () => {

it('counts the correct number of visible occurrences', () => {
cy.window().then((window) => {
const iframes = Array.from(<NodeListOf<HTMLIFrameElement>>window.document.querySelectorAll('iframe'))
Expand Down Expand Up @@ -145,7 +142,7 @@ describe('Search Replace ', () => {
iframes,
ELEMENT_FILTER
).then((result) => {
expect(result.searchReplaceResult.count.original).to.equal(4)
expect(result.searchReplaceResult.count.original).to.equal(5)
})
).then(() => {
console.log('done')
Expand Down Expand Up @@ -174,7 +171,7 @@ describe('Search Replace ', () => {
iframes,
ELEMENT_FILTER
).then((result) => {
expect(result.searchReplaceResult.count.original).to.equal(3)
expect(result.searchReplaceResult.count.original).to.equal(4)
})
).then(() => {
console.log('done')
Expand Down
4 changes: 3 additions & 1 deletion src/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export function getInputElements(
elementFilter: Map<Element, SearchReplaceResult>,
hiddenContent?: boolean
): (HTMLInputElement | HTMLTextAreaElement)[] {
const inputs = Array.from(<NodeListOf<HTMLInputElement>>document.querySelectorAll('input,textarea'))
const inputs = Array.from(
<NodeListOf<HTMLInputElement>>document.querySelectorAll('input,textarea,div[contenteditable="true"]')
)
const visibleElements = !hiddenContent ? inputs.filter((input) => elementIsVisible(input, true, false)) : inputs
return visibleElements.filter((input) => !elementFilter.has(input))
}
Expand Down
Loading
Loading