mirror of
https://github.com/ansible/awx.git
synced 2026-01-20 14:11:24 -03:30
Adds test for link add/edit/delete modals
This commit is contained in:
parent
f9debb8f94
commit
887469d73e
@ -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 })}
|
||||
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 })}
|
||||
|
||||
@ -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' });
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user