mirror of
https://github.com/ansible/awx.git
synced 2026-04-06 18:49:21 -02:30
Adds tests for delete all nodes and unsaved changes modals
This commit is contained in:
@@ -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',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -15,6 +15,7 @@ function UnsavedChangesModal({ i18n, onSaveAndExit, onExit }) {
|
|||||||
onClose={() => dispatch({ type: 'TOGGLE_UNSAVED_CHANGES_MODAL' })}
|
onClose={() => dispatch({ type: 'TOGGLE_UNSAVED_CHANGES_MODAL' })}
|
||||||
actions={[
|
actions={[
|
||||||
<Button
|
<Button
|
||||||
|
id="confirm-exit-without-saving"
|
||||||
key="exit"
|
key="exit"
|
||||||
variant="danger"
|
variant="danger"
|
||||||
aria-label={i18n._(t`Exit Without Saving`)}
|
aria-label={i18n._(t`Exit Without Saving`)}
|
||||||
@@ -23,6 +24,7 @@ function UnsavedChangesModal({ i18n, onSaveAndExit, onExit }) {
|
|||||||
{i18n._(t`Exit Without Saving`)}
|
{i18n._(t`Exit Without Saving`)}
|
||||||
</Button>,
|
</Button>,
|
||||||
<Button
|
<Button
|
||||||
|
id="confirm-save-and-exit"
|
||||||
key="save"
|
key="save"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
aria-label={i18n._(t`Save & Exit`)}
|
aria-label={i18n._(t`Save & Exit`)}
|
||||||
|
|||||||
@@ -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',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user