-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[RAM] Fix flaky test for update api key tests #152277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
43eb8df
bring tests
XavierM b0ecc29
Merge branch 'main' of github.com:elastic/kibana
XavierM a68aec7
Merge branch 'main' of github.com:elastic/kibana
XavierM 561b6e0
Merge branch 'main' of github.com:elastic/kibana
XavierM db8a5f6
Merge branch 'main' of github.com:elastic/kibana
XavierM 182ed1f
Merge branch 'main' of github.com:elastic/kibana
XavierM 7bcac6c
Merge branch 'main' of github.com:elastic/kibana
XavierM f6f677d
Merge branch 'main' of github.com:elastic/kibana into update_api_key_…
XavierM 19134ea
bring back update api keys tests
XavierM 23aaf8f
add test to check when http call failler
XavierM 1430bef
Merge branch 'main' of github.com:elastic/kibana into update_api_key_…
XavierM 9592efa
Merge branch 'main' into update_api_key_tests
XavierM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
...ggers_actions_ui/public/application/components/update_api_key_modal_confirmation.test.tsx
This file contains hidden or 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,131 @@ | ||
| /* | ||
| * 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 * as React from 'react'; | ||
| import { __IntlProvider as IntlProvider } from '@kbn/i18n-react'; | ||
| import { IToasts } from '@kbn/core/public'; | ||
| import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
| import { UpdateApiKeyModalConfirmation } from './update_api_key_modal_confirmation'; | ||
| import { useKibana } from '../../common/lib/kibana'; | ||
|
|
||
| const Providers = ({ children }: { children: any }) => ( | ||
| <IntlProvider locale="en">{children}</IntlProvider> | ||
| ); | ||
|
|
||
| const renderWithProviders = (ui: any) => { | ||
| return render(ui, { wrapper: Providers }); | ||
| }; | ||
|
|
||
| jest.mock('../../common/lib/kibana'); | ||
| const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>; | ||
|
|
||
| describe('Update Api Key', () => { | ||
| const onCancel = jest.fn(); | ||
| const apiUpdateApiKeyCall = jest.fn(); | ||
| const setIsLoadingState = jest.fn(); | ||
| const onUpdated = jest.fn(); | ||
| const onSearchPopulate = jest.fn(); | ||
|
|
||
| const addSuccess = jest.fn(); | ||
| const addError = jest.fn(); | ||
|
|
||
| beforeAll(() => { | ||
| useKibanaMock().services.notifications.toasts = { | ||
| addSuccess, | ||
| addError, | ||
| } as unknown as IToasts; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('Render modal updates Api Key', async () => { | ||
| renderWithProviders( | ||
| <UpdateApiKeyModalConfirmation | ||
| onCancel={onCancel} | ||
| idsToUpdate={['2']} | ||
| apiUpdateApiKeyCall={apiUpdateApiKeyCall} | ||
| setIsLoadingState={setIsLoadingState} | ||
| onUpdated={onUpdated} | ||
| onSearchPopulate={onSearchPopulate} | ||
| /> | ||
| ); | ||
|
|
||
| expect( | ||
| await screen.findByText('You will not be able to recover the old API key') | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('Cancel modal updates Api Key', async () => { | ||
| renderWithProviders( | ||
| <UpdateApiKeyModalConfirmation | ||
| onCancel={onCancel} | ||
| idsToUpdate={['2']} | ||
| apiUpdateApiKeyCall={apiUpdateApiKeyCall} | ||
| setIsLoadingState={setIsLoadingState} | ||
| onUpdated={onUpdated} | ||
| onSearchPopulate={onSearchPopulate} | ||
| /> | ||
| ); | ||
|
|
||
| fireEvent.click(await screen.findByText('Cancel')); | ||
| expect(onCancel).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('Update an Api Key', async () => { | ||
| apiUpdateApiKeyCall.mockResolvedValue({}); | ||
| renderWithProviders( | ||
| <UpdateApiKeyModalConfirmation | ||
| onCancel={onCancel} | ||
| idsToUpdate={['2']} | ||
| apiUpdateApiKeyCall={apiUpdateApiKeyCall} | ||
| setIsLoadingState={setIsLoadingState} | ||
| onUpdated={onUpdated} | ||
| onSearchPopulate={onSearchPopulate} | ||
| /> | ||
| ); | ||
|
|
||
| fireEvent.click(await screen.findByText('Update')); | ||
| expect(setIsLoadingState).toBeCalledTimes(1); | ||
| expect(apiUpdateApiKeyCall).toHaveBeenLastCalledWith(expect.objectContaining({ ids: ['2'] })); | ||
| await waitFor(() => { | ||
| expect(setIsLoadingState).toBeCalledTimes(2); | ||
| expect(onUpdated).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| it('Failed to update an Api Key', async () => { | ||
| apiUpdateApiKeyCall.mockRejectedValue(500); | ||
| renderWithProviders( | ||
| <UpdateApiKeyModalConfirmation | ||
| onCancel={onCancel} | ||
| idsToUpdate={['2']} | ||
| apiUpdateApiKeyCall={apiUpdateApiKeyCall} | ||
| setIsLoadingState={setIsLoadingState} | ||
| onUpdated={onUpdated} | ||
| onSearchPopulate={onSearchPopulate} | ||
| /> | ||
| ); | ||
|
|
||
| fireEvent.click(await screen.findByText('Update')); | ||
| expect(setIsLoadingState).toBeCalledTimes(1); | ||
| expect(apiUpdateApiKeyCall).toHaveBeenLastCalledWith(expect.objectContaining({ ids: ['2'] })); | ||
| await waitFor(() => { | ||
| expect(setIsLoadingState).toBeCalledTimes(2); | ||
| expect(addError).toHaveBeenCalled(); | ||
| expect(addError.mock.calls[0]).toMatchInlineSnapshot(` | ||
| Array [ | ||
| 500, | ||
| Object { | ||
| "title": "Failed to update the API key", | ||
| }, | ||
| ] | ||
| `); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.