Adds tests for delete all nodes and unsaved changes modals

This commit is contained in:
mabashian 2020-02-04 10:43:39 -05:00
parent b3929d1177
commit f9debb8f94
3 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,44 @@
import React from 'react';
import {
WorkflowDispatchContext,
} from '@contexts/Workflow';
import { mountWithContexts } from '@testUtils/enzymeHelpers';
import DeleteAllNodesModal from './DeleteAllNodesModal';
let wrapper;
const dispatch = jest.fn();
describe('DeleteAllNodesModal', () => {
beforeAll(() => {
wrapper = mountWithContexts(
<WorkflowDispatchContext.Provider value={dispatch}>
<DeleteAllNodesModal />
</WorkflowDispatchContext.Provider>
);
});
afterAll(() => {
wrapper.unmount();
});
test('Delete All button dispatches as expected', () => {
wrapper.find('button#confirm-delete-all-nodes').simulate('click');
expect(dispatch).toHaveBeenCalledWith({
type: 'DELETE_ALL_NODES',
});
});
test('Cancel button dispatches as expected', () => {
wrapper.find('button#cancel-delete-all-nodes').simulate('click');
expect(dispatch).toHaveBeenCalledWith({
type: 'TOGGLE_DELETE_ALL_NODES_MODAL',
});
});
test('Close button dispatches as expected', () => {
wrapper.find('TimesIcon').simulate('click');
expect(dispatch).toHaveBeenCalledWith({
type: 'TOGGLE_DELETE_ALL_NODES_MODAL',
});
});
});

View File

@ -15,6 +15,7 @@ function UnsavedChangesModal({ i18n, onSaveAndExit, onExit }) {
onClose={() => dispatch({ type: 'TOGGLE_UNSAVED_CHANGES_MODAL' })}
actions={[
<Button
id="confirm-exit-without-saving"
key="exit"
variant="danger"
aria-label={i18n._(t`Exit Without Saving`)}
@ -23,6 +24,7 @@ function UnsavedChangesModal({ i18n, onSaveAndExit, onExit }) {
{i18n._(t`Exit Without Saving`)}
</Button>,
<Button
id="confirm-save-and-exit"
key="save"
variant="primary"
aria-label={i18n._(t`Save & Exit`)}

View File

@ -0,0 +1,42 @@
import React from 'react';
import {
WorkflowDispatchContext,
} from '@contexts/Workflow';
import { mountWithContexts } from '@testUtils/enzymeHelpers';
import UnsavedChangesModal from './UnsavedChangesModal';
let wrapper;
const dispatch = jest.fn();
const onSaveAndExit = jest.fn();
const onExit = jest.fn();
describe('UnsavedChangesModal', () => {
beforeAll(() => {
wrapper = mountWithContexts(
<WorkflowDispatchContext.Provider value={dispatch}>
<UnsavedChangesModal onSaveAndExit={onSaveAndExit} onExit={onExit} />
</WorkflowDispatchContext.Provider>
);
});
afterAll(() => {
wrapper.unmount();
});
test('Exit Without Saving button dispatches as expected', () => {
wrapper.find('button#confirm-exit-without-saving').simulate('click');
expect(onExit).toHaveBeenCalled();
});
test('Save and Exit button dispatches as expected', () => {
wrapper.find('button#confirm-save-and-exit').simulate('click');
expect(onSaveAndExit).toHaveBeenCalled();
});
test('Close button dispatches as expected', () => {
wrapper.find('TimesIcon').simulate('click');
expect(dispatch).toHaveBeenCalledWith({
type: 'TOGGLE_UNSAVED_CHANGES_MODAL',
});
});
});