mirror of
https://github.com/ansible/awx.git
synced 2026-05-12 11:57:37 -02:30
Adds test for link add/edit/delete modals
This commit is contained in:
@@ -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' });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -19,6 +19,7 @@ function LinkDeleteModal({ i18n }) {
|
|||||||
onClose={() => dispatch({ type: 'SET_LINK_TO_DELETE', value: null })}
|
onClose={() => dispatch({ type: 'SET_LINK_TO_DELETE', value: null })}
|
||||||
actions={[
|
actions={[
|
||||||
<Button
|
<Button
|
||||||
|
id="confirm-link-removal"
|
||||||
aria-label={i18n._(t`Confirm link removal`)}
|
aria-label={i18n._(t`Confirm link removal`)}
|
||||||
key="remove"
|
key="remove"
|
||||||
onClick={() => dispatch({ type: 'DELETE_LINK' })}
|
onClick={() => dispatch({ type: 'DELETE_LINK' })}
|
||||||
@@ -27,6 +28,7 @@ function LinkDeleteModal({ i18n }) {
|
|||||||
{i18n._(t`Remove`)}
|
{i18n._(t`Remove`)}
|
||||||
</Button>,
|
</Button>,
|
||||||
<Button
|
<Button
|
||||||
|
id="cancel-link-removal"
|
||||||
aria-label={i18n._(t`Cancel link removal`)}
|
aria-label={i18n._(t`Cancel link removal`)}
|
||||||
key="cancel"
|
key="cancel"
|
||||||
onClick={() => dispatch({ type: 'SET_LINK_TO_DELETE', value: null })}
|
onClick={() => dispatch({ type: 'SET_LINK_TO_DELETE', value: null })}
|
||||||
|
|||||||
@@ -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
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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' });
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user