Skip to content

Commit

Permalink
chore: test that autocapture allowlists are unioned (#1476)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Oct 21, 2024
1 parent 81e97f1 commit 38744a5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/__tests__/autocapture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1237,5 +1237,40 @@ describe('Autocapture system', () => {
}
expect(shouldCaptureDomEvent(button, e, autocapture_config)).toBe(false)
})

it('If a user sets dom_event_allowlist and element_allowlist with css_selector_allowlist it us a union so only the dom events on the element allow list with the css selector', () => {
const elements = ['button', 'input', 'select']
const createdElements = []
elements.forEach((element, index) => {
const el = document.createElement(element)
el.className = index === 0 ? 'capturable' : 'something-else'
document.body.appendChild(el)
createdElements.push(el)
})

const autocapture_config: AutocaptureConfig = {
dom_event_allowlist: ['click'],
element_allowlist: ['button'],
css_selector_allowlist: ['.capturable'],
}

const events = ['click', 'touchstart']

// for an allowed and a disallowed event
events.forEach((event) => {
// for a range of elements where only one matches the allowlists
createdElements.forEach((element) => {
const expectedCapturable =
element.tagName === 'BUTTON' && element.className === 'capturable' && event === 'click'
const fakeEvent = makeMouseEvent({
target: element,
type: event,
})

// check if we allow capture only as a union of allowlists
expect(shouldCaptureDomEvent(element, fakeEvent, autocapture_config)).toBe(expectedCapturable)
})
})
})
})
})

0 comments on commit 38744a5

Please sign in to comment.