-
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
1 parent
42d6576
commit 4a8b6f5
Showing
3 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
...nt/components/endpoint_response_actions_list/components/actions_log_users_filter.test.tsx
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import * as reactTestingLibrary from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { | ||
createAppRootMockRenderer, | ||
type AppContextTestRender, | ||
} from '../../../../common/mock/endpoint'; | ||
import { ActionsLogUsersFilter } from './actions_log_users_filter'; | ||
import { MANAGEMENT_PATH } from '../../../../../common/constants'; | ||
|
||
describe('Users filter', () => { | ||
let render: ( | ||
props?: React.ComponentProps<typeof ActionsLogUsersFilter> | ||
) => ReturnType<AppContextTestRender['render']>; | ||
let renderResult: ReturnType<typeof render>; | ||
let history: AppContextTestRender['history']; | ||
let mockedContext: AppContextTestRender; | ||
|
||
const testPrefix = 'response-actions-list-users-filter'; | ||
let onChangeUsersFilter: jest.Mock; | ||
|
||
beforeEach(async () => { | ||
onChangeUsersFilter = jest.fn(); | ||
mockedContext = createAppRootMockRenderer(); | ||
({ history } = mockedContext); | ||
render = (props?: React.ComponentProps<typeof ActionsLogUsersFilter>) => | ||
(renderResult = mockedContext.render( | ||
<ActionsLogUsersFilter {...{ isFlyout: false, onChangeUsersFilter }} /> | ||
)); | ||
reactTestingLibrary.act(() => { | ||
history.push(`${MANAGEMENT_PATH}/response_actions`); | ||
}); | ||
}); | ||
|
||
it('should show a search input for users', () => { | ||
render(); | ||
|
||
const searchInput = renderResult.getByTestId(`${testPrefix}-search`); | ||
expect(searchInput).toBeTruthy(); | ||
expect(searchInput.getAttribute('placeholder')).toEqual( | ||
'Filter by user or comma separated list of users' | ||
); | ||
}); | ||
|
||
it('should search on given search string on enter', () => { | ||
render(); | ||
|
||
const searchInput = renderResult.getByTestId(`${testPrefix}-search`); | ||
userEvent.type(searchInput, 'usernameX'); | ||
userEvent.type(searchInput, '{enter}'); | ||
expect(onChangeUsersFilter).toHaveBeenCalledWith(['usernameX']); | ||
}); | ||
|
||
it('should search comma separated strings as multiple users', () => { | ||
render(); | ||
|
||
const searchInput = renderResult.getByTestId(`${testPrefix}-search`); | ||
userEvent.type(searchInput, 'usernameX,usernameY,usernameZ'); | ||
userEvent.type(searchInput, '{enter}'); | ||
expect(onChangeUsersFilter).toHaveBeenCalledWith(['usernameX', 'usernameY', 'usernameZ']); | ||
}); | ||
|
||
it('should ignore white spaces in a given username when updating the API params', () => { | ||
render(); | ||
|
||
const searchInput = renderResult.getByTestId(`${testPrefix}-search`); | ||
userEvent.type(searchInput, ' usernameX '); | ||
userEvent.type(searchInput, '{enter}'); | ||
expect(onChangeUsersFilter).toHaveBeenCalledWith(['usernameX']); | ||
}); | ||
|
||
it('should ignore white spaces in comma separated usernames when updating the API params', () => { | ||
render(); | ||
|
||
const searchInput = renderResult.getByTestId(`${testPrefix}-search`); | ||
userEvent.type(searchInput, ' , usernameX ,usernameY , '); | ||
userEvent.type(searchInput, '{enter}'); | ||
expect(onChangeUsersFilter).toHaveBeenCalledWith(['usernameX', 'usernameY']); | ||
}); | ||
}); |
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