Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Nov 23, 2020
1 parent c882c67 commit b8f1ecd
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('AddComment ', () => {
wrapper.find(`[data-test-subj="submit-comment"]`).first().simulate('click');
await waitFor(() => {
expect(onCommentSaving).toBeCalled();
expect(postComment).toBeCalledWith(sampleData, onCommentPosted);
expect(postComment).toBeCalledWith(addCommentProps.caseId, sampleData, onCommentPosted);
expect(formHookMock.reset).toBeCalled();
});
});
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 Down Expand Up @@ -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,11 +34,11 @@ export const useAllCasesModal = ({
[closeModal, onRowClick]
);

const Modal: React.FC = useCallback(
() =>
isModalOpen ? <AllCasesModal onCloseCaseModal={closeModal} onRowClick={onClick} /> : null,
[closeModal, onClick, isModalOpen]
);
const Modal: React.FC = useCallback(() => {
return isModalOpen ? (
<AllCasesModal onCloseCaseModal={closeModal} onRowClick={onClick} />
) : null;
}, [closeModal, onClick, isModalOpen]);

const state = useMemo(
() => ({
Expand Down

0 comments on commit b8f1ecd

Please sign in to comment.