-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: report element with declaration in
pointerEventsCheck
(#950)
- Loading branch information
1 parent
7ea7a77
commit 31b7091
Showing
5 changed files
with
169 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import {createConfig} from '#src/setup/setup' | ||
import {assertPointerEvents, hasPointerEvents} from '#src/utils' | ||
import {setup} from '#testHelpers' | ||
|
||
test('get pointer-events from element or ancestor', async () => { | ||
const {element} = setup(` | ||
<div style="pointer-events: none"> | ||
<input style="pointer-events: initial"/> | ||
<input style="pointer-events: inherit"/> | ||
<input/> | ||
</div> | ||
`) | ||
|
||
expect(hasPointerEvents(element)).toBe(false) | ||
expect(hasPointerEvents(element.children[0])).toBe(true) | ||
expect(hasPointerEvents(element.children[1])).toBe(false) | ||
expect(hasPointerEvents(element.children[2])).toBe(false) | ||
}) | ||
|
||
test('report element that declared pointer-events', async () => { | ||
const {element} = setup(` | ||
<div id="foo" style="pointer-events: none"> | ||
<span id="listlabel">Some list</span> | ||
<ul aria-labelledby="listlabel"> | ||
<li aria-label="List entry"> | ||
<span data-testid="target"></span> | ||
<button>foo</button> | ||
<label> | ||
An input element with a really long label text | ||
<input/> | ||
</label> | ||
</li> | ||
</ul> | ||
</div> | ||
`) | ||
|
||
expect(() => assertPointerEvents(createConfig(), element)) | ||
.toThrowErrorMatchingInlineSnapshot(` | ||
Unable to perform pointer interaction as the element has \`pointer-events: none\`: | ||
DIV#foo | ||
`) | ||
|
||
expect(() => | ||
assertPointerEvents( | ||
createConfig(), | ||
element.querySelector('[data-testid="target"]') as Element, | ||
), | ||
).toThrowErrorMatchingInlineSnapshot(` | ||
Unable to perform pointer interaction as the element inherits \`pointer-events: none\`: | ||
DIV#foo <-- This element declared \`pointer-events: none\` | ||
UL(label=Some list) | ||
LI(label=List entry) | ||
SPAN(testId=target) <-- Asserted pointer events here | ||
`) | ||
|
||
expect(() => | ||
assertPointerEvents( | ||
createConfig(), | ||
element.querySelector('button') as Element, | ||
), | ||
).toThrowErrorMatchingInlineSnapshot(` | ||
Unable to perform pointer interaction as the element inherits \`pointer-events: none\`: | ||
DIV#foo <-- This element declared \`pointer-events: none\` | ||
UL(label=Some list) | ||
LI(label=List entry) | ||
BUTTON(label=foo) <-- Asserted pointer events here | ||
`) | ||
|
||
expect(() => | ||
assertPointerEvents( | ||
createConfig(), | ||
element.querySelector('input') as Element, | ||
), | ||
).toThrowErrorMatchingInlineSnapshot(` | ||
Unable to perform pointer interaction as the element inherits \`pointer-events: none\`: | ||
DIV#foo <-- This element declared \`pointer-events: none\` | ||
UL(label=Some list) | ||
LI(label=List entry) | ||
LABEL | ||
INPUT(label=An input element with a reall…) <-- Asserted pointer events here | ||
`) | ||
}) |