Skip to content

Commit 97092ff

Browse files
committed
add migration guide, additional edge cases, behavior table
1 parent dd53d96 commit 97092ff

File tree

7 files changed

+435
-9
lines changed

7 files changed

+435
-9
lines changed

packages/driver/cypress/e2e/dom/visibility.cy.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
// @ts-ignore
22
const { $, dom } = Cypress
33

4+
/**
5+
* Most of the tests in here are declarative. Due to the range of visibility scenarios, test case
6+
* understandability is paramount. These test cases are defined declaratively *in the fixture html
7+
* file, and are iterated upon with the helper functions in the `visibility scenarios` describe block.
8+
*
9+
* CSS for test cases are inlined into the DOM purposefully, to ensure easy reference and debugging.
10+
*
11+
* Test case elements that are expected to be visible typically have a `lightgreen` background color,
12+
* while test case elements that are expected to be hidden typically have a `lightcoral` background color.
13+
* This helps to quickly identify if a given element's assertions are in-line with browser behavior.
14+
*
15+
* A test case where the visibility behavior is expected to be identical between the legacy and fast
16+
* algorithms:
17+
*
18+
* <div class="testCase"
19+
* cy-expect="visible"
20+
* cy-label="helpful description for the assertion"
21+
* style="height: 100px; width: 100px;">
22+
* </div>
23+
*
24+
* A test case where the visibility behavior is expected to be different between the legacy and fast
25+
* algorithms (note the css of the example does not accurately reflect this visibility behavior):
26+
*
27+
* <div class="testCase"
28+
* cy-legacy-expect="visible"
29+
* cy-fast-expect="hidden"
30+
* cy-label="helpful description for the assertion"
31+
* style="height: 100px; width: 100px;">
32+
* </div>
33+
*/
34+
435
describe('src/cypress/dom/visibility', {
536
slowTestThreshold: 500,
637
}, () => {
@@ -268,9 +299,11 @@ describe('src/cypress/dom/visibility', {
268299
'visibility-property',
269300
'display-property',
270301
'opacity-property',
271-
'input-elements',
272302
'table-elements',
273303
'box-interactions',
304+
'style-filters',
305+
'contain-property',
306+
'pointer-events-none',
274307
])
275308
})
276309

@@ -307,7 +340,8 @@ describe('src/cypress/dom/visibility', {
307340
'overflow-relative-positioning',
308341
'overflow-flex-container',
309342
'overflow-complex-scenarios',
310-
'clip-path-scenarios',
343+
'clip-scenarios',
344+
'viewport-scenarios',
311345
])
312346
})
313347

@@ -324,6 +358,8 @@ describe('src/cypress/dom/visibility', {
324358
'fixed-positioning-with-zero-dimensions',
325359
'position-absolute-scenarios',
326360
'position-sticky-scenarios',
361+
'positioning-cousin-coverage',
362+
'z-index-coverage',
327363
])
328364
})
329365

@@ -364,7 +400,6 @@ describe('src/cypress/dom/visibility', {
364400
})
365401

