import * as React from 'react' ; import { ReactWrapper } from 'enzyme' ; import { createStore } from '@client/store' ; import { createTestComponent , userDetails } from '@client/tests/util' ; import { ProfileMenu } from '@client/components/ProfileMenu' ; import { getStorageUserDetailsSuccess } from '@opencrvs/client/src/profile/profileActions' ; const { store } = createStore ( ) ; describe ( 'when user opens profile menu without user details' , ( ) => { let component ; beforeEach ( async ( ) => { const testComponent = await createTestComponent ( < ProfileMenu />, store); component = testComponent . component ; } ) ; it ( 'open menu' , ( ) => { component . find ( '#ProfileMenuToggleButton' ) . hostNodes ( ) . simulate ( 'click' ) ; expect ( component . find ( '#ProfileMenuSubMenu' ) . hostNodes ( ) ) . toHaveLength ( 1 ) ; } ) ; } ) ; describe ( 'when user opens profile menu with user details' , ( ) => { let component ; beforeEach ( async ( ) => { const details = userDetails ; details . name = [ { use : 'bn' , firstNames : 'সাকিব' , familyName : 'হাসান' } ] ; store . dispatch ( getStorageUserDetailsSuccess ( JSON . stringify ( details ) ) ) ; const testComponent = await createTestComponent ( < ProfileMenu />, store); component = testComponent . component ; } ) ; it ( 'open menu' , ( ) => { component . find ( '#ProfileMenuToggleButton' ) . hostNodes ( ) . simulate ( 'click' ) ; expect ( component . find ( '#ProfileMenuSubMenu' ) . hostNodes ( ) ) . toHaveLength ( 1 ) ; } ) ; it ( 'handle clicks' , ( ) => { component . find ( '#ProfileMenuToggleButton' ) . hostNodes ( ) . simulate ( 'click' ) ; component . find ( '#ProfileMenuSubMenu' ) . hostNodes ( ) . childAt ( 1 ) . simulate ( 'click' ) ; component . find ( '#ProfileMenuSubMenu' ) . hostNodes ( ) . childAt ( 2 ) . simulate ( 'click' ) ; expect ( component . find ( '#ProfileMenuSubMenu' ) . hostNodes ( ) ) . toHaveLength ( 1 ) ; } ) ; } ) ;