Adds test for link add/edit/delete modals

This commit is contained in:
mabashian 2020-02-04 11:14:28 -05:00
parent f9debb8f94
commit 887469d73e
4 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import React from 'react';
import { mountWithContexts } from '@testUtils/enzymeHelpers';
import { WorkflowDispatchContext, WorkflowStateContext } from '@contexts/Workflow';
import LinkAddModal from './LinkAddModal';
const dispatch = jest.fn();
const workflowContext = {
linkToEdit: null
};
describe('LinkAddModal', () => {
test('Confirm button dispatches as expected', () => {
const wrapper = mountWithContexts(
<WorkflowDispatchContext.Provider value={dispatch}>
<WorkflowStateContext.Provider value={workflowContext}>
<LinkAddModal />
</WorkflowStateContext.Provider>
</WorkflowDispatchContext.Provider>
);
wrapper.find('button#link-confirm').simulate('click');
expect(dispatch).toHaveBeenCalledWith({ type: 'CREATE_LINK', linkType: 'success' });
});
});

View File

@ -19,6 +19,7 @@ function LinkDeleteModal({ i18n }) {
onClose={() => dispatch({ type: 'SET_LINK_TO_DELETE', value: null })}
actions={[
<Button
id="confirm-link-removal"
aria-label={i18n._(t`Confirm link removal`)}
key="remove"
onClick={() => dispatch({ type: 'DELETE_LINK' })}
@ -27,6 +28,7 @@ function LinkDeleteModal({ i18n }) {
{i18n._(t`Remove`)}
</Button>,
<Button
id="cancel-link-removal"
aria-label={i18n._(t`Cancel link removal`)}
key="cancel"
onClick={() => dispatch({ type: 'SET_LINK_TO_DELETE', value: null })}

View File

@ -0,0 +1,60 @@
import React from 'react';
import {
WorkflowDispatchContext,
WorkflowStateContext
} from '@contexts/Workflow';
import { mountWithContexts } from '@testUtils/enzymeHelpers';
import LinkDeleteModal from './LinkDeleteModal';
let wrapper;
const dispatch = jest.fn();
const workflowContext = {
linkToDelete: {
source: {
id: 2
},
target: {
id: 3
},
linkType: 'always'
}
};
describe('LinkDeleteModal', () => {
beforeAll(() => {
wrapper = mountWithContexts(
<WorkflowDispatchContext.Provider value={dispatch}>
<WorkflowStateContext.Provider value={workflowContext}>
<LinkDeleteModal />
</WorkflowStateContext.Provider>
</WorkflowDispatchContext.Provider>
);
});
afterAll(() => {
wrapper.unmount();
});
test('Confirm button dispatches as expected', () => {
wrapper.find('button#confirm-link-removal').simulate('click');
expect(dispatch).toHaveBeenCalledWith({
type: 'DELETE_LINK',
});
});
test('Cancel button dispatches as expected', () => {
wrapper.find('button#cancel-link-removal').simulate('click');
expect(dispatch).toHaveBeenCalledWith({
type: 'SET_LINK_TO_DELETE',
value: null,
});
});
test('Close button dispatches as expected', () => {
wrapper.find('TimesIcon').simulate('click');
expect(dispatch).toHaveBeenCalledWith({
type: 'SET_LINK_TO_DELETE', value: null
});
});
});

View File

@ -0,0 +1,32 @@
import React from 'react';
import { mountWithContexts } from '@testUtils/enzymeHelpers';
import { WorkflowDispatchContext, WorkflowStateContext } from '@contexts/Workflow';
import LinkEditModal from './LinkEditModal';
const dispatch = jest.fn();
const workflowContext = {
linkToEdit: {
source: {
id: 2
},
target: {
id: 3
},
linkType: 'always'
}
};
describe('LinkEditModal', () => {
test('Confirm button dispatches as expected', () => {
const wrapper = mountWithContexts(
<WorkflowDispatchContext.Provider value={dispatch}>
<WorkflowStateContext.Provider value={workflowContext}>
<LinkEditModal />
</WorkflowStateContext.Provider>
</WorkflowDispatchContext.Provider>
);
wrapper.find('button#link-confirm').simulate('click');
expect(dispatch).toHaveBeenCalledWith({ type: 'UPDATE_LINK', linkType: 'always' });
});
});