Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed May 13, 2021
1 parent 29068cb commit 339c0db
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import styled from 'styled-components';
import { EuiCallOut, EuiSpacer } from '@elastic/eui';

import { ActionParamsProps } from '../../../../../triggers_actions_ui/public/types';
import { CommentType } from '../../../../common';
import { CommentType, SECURITY_SOLUTION_OWNER } from '../../../../common';

import { CaseActionParams } from './types';
import { ExistingCase } from './existing_case';
Expand Down Expand Up @@ -98,7 +98,7 @@ const CaseParamsFields: React.FunctionComponent<ActionParamsProps<CaseActionPara
<ExistingCase
onCaseChanged={onCaseChanged}
selectedCase={selectedCase}
owner="securitySolution"
owner={SECURITY_SOLUTION_OWNER}
/>
<EuiSpacer size="m" />
<EuiCallOut size="s" title={i18n.CASE_CONNECTOR_CALL_OUT_TITLE} iconType="iInCircle">
Expand Down
8 changes: 7 additions & 1 deletion x-pack/plugins/cases/public/components/create/form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { useConnectors } from '../../containers/configure/use_connectors';
import { connectorsMock } from '../../containers/mock';
import { schema, FormProps } from './schema';
import { CreateCaseForm } from './form';
import { OwnerProvider } from '../owner_context';
import { SECURITY_SOLUTION_OWNER } from '../../../common';

jest.mock('../../containers/use_get_tags');
jest.mock('../../containers/configure/use_connectors');
Expand All @@ -41,7 +43,11 @@ describe('CreateCaseForm', () => {

globalForm = form;

return <Form form={form}>{children}</Form>;
return (
<OwnerProvider owner={[SECURITY_SOLUTION_OWNER]}>
<Form form={form}>{children}</Form>
</OwnerProvider>
);
};

beforeEach(() => {
Expand Down
8 changes: 7 additions & 1 deletion x-pack/plugins/cases/public/components/create/tags.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { useForm, Form, FormHook } from '../../common/shared_imports';
import { useGetTags } from '../../containers/use_get_tags';
import { Tags } from './tags';
import { schema, FormProps } from './schema';
import { OwnerProvider } from '../owner_context';
import { SECURITY_SOLUTION_OWNER } from '../../../common';

jest.mock('../../containers/use_get_tags');
const useGetTagsMock = useGetTags as jest.Mock;
Expand All @@ -31,7 +33,11 @@ describe('Tags', () => {

globalForm = form;

return <Form form={form}>{children}</Form>;
return (
<OwnerProvider owner={[SECURITY_SOLUTION_OWNER]}>
<Form form={form}>{children}</Form>
</OwnerProvider>
);
};

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import React, { useState } from 'react';

// This context is available to all children of the stateful_event component where the provider is currently set
export const OwnerContext = React.createContext<string[]>([]);

export const OwnerProvider: React.FC<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('RecentCases', () => {
jest.clearAllMocks();
useGetCasesMock.mockImplementation(() => mockData);
});

it('is good at loading', () => {
useGetCasesMock.mockImplementation(() => ({
...mockData,
Expand All @@ -55,6 +56,7 @@ describe('RecentCases', () => {
);
expect(getAllByTestId('loadingPlaceholders')).toHaveLength(3);
});

it('is good at rendering cases', () => {
const { getAllByTestId } = render(
<TestProviders>
Expand All @@ -63,14 +65,19 @@ describe('RecentCases', () => {
);
expect(getAllByTestId('case-details-link')).toHaveLength(5);
});

it('is good at rendering max cases', () => {
render(
<TestProviders>
<RecentCases {...{ ...defaultProps, maxCasesToShow: 2 }} />
</TestProviders>
);
expect(useGetCasesMock).toBeCalledWith({ perPage: 2 });
expect(useGetCasesMock).toBeCalledWith({
initialQueryParams: { perPage: 2 },
initialFilterOptions: { owner: [SECURITY_SOLUTION_OWNER] },
});
});

it('updates filters', () => {
const { getByTestId } = render(
<TestProviders>
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/public/containers/api.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe('Case Configuration API', () => {
method: 'GET',
signal: abortCtrl.signal,
query: {
owner: SECURITY_SOLUTION_OWNER,
owner: [SECURITY_SOLUTION_OWNER],
},
});
});
Expand All @@ -278,7 +278,7 @@ describe('Case Configuration API', () => {
method: 'GET',
signal: abortCtrl.signal,
query: {
owner: SECURITY_SOLUTION_OWNER,
owner: [SECURITY_SOLUTION_OWNER],
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Case Configuration API', () => {
method: 'GET',
signal: abortCtrl.signal,
query: {
owner: SECURITY_SOLUTION_OWNER,
owner: [SECURITY_SOLUTION_OWNER],
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const initialState: State = {
};

/**
* Configurations across multiple plugins in
* Configurations across multiple plugins is
* not supported at the moment. For that reason owner: string;
* instead of owner: string[]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Create case', () => {
);

expect(mockCreateCase).toHaveBeenCalled();
expect(mockCreateCase.mock.calls[0][0].owner).toBe([APP_ID]);
expect(mockCreateCase.mock.calls[0][0].owner).toEqual([APP_ID]);
});

it('should redirect to all cases on cancel click', async () => {
Expand Down

0 comments on commit 339c0db

Please sign in to comment.