import { ChainableElement , ScopeContext } from '../../common/types' ; import { getClaims } from '../helpers' ; const CLAIM_LABELS = { address : 'Adresse postale' , birthcountry : 'Pays de naissance' , birthdate : 'Date de naissance' , birthplace : 'Lieu de naissance' , email : 'Adresse email' , family_name : 'Nom de naissance' , gender : 'Sexe' , given_name : 'Prénom(s)' , phone_number : 'Téléphone' , preferred_username : "Nom d'usage" , } ; export default class InfoConsentPage { get consentCheckbox ( ) : ChainableElement { return cy . get ( '#fc-ask-consent-checkbox' ) ; } get consentButton ( ) : ChainableElement { return cy . get ( '#consent' ) ; } get showClaimsToggle ( ) : ChainableElement { return cy . get ( '#toggleOpenCloseMenu' ) ; } get claimDetails ( ) : ChainableElement { return cy . get ( '.content-details__content ul' ) ; } checkIsVisible ( ) { cy . url ( ) . should ( 'match' , /\/api\/v2\/interaction\/[0-9a-z_-]+\/consent/i ) ; } checkAnonymousScope ( ) { cy . get ( '.section__identity' ) . contains ( 'Vous avez été connecté de façon anonyme' ) ; cy . get ( '.section__more-info' ) . contains ( "Aucune donnée n'a été échangée pour vous connecter." ) ; } checkInformationConsent ( scopeContext , explicitConsent ) { const expectedClaims = getClaims ( scopeContext ) . filter ( ( claimName ) => claimName !== 'sub' ) ; if ( ! explicitConsent ) { this . showClaimsToggle . should ( 'be.visible' ) ; this . claimDetails . should ( 'not.be.visible' ) ; this . showClaimsToggle . click ( ) ; } else { this . showClaimsToggle . should ( 'not.exist' ) ; } this . claimDetails . should ( 'be.visible' ) ; this . claimDetails . invoke ( 'text' ) . then ( ( text ) => { const arrClaims = text . trim ( ) . split ( /\s\s+/ ) ; expectedClaims . forEach ( ( claimName ) => expect ( arrClaims ) . include ( CLAIM_LABELS [ claimName ] ) ) ; expect ( arrClaims . length ) . to . equal ( expectedClaims . length , `The claims count should be ${ expectedClaims . length }` ) ; } ) ; } }