Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed May 14, 2021
1 parent 3b4634e commit 11b01b0
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ describe('RecentCases', () => {
);
expect(useGetCasesMock).toBeCalledWith({
initialQueryParams: { perPage: 2 },
initialFilterOptions: { owner: [SECURITY_SOLUTION_OWNER] },
});
});

Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/cases/public/containers/api.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ describe('Case Configuration API', () => {
...DEFAULT_QUERY_PARAMS,
reporters: [],
tags: [],
owner: [SECURITY_SOLUTION_OWNER],
},
signal: abortCtrl.signal,
});
Expand All @@ -163,6 +164,7 @@ describe('Case Configuration API', () => {
tags: ['"coke"', '"pepsi"'],
search: 'hello',
status: CaseStatuses.open,
owner: [SECURITY_SOLUTION_OWNER],
},
signal: abortCtrl.signal,
});
Expand Down Expand Up @@ -191,6 +193,7 @@ describe('Case Configuration API', () => {
tags: ['"("', '"\\"double\\""'],
search: 'hello',
status: CaseStatuses.open,
owner: [SECURITY_SOLUTION_OWNER],
},
signal: abortCtrl.signal,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import React from 'react';
import { renderHook, act } from '@testing-library/react-hooks';
import {
initialState,
Expand All @@ -15,6 +16,7 @@ import {
import { mappings, caseConfigurationCamelCaseResponseMock } from './mock';
import * as api from './api';
import { ConnectorTypes } from '../../../common';
import { TestProviders } from '../../common/mock';

const mockErrorToast = jest.fn();
const mockSuccessToast = jest.fn();
Expand Down Expand Up @@ -49,8 +51,11 @@ describe('useConfigure', () => {

test('init', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);
await waitForNextUpdate();
expect(result.current).toEqual({
Expand All @@ -67,8 +72,11 @@ describe('useConfigure', () => {

test('fetch case configuration', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);
await waitForNextUpdate();
await waitForNextUpdate();
Expand Down Expand Up @@ -99,8 +107,11 @@ describe('useConfigure', () => {
const spyOnGetCaseConfigure = jest.spyOn(api, 'getCaseConfigure');

await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);
await waitForNextUpdate();
await waitForNextUpdate();
Expand All @@ -111,8 +122,11 @@ describe('useConfigure', () => {

test('correctly sets mappings', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);
await waitForNextUpdate();
await waitForNextUpdate();
Expand All @@ -124,8 +138,11 @@ describe('useConfigure', () => {

test('set isLoading to true when fetching case configuration', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);
await waitForNextUpdate();
await waitForNextUpdate();
Expand All @@ -137,8 +154,11 @@ describe('useConfigure', () => {

test('persist case configuration', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);
await waitForNextUpdate();
await waitForNextUpdate();
Expand Down Expand Up @@ -166,8 +186,11 @@ describe('useConfigure', () => {
);

await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);
await waitForNextUpdate();
await waitForNextUpdate();
Expand All @@ -192,8 +215,11 @@ describe('useConfigure', () => {
);

await act(async () => {
const { waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);
await waitForNextUpdate();
await waitForNextUpdate();
Expand Down Expand Up @@ -221,8 +247,11 @@ describe('useConfigure', () => {
);

await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);
await waitForNextUpdate();
await waitForNextUpdate();
Expand All @@ -245,8 +274,11 @@ describe('useConfigure', () => {
);

await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);
await waitForNextUpdate();
await waitForNextUpdate();
Expand All @@ -266,8 +298,11 @@ describe('useConfigure', () => {
});

await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);

await waitForNextUpdate();
Expand Down Expand Up @@ -302,8 +337,11 @@ describe('useConfigure', () => {
});

await act(async () => {
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(() =>
useCaseConfigure()
const { result, waitForNextUpdate } = renderHook<string, ReturnUseCaseConfigure>(
() => useCaseConfigure(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);

await waitForNextUpdate();
Expand Down
Loading

0 comments on commit 11b01b0

Please sign in to comment.