Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Dec 8, 2020
1 parent 1da1728 commit 812de1e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

/* eslint-disable react/display-name */
import { mount } from 'enzyme';
import React from 'react';
import '../../../common/mock/match_media';
import { AllCasesModal } from './all_cases_modal';
import { TestProviders } from '../../../common/mock';

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

jest.mock('../../../common/lib/kibana', () => {
Expand Down Expand Up @@ -82,4 +89,15 @@ describe('AllCasesModal', () => {
isModal: true,
});
});

it('onRowClick called when row is clicked', () => {
const wrapper = mount(
<TestProviders>
<AllCasesModal {...defaultProps} />
</TestProviders>
);

wrapper.find(`[data-test-subj='all-cases-row']`).first().simulate('click');
expect(onRowClick).toHaveBeenCalledWith({ id: 'case-id' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

/* eslint-disable react/display-name */

import React from 'react';
import { renderHook, act } from '@testing-library/react-hooks';
import { render, screen } from '@testing-library/react';
Expand All @@ -29,9 +28,9 @@ jest.mock('react-redux', () => {
jest.mock('../../../common/lib/kibana');
jest.mock('../all_cases', () => {
return {
AllCases: ({ onRowClick }: { onRowClick: (id: string, title: string) => void }) => {
AllCases: ({ onRowClick }: { onRowClick: ({ id }: { id: string }) => void }) => {
return (
<button type="button" onClick={() => onRowClick('case-id', 'case title')}>
<button type="button" onClick={() => onRowClick({ id: 'case-id' })}>
{'case-row'}
</button>
);
Expand Down Expand Up @@ -130,6 +129,6 @@ describe('useAllCasesModal', () => {
});

expect(result.current.isModalOpen).toBe(false);
expect(onRowClick).toHaveBeenCalledWith('case-id', 'case title');
expect(onRowClick).toHaveBeenCalledWith({ id: 'case-id' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('EventColumnView', () => {
selectedEventIds: {},
showCheckboxes: false,
showNotes: false,
timelineId: 'timeline-1',
timelineId: 'timeline-test',
toggleShowNotes: jest.fn(),
updateNote: jest.fn(),
isEventPinned: false,
Expand Down

0 comments on commit 812de1e

Please sign in to comment.