import { DETAIL_PANEL } from './selectors' ; declare global { namespace Cypress { interface Chainable < Subject > { checkTermAndDefinition ( definitionlistNumber , listTerm , value ) : void ; checkInfoBoxes ( arrayTerms ) : void ; checkListItems ( fixturePath ) : void ; checkLinkItems ( fixturePath ) : void ; checkPanelHeader ( fixturePath ) : void ; checkSubheaderLinkList ( fixturePath , definitionlistNumber ) : void ; checkSubheader ( fixturePath , definitionlistNumber ) : void ; } } } interface DefinitionList { [ key ] : { items : { [ key ] : string ; } ; } ; } interface ListItem { definitionLists : DefinitionList ; } Cypress . Commands . add ( 'checkTermAndDefinition' , ( definitionlistNumber , listTerm , value ) => { if ( value ) { cy . get ( '[class*=DefinitionList__DefinitionList]' ) . eq ( definitionlistNumber ) . within ( ( ) => { cy . get ( '[class*="DefinitionListTerm"]' ) . contains ( new RegExp ( `^${ listTerm }$` , 'g' ) ) . siblings ( DETAIL_PANEL . definitionListDescription ) . contains ( value ) . scrollIntoView ( ) . should ( 'be.visible' ) ; } ) ; } else { cy . get ( '[class*=DefinitionList__DefinitionList]' ) . eq ( definitionlistNumber ) . within ( ( ) => { cy . get ( '[class*="DefinitionListTerm"]' ) . contains ( new RegExp ( `^${ listTerm }$` , 'g' ) ) . siblings ( DETAIL_PANEL . definitionListDescription ) . should ( 'have.text' , '' ) . scrollIntoView ( ) . should ( 'be.visible' ) ; } ) ; } } ) ; Cypress . Commands . add ( 'checkInfoBoxes' , ( arrayTerms ) => { cy . wrap ( arrayTerms ) . each ( ( term , i ) => { cy . get ( DETAIL_PANEL . buttonInfo ) . eq ( i ) . click ( ) ; cy . contains ( `Uitleg over ${ term }` ) . should ( 'be.visible' ) ; cy . get ( '[class*="DetailInfoBox"]' ) . find ( DETAIL_PANEL . buttonClose ) . eq ( 0 ) . click ( ) ; cy . contains ( `Uitleg over ${ term }` ) . should ( 'not.exist' ) ; } ) ; } ) ; Cypress . Commands . add ( 'checkListItems' , ( fixturePath ) => { cy . fixture ( fixturePath ) . then ( ( json ) => { cy . checkPanelHeader ( fixturePath ) ; Object . entries ( json . definitionLists ) . forEach ( ( [ , valueA ] , indexA ) => { cy . checkSubheader ( fixturePath , indexA ) ; Object . entries ( valueA . items ) . forEach ( ( [ keyB , valueB ] ) => { cy . checkTermAndDefinition ( indexA , keyB , valueB ) ; } ) ; } ) ; } ) ; } ) ; Cypress . Commands . add ( 'checkLinkItems' , ( fixturePath ) => { cy . fixture ( fixturePath ) . then ( ( json ) => { Object . entries ( json . linkLists ) . forEach ( ( [ , valueA ] , indexA ) => { cy . checkSubheaderLinkList ( fixturePath , indexA ) ; Object . entries ( valueA . items ) . forEach ( ( [ , valueB ] ) => { cy . get ( DETAIL_PANEL . linkList ) . should ( 'contain' , valueB ) ; } ) ; } ) ; } ) ; } ) ; Cypress . Commands . add ( 'checkSubheader' , ( fixturePath , definitionlistNumber ) => { cy . fixture ( fixturePath ) . then ( ( json ) => { if ( json . definitionLists [ definitionlistNumber ] . subheading ) { cy . get ( DETAIL_PANEL . subHeader ) . contains ( json . definitionLists [ definitionlistNumber ] . subheading ) ; } else { cy . log ( 'No subheader' ) ; } } ) ; } ) ; Cypress . Commands . add ( 'checkSubheaderLinkList' , ( fixturePath , linklistNumber ) => { cy . fixture ( fixturePath ) . then ( ( json ) => { if ( json . linkLists [ linklistNumber ] . subheading ) { cy . get ( DETAIL_PANEL . subHeader ) . contains ( json . linkLists [ linklistNumber ] . subheading ) ; } else { cy . log ( 'No subheader' ) ; } } ) ; } ) ; Cypress . Commands . add ( 'checkPanelHeader' , ( fixturePath ) => { cy . fixture ( fixturePath ) . then ( ( json ) => { if ( json . panelHeading ) { cy . get ( DETAIL_PANEL . panelTypeTitle ) . contains ( json . panelType ) . should ( 'be.visible' ) ; cy . get ( DETAIL_PANEL . panelSubject ) . contains ( json . panelHeading ) . should ( 'be.visible' ) ; } } ) ; } ) ;