-
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
7 changed files
with
1,182 additions
and
213 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
x-pack/plugins/cases/public/common/use_is_user_typing.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,81 @@ | ||
/* | ||
* 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 { act, renderHook } from '@testing-library/react-hooks'; | ||
import type { AppMockRenderer } from './mock'; | ||
import { createAppMockRenderer } from './mock'; | ||
import { useIsUserTyping } from './use_is_user_typing'; | ||
|
||
describe('useIsUserTyping', () => { | ||
let appMockRender: AppMockRenderer; | ||
|
||
beforeEach(() => { | ||
appMockRender = createAppMockRenderer(); | ||
}); | ||
|
||
it('set isUserTyping=false on init', () => { | ||
const { result } = renderHook(() => useIsUserTyping(), { | ||
wrapper: appMockRender.AppWrapper, | ||
}); | ||
|
||
expect(result.current.isUserTyping).toBe(false); | ||
}); | ||
|
||
it('set isUserTyping to true with setIsUserTyping', () => { | ||
const { result } = renderHook(() => useIsUserTyping(), { | ||
wrapper: appMockRender.AppWrapper, | ||
}); | ||
|
||
act(() => { | ||
result.current.setIsUserTyping(true); | ||
}); | ||
|
||
expect(result.current.isUserTyping).toBe(true); | ||
}); | ||
|
||
it('set isUserTyping to true onContentChange', () => { | ||
const { result } = renderHook(() => useIsUserTyping(), { | ||
wrapper: appMockRender.AppWrapper, | ||
}); | ||
|
||
act(() => { | ||
result.current.onContentChange('a value'); | ||
}); | ||
|
||
expect(result.current.isUserTyping).toBe(true); | ||
}); | ||
|
||
it('does not set isUserTyping to true onContentChange when the value is empty', () => { | ||
const { result } = renderHook(() => useIsUserTyping(), { | ||
wrapper: appMockRender.AppWrapper, | ||
}); | ||
|
||
act(() => { | ||
result.current.onContentChange(''); | ||
}); | ||
|
||
expect(result.current.isUserTyping).toBe(false); | ||
}); | ||
|
||
it('set isUserTyping to false onDebounce', () => { | ||
const { result } = renderHook(() => useIsUserTyping(), { | ||
wrapper: appMockRender.AppWrapper, | ||
}); | ||
|
||
act(() => { | ||
result.current.setIsUserTyping(true); | ||
}); | ||
|
||
expect(result.current.isUserTyping).toBe(true); | ||
|
||
act(() => { | ||
result.current.onDebounce(); | ||
}); | ||
|
||
expect(result.current.isUserTyping).toBe(false); | ||
}); | ||
}); |
144 changes: 144 additions & 0 deletions
144
x-pack/plugins/cases/public/components/actions/assignees/use_assignees_action.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,144 @@ | ||
/* | ||
* 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 type { AppMockRenderer } from '../../../common/mock'; | ||
import { createAppMockRenderer } from '../../../common/mock'; | ||
import { act, renderHook } from '@testing-library/react-hooks'; | ||
import { useAssigneesAction } from './use_assignees_action'; | ||
|
||
import * as api from '../../../containers/api'; | ||
import { basicCase } from '../../../containers/mock'; | ||
|
||
jest.mock('../../../containers/api'); | ||
|
||
describe('useAssigneesAction', () => { | ||
let appMockRender: AppMockRenderer; | ||
const onAction = jest.fn(); | ||
const onActionSuccess = jest.fn(); | ||
|
||
beforeEach(() => { | ||
appMockRender = createAppMockRenderer(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders an action', async () => { | ||
const { result } = renderHook( | ||
() => | ||
useAssigneesAction({ | ||
onAction, | ||
onActionSuccess, | ||
isDisabled: false, | ||
}), | ||
{ | ||
wrapper: appMockRender.AppWrapper, | ||
} | ||
); | ||
|
||
expect(result.current.getAction([basicCase])).toMatchInlineSnapshot(` | ||
Object { | ||
"data-test-subj": "cases-bulk-action-assignees", | ||
"disabled": false, | ||
"icon": <EuiIcon | ||
size="m" | ||
type="userAvatar" | ||
/>, | ||
"key": "cases-bulk-action-assignees", | ||
"name": "Edit assignees", | ||
"onClick": [Function], | ||
} | ||
`); | ||
}); | ||
|
||
it('update the assignees correctly', async () => { | ||
const updateSpy = jest.spyOn(api, 'updateCases'); | ||
|
||
const { result, waitFor } = renderHook( | ||
() => useAssigneesAction({ onAction, onActionSuccess, isDisabled: false }), | ||
{ | ||
wrapper: appMockRender.AppWrapper, | ||
} | ||
); | ||
|
||
const action = result.current.getAction([basicCase]); | ||
|
||
act(() => { | ||
action.onClick(); | ||
}); | ||
|
||
expect(onAction).toHaveBeenCalled(); | ||
expect(result.current.isFlyoutOpen).toBe(true); | ||
|
||
act(() => { | ||
result.current.onSaveAssignees({ selectedItems: ['1'], unSelectedItems: [] }); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(result.current.isFlyoutOpen).toBe(false); | ||
expect(onActionSuccess).toHaveBeenCalled(); | ||
expect(updateSpy).toHaveBeenCalledWith( | ||
[ | ||
{ | ||
assignees: [{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }, { uid: '1' }], | ||
id: basicCase.id, | ||
version: basicCase.version, | ||
}, | ||
], | ||
expect.anything() | ||
); | ||
}); | ||
}); | ||
|
||
it('shows the success toaster correctly when updating one case', async () => { | ||
const { result, waitFor } = renderHook( | ||
() => useAssigneesAction({ onAction, onActionSuccess, isDisabled: false }), | ||
{ | ||
wrapper: appMockRender.AppWrapper, | ||
} | ||
); | ||
|
||
const action = result.current.getAction([basicCase]); | ||
|
||
act(() => { | ||
action.onClick(); | ||
}); | ||
|
||
act(() => { | ||
result.current.onSaveAssignees({ selectedItems: ['1', '1'], unSelectedItems: ['2'] }); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith( | ||
'Edited case' | ||
); | ||
}); | ||
}); | ||
|
||
it('shows the success toaster correctly when updating multiple cases', async () => { | ||
const { result, waitFor } = renderHook( | ||
() => useAssigneesAction({ onAction, onActionSuccess, isDisabled: false }), | ||
{ | ||
wrapper: appMockRender.AppWrapper, | ||
} | ||
); | ||
|
||
const action = result.current.getAction([basicCase, basicCase]); | ||
|
||
act(() => { | ||
action.onClick(); | ||
}); | ||
|
||
act(() => { | ||
result.current.onSaveAssignees({ selectedItems: ['1', '1'], unSelectedItems: ['2'] }); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(appMockRender.coreStart.notifications.toasts.addSuccess).toHaveBeenCalledWith( | ||
'Edited 2 cases' | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.