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 df9b83f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@
* 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: string, title: string) => void }) => {
return (
<button
type="button"
data-test-subj="all-cases-row"
onClick={() => onRowClick('case-id', 'case title')}
>
{'case-row'}
</button>
);
},
};
return { AllCases };
});

jest.mock('../../../common/lib/kibana', () => {
Expand Down Expand Up @@ -82,4 +93,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('case-id', 'case title');
});
});
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 Down

0 comments on commit df9b83f

Please sign in to comment.