366402
it('has a parent with `display: none`', function () {
367-
cy.visit('/fixtures/visibility/basic-css-properties.html')
368403
prepareFixtureSection('display-property')
369404
cy.get('[cy-section="display-property"] .testCase[cy-expect="hidden"] span').then(($el) => {
370405
reasonIs($el, 'This element `<span.testCase>` is not visible because its parent `<div.testCase>` has CSS property: `display: none`')

packages/driver/cypress/fixtures/visibility/basic-css-properties.html

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ <h3>Opacity Property</h3>
3636
</div>
3737
</div>
3838

39-
<div class="test-section" cy-section="input-elements">
40-
<h3>Input Elements</h3>
41-
<input class="testCase" cy-expect="hidden" cy-label="Hidden input" type="hidden" value="hidden input">
42-
<input class="testCase" cy-expect="visible" cy-label="Visible input" type="text" value="visible input">
39+
<div class="test-section" cy-section="style-filters">
40+
<h3>Style Filters</h3>
41+
<!-- while opacity(0) renders the element as fully transparent, it is still considered visible: it has a box model, and it is clickable -->
42+
<div class="testCase" cy-expect="visible" cy-label="Hidden by style filter: opacity(0)" style="filter: opacity(0);">Hidden by style filter: opacity(0)</div>
4343
</div>
44-
44+
4545
<div class="test-section" cy-section="table-elements">
4646
<h3>Table Elements</h3>
4747
<table>
@@ -63,5 +63,30 @@ <h3>Table Elements</h3>
6363
</span>
6464
</div>
6565
</div>
66+
67+
<div class="test-section" cy-section="pointer-events-none">
68+
<h3>Pointer Events: None</h3>
69+
<div class="testCase" cy-legacy-expect="visible" cy-fast-expect="hidden" cy-label="Element with pointer-events: none" style="pointer-events: none;">Element with pointer-events: none</div>
70+
</div>
71+
72+
<div class="test-section" cy-section="contain-property">
73+
<h3>CSS Contain Property</h3>
74+
75+
<!-- Element with contain: layout -->
76+
<div class="testCase" cy-expect="visible" cy-label="Element with contain: layout" style="width: 100px; height: 100px; background: lightcoral; contain: layout;">
77+
<span class="testCase" cy-expect="visible" cy-label="Child of contain: layout element">contain: layout</span>
78+
</div>
79+
80+
<!-- Element with contain: paint -->
81+
<div class="testCase" cy-expect="visible" cy-label="Element with contain: paint" style="width: 100px; height: 100px; background: lightcoral; contain: paint;">
82+
<span class="testCase" cy-legacy-expect="visible" cy-fast-expect="hidden" cy-label="Child positioned out of bounds of its `contain: paint` parent" style="position:relative; top:500px">contain: paint</span>
83+
</div>
84+
85+
<!-- Element with contain: strict -->
86+
<div class="testCase" cy-expect="visible" cy-label="Element with contain: strict" style="width: 100px; height: 100px; background: lightcoral; contain: strict;">
87+
<span class="testCase" cy-expect="visible" cy-label="Child of contain: strict element">contain: strict</span>
88+
</div>
89+
</div>
90+
6691
</body>
6792
</html>

packages/driver/cypress/fixtures/visibility/overflow.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ <h3 class="testCase" cy-expect="visible" cy-label="Heading">Example</h3>
235235
</div>
236236
</div>
237237

238-
<div class="test-section" cy-section="clip-path-scenarios">
238+
<div class="test-section" cy-section="clip-scenarios">
239239
<h3>Clip-Path Scenarios (note: legacy mode does not support clip-path)</h3>
240240

241241
<!-- Clip-path polygon that clips everything -->
@@ -267,6 +267,23 @@ <h3>Clip-Path Scenarios (note: legacy mode does not support clip-path)</h3>
267267
<div class="testCase" cy-expect="visible" cy-label="Parent with clip-path path" style="position: relative; clip-path: path('M 0 0 L 100 0 L 100 100 L 0 100 Z');">
268268
<span class="testCase" cy-expect="visible" cy-label="Element inside clip-path path" style="background: lightgreen;">path content</span>
269269
</div>
270+
271+
<!-- CSS clip property -->
272+
<div class="testCase" cy-legacy-expect="visible" cy-fast-expect="hidden" cy-label="Element clipped by CSS clip property" style="position: absolute; clip: rect(0, 0, 0, 0); background: lightcoral; width: 100px; height: 100px;">clipped by clip: rect(0,0,0,0)</div>
273+
274+
<!-- CSS mask property note: this yields an element that is not rendered as visible, but has a box model that is visible and is clickable -->
275+
<div class="testCase" cy-expect="visible" cy-label="Element masked by CSS mask" style="width: 100px; height: 100px; background: lightcoral; mask: linear-gradient(black, black); mask-size: 0 0;">masked by CSS mask</div>
276+
</div>
277+
278+
<div cy-section="viewport-scenarios">
279+
<h3>Viewport Scenarios</h3>
280+
<div class="testCase" cy-legacy-expect="visible" cy-fast-expect="hidden" cy-label="Position absolute element outside viewport" style="position: absolute; top: -100px; left: -100px; width: 100px; height: 100px; background: lightcoral;">Element outside viewport</div>
281+
<div class="testCase" cy-expect="hidden" cy-label="Position fixed element outside of viewport" style="position: fixed; top: -100px; left: -100px; width: 100px; height: 100px; background: lightcoral;">Position fixed element outside of viewport</div>
282+
<iframe style="display:none;">
283+
<body>
284+
<div class="testCase" cy-expect="hidden" cy-label="Element inside hidden iframe" style="width: 100px; height: 100px; background: lightcoral;">Element inside hidden iframe</div>
285+
</body>
286+
</iframe>
270287
</div>
271288
</body>
272289
</html>

packages/driver/cypress/fixtures/visibility/positioning.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,27 @@ <h3>Position Sticky Scenarios</h3>
109109
</div>
110110
</div>
111111

112+
<div class="test-section" cy-section="positioning-cousin-coverage" >
113+
<h3>Positioning Cousin Coverage</h3>
114+
115+
<!-- Element covered by an absolutely positioned cousin -->
116+
<div style="position: relative;">
117+
<div style="width: 200px; height: 100px; background: lightblue;">
118+
<span class="testCase" cy-fast-expect="hidden" cy-legacy-expect="visible" cy-label="Target element to be covered" style="display: block; width: 100px; height: 50px; background: lightgreen;">Target element</span>
119+
</div>
120+
<div class="testCase" cy-expect="visible" cy-label="Absolutely positioned cousin covering target" style="position: absolute; top: 0px; left: 0px; width: 100px; height: 50px; background: lightcoral;">Covering cousin</div>
121+
</div>
122+
</div>
123+
124+
<div class="test-section" cy-section="z-index-coverage">
125+
<h3>Z-Index Coverage</h3>
126+
127+
<!-- Element covered by higher z-index element -->
128+
<div style="position: relative; width: 300px; height: 150px; background: lightgray;">
129+
<div class="testCase" cy-legacy-expect="visible" cy-fast-expect="hidden" cy-label="Element covered by higher z-index" style="position: absolute; top: 20px; left: 20px; width: 100px; height: 100px; background: lightgreen; z-index: 1;">Lower z-index element</div>
130+
<div class="testCase" cy-expect="visible" cy-label="Higher z-index covering element" style="position: absolute; top: 20px; left: 20px; width: 100px; height: 100px; background: lightcoral; z-index: 2;">Higher z-index element</div>
131+
</div>
132+
</div>
133+
112134
</body>
113135
</html>

packages/driver/cypress/fixtures/visibility/transforms.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ <h3>Translation</h3>
3737
<div class="testCase" cy-expect="visible" cy-label="Translate 2D" style="transform: translate(10px, 15px)">Translated in 2 dimensions</div>
3838
<div class="testCase" cy-expect="visible" cy-label="Translate Z" style="transform: translateZ(10px)">Translated in 3rd dimension</div>
3939
<div class="testCase" cy-expect="visible" cy-label="Translate 3D" style="transform: translate3d(10px, 15px, 20px)">Translated in 3 dimensions</div>
40+
<div class="testCase" cy-legacy-expect="visible" cy-fast-expect="hidden" cy-label="Translate outside viewport" style="transform: translateY(-9999px)">Translated outside viewport</div>
4041
</div>
4142
<div class="test-section" cy-section="rotation">
4243
<h3>Rotation</h3>

packages/driver/cypress/fixtures/visibility/ux.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ document.addEventListener('DOMContentLoaded', () => {
2424
})
2525

2626
document.addEventListener('click', (ev) => {
27+
// eslint-disable-next-line no-console
28+
console.log('click', ev.target)
2729
const [, section] = ev.target?.href?.split('#') ?? []
2830

2931
if (!section) return

0 commit comments

Comments
 (0)