Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Jul 16, 2020
1 parent a48c3c0 commit b7c692a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,31 @@ describe('CaseView ', () => {
wrapper.find('button[data-test-subj="push-to-external-service"]').first().prop('disabled')
).toBeTruthy();
});

it('should revert to the initial connector in case of failure', async () => {
updateCaseProperty.mockImplementation(({ onError }) => {
onError();
});
const wrapper = mount(
<TestProviders>
<Router history={mockHistory}>
<CaseComponent
{...caseProps}
caseData={{ ...caseProps.caseData, connectorId: 'servicenow-1' }}
/>
</Router>
</TestProviders>
);
await wait();
wrapper.find('button[data-test-subj="dropdown-connectors"]').simulate('click');
wrapper.update();
wrapper.find('button[data-test-subj="dropdown-connector-servicenow-2"]').simulate('click');
wrapper.update();
wrapper.find(`[data-test-subj="edit-connectors-submit"]`).last().simulate('click');
wrapper.update();
await wait();
expect(wrapper.find('button[data-test-subj="dropdown-connectors"]').text()).toBe(
'My Connector'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,35 @@ describe('EditConnector ', () => {
await act(async () => {
wrapper.find(`[data-test-subj="edit-connectors-submit"]`).last().simulate('click');
await wait();
expect(onSubmit).toBeCalledWith(sampleConnector);
expect(onSubmit.mock.calls[0][0]).toBe(sampleConnector);
});
});

it('Revert to initial external service on error', async () => {
onSubmit.mockImplementation((connector, onSuccess, onError) => {
onError(new Error('An error has occurred'));
});
const wrapper = mount(
<TestProviders>
<EditConnector {...defaultProps} />
</TestProviders>
);

wrapper.find('button[data-test-subj="dropdown-connectors"]').simulate('click');
wrapper.update();
wrapper.find('button[data-test-subj="dropdown-connector-servicenow-2"]').simulate('click');
wrapper.update();

expect(wrapper.find(`[data-test-subj="edit-connectors-submit"]`).last().exists()).toBeTruthy();

await act(async () => {
wrapper.find(`[data-test-subj="edit-connectors-submit"]`).last().simulate('click');
await wait();
wrapper.update();
});
expect(formHookMock.setFieldValue).toHaveBeenCalledWith('connector', 'none');
});

it('Resets selector on cancel', async () => {
const props = {
...defaultProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ describe('UserActionTree ', () => {
)
.exists()
).toEqual(false);
expect(onUpdateField).toBeCalledWith('description', sampleData.content);
expect(onUpdateField).toBeCalledWith({ key: 'description', value: sampleData.content });
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ describe('useUpdateCase', () => {
const fetchCaseUserActions = jest.fn();
const updateCase = jest.fn();
const updateKey: UpdateKey = 'description';
const onSuccess = jest.fn();
const onError = jest.fn();

const sampleUpdate = {
fetchCaseUserActions,
updateKey,
updateValue: 'updated description',
updateCase,
version: basicCase.version,
onSuccess,
onError,
};
beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -79,6 +84,7 @@ describe('useUpdateCase', () => {
});
expect(fetchCaseUserActions).toBeCalledWith(basicCase.id);
expect(updateCase).toBeCalledWith(basicCase);
expect(onSuccess).toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -114,6 +120,7 @@ describe('useUpdateCase', () => {
isError: true,
updateCaseProperty: result.current.updateCaseProperty,
});
expect(onError).toHaveBeenCalled();
});
});
});

0 comments on commit b7c692a

Please sign in to comment.