@@ -14,13 +14,15 @@ import {
14
14
getScrollRight ,
15
15
expectInRange ,
16
16
scrollWithTouch ,
17
- getFirstItemRtl ,
18
17
scrollToLeft ,
19
18
getVirtualizer ,
20
19
getScrollable ,
21
20
clearTimer ,
22
21
scrollTo ,
23
22
listenScrollCount ,
23
+ relativeRight ,
24
+ relativeTop ,
25
+ relativeBottom ,
24
26
} from "./utils" ;
25
27
26
28
test . describe ( "smoke" , ( ) => {
@@ -578,12 +580,10 @@ test.describe("check if scrollToIndex works", () => {
578
580
await input . fill ( "700" ) ;
579
581
await button . click ( ) ;
580
582
581
- await ( await component . elementHandle ( ) ) ! . waitForElementState ( "stable" ) ;
582
-
583
583
// Check if scrolled precisely
584
- const firstItem = await getFirstItem ( component ) ;
585
- expect ( firstItem . text ) . toEqual ( "700" ) ;
586
- expect ( firstItem . top ) . toEqual ( 0 ) ;
584
+ const firstItem = component . getByText ( "700" , { exact : true } ) ;
585
+ await expect ( firstItem ) . toBeVisible ( ) ;
586
+ expect ( await relativeTop ( component , firstItem ) ) . toEqual ( 0 ) ;
587
587
588
588
// Check if unnecessary items are not rendered
589
589
await expect (
@@ -609,24 +609,20 @@ test.describe("check if scrollToIndex works", () => {
609
609
await input . fill ( "500" ) ;
610
610
await button . click ( ) ;
611
611
612
- await ( await component . elementHandle ( ) ) ! . waitForElementState ( "stable" ) ;
613
-
614
612
await expect ( component . getByText ( "500" , { exact : true } ) ) . toBeVisible ( ) ;
615
613
616
614
await clearInput ( input ) ;
617
615
await input . fill ( "0" ) ;
618
616
await button . click ( ) ;
619
617
620
- await ( await component . elementHandle ( ) ) ! . waitForElementState ( "stable" ) ;
621
-
622
618
// Check if scrolled precisely
623
- const firstItem = await getFirstItem ( component ) ;
624
- expect ( firstItem . text ) . toEqual ( "0" ) ;
625
- expect ( firstItem . top ) . toEqual ( 0 ) ;
619
+ const firstItem = component . getByText ( "0" , { exact : true } ) ;
620
+ await expect ( firstItem ) . toBeVisible ( ) ;
621
+ expect ( await relativeTop ( component , firstItem ) ) . toEqual ( 0 ) ;
626
622
627
623
// Check if unnecessary items are not rendered
628
624
await expect (
629
- component . getByText ( "50\n " , { exact : true } )
625
+ component . getByText ( "50" , { exact : true } )
630
626
) . not . toBeVisible ( ) ;
631
627
} ) ;
632
628
@@ -645,12 +641,13 @@ test.describe("check if scrollToIndex works", () => {
645
641
await input . fill ( "999" ) ;
646
642
await button . click ( ) ;
647
643
648
- await ( await component . elementHandle ( ) ) ! . waitForElementState ( "stable" ) ;
649
-
650
644
// Check if scrolled precisely
651
- const lastItem = await getLastItem ( component ) ;
652
- expect ( lastItem . text ) . toEqual ( "999" ) ;
653
- expectInRange ( lastItem . bottom , { min : - 0.9 , max : 1 } ) ;
645
+ const lastItem = component . getByText ( "999" , { exact : true } ) ;
646
+ await expect ( lastItem ) . toBeVisible ( ) ;
647
+ expectInRange ( await relativeBottom ( component , lastItem ) , {
648
+ min : - 0.9 ,
649
+ max : 1 ,
650
+ } ) ;
654
651
655
652
// Check if unnecessary items are not rendered
656
653
await expect (
@@ -722,12 +719,13 @@ test.describe("check if scrollToIndex works", () => {
722
719
await input . fill ( "700" ) ;
723
720
await button . click ( ) ;
724
721
725
- await ( await component . elementHandle ( ) ) ! . waitForElementState ( "stable" ) ;
726
-
727
722
// Check if scrolled precisely
728
- const lastItem = await getLastItem ( component ) ;
729
- expect ( lastItem . text ) . toEqual ( "700" ) ;
730
- expectInRange ( lastItem . bottom , { min : 0 , max : 1 } ) ;
723
+ const lastItem = component . getByText ( "700" , { exact : true } ) ;
724
+ await expect ( lastItem ) . toBeVisible ( ) ;
725
+ expectInRange ( await relativeBottom ( component , lastItem ) , {
726
+ min : 0 ,
727
+ max : 1 ,
728
+ } ) ;
731
729
732
730
// Check if unnecessary items are not rendered
733
731
await expect (
@@ -753,24 +751,20 @@ test.describe("check if scrollToIndex works", () => {
753
751
await input . fill ( "500" ) ;
754
752
await button . click ( ) ;
755
753
756
- await ( await component . elementHandle ( ) ) ! . waitForElementState ( "stable" ) ;
757
-
758
754
await expect ( component . getByText ( "500" , { exact : true } ) ) . toBeVisible ( ) ;
759
755
760
756
await clearInput ( input ) ;
761
757
await input . fill ( "0" ) ;
762
758
await button . click ( ) ;
763
759
764
- await ( await component . elementHandle ( ) ) ! . waitForElementState ( "stable" ) ;
765
-
766
760
// Check if scrolled precisely
767
- const firstItem = await getFirstItem ( component ) ;
768
- expect ( firstItem . text ) . toEqual ( "0" ) ;
769
- expect ( firstItem . top ) . toEqual ( 0 ) ;
761
+ const firstItem = component . getByText ( "0" , { exact : true } ) ;
762
+ await expect ( firstItem ) . toBeVisible ( ) ;
763
+ expect ( await relativeTop ( component , firstItem ) ) . toEqual ( 0 ) ;
770
764
771
765
// Check if unnecessary items are not rendered
772
766
await expect (
773
- component . getByText ( "50\n " , { exact : true } )
767
+ component . getByText ( "50" , { exact : true } )
774
768
) . not . toBeVisible ( ) ;
775
769
} ) ;
776
770
@@ -789,12 +783,13 @@ test.describe("check if scrollToIndex works", () => {
789
783
await input . fill ( "999" ) ;
790
784
await button . click ( ) ;
791
785
792
- await ( await component . elementHandle ( ) ) ! . waitForElementState ( "stable" ) ;
793
-
794
786
// Check if scrolled precisely
795
- const lastItem = await getLastItem ( component ) ;
796
- expect ( lastItem . text ) . toEqual ( "999" ) ;
797
- expectInRange ( lastItem . bottom , { min : - 0.5 , max : 1 } ) ;
787
+ const lastItem = component . getByText ( "999" , { exact : true } ) ;
788
+ await expect ( lastItem ) . toBeVisible ( ) ;
789
+ expectInRange ( await relativeBottom ( component , lastItem ) , {
790
+ min : - 0.5 ,
791
+ max : 1 ,
792
+ } ) ;
798
793
799
794
// Check if unnecessary items are not rendered
800
795
await expect (
@@ -1258,9 +1253,9 @@ test.describe("RTL", () => {
1258
1253
const component = await getScrollable ( page ) ;
1259
1254
1260
1255
// check if start is displayed
1261
- const first = await getFirstItemRtl ( component ) ;
1262
- expect ( first . text ) . toEqual ( "Column 0" ) ;
1263
- expect ( first . right ) . toEqual ( 0 ) ;
1256
+ const first = component . getByText ( "Column 0" , { exact : true } ) ;
1257
+ await expect ( first ) . toBeVisible ( ) ;
1258
+ expect ( await relativeRight ( component , first ) ) . toEqual ( 0 ) ;
1264
1259
1265
1260
// scroll to the end
1266
1261
await scrollToLeft ( component ) ;
0 commit comments