-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,13 @@ | |
*/ | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { UserList } from './user_list'; | ||
import * as i18n from '../translations'; | ||
import { basicCase } from '../../../containers/mock'; | ||
import { useCaseViewNavigation } from '../../../common/navigation/hooks'; | ||
import type { AppMockRenderer } from '../../../common/mock'; | ||
import { createAppMockRenderer } from '../../../common/mock'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
jest.mock('../../../common/navigation/hooks'); | ||
|
||
|
@@ -27,15 +29,17 @@ describe('UserList ', () => { | |
|
||
const open = jest.fn(); | ||
const getCaseViewUrl = jest.fn().mockReturnValue(caseLink); | ||
let appMockRender: AppMockRenderer; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
appMockRender = createAppMockRenderer(); | ||
useCaseViewNavigationMock.mockReturnValue({ getCaseViewUrl }); | ||
window.open = open; | ||
}); | ||
|
||
it('triggers mailto when email icon clicked', () => { | ||
const wrapper = shallow( | ||
const result = appMockRender.render( | ||
<UserList | ||
theCase={basicCase} | ||
headline={i18n.REPORTER} | ||
|
@@ -47,11 +51,37 @@ describe('UserList ', () => { | |
/> | ||
); | ||
|
||
wrapper.find('[data-test-subj="user-list-email-button"]').simulate('click'); | ||
userEvent.click(result.getByTestId('user-list-email-button')); | ||
|
||
expect(open).toBeCalledWith( | ||
`mailto:${user.email}?subject=${i18n.EMAIL_SUBJECT(title)}&body=${i18n.EMAIL_BODY(caseLink)}`, | ||
'_blank' | ||
); | ||
}); | ||
|
||
it('sort the users correctly', () => { | ||
const result = appMockRender.render( | ||
<UserList | ||
theCase={basicCase} | ||
headline={i18n.REPORTER} | ||
users={[ | ||
{ | ||
user: { ...user, full_name: 'Cases' }, | ||
}, | ||
{ | ||
user: { ...user, username: 'elastic', email: '[email protected]', full_name: null }, | ||
}, | ||
{ | ||
user: { ...user, username: 'test', full_name: null, email: null }, | ||
}, | ||
]} | ||
/> | ||
); | ||
|
||
const userProfiles = result.getAllByTestId('user-profile-username'); | ||
|
||
expect(userProfiles[0].textContent).toBe('Cases'); | ||
expect(userProfiles[1].textContent).toBe('[email protected]'); | ||
expect(userProfiles[2].textContent).toBe('test'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters