-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathvisibility.cy.ts
1197 lines (938 loc) · 44.7 KB
/
visibility.cy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @ts-ignore
const { $, dom } = Cypress
describe('src/cypress/dom/visibility', () => {
beforeEach(() => {
cy.visit('/fixtures/generic.html')
})
context('isHidden', () => {
it('exposes isHidden', () => {
expect(dom.isHidden).to.be.a('function')
})
it('throws when not passed a DOM element', () => {
const fn = () => {
dom.isHidden(null!)
}
expect(fn).to.throw('`Cypress.dom.isHidden()` failed because it requires a DOM element. The subject received was: `null`')
})
})
context('isVisible', () => {
it('exposes isVisible', () => {
expect(dom.isVisible).to.be.a('function')
})
it('throws when not passed a DOM element', () => {
const fn = () => {
// @ts-ignore
dom.isVisible('form')
}
expect(fn).to.throw('`Cypress.dom.isVisible()` failed because it requires a DOM element. The subject received was: `form`')
})
})
context('#isScrollable', () => {
beforeEach(function () {
this.add = (el) => {
return $(el).appendTo(cy.$$('body'))
}
})
it('returns true if window and body > window height', function () {
this.add('<div style="height: 1000px; width: 10px;" />')
const win = cy.state('window')
const fn = () => {
return dom.isScrollable(win)
}
expect(fn()).to.be.true
})
it('returns false if window and body < window height', () => {
cy.$$('body').html('<div>foo</div>')
const win = cy.state('window')
const fn = () => {
return dom.isScrollable(win)
}
expect(fn()).to.be.false
})
it('returns true if document element and body > window height', function () {
this.add('<div style="height: 1000px; width: 10px;" />')
const documentElement = Cypress.dom.wrap(cy.state('document').documentElement)
const fn = () => {
return dom.isScrollable(documentElement)
}
expect(fn()).to.be.true
})
it('returns false if document element and body < window height', () => {
cy.$$('body').html('<div>foo</div>')
const documentElement = Cypress.dom.wrap(cy.state('document').documentElement)
const fn = () => {
return dom.isScrollable(documentElement)
}
expect(fn()).to.be.false
})
it('returns false el is not scrollable', function () {
const noScroll = this.add(`\
<div style="height: 100px; overflow: auto;">
<div>No Scroll</div>
</div>\
`)
const fn = () => {
return dom.isScrollable(noScroll)
}
expect(fn()).to.be.false
})
it('returns false el has no overflow', function () {
const noOverflow = this.add(`\
<div style="height: 100px; width: 100px; border: 1px solid green;">
<div style="height: 150px;">
No Overflow Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Aenean lacinia bibendum nulla sed consectetur. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Etiam porta sem malesuada magna mollis euismod.
</div>
</div>\
`)
const fn = () => {
return dom.isScrollable(noOverflow)
}
expect(fn()).to.be.false
})
it('returns true when vertically scrollable', function () {
const vertScrollable = this.add(`\
<div style="height: 100px; width: 100px; overflow: auto;">
<div style="height: 150px;">Vertical Scroll</div>
</div>\
`)
const fn = () => {
return dom.isScrollable(vertScrollable)
}
expect(fn()).to.be.true
})
it('returns true when horizontal scrollable', function () {
const horizScrollable = this.add(`\
<div style="height: 100px; width: 100px; overflow: auto; ">
<div style="height: 150px;">Horizontal Scroll</div>
</div>\
`)
const fn = () => {
return dom.isScrollable(horizScrollable)
}
expect(fn()).to.be.true
})
it('returns true when overflow scroll forced and content larger', function () {
const forcedScroll = this.add(`\
<div style="height: 100px; width: 100px; overflow: scroll; border: 1px solid yellow;">
<div style="height: 300px; width: 300px;">Forced Scroll</div>
</div>\
`)
const fn = () => {
return dom.isScrollable(forcedScroll)
}
expect(fn()).to.be.true
})
})
context('hidden/visible overrides', () => {
beforeEach(function () {
const add = (el) => {
return $(el).appendTo(cy.$$('body'))
}
// ensure all tests run against a scrollable window
const scrollThisIntoView = add('<div style=`height: 1000px;` /><div>Should be in view</div>')
this.$visHidden = add('<ul style="visibility: hidden;"></ul>')
this.$parentVisHidden = add('<div class="invis" style="visibility: hidden;"><button>parent visibility: hidden</button></div>')
this.$displayNone = add('<button style="display: none">display: none</button>')
this.$inputHidden = add('<input type="hidden" value="abcdef">')
this.$divNoWidth = add('<div style="width: 0; height: 100px;">width: 0</div>')
this.$divNoHeight = add('<div style="width: 50px; height: 0px;">height: 0</div>')
this.$divDetached = $('<div>foo</div>')
this.$divVisible = add(`<div>visible</div>`)
this.$optionInSelect = add(`\
<select>
<option>Naruto</option>
</select>\
`)
this.$optgroupInSelect = add(`\
<select>
<optgroup label='Shinobi'>
<option>Naruto</option>
</optgroup>
</select>\
`)
this.$optionInHiddenSelect = add(`\
<select style='display: none'>
<option>Sasuke</option>
</select>\
`)
this.$optionOutsideSelect = add(`\
<div style='display: none'>
<option id='option-hidden'>Sasuke</option>
</div>
<div>
<option id='option-visible'>Naruto</option>
</div>\
`)
this.$optionHiddenInSelect = add(`\
<select>
<option>--Select--</option>
<option id="hidden-opt" style='display: none'>Sakura</option>
</select>\
`)
this.$btnOpacityZero = add(`\
<button style="opacity: 0;">opacity: 0</button>\
`)
this.$btnOpacityHalf = add(`\
<button style="opacity: 0.5;">opacity: 0.5</button>\
`)
this.$parentOpacityZero = add(`\
<div style="opacity: 0;">
<button>parent opacity: 0</button>
</div>\
`)
this.$tableVisCollapse = add(`\
<table>
<tr>
<td>Naruto</td>
<td class='collapse' style='visibility: collapse;'>Sasuke</td>
<td>Sakura</td>
</tr>
<tr class='collapse' style='visibility: collapse;'>
<td>Kaguya</td>
<td><span id='collapse-span'>Madara</span></td>
<td>Orochimaro</td>
</tr>
</table>\
`)
this.$parentNoWidth = add(`\
<div style='width: 0; height: 100px; overflow: hidden;'>
<div style='height: 500px; width: 500px;'>
<span>parent width: 0</span>
</div>
</div>`)
this.$parentNoHeight = add(`\
<div style='width: 100px; height: 0px; overflow: hidden;'>
<span>parent height: 0</span>
</div>`)
this.$parentNoWidthHeightOverflowAuto = add(`\
<div style='width: 0; height: 0px; overflow: auto;'>
<span>parent no size, overflow: auto</span>
</div>`)
this.$parentWithWidthHeightNoOverflow = add(`\
<div style='width: 100px; height: 100px; overflow: hidden;'>
<div style='height: 100px; width: 100px;'>
<span>parent with size, overflow: hidden</span>
</div>
</div>`)
this.$childPosAbs = add(`\
<div style='width: 0; height: 100px; overflow: hidden;'>
<div style='height: 500px; width: 500px;'>
<span style='position: absolute;'>position: absolute</span>
</div>
</div>`)
this.$childPosFixed = add(`\
<div id="childPosFixed" style='width: 100px; height: 100px; overflow: hidden;'>
<button style='position: fixed; top: 0;'>position: fixed</button>
</div>`)
this.$childPointerEventsNone = add(`\
<div style="position: fixed; top: 60px;">
<span style="pointer-events: none;">child pointer-events: none</span>
</div>\
`)
this.$descendentPosAbs = add(`\
<div style='width: 0; height: 100px; overflow: hidden;'>
<div style='height: 500px; width: 500px; position: absolute;'>
<span>no width, descendant position: absolute</span>
</div>
</div>`)
this.$descendentPosFixed = add(`\
<div id="descendentPosFixed" style='width: 0; height: 100px; overflow: hidden;'>
<div style='height: 500px; width: 500px; position: fixed; top: 0; right: 0;'>
<button>no width, descendant position: fixed</button>
</div>
</div>`)
this.$descendantInPosFixed = add(`\
<div>
<div id="descendantInPosFixed" style="width: 200px; position: fixed; bottom: 0; right: 0">
underneath
<div style="width: 200px; position: fixed; bottom: 0; right: 0">on top of the other</div>
</div>
</div>\
`)
this.$coveredUpPosFixed = add(`\
<div>
<div id="coveredUpPosFixed" style="position: fixed; bottom: 0; left: 0">underneath</div>
<div style="position: fixed; bottom: 0; left: 0">on top</div>
</div>\
`)
this.$offScreenPosFixed = add(`\
<div id="offScreenPosFixed" style="position: fixed; bottom: 0; left: -100px;">off screen</div>\
`)
this.$parentPosAbs = add(`\
<div style='width: 0; height: 100px; overflow: hidden; position: absolute;'>
<div style='height: 500px; width: 500px;'>
<span>parent position: absolute</span>
</div>
</div>`)
this.$parentDisplayNone = add(`\
<div id="none" style='display: none;'>
<span>parent display: none</span>
</div>\
`)
this.$parentPointerEventsNone = add(`\
<div style="pointer-events: none">
<span style="position: fixed; left: 0; top: 50%;">parent pointer-events: none</span>
</div>\
`)
this.$parentPointerEventsNoneCovered = add(`\
<div style="pointer-events: none;">
<span style="position: fixed; top: 40px;">parent pointer-events: none</span>
</div>
<span style="position: fixed; top: 40px; background: red;">covering the element with pointer-events: none</span>\
`)
this.$parentDisplayInlineChildDisplayBlock = add(`\
<div>
<span>
<label style="display: block;">display: block</label>
</span>
</div>\
`)
this.$elOutOfParentBoundsToLeft = add(`\
<div style='width: 100px; height: 100px; overflow: hidden; position: relative;'>
<span style='position: absolute; width: 100px; height: 100px; left: -100px; top: 0px;'>position: absolute, out of bounds left</span>
</div>\
`)
this.$elOutOfParentBoundsToRight = add(`\
<div id="elOutOfParentBoundsToRight" style='width: 100px; height: 100px; overflow: hidden; position: relative;'>
<span style='position: absolute; width: 100px; height: 100px; right: -100px; top: 0px;'>position: absolute, out of bounds right</span>
</div>\
`)
this.$elOutOfParentBoundsAbove = add(`\
<div style='width: 100px; height: 100px; overflow: hidden; position: relative;'>
<span style='position: absolute; width: 100px; height: 100px; left: 0px; top: -100px;'>position: absolute, out of bounds above</span>
</div>\
`)
this.$elOutOfParentBoundsBelow = add(`\
<div id="elOutOfParentBoundsBelow" style='width: 100px; height: 100px; overflow: hidden; position: relative;'>
<span style='position: absolute; width: 100px; height: 100px; left: 0px; bottom: -100px;'>position: absolute, out of bounds below</span>
</div>\
`)
this.$elOutOfParentWithOverflowYHiddenBounds = add(`\
<div style='width: 100px; height: 100px; overflow-y: hidden; position: relative;'>
<span style='position: absolute; left: 0px; top: 200px;'>position: absolute, out of bounds below</span>
</div>\
`)
this.$elOutOfParentWithOverflowXHiddenBounds = add(`\
<div style='width: 100px; height: 100px; overflow-x: hidden; position: relative;'>
<span style='position: absolute; left: 200px; top: 0;'>position: absolute, out of bounds below</span>
</div>\
`)
this.$elOutOfParentWithFlexAndOverflowHiddenBounds = add(`\
<div style="display: flex; overflow: hidden;">
<div id="red" style="flex: 0 0 80%; background-color: red;">red</div>
<div id="green" style="flex: 0 0 80%; background-color: green;">green</div>
<div id="blue" style="background-color: blue;">blue</div>
</div>\
`)
this.$elOutOfParentWithOverflowHiddenBoundsButCloserPositionAbsoluteParent = add(`\
<div style="border: 1px solid red; width: 200px; height: 200px; overflow: hidden;">
<div style="position: absolute; left: 300px; border: 1px solid blue; width: 200px; height: 200px;">
<span style="border: 1px solid green;">Hello</span>
</div>\
`)
this.$elOutOfAncestorOverflowAutoBounds = add(`\
<div style='width: 100px; height: 100px; overflow: auto;'>
<div style='width: 1000px; position: relative;'>
<span style='position: absolute; left: 300px; top: 0px;'>out of bounds, parent wide, ancestor overflow: auto</span>
</div>
</div>\
`)
this.$elInPosAbsParentsBounds = add(`\
<div style='width: 200px; height: 200px; overflow: hidden; position: relative;'>
<div style='position: absolute;'>
<div style='position: absolute;'>
<span style='position: absolute; left: 50px; top: 50px;'>in bounds, parent position: absolute</span>
</div>
</div>
</div>\
`)
this.$elOutOfPosAbsParentsBounds = add(`\
<div style='width: 100px; height: 100px; overflow: hidden; position: relative; top: 700px; left: 700px;'>
<div style='position: absolute;'>
<div style='position: absolute;'>
<span style='position: absolute; left: -350px; top: 0px;'>out of bounds, parent position: absolute</span>
</div>
</div>
</div>\
`)
this.$elInParentBounds = add(`\
<div style='width: 100px; height: 100px; overflow: hidden; position: relative;'>
<span style='position: absolute; left: 0px; top: 0px;'>in bounds, position: absolute</span>
</div>\
`)
this.$elOutOfScrollingParentBounds = add(`\
<div style='width: 100px; height: 100px; overflow: scroll; position: relative; top: 700px; left: 700px;'>
<div style='position: absolute;'>
<div style='position: absolute;'>
<span style='position: absolute; left: 300px; top: 0px;'>out of scrolling bounds, position: absolute</span>
</div>
</div>
</div>\
`)
this.$elIsOutOfBoundsOfAncestorsOverflowButWithinRelativeAncestor = add(`\
<div style='padding: 100px; position: relative;'>
<div style='overflow: hidden;'>
<div>
<span style='position: absolute; left: 0; top: 0;'>in bounds of ancestor, position: absolute, parent overflow: hidden</span>
</div>
</div>
</div>\
`)
this.$elIsRelativeAndOutOfBoundsOfAncestorOverflow = add(`\
<div style='overflow: hidden;'>
<div>
<span style='position: relative; left: 0; top: -200px;'>out of bounds, position: relative</span>
</div>
</div>\
`)
this.$elIsRelativeAndOutOfBoundsOfAncestorButAncestorShowsOverflow = add(`\
<div>
<div>
<span style='position: relative; left: 0; top: -200px;'>out of bounds but visible, position: relative</span>
</div>
</div>\
`)
this.$parentOutOfBoundsButElInBounds = add(`\
<div style='position: relative; padding: 20px;'>
<div style='overflow: hidden;'>
<div style='position: relative; left: 0; top: -100px;'>
<span style='position: relative; left: 0; top: 100px;'>in bounds of ancestor, parent out of bounds</span>
</div>
</div>
</div>\
`)
this.$parentWithClipPathAbsolutePositionElOutsideClipPath = add(`\
<div style="position: absolute; clip-path: polygon(0 0, 0 0, 0 0, 0 0);">
<span>clip-path</span>
</div>\
`)
this.$parentWithClipPathAbsolutePositionElInsideClipPath = add(`\
<div style="position: absolute; clip-path: circle(100%);">
<span>clip-path</span>
</div>\
`)
this.$parentWithTransformScaleElOutsideScale = add(`\
<div style="transform: scale(0,0)">
<span>TRANSFORMERS</span>
</div>\
`)
this.$parentWithTransformScaleElInsideScale = add(`\
<div style="transform: scale(1,1)">
<span>TRANSFORMERS</span>
</div>\
`)
this.$ancestorTransformMakesElOutOfBoundsOfAncestor = add(`\
<div style='margin-left: 100px; overflow: hidden; width: 100px;'>
<div style='transform: translateX(-100px); width: 200px;'>
<div style='width: 100px;'>
<span>out of ancestor's bounds due to ancestor translate</span>
</div>
</div>
</div>\
`)
this.$ancestorTransformMakesElInBoundsOfAncestor = add(`\
<div style='margin-left: 100px; overflow: hidden; width: 100px;'>
<div style='transform: translateX(-100px); width: 300px;'>
<div style='display: inline-block; width: 100px;'>
<span>out of ancestor's bounds due to ancestor translate</span>
</div>
<div id='inbounds' style='display: inline-block; width: 100px;'>
<span>in ancestor's bounds due to ancestor translate</span>
</div>
</div>
</div>\
`)
// scroll the 2nd element into view so that
// there is always a scrollTop so we ensure
// its factored in (window vs viewport) calculations
scrollThisIntoView.get(1).scrollIntoView()
})
describe('html or body', () => {
it('is visible if html', () => {
expect(cy.$$('html').is(':hidden')).to.be.false
expect(cy.$$('html').is(':visible')).to.be.true
expect(cy.$$('html')).not.to.be.hidden
expect(cy.$$('html')).to.be.visible
cy.wrap(cy.$$('html')).should('not.be.hidden')
cy.wrap(cy.$$('html')).should('be.visible')
})
it('is visible if body', () => {
expect(cy.$$('body').is(':hidden')).to.be.false
expect(cy.$$('body').is(':visible')).to.be.true
expect(cy.$$('body')).not.to.be.hidden
expect(cy.$$('body')).to.be.visible
cy.wrap(cy.$$('body')).should('not.be.hidden')
cy.wrap(cy.$$('body')).should('be.visible')
})
it('is visible if display none on body or html', () => {
cy.$$('html').css('display', 'none')
cy.$$('body').css('display', 'none')
expect(cy.$$('html')).not.to.be.hidden
expect(cy.$$('html')).to.be.visible
expect(cy.$$('body')).not.to.be.hidden
expect(cy.$$('body')).to.be.visible
})
})
describe('css visibility', () => {
it('is hidden if .css(visibility) is hidden', function () {
expect(this.$visHidden.is(':hidden')).to.be.true
expect(this.$visHidden.is(':visible')).to.be.false
expect(this.$visHidden).to.be.hidden
expect(this.$visHidden).to.not.be.visible
cy.wrap(this.$visHidden).should('be.hidden')
cy.wrap(this.$visHidden).should('not.be.visible')
})
it('is hidden if parents have .css(visibility) hidden', function () {
expect(this.$parentVisHidden.find('button').is(':hidden')).to.be.true
expect(this.$parentVisHidden.find('button').is(':visible')).to.be.false
expect(this.$parentVisHidden.find('button')).to.be.hidden
expect(this.$parentVisHidden.find('button')).to.not.be.visible
cy.wrap(this.$parentVisHidden).find('button').should('be.hidden')
cy.wrap(this.$parentVisHidden).find('button').should('not.be.visible')
})
it('is hidden if visibility collapse', function () {
expect(this.$tableVisCollapse.find('td.collapse')).to.be.hidden
expect(this.$tableVisCollapse.find('td.collapse')).to.not.be.visible
expect(this.$tableVisCollapse.find('tr.collapse')).to.be.hidden
expect(this.$tableVisCollapse.find('tr.collapse')).to.not.be.visible
expect(this.$tableVisCollapse.find('tr.collapse td')).to.be.hidden
expect(this.$tableVisCollapse.find('tr.collapse td')).to.not.be.visible
})
it('is hidden if parent has visibility collapse', function () {
expect(this.$tableVisCollapse.find('tr.collapse td')).to.be.hidden
expect(this.$tableVisCollapse.find('tr.collapse td')).to.not.be.visible
expect(this.$tableVisCollapse.find('#collapse-span')).to.be.hidden
expect(this.$tableVisCollapse.find('#collapse-span')).to.not.be.visible
})
it('is hidden if input type hidden', function () {
expect(this.$inputHidden.is(':hidden')).to.be.true
expect(this.$inputHidden.is(':visible')).to.be.false
expect(this.$inputHidden).to.be.hidden
expect(this.$inputHidden).to.not.be.visible
cy.wrap(this.$inputHidden).should('be.hidden')
cy.wrap(this.$inputHidden).should('not.be.visible')
})
})
describe('option and optgroup', () => {
it('is visible if option in visible select', function () {
expect(this.$optionInSelect.find('option').is(':hidden')).to.be.false
expect(this.$optionInSelect.find('option').is(':visible')).to.be.true
expect(this.$optionInSelect.find('option')).not.to.be.hidden
expect(this.$optionInSelect.find('option')).to.be.visible
cy.wrap(this.$optionInSelect.find('option')).should('not.be.hidden')
cy.wrap(this.$optionInSelect.find('option')).should('be.visible')
})
it('is visible if optgroup in visible select', function () {
expect(this.$optgroupInSelect.find('optgroup').is(':hidden')).to.be.false
expect(this.$optgroupInSelect.find('optgroup').is(':visible')).to.be.true
expect(this.$optgroupInSelect.find('optgroup')).not.to.be.hidden
expect(this.$optgroupInSelect.find('optgroup')).to.be.visible
cy.wrap(this.$optgroupInSelect.find('optgroup')).should('not.be.hidden')
cy.wrap(this.$optgroupInSelect.find('optgroup')).should('be.visible')
})
it('is hidden if option in hidden select', function () {
expect(this.$optionInHiddenSelect.find('option').is(':hidden')).to.be.true
expect(this.$optionInHiddenSelect.find('option').is(':visible')).to.be.false
expect(this.$optionInHiddenSelect.find('option')).to.be.hidden
expect(this.$optionInHiddenSelect.find('option')).not.to.be.visible
cy.wrap(this.$optionInHiddenSelect.find('option')).should('be.hidden')
cy.wrap(this.$optionInHiddenSelect.find('option')).should('not.be.visible')
})
it('is hidden if option is display none', function () {
expect(this.$optionHiddenInSelect.find('#hidden-opt').is(':hidden')).to.be.true
expect(this.$optionHiddenInSelect.find('#hidden-opt').is(':visible')).to.be.false
expect(this.$optionHiddenInSelect.find('#hidden-opt')).to.be.hidden
expect(this.$optionHiddenInSelect.find('#hidden-opt')).not.to.be.visible
cy.wrap(this.$optionHiddenInSelect.find('#hidden-opt')).should('be.hidden')
cy.wrap(this.$optionHiddenInSelect.find('#hidden-opt')).should('not.be.visible')
})
// TODO(webkit): fix+unskip
it('follows regular visibility logic if option outside of select', { browser: '!webkit' }, function () {
expect(this.$optionOutsideSelect.find('#option-hidden').is(':hidden')).to.be.true
expect(this.$optionOutsideSelect.find('#option-hidden')).to.be.hidden
cy.wrap(this.$optionOutsideSelect.find('#option-hidden')).should('be.hidden')
expect(this.$optionOutsideSelect.find('#option-visible').is(':visible')).to.be.true
expect(this.$optionOutsideSelect.find('#option-visible')).to.be.visible
cy.wrap(this.$optionOutsideSelect.find('#option-visible')).should('be.visible')
})
})
describe('css opacity', () => {
it('is hidden if opacity is 0', function () {
expect(this.$btnOpacityZero.is(':hidden')).to.be.true
expect(this.$btnOpacityZero.is(':visible')).to.be.false
expect(this.$btnOpacityZero).to.be.hidden
expect(this.$btnOpacityZero).not.to.be.visible
cy.wrap(this.$btnOpacityZero).should('be.hidden')
cy.wrap(this.$btnOpacityZero).should('not.be.visible')
})
it('is hidden if parent has `opacity: 0`', function () {
expect(this.$parentOpacityZero.find('button').is(':hidden')).to.be.true
expect(this.$parentOpacityZero.find('button').is(':visible')).to.be.false
expect(this.$parentOpacityZero.find('button')).to.be.hidden
expect(this.$parentOpacityZero.find('button')).not.to.be.visible
cy.wrap(this.$parentOpacityZero.find('button')).should('be.hidden')
cy.wrap(this.$parentOpacityZero.find('button')).should('not.be.visible')
})
it('is visible if opacity is greater than 0 but less than 1', function () {
expect(this.$btnOpacityHalf.is(':visible')).to.be.true
expect(this.$btnOpacityHalf.is(':hidden')).to.be.false
expect(this.$btnOpacityHalf).to.be.visible
expect(this.$btnOpacityHalf).not.to.be.hidden
cy.wrap(this.$btnOpacityHalf).should('be.visible')
cy.wrap(this.$btnOpacityHalf).should('not.be.hidden')
})
})
describe('width and height', () => {
it('is hidden if offsetWidth is 0', function () {
expect(this.$divNoWidth.is(':hidden')).to.be.true
expect(this.$divNoWidth.is(':visible')).to.be.false
expect(this.$divNoWidth).to.be.hidden
expect(this.$divNoWidth).to.not.be.visible
cy.wrap(this.$divNoWidth).should('be.hidden')
cy.wrap(this.$divNoWidth).should('not.be.visible')
})
it('is hidden if parent has overflow: hidden and no width', function () {
expect(this.$parentNoWidth.find('span')).to.be.hidden
expect(this.$parentNoWidth.find('span')).to.not.be.visible
})
it('is hidden if parent has overflow: hidden and no height', function () {
expect(this.$parentNoHeight.find('span')).to.be.hidden
expect(this.$parentNoHeight.find('span')).to.not.be.visible
})
it('is visible when parent has positive dimensions even with overflow hidden', function () {
expect(this.$parentWithWidthHeightNoOverflow.find('span')).to.be.visible
expect(this.$parentWithWidthHeightNoOverflow.find('span')).to.not.be.hidden
})
})
describe('css position', () => {
it('is visible if child has position: absolute', function () {
expect(this.$childPosAbs.find('span')).to.be.visible
expect(this.$childPosAbs.find('span')).not.be.hidden
})
it('is visible if child has position: fixed', function () {
expect(this.$childPosFixed.find('button')).to.be.visible
expect(this.$childPosFixed.find('button')).not.to.be.hidden
})
it('is visible if descendent from parent has position: fixed', function () {
expect(this.$descendentPosFixed.find('button')).to.be.visible
expect(this.$descendentPosFixed.find('button')).not.to.be.hidden
})
it('is visible if has position: fixed and descendent is found', function () {
expect(this.$descendantInPosFixed.find('#descendantInPosFixed')).to.be.visible
expect(this.$descendantInPosFixed.find('#descendantInPosFixed')).not.to.be.hidden
})
it('is hidden if position: fixed and covered up', function () {
expect(this.$coveredUpPosFixed.find('#coveredUpPosFixed')).to.be.hidden
expect(this.$coveredUpPosFixed.find('#coveredUpPosFixed')).not.to.be.visible
})
it('is hidden if position: fixed and off screen', function () {
expect(this.$offScreenPosFixed).to.be.hidden
expect(this.$offScreenPosFixed).not.to.be.visible
})
it('is visible if descendent from parent has position: absolute', function () {
expect(this.$descendentPosAbs.find('span')).to.be.visible
expect(this.$descendentPosAbs.find('span')).to.not.be.hidden
})
it('is hidden if only the parent has position absolute', function () {
expect(this.$parentPosAbs.find('span')).to.be.hidden
expect(this.$parentPosAbs.find('span')).to.not.be.visible
})
it('is visible if position: fixed and parent has pointer-events: none', function () {
expect(this.$parentPointerEventsNone.find('span')).to.be.visible
expect(this.$parentPointerEventsNone.find('span')).to.not.be.hidden
})
it('is not visible if covered when position: fixed and parent has pointer-events: none', function () {
expect(this.$parentPointerEventsNoneCovered.find('span')).to.be.hidden
expect(this.$parentPointerEventsNoneCovered.find('span')).to.not.be.visible
})
it('is visible if pointer-events: none and parent has position: fixed', function () {
expect(this.$childPointerEventsNone.find('span')).to.be.visible
expect(this.$childPointerEventsNone.find('span')).to.not.be.hidden
})
it('is visible when position: sticky', () => {
cy.visit('fixtures/sticky.html')
cy.get('#button').should('be.visible')
})
})
describe('css display', function () {
// https://github.com/cypress-io/cypress/issues/6183
it('parent is visible if display inline and child has display block', function () {
expect(this.$parentDisplayInlineChildDisplayBlock.find('span')).to.be.visible
expect(this.$parentDisplayInlineChildDisplayBlock.find('span')).to.not.be.hidden
})
})
describe('css overflow', () => {
it('is hidden when parent overflow auto and no width/height', function () {
expect(this.$parentNoWidthHeightOverflowAuto.find('span')).to.not.be.visible
expect(this.$parentNoWidthHeightOverflowAuto.find('span')).to.be.hidden
})
it('is hidden when parent overflow hidden and out of bounds to left', function () {
expect(this.$elOutOfParentBoundsToLeft.find('span')).to.be.hidden
})
it('is hidden when parent overflow hidden and out of bounds to right', function () {
expect(this.$elOutOfParentBoundsToRight.find('span')).to.be.hidden
})
it('is hidden when parent overflow hidden and out of bounds above', function () {
expect(this.$elOutOfParentBoundsAbove.find('span')).to.be.hidden
})
it('is hidden when parent overflow hidden and out of bounds below', function () {
expect(this.$elOutOfParentBoundsBelow.find('span')).to.be.hidden
})
it('is hidden when parent overflow-y hidden and out of bounds', function () {
expect(this.$elOutOfParentWithOverflowYHiddenBounds.find('span')).to.be.hidden
})
it('is hidden when parent overflow-x hidden and out of bounds', function () {
expect(this.$elOutOfParentWithOverflowXHiddenBounds.find('span')).to.be.hidden
})
it('is visible when parent overflow hidden but el in a closer parent with position absolute', function () {
expect(this.$elOutOfParentWithOverflowHiddenBoundsButCloserPositionAbsoluteParent.find('span')).to.be.visible
})
it('is hidden when parent flex and overflow hidden and el out of bounds', function () {
expect(this.$elOutOfParentWithFlexAndOverflowHiddenBounds.find('#red')).to.be.visible
expect(this.$elOutOfParentWithFlexAndOverflowHiddenBounds.find('#green')).to.be.visible
expect(this.$elOutOfParentWithFlexAndOverflowHiddenBounds.find('#blue')).to.be.hidden
})
it('is hidden when parent is wide and ancestor is overflow auto', function () {
expect(this.$elOutOfAncestorOverflowAutoBounds.find('span')).to.be.hidden
})
it('is hidden when parent overflow scroll and out of bounds', function () {
expect(this.$elOutOfScrollingParentBounds.find('span')).to.be.hidden
})
it('is hidden when parent absolutely positioned and overflow hidden and out of bounds', function () {
expect(this.$elOutOfPosAbsParentsBounds.find('span')).to.be.hidden
})
it('is visible when parent absolutely positioned and overflow hidden and not out of bounds', function () {
expect(this.$elInPosAbsParentsBounds.find('span')).to.be.visible
})
it('is visible when parent overflow hidden and not out of bounds', function () {
expect(this.$elInParentBounds.find('span')).to.be.visible
})
it('is visible when ancestor is overflow hidden but more distant ancestor is the offset parent', function () {
expect(this.$elIsOutOfBoundsOfAncestorsOverflowButWithinRelativeAncestor.find('span')).to.be.visible
})
it('is hidden when relatively positioned outside ancestor with overflow hidden', function () {
expect(this.$elIsRelativeAndOutOfBoundsOfAncestorOverflow.find('span')).to.be.hidden
})
it('is visible when el is relatively positioned outside ancestor that does not hide overflow', function () {
expect(this.$elIsRelativeAndOutOfBoundsOfAncestorButAncestorShowsOverflow.find('span')).to.be.visible
})
it('is visible when parent is relatively positioned out of bounds but el is relatively positioned back in bounds', function () {
expect(this.$parentOutOfBoundsButElInBounds.find('span')).to.be.visible
})
})
describe('css clip-path', () => {
// TODO: handle clip path 'hidden' equivalents
it.skip('is hidden when outside of parents clip-path', function () {
expect(this.$parentWithClipPathAbsolutePositionElOutsideClipPath.find('span')).to.be.hidden
})
it('is visible when inside of parents clip-path', function () {
expect(this.$parentWithClipPathAbsolutePositionElInsideClipPath.find('span')).to.be.visible
})
})
describe('css transform', () => {
const add = (el) => {
return $(el).appendTo(cy.$$('body'))
}
describe('element visibility by css transform', () => {
it('is visible when an element is translated a bit', () => {
const el = add(`<div style="transform: translate(10px, 10px)">Translated</div>`)
expect(el).to.be.visible
})
it('is visible when an element is only skewed', () => {
const el = add(`<div style="transform: skew(10deg, 15deg)">Skewed</div>`)
expect(el).to.be.visible
})
it('is visible when an element is only rotated', () => {
const el = add(`<div style="transform: rotate(20deg)">Rotated</div>`)
expect(el).to.be.visible
})
it('is visible when an element is scaled by non-zero', () => {
const el = add(`<div style="transform: scale(2, 3)">Scaled</div>`)
expect(el).to.be.visible
})
it('is visible when an element is transformed in multiple ways but not scaled to zero', () => {
const el = add(`<div style="transform: translate(10px, 15px) skew(30deg) rotate(30deg) scale(4, 1)">Multiple transform</div>`)
expect(el).to.be.visible
})
it('is visible when an element is rotateZ(90deg)', () => {
const el = add(`<div style="transform: rotateZ(90deg)">rotateZ(90deg)</div>`)
expect(el).to.be.visible
})
// https://github.com/cypress-io/cypress/issues/6745
it('is visible even if there is a dangling element in the tree', () => {
cy.visit('/fixtures/dangling-element.html')
cy.get('.hello')
})
it('is hidden when an element is scaled to X axis in 0', () => {
const el = add(`<div style="transform: scaleX(0)">ScaleX(0)</div>`)
expect(el).to.be.hidden
})
it('is hidden when an element is scaled to Y axis in 0', () => {
const el = add(`<div style="transform: scaleY(0)">ScaleY(0)</div>`)
expect(el).to.be.hidden
})
it('is hidden when an element is scaled to Z axis in 0', () => {
const el = add(`<div style="transform: scaleZ(0)">ScaleZ(0)</div>`)
expect(el).to.be.hidden
})
it('is hidden when an element is transformed in multiple ways but scaled to 0 in one axis', () => {
const el = add(`<div style="transform: translate(15px, 30px) skew(20deg) rotate(40deg) scale(0, 0)">Multiple 2</div>`)
expect(el).to.be.hidden
})
it('is hidden when an element is rotateX(90deg)', () => {
const el = add(`<div style="transform: rotateX(90deg)">rotateX(90deg)</div>`)
expect(el).to.be.hidden
})
it('is hidden when an element is rotateY(90deg)', () => {
const el = add(`<div style="transform: rotateX(90deg)">rotateY(90deg)</div>`)
expect(el).to.be.hidden
})
it('is hidden when an element is rotateX(90deg) rotateY(90deg)', () => {
const el = add(`<div style="transform: rotateX(90deg) rotateY(90deg)">rotateX(90deg)</div>`)
expect(el).to.be.hidden
})
it('is hidden when an element is transformed in multiple ways but rotated to 90 deg in X or Y axis', () => {
const el = add(`<div style="transform: rotateX(90deg) skew(30deg, 50deg) translate(15px, 60px) scale(3.5)">rotateX(90deg)</div>`)