1- import { DEFAULT_LEAVE_DELTA , DEFAULT_ENTER_DELTA } from '../../src/constants'
21import { isCustomContainer } from './constants'
32
43import type { CSSProperties } from 'vue'
54
6- type scrollRootWithDeltaOptions = {
7- delta : number
8- scrollDown ?: boolean
9- minDuration ?: number
10- }
5+ import 'cypress-wait-frames'
116
127declare global {
138 namespace Cypress {
149 interface Chainable {
1510 getScrollSubject : ( ) => Cypress . Chainable
16- scrollRootWithDelta : ( options : scrollRootWithDeltaOptions ) => Cypress . Chainable
17- scrollToHide : ( ) => Cypress . Chainable
18- scrollToShow : ( ) => Cypress . Chainable
11+ scrollUp : ( ) => Cypress . Chainable
12+ scrollDown : ( ) => Cypress . Chainable
1913 checkStyles : ( styles : CSSProperties ) => Cypress . Chainable
2014 resizeRoot : ( newWidth : number ) => Cypress . Chainable
2115 }
@@ -29,41 +23,29 @@ Cypress.Commands.add('getScrollSubject', () => {
2923
3024Cypress . Commands . add ( 'resizeRoot' , ( newWidth : number ) => {
3125 if ( isCustomContainer ) {
32- return cy . get ( '.Scroller' ) . then ( ( $el ) => {
33- $el . css ( { width : `${ newWidth } px` } )
34- } )
26+ return cy
27+ . get ( '.Scroller' )
28+ . then ( ( $el ) => {
29+ $el . css ( { width : `${ newWidth } px` } )
30+ } )
31+ . waitFrames ( {
32+ subject : ( ) => cy . get ( '.Scroller' ) ,
33+ property : 'clientWidth' ,
34+ frames : 10 ,
35+ } )
3536 }
3637
37- return cy . viewport ( newWidth , newWidth )
38+ return cy . viewport ( newWidth , newWidth ) . waitFrames ( {
39+ subject : cy . window ,
40+ property : 'outerWidth' ,
41+ frames : 10 ,
42+ } )
3843} )
3944
40- Cypress . Commands . add (
41- 'scrollRootWithDelta' ,
42- ( { delta, scrollDown = true , minDuration = 1000 } : scrollRootWithDeltaOptions ) => {
43- let distance = delta * minDuration
44- let duration = minDuration
45-
46- // If obtained distance is below header height, throw an error
47- cy . get ( 'header' ) . then ( ( $header ) => {
48- const headerHeight = $header . height ( )
49-
50- if ( headerHeight && distance < headerHeight ) {
51- throw new Error ( `Scrolling distance is less than ${ headerHeight } px. Increase duration.` )
52- }
53- } )
54-
55- const scrollDistance = scrollDown ? distance : - 1 * distance
56-
57- cy . log ( `Scrolling ${ scrollDistance } px with a delta of ${ delta } in ${ duration } ms` )
58-
59- return cy . getScrollSubject ( ) . scrollTo ( 0 , scrollDistance , { duration } )
60- }
61- )
62-
63- Cypress . Commands . add ( 'scrollToHide' , ( ) => cy . scrollRootWithDelta ( { delta : DEFAULT_LEAVE_DELTA } ) )
45+ Cypress . Commands . add ( 'scrollUp' , ( ) => cy . getScrollSubject ( ) . scrollTo ( 'top' , { duration : 300 } ) )
6446
65- Cypress . Commands . add ( 'scrollToShow ' , ( ) =>
66- cy . scrollRootWithDelta ( { delta : DEFAULT_ENTER_DELTA , scrollDown : false } )
47+ Cypress . Commands . add ( 'scrollDown ' , ( ) =>
48+ cy . getScrollSubject ( ) . scrollTo ( 'bottom' , { duration : 300 } ) ,
6749)
6850
6951Cypress . Commands . add ( 'checkStyles' , { prevSubject : 'element' } , ( subject , styles ) => {
0 commit comments