import { User } from '../../common/helpers' ; import { ChainableElement , UserClaims } from '../../common/types' ; import { OperatorUser } from '../helpers' ; const RNIPP_PAGE_TITLE = 'Rechercher un usager' ; const RNIPP_ERROR_MESSAGE = "Une erreur s'est produite lors de l'appel au RNIPP." ; const DEAD_FEMALE_USER_MESSAGE = "L'utilisatrice est déclarée décédée." ; const DEAD_MALE_USER_MESSAGE = "L'utilisateur est déclaré décédé." ; const DEAD_USER_MESSAGE_NEXT = " Aucune autre information n'est disponible." ; export default class RedressementRNIPPPage { get supportIdInput ( ) : ChainableElement { return cy . get ( '[name="supportId"]' ) ; } get genderRadio ( ) : ChainableElement { return cy . get ( '[name="gender"]' ) ; } get familyNameInput ( ) : ChainableElement { return cy . get ( '[name="familyName"]' ) ; } get givenNameInput ( ) : ChainableElement { return cy . get ( '[name="givenName"]' ) ; } get birthDateInput ( ) : ChainableElement { return cy . get ( '[name="birthdate"]' ) ; } get isFrenchRadio ( ) : ChainableElement { return cy . get ( '[name="isFrench"]' ) ; } get cogInput ( ) : ChainableElement { return cy . get ( '[name="cog"]' ) ; } get searchButton ( ) : ChainableElement { return cy . get ( '#btn-research' ) ; } get rnippErrorMessage ( ) : ChainableElement { return cy . get ( '#message.alert' ) ; } get deadUserMessage ( ) : ChainableElement { return cy . get ( '#dead' ) ; } getRnippLabelByAttribute ( attribute ) { return cy . xpath ( `//div[@class='card-body']//div[div/text()="${ attribute }"]/div[2]` ) ; } get rnippStatusLabel ( ) : ChainableElement { return cy . xpath ( '//div[contains(text(),"Code retour RNIPP :")]/strong' ) ; } get accountStatusLabel ( ) : ChainableElement { return cy . get ( '#citizen-status li:nth-of-type(1) span' ) ; } get accountLastConnectionLabel ( ) : ChainableElement { return cy . get ( '#citizen-status li:nth-of-type(2)' ) ; } get accountIdLabel ( ) : ChainableElement { return cy . get ( '#citizen-status li:nth-of-type(3)' ) ; } get disableAccountButton ( ) : ChainableElement { return cy . xpath ( '//button[@type="submit" and contains(.,"Désactiver")]' ) ; } get enableAccountButton ( ) : ChainableElement { return cy . xpath ( '//button[@type="submit" and contains(.,"Activer")]' ) ; } get totpInput ( ) : ChainableElement { return cy . get ( 'div.modal-content input#totpModal' ) ; } fillInTotp ( user ) { user . wrapTotp ( ) . then ( ( token ) => this . totpInput . clear ( ) . type ( token ) ) ; } submitTotp ( ) { cy . get ( 'div.modal-content button.btn-yes' ) . click ( ) ; } checkIsVisible ( ) { cy . get ( 'h3' ) . contains ( RNIPP_PAGE_TITLE ) ; } fillInUserDetails ( user ) { const supportId = '1000000000000000' ; this . supportIdInput . clear ( ) . type ( supportId ) ; this . genderRadio . check ( user . claims [ 'gender' ] , { force : true } ) ; const familyName = user . claims [ 'family_name' ] || 'NoFamilyName' ; this . familyNameInput . clear ( ) . type ( familyName ) ; this . givenNameInput . clear ( ) . type ( user . claims [ 'given_name' ] ) ; this . birthDateInput . clear ( ) . type ( user . claims [ 'birthdate' ] ) ; if ( user . claims [ 'birthcountry' ] === '99100' ) { this . isFrenchRadio . check ( 'true' , { force : true } ) ; this . cogInput . clear ( ) . type ( user . claims [ 'birthplace' ] ) ; } else { this . isFrenchRadio . check ( 'false' , { force : true } ) ; this . cogInput . clear ( ) . type ( user . claims [ 'birthcountry' ] ) ; } } checkRnippStatus ( rnippStatus ) { this . rnippStatusLabel . contains ( rnippStatus ) ; } checkIsRnippErrorDisplayed ( displayed = true , rnippStatus = '' ) { if ( ! displayed ) { this . rnippErrorMessage . should ( 'not.exist' ) ; return ; } this . rnippErrorMessage . should ( 'be.visible' ) ; this . rnippErrorMessage . contains ( RNIPP_ERROR_MESSAGE ) ; this . rnippErrorMessage . within ( ( ) => { if ( rnippStatus ) { this . checkRnippStatus ( rnippStatus ) ; } else { this . rnippStatusLabel . should ( 'not.exist' ) ; } } ) ; } checkIsDeadUser ( isMale ) { this . deadUserMessage . should ( 'be.visible' ) ; const message = isMale ? DEAD_MALE_USER_MESSAGE : DEAD_FEMALE_USER_MESSAGE ; this . deadUserMessage . contains ( `${ message }${ DEAD_USER_MESSAGE_NEXT }` ) ; } checkSupportId ( ) { this . supportIdInput . invoke ( 'attr' , 'value' ) . then ( ( supportId ) => { this . getRnippLabelByAttribute ( 'Numéro de ticket support' ) . contains ( supportId ) ; } ) ; } checkRnippUserDetails ( userClaims ) { const rnippData = { birthcountry : { format : ( text ) => text , label : 'COG du pays de naissance' , } , birthdate : { format : ( text ) => text . replaceAll ( '-00' , '' ) , label : 'Date de naissance' , } , birthplace : { format : ( text ) => text , label : 'COG du lieu de naissance' , } , family_name : { format : ( text ) => text . toUpperCase ( ) , label : 'Nom' , } , gender : { format : ( text ) => ( text === 'male' ? 'Masculin' : 'Féminin' ) , label : 'Genre' , } , given_name : { format : ( text ) => text , label : 'Prénoms' , } , } ; Object . entries ( rnippData ) . forEach ( ( [ key , value ] ) => { const { format , label : labelName } = value ; const label = this . getRnippLabelByAttribute ( labelName ) ; if ( userClaims [ key ] ) { label . invoke ( 'text' ) . should ( 'contain' , format ( userClaims [ key ] ) ) ; } else { label . invoke ( 'text' ) . should ( 'match' , /^\s*$/ ) ; } } ) ; } checkIsUnknownUser ( ) { cy . get ( '#citizen-status' ) . contains ( 'Inconnu(e) de FranceConnect' ) ; this . accountStatusLabel . should ( 'not.exist' ) ; this . accountLastConnectionLabel . should ( 'not.exist' ) ; this . accountIdLabel . should ( 'not.exist' ) ; } checkIsEnabledUser ( enabled ) { const statusText = enabled ? 'Oui' : 'Non' ; this . accountStatusLabel . contains ( statusText ) ; } checkIsLastConnectionDisplayed ( displayed ) { if ( ! displayed ) { this . accountLastConnectionLabel . should ( 'not.exist' ) ; return ; } const regExp = /Dernière connexion : le (\d{2})\/(\d{2})\/(\d{4}) à (\d{2}:\d{2}:\d{2})/ ; this . accountLastConnectionLabel . invoke ( 'text' ) . should ( 'match' , regExp ) ; } checkIsLastConnectionCorrect ( ) { this . accountLastConnectionLabel . invoke ( 'text' ) . then ( ( text ) => { const regExp = /Dernière connexion : le (\d{2})\/(\d{2})\/(\d{4}) à (\d{2}:\d{2}:\d{2})/ ; const found = regExp . exec ( text ) ; expect ( found , 'The last connection date is missing' ) . to . exist ; const [ , dd , mm , yyyy , time ] = found ; const lastConnectionDate = new Date ( `${ yyyy }-${ mm }-${ dd }T${ time }` ) ; const nowDate = new Date ( ) ; const delay = 30000 ; expect ( lastConnectionDate . valueOf ( ) , `The last connection date is in the future.` ) . to . be . below ( nowDate . valueOf ( ) ) ; expect ( lastConnectionDate . valueOf ( ) , `The last connection has not been refreshed since last time.` ) . to . be . above ( nowDate . valueOf ( ) - delay ) ; } ) ; } checkIsAccountIdDisplayed ( displayed ) { const accountIdRegExp = /AccountId : [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ ; if ( ! displayed ) { this . accountIdLabel . should ( 'not.exist' ) ; } else { this . accountIdLabel . invoke ( 'text' ) . should ( 'match' , accountIdRegExp ) ; } } disableUser ( user ) { this . disableAccountButton . click ( ) ; this . fillInTotp ( user ) ; this . submitTotp ( ) ; } enableUser ( user ) { this . enableAccountButton . click ( ) ; this . fillInTotp ( user ) ; this . submitTotp ( ) ; } }