@@ -12,6 +12,7 @@ import type { ResponseFuzzing, Size, SnapshotOptions, SnapshotViewport } from 't
12
12
import { breakpoints } from 'src/hooks/useDeviceWidths' ;
13
13
import { getInstanceIdRegExp } from 'src/utils/instanceIdRegExp' ;
14
14
import type { LayoutContextValue } from 'src/features/form/layout/LayoutsContext' ;
15
+ import type { IFeatureToggles } from 'src/features/toggles' ;
15
16
import type { ILayoutFile } from 'src/layout/common.generated' ;
16
17
import JQueryWithSelector = Cypress . JQueryWithSelector ;
17
18
@@ -635,6 +636,7 @@ Cypress.Commands.add(
635
636
snapshotName = false ,
636
637
beforeReload,
637
638
callback,
639
+ freeze = true ,
638
640
returnToForm = false ,
639
641
enableResponseFuzzing = false ,
640
642
buildUrl = buildPdfUrl ,
@@ -685,19 +687,24 @@ Cypress.Commands.add(
685
687
cy . viewport ( 794 , 1123 ) ;
686
688
cy . get ( 'body' ) . invoke ( 'css' , 'margin' , '0.75in' ) ;
687
689
688
- // Stops timers which helps in 'freezing' the page in its current state, makes it easier to see when data is missing
689
- cy . clock ( ) ;
690
-
691
- cy . then ( ( ) => {
692
- const timeout = setTimeout ( ( ) => {
693
- throw 'PDF callback failed, print was not ready when #readyForPrint appeared' ;
694
- } , 0 ) ;
695
- // Verify that generic elements that should be hidden are not present
690
+ if ( freeze ) {
691
+ // Stops timers which helps in 'freezing' the page in its current state, makes it easier to see when data is missing
692
+ cy . clock ( ) ;
693
+
694
+ cy . then ( ( ) => {
695
+ const timeout = setTimeout ( ( ) => {
696
+ throw 'PDF callback failed, print was not ready when #readyForPrint appeared' ;
697
+ } , 0 ) ;
698
+ // Verify that generic elements that should be hidden are not present
699
+ cy . findAllByRole ( 'button' ) . should ( 'not.exist' ) ;
700
+ // Run tests from callback
701
+ callback ( ) ;
702
+ cy . then ( ( ) => clearTimeout ( timeout ) ) ;
703
+ } ) ;
704
+ } else {
696
705
cy . findAllByRole ( 'button' ) . should ( 'not.exist' ) ;
697
- // Run tests from callback
698
706
callback ( ) ;
699
- cy . then ( ( ) => clearTimeout ( timeout ) ) ;
700
- } ) ;
707
+ }
701
708
702
709
// Disable response fuzzing and re-enable caching
703
710
cy . get < ResponseFuzzing > ( '@responseFuzzing' ) . invoke ( 'disable' ) ;
@@ -987,3 +994,20 @@ Cypress.Commands.add('openNavGroup', (groupName, pageName, subformName) => {
987
994
} ) ;
988
995
}
989
996
} ) ;
997
+
998
+ Cypress . Commands . add ( 'expectPageBreaks' , ( expectedCount : number ) => {
999
+ cy . window ( ) . should ( ( win ) => {
1000
+ if ( ! win . matchMedia ( 'print' ) . matches ) {
1001
+ throw new Error ( 'expectPageBreaks can only be called when media is in print mode' ) ;
1002
+ }
1003
+ const allElements = Array . from ( win . document . querySelectorAll ( '*' ) ) ;
1004
+ const breakBeforeCount = allElements . filter ( ( e ) => win . getComputedStyle ( e ) . breakBefore === 'page' ) . length ;
1005
+ const breakAfterCount = allElements . filter ( ( e ) => win . getComputedStyle ( e ) . breakAfter === 'page' ) . length ;
1006
+ const pageCount = breakBeforeCount + breakAfterCount ;
1007
+ expect ( pageCount ) . to . equal ( expectedCount ) ;
1008
+ } ) ;
1009
+ } ) ;
1010
+
1011
+ Cypress . Commands . add ( 'setFeatureToggle' , ( toggleName : IFeatureToggles , value : boolean ) => {
1012
+ cy . setCookie ( `FEATURE_${ toggleName } ` , value . toString ( ) ) ;
1013
+ } ) ;
0 commit comments