import * as React from 'react' ; import { createTestComponent , flushPromises , validToken , mockUserResponse , userDetails } from '@client/tests/util' ; import { queries } from '@client/profile/queries' ; import { merge } from 'lodash' ; import { createStore , AppStore } from '@client/store' ; import { checkAuth , getStorageUserDetailsSuccess } from '@client/profile/profileActions' ; import { UserSetupPage } from '@client/views/UserSetup/UserSetupPage' ; import { ProtectedAccount } from '@client/components/ProtectedAccount' ; const nameObj = { data : { getUser : { name : [ { use : 'en' , firstNames : 'Sahriar' , familyName : 'Nafis' } ] , role : 'FIELD_AGENT' , status : 'pending' , type : 'CHA' , practitionerId : '43ac3486-7df1-4bd9-9b5e-728054ccd6ba' } } } ; merge ( mockUserResponse , nameObj ) ; ( queries . fetchUserDetails as jest . Mock ) . mockReturnValue ( mockUserResponse ) ; describe ( 'UserSetupPage tests' , ( ) => { let store ; beforeEach ( ( ) => { store = createStore ( ) . store ; } ) ; it ( 'renders page successfully without type' , async ( ) => { await store . dispatch ( getStorageUserDetailsSuccess ( JSON . stringify ( userDetails ) ) ) ; const testComponent = await createTestComponent ( < UserSetupPage />, store); const app = testComponent . component ; expect ( app . find ( '#user-setup-landing-page' ) . hostNodes ( ) ) . toHaveLength ( 1 ) ; expect ( app . find ( '#user-setup-name-holder' ) . hostNodes ( ) . text ( ) ) . toEqual ( 'Shakib Al Hasan' ) ; } ) ; it ( 'go to password page' , async ( ) => { const testComponent = await createTestComponent ( < ProtectedAccount />, store); const app = testComponent . component ; app . find ( '#user-setup-start-button' ) . hostNodes ( ) . simulate ( 'click' ) ; await flushPromises ( ) ; expect ( app . find ( '#NewPassword' ) ) . toBeDefined ( ) ; } ) ; it ( 'go to password page without userDetails' , async ( ) => { await store . dispatch ( checkAuth ( { '?token' : validToken } ) ) ; store . dispatch ( getStorageUserDetailsSuccess ( 'null' ) ) ; const testComponent = await createTestComponent ( < UserSetupPage goToStep = { ( ) => { } } />, store); const app = testComponent . component ; app . find ( '#user-setup-start-button' ) . hostNodes ( ) . simulate ( 'click' ) ; await flushPromises ( ) ; expect ( app . find ( '#NewPassword' ) ) . toBeDefined ( ) ; } ) ; } ) ;