Skip to content

Commit

Permalink
[8.14] [Cases] Fix useGetCases flaky test (#181254) (#181275)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.14`:
- [[Cases] Fix `useGetCases` flaky test
(#181254)](#181254)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Christos
Nasikas","email":"christos.nasikas@elastic.co"},"sourceCommit":{"committedDate":"2024-04-22T09:21:00Z","message":"[Cases]
Fix `useGetCases` flaky test (#181254)\n\n## Summary\r\n\r\nFollowing
@JiaweiWu advice I replaced `waitForNextUpdate`
with\r\n`waitFor`.\r\n\r\nFix:
#178163
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [x] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d5c1335f78a0b578092d5e435308f028d4a7feed","branchLabelMapping":{"^v8.15.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","Feature:Cases","v8.14.0","v8.15.0"],"title":"[Cases]
Fix `useGetCases` flaky
test","number":181254,"url":"#181254
Fix `useGetCases` flaky test (#181254)\n\n## Summary\r\n\r\nFollowing
@JiaweiWu advice I replaced `waitForNextUpdate`
with\r\n`waitFor`.\r\n\r\nFix:
#178163
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [x] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d5c1335f78a0b578092d5e435308f028d4a7feed"}},"sourceBranch":"main","suggestedTargetBranches":["8.14"],"targetPullRequestStates":[{"branch":"8.14","label":"v8.14.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.15.0","branchLabelMappingKey":"^v8.15.0$","isSourceBranch":true,"state":"MERGED","url":"#181254
Fix `useGetCases` flaky test (#181254)\n\n## Summary\r\n\r\nFollowing
@JiaweiWu advice I replaced `waitForNextUpdate`
with\r\n`waitFor`.\r\n\r\nFix:
#178163
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### For
maintainers\r\n\r\n- [x] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"d5c1335f78a0b578092d5e435308f028d4a7feed"}}]}]
BACKPORT-->

Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
  • Loading branch information
kibanamachine and cnasikas committed Apr 22, 2024
1 parent adc946a commit bce0d98
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions x-pack/plugins/cases/public/containers/use_get_cases.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { OWNERS } from '../../common/constants';
jest.mock('./api');
jest.mock('../common/lib/kibana/hooks');

// FLAKY: https://github.com/elastic/kibana/issues/178163
describe.skip('useGetCases', () => {
describe('useGetCases', () => {
const abortCtrl = new AbortController();
const addSuccess = jest.fn();
(useToasts as jest.Mock).mockReturnValue({ addSuccess, addError: jest.fn() });
Expand All @@ -32,11 +31,14 @@ describe.skip('useGetCases', () => {

it('calls getCases with correct arguments', async () => {
const spyOnGetCases = jest.spyOn(api, 'getCases');
const { waitForNextUpdate } = renderHook(() => useGetCases(), {
const { waitFor } = renderHook(() => useGetCases(), {
wrapper: appMockRender.AppWrapper,
});

await waitForNextUpdate();
await waitFor(() => {
expect(spyOnGetCases).toBeCalled();
});

expect(spyOnGetCases).toBeCalledWith({
filterOptions: { ...DEFAULT_FILTER_OPTIONS, owner: ['securitySolution'] },
queryParams: DEFAULT_QUERY_PARAMS,
Expand All @@ -53,12 +55,13 @@ describe.skip('useGetCases', () => {
const addError = jest.fn();
(useToasts as jest.Mock).mockReturnValue({ addSuccess, addError });

const { waitForNextUpdate } = renderHook(() => useGetCases(), {
const { waitFor } = renderHook(() => useGetCases(), {
wrapper: appMockRender.AppWrapper,
});

await waitForNextUpdate();
expect(addError).toHaveBeenCalled();
await waitFor(() => {
expect(addError).toHaveBeenCalled();
});
});

it('should set all owners when no owner is provided', async () => {
Expand Down Expand Up @@ -87,11 +90,13 @@ describe.skip('useGetCases', () => {
};

const spyOnGetCases = jest.spyOn(api, 'getCases');
const { waitForNextUpdate } = renderHook(() => useGetCases(), {
const { waitFor } = renderHook(() => useGetCases(), {
wrapper: appMockRender.AppWrapper,
});

await waitForNextUpdate();
await waitFor(() => {
expect(spyOnGetCases).toHaveBeenCalled();
});

expect(spyOnGetCases).toBeCalledWith({
filterOptions: { ...DEFAULT_FILTER_OPTIONS, owner: [...OWNERS] },
Expand All @@ -104,11 +109,13 @@ describe.skip('useGetCases', () => {
appMockRender = createAppMockRenderer({ owner: [] });
const spyOnGetCases = jest.spyOn(api, 'getCases');

const { waitForNextUpdate } = renderHook(() => useGetCases(), {
const { waitFor } = renderHook(() => useGetCases(), {
wrapper: appMockRender.AppWrapper,
});

await waitForNextUpdate();
await waitFor(() => {
expect(spyOnGetCases).toHaveBeenCalled();
});

expect(spyOnGetCases).toBeCalledWith({
filterOptions: { ...DEFAULT_FILTER_OPTIONS, owner: ['cases'] },
Expand All @@ -121,11 +128,13 @@ describe.skip('useGetCases', () => {
appMockRender = createAppMockRenderer({ owner: ['observability'] });
const spyOnGetCases = jest.spyOn(api, 'getCases');

const { waitForNextUpdate } = renderHook(() => useGetCases(), {
const { waitFor } = renderHook(() => useGetCases(), {
wrapper: appMockRender.AppWrapper,
});

await waitForNextUpdate();
await waitFor(() => {
expect(spyOnGetCases).toHaveBeenCalled();
});

expect(spyOnGetCases).toBeCalledWith({
filterOptions: { ...DEFAULT_FILTER_OPTIONS, owner: ['observability'] },
Expand All @@ -138,14 +147,13 @@ describe.skip('useGetCases', () => {
appMockRender = createAppMockRenderer({ owner: ['observability'] });
const spyOnGetCases = jest.spyOn(api, 'getCases');

const { waitForNextUpdate } = renderHook(
() => useGetCases({ filterOptions: { owner: ['my-owner'] } }),
{
wrapper: appMockRender.AppWrapper,
}
);
const { waitFor } = renderHook(() => useGetCases({ filterOptions: { owner: ['my-owner'] } }), {
wrapper: appMockRender.AppWrapper,
});

await waitForNextUpdate();
await waitFor(() => {
expect(spyOnGetCases).toHaveBeenCalled();
});

expect(spyOnGetCases).toBeCalledWith({
filterOptions: { ...DEFAULT_FILTER_OPTIONS, owner: ['my-owner'] },
Expand Down

0 comments on commit bce0d98

Please sign in to comment.