Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Dec 2, 2020
1 parent 0b176ff commit 6be47ae
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('AddComment ', () => {

await waitFor(() => {
expect(onCommentSaving).toBeCalled();
expect(postComment).toBeCalledWith(sampleData, onCommentPosted);
expect(postComment).toBeCalledWith(addCommentProps.caseId, sampleData, onCommentPosted);
expect(wrapper.find(`[data-test-subj="add-comment"] textarea`).text()).toBe('');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,44 @@ describe('AllCases', () => {
);
await waitFor(() => {
wrapper.find('[data-test-subj="cases-table-row-1"]').first().simulate('click');
expect(onRowClick).toHaveBeenCalledWith('1');
expect(onRowClick).toHaveBeenCalledWith({
closedAt: null,
closedBy: null,
comments: [],
connector: { fields: null, id: '123', name: 'My Connector', type: '.none' },
createdAt: '2020-02-19T23:06:33.798Z',
createdBy: {
email: 'leslie.knope@elastic.co',
fullName: 'Leslie Knope',
username: 'lknope',
},
description: 'Security banana Issue',
externalService: {
connectorId: '123',
connectorName: 'connector name',
externalId: 'external_id',
externalTitle: 'external title',
externalUrl: 'basicPush.com',
pushedAt: '2020-02-20T15:02:57.995Z',
pushedBy: {
email: 'leslie.knope@elastic.co',
fullName: 'Leslie Knope',
username: 'lknope',
},
},
id: '1',
status: 'open',
tags: ['coke', 'pepsi'],
title: 'Another horrible breach!!',
totalComment: 0,
updatedAt: '2020-02-20T15:02:57.995Z',
updatedBy: {
email: 'leslie.knope@elastic.co',
fullName: 'Leslie Knope',
username: 'lknope',
},
version: 'WzQ3LDFd',
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@

import React from 'react';
import { renderHook, act } from '@testing-library/react-hooks';
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { useKibana } from '../../../common/lib/kibana';
import '../../../common/mock/match_media';
import { useAllCasesModal, UseAllCasesModalProps, UseAllCasesModalReturnedValues } from '.';
import { TestProviders } from '../../../common/mock';

jest.mock('../../../common/lib/kibana');
jest.mock('../all_cases', () => {
return {
AllCases: ({ onRowClick }: { onRowClick: ({ id }: { id: string }) => void }) => {
return (
<button type="button" onClick={() => onRowClick({ id: 'case-id' })}>
{'case-row'}
</button>
);
},
};
});

const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
const onRowClick = jest.fn();
Expand All @@ -32,7 +44,7 @@ describe('useAllCasesModal', () => {
const { result } = renderHook<UseAllCasesModalProps, UseAllCasesModalReturnedValues>(
() => useAllCasesModal({ onRowClick }),
{
wrapper: ({ children }) => <TestProviders> {children}</TestProviders>,
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);

Expand All @@ -43,7 +55,7 @@ describe('useAllCasesModal', () => {
const { result } = renderHook<UseAllCasesModalProps, UseAllCasesModalReturnedValues>(
() => useAllCasesModal({ onRowClick }),
{
wrapper: ({ children }) => <TestProviders> {children}</TestProviders>,
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);

Expand All @@ -58,7 +70,7 @@ describe('useAllCasesModal', () => {
const { result } = renderHook<UseAllCasesModalProps, UseAllCasesModalReturnedValues>(
() => useAllCasesModal({ onRowClick }),
{
wrapper: ({ children }) => <TestProviders> {children}</TestProviders>,
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);

Expand All @@ -74,7 +86,7 @@ describe('useAllCasesModal', () => {
const { result, rerender } = renderHook<UseAllCasesModalProps, UseAllCasesModalReturnedValues>(
() => useAllCasesModal({ onRowClick }),
{
wrapper: ({ children }) => <TestProviders> {children}</TestProviders>,
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);

Expand All @@ -84,4 +96,27 @@ describe('useAllCasesModal', () => {

expect(result1).toBe(result2);
});

it('closes the modal when clicking a row', async () => {
const { result } = renderHook<UseAllCasesModalProps, UseAllCasesModalReturnedValues>(
() => useAllCasesModal({ onRowClick }),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);

act(() => {
result.current.openModal();
});

const Modal = result.current.Modal;
render(<Modal />);

act(() => {
userEvent.click(screen.getByText('case-row'));
});

expect(result.current.isModalOpen).toBe(false);
expect(onRowClick).toHaveBeenCalledWith({ id: 'case-id' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ import { timelineDefaults } from '../../store/timeline/defaults';
import { TimelineModel } from '../../store/timeline/model';
import { isFullScreen } from '../timeline/body/column_headers';
import { NewCase, ExistingCase } from '../timeline/properties/helpers';
import { updateTimelineGraphEventId } from '../../../timelines/store/timeline/actions';
import {
setInsertTimeline,
updateTimelineGraphEventId,
} from '../../../timelines/store/timeline/actions';
import { Resolver } from '../../../resolver/view';
import { useAllCasesModal } from '../../../cases/components/use_all_cases_modal';
import { useKibana, useUiSetting$ } from '../../../common/lib/kibana';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Case } from '../../../../cases/containers/types';
import { TimelineProperties } from './styles';
import { PropertiesRight } from './properties_right';
import { PropertiesLeft } from './properties_left';
import { setInsertTimeline } from '../../../store/timeline/actions';

type UpdateIsFavorite = ({ id, isFavorite }: { id: string; isFavorite: boolean }) => void;
type UpdateTitle = ({ id, title }: { id: string; title: string }) => void;
Expand Down

0 comments on commit 6be47ae

Please sign in to comment.