11// @ts -ignore
22import App from './App.vue' ;
3- import { getInt , getRandomSequence } from '../cypress/support/component' ;
3+ import { getIntRange , getRandomSequence } from '../cypress/support/component' ;
44
5- it ( 'Should give priority to URL hash on mount ' , ( ) => {
6- const targetsLength = 30 ;
5+ it ( 'Should jump to last target ' , ( ) => {
6+ const targetsLength = 20 ;
77
88 cy . mount ( App , {
99 props : {
10+ jumpToLast : true ,
1011 targetsLength,
1112 } ,
1213 } ) ;
1314
14- const randomIndex = getInt ( targetsLength ) ;
15+ cy . scrollTo ( 'bottom' ) ;
16+ cy . wait ( 2000 ) ;
1517
1618 cy . get ( 'a' )
17- . eq ( randomIndex )
18- . click ( )
19- . should ( 'have.class' , 'active' )
20- . invoke ( 'attr' , 'href' )
21- . then ( ( href ) => {
22- cy . hash ( ) . should ( 'eq' , href ) ;
23- } ) ;
19+ . eq ( targetsLength - 1 )
20+ . should ( 'have.class' , 'active' ) ;
2421} ) ;
2522
26- it . only ( 'Should set active clicked links without scroll interferences' , ( ) => {
27- const targetsLength = 30 ;
23+ it ( 'Should not jump to last target' , ( ) => {
24+ const targetsLength = 20 ;
25+
26+ cy . mount ( App , {
27+ props : {
28+ jumpToLast : false ,
29+ targetsLength,
30+ } ,
31+ } ) ;
32+
33+ cy . scrollTo ( 'bottom' ) ;
34+ cy . wait ( 2000 ) ;
35+
36+ cy . get ( 'a' )
37+ . eq ( targetsLength - 1 )
38+ . should ( 'not.have.class' , 'active' ) ;
39+ } ) ;
40+
41+ it ( 'Should set active clicked links without scroll interferences' , ( ) => {
42+ const targetsLength = 20 ;
2843
2944 cy . mount ( App , {
3045 props : {
@@ -35,15 +50,36 @@ it.only('Should set active clicked links without scroll interferences', () => {
3550 const randomIndices = getRandomSequence ( targetsLength ) ;
3651
3752 randomIndices . forEach ( ( index ) => {
38- cy . wait ( 100 ) ; // Trigger smoothscroll
3953 cy . get ( 'a' ) . eq ( index ) . click ( ) . should ( 'have.class' , 'active' ) ;
40- cy . wait ( 100 ) ;
54+ cy . wait ( 200 ) ; // Wait for some smoothscrolling
55+ cy . get ( 'a' ) . eq ( index ) . should ( 'have.class' , 'active' ) ;
4156 } ) ;
4257} ) ;
4358
44- /* it('Should update targets on cancel while scrolling from click', () => {});
59+ it ( 'Should update targets on cancel while scrolling from click' , ( ) => {
60+ const targetsLength = 20 ;
61+
62+ cy . mount ( App , {
63+ props : {
64+ jumpToLast : true ,
65+ targetsLength,
66+ } ,
67+ } ) ;
68+
69+ for ( let i = 0 ; i < 10 ; i ++ ) {
70+ const randomIndex = getIntRange ( 10 , 19 ) ;
71+ cy . get ( 'a' ) . eq ( randomIndex ) . click ( ) . should ( 'have.class' , 'active' ) ;
72+
73+ cy . get ( '.Content' ) . trigger ( 'pointerdown' , { force : true } ) ;
74+ cy . get ( 'a' ) . eq ( randomIndex ) . should ( 'not.have.class' , 'active' ) ;
75+
76+ // Back to top
77+ cy . get ( 'a' ) . eq ( 0 ) . click ( ) ;
78+ cy . wait ( 1000 ) ;
79+ }
80+ } ) ;
4581
46- it('Should jump to first target', () => {});
82+ /* it('Should jump to first target', () => {});
4783
4884it('Should jump to last target', () => {});
4985
0 commit comments