mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 23:51:09 +03:00
Adds unit test coverage for shared workflow components
This commit is contained in:
parent
5a9248e619
commit
01cc0ac8f1
@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import WorkflowActionTooltip from './WorkflowActionTooltip';
|
||||
|
||||
describe('WorkflowActionTooltip', () => {
|
||||
test('successfully mounts', () => {
|
||||
const wrapper = mount(
|
||||
<svg>
|
||||
<WorkflowActionTooltip actions={[]} pointX={0} pointY={0} />
|
||||
</svg>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
});
|
||||
});
|
@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import WorkflowActionTooltipItem from './WorkflowActionTooltipItem';
|
||||
|
||||
describe('WorkflowActionTooltipItem', () => {
|
||||
test('successfully mounts', () => {
|
||||
const wrapper = mount(<WorkflowActionTooltipItem />);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
});
|
||||
});
|
10
awx/ui_next/src/components/Workflow/WorkflowHelp.test.jsx
Normal file
10
awx/ui_next/src/components/Workflow/WorkflowHelp.test.jsx
Normal file
@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import WorkflowHelp from './WorkflowHelp';
|
||||
|
||||
describe('WorkflowHelp', () => {
|
||||
test('successfully mounts', () => {
|
||||
const wrapper = mount(<WorkflowHelp />);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
});
|
||||
});
|
10
awx/ui_next/src/components/Workflow/WorkflowKey.test.jsx
Normal file
10
awx/ui_next/src/components/Workflow/WorkflowKey.test.jsx
Normal file
@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
import WorkflowKey from './WorkflowKey';
|
||||
|
||||
describe('WorkflowKey', () => {
|
||||
test('renders the expected content', () => {
|
||||
const wrapper = mountWithContexts(<WorkflowKey />);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
});
|
||||
});
|
@ -38,7 +38,7 @@ function WorkflowLinkHelp({ link, i18n }) {
|
||||
<dt>
|
||||
<b>{i18n._(t`Run`)}</b>
|
||||
</dt>
|
||||
<dd>{linkType}</dd>
|
||||
<dd id="workflow-link-help-type">{linkType}</dd>
|
||||
</GridDL>
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
import WorkflowLinkHelp from './WorkflowLinkHelp';
|
||||
|
||||
describe('WorkflowLinkHelp', () => {
|
||||
test('successfully mounts', () => {
|
||||
const wrapper = mountWithContexts(<WorkflowLinkHelp link={{}} />);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
});
|
||||
test('renders the expected content for an on success link', () => {
|
||||
const link = {
|
||||
linkType: 'success',
|
||||
};
|
||||
const wrapper = mountWithContexts(<WorkflowLinkHelp link={link} />);
|
||||
expect(wrapper.find('#workflow-link-help-type').text()).toBe('On Success');
|
||||
});
|
||||
test('renders the expected content for an on failure link', () => {
|
||||
const link = {
|
||||
linkType: 'failure',
|
||||
};
|
||||
const wrapper = mountWithContexts(<WorkflowLinkHelp link={link} />);
|
||||
expect(wrapper.find('#workflow-link-help-type').text()).toBe('On Failure');
|
||||
});
|
||||
test('renders the expected content for an always link', () => {
|
||||
const link = {
|
||||
linkType: 'always',
|
||||
};
|
||||
const wrapper = mountWithContexts(<WorkflowLinkHelp link={link} />);
|
||||
expect(wrapper.find('#workflow-link-help-type').text()).toBe('Always');
|
||||
});
|
||||
});
|
@ -104,11 +104,11 @@ function WorkflowNodeHelp({ node, i18n }) {
|
||||
<dt>
|
||||
<b>{i18n._(t`Name`)}</b>
|
||||
</dt>
|
||||
<dd>{node.unifiedJobTemplate.name}</dd>
|
||||
<dd id="workflow-node-help-name">{node.unifiedJobTemplate.name}</dd>
|
||||
<dt>
|
||||
<b>{i18n._(t`Type`)}</b>
|
||||
</dt>
|
||||
<dd>{nodeType}</dd>
|
||||
<dd id="workflow-node-help-type">{nodeType}</dd>
|
||||
</Fragment>
|
||||
)}
|
||||
{node.job && (
|
||||
@ -116,13 +116,15 @@ function WorkflowNodeHelp({ node, i18n }) {
|
||||
<dt>
|
||||
<b>{i18n._(t`Job Status`)}</b>
|
||||
</dt>
|
||||
<dd>{jobStatus}</dd>
|
||||
<dd id="workflow-node-help-status">{jobStatus}</dd>
|
||||
{node.job.elapsed && (
|
||||
<Fragment>
|
||||
<dt>
|
||||
<b>{i18n._(t`Elapsed`)}</b>
|
||||
</dt>
|
||||
<dd>{secondsToHHMMSS(node.job.elapsed)}</dd>
|
||||
<dd id="workflow-node-help-elapsed">
|
||||
{secondsToHHMMSS(node.job.elapsed)}
|
||||
</dd>
|
||||
</Fragment>
|
||||
)}
|
||||
</Fragment>
|
||||
|
@ -0,0 +1,33 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
import WorkflowNodeHelp from './WorkflowNodeHelp';
|
||||
|
||||
describe('WorkflowNodeHelp', () => {
|
||||
test('successfully mounts', () => {
|
||||
const wrapper = mountWithContexts(<WorkflowNodeHelp node={{}} />);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
});
|
||||
test('renders the expected content for a completed job template job', () => {
|
||||
const node = {
|
||||
job: {
|
||||
elapsed: 9000,
|
||||
status: 'successful',
|
||||
},
|
||||
unifiedJobTemplate: {
|
||||
name: 'Foo Job Template',
|
||||
unified_job_type: 'job',
|
||||
},
|
||||
};
|
||||
const wrapper = mountWithContexts(<WorkflowNodeHelp node={node} />);
|
||||
expect(wrapper.find('#workflow-node-help-name').text()).toBe(
|
||||
'Foo Job Template'
|
||||
);
|
||||
expect(wrapper.find('#workflow-node-help-type').text()).toBe(
|
||||
'Job Template'
|
||||
);
|
||||
expect(wrapper.find('#workflow-node-help-status').text()).toBe(
|
||||
'Successful'
|
||||
);
|
||||
expect(wrapper.find('#workflow-node-help-elapsed').text()).toBe('02:30:00');
|
||||
});
|
||||
});
|
@ -0,0 +1,121 @@
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import { PauseIcon } from '@patternfly/react-icons';
|
||||
import WorkflowNodeTypeLetter from './WorkflowNodeTypeLetter';
|
||||
|
||||
describe('WorkflowNodeTypeLetter', () => {
|
||||
test('renders JT when type=job_template', () => {
|
||||
const wrapper = mount(
|
||||
<svg>
|
||||
<WorkflowNodeTypeLetter
|
||||
node={{ unifiedJobTemplate: { type: 'job_template' } }}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
expect(wrapper.text()).toBe('JT');
|
||||
});
|
||||
test('renders JT when unified_job_type=job', () => {
|
||||
const wrapper = mount(
|
||||
<svg>
|
||||
<WorkflowNodeTypeLetter
|
||||
node={{ unifiedJobTemplate: { unified_job_type: 'job' } }}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
expect(wrapper.text()).toBe('JT');
|
||||
});
|
||||
test('renders P when type=project', () => {
|
||||
const wrapper = mount(
|
||||
<svg>
|
||||
<WorkflowNodeTypeLetter
|
||||
node={{ unifiedJobTemplate: { type: 'project' } }}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
expect(wrapper.text()).toBe('P');
|
||||
});
|
||||
test('renders P when unified_job_type=project_update', () => {
|
||||
const wrapper = mount(
|
||||
<svg>
|
||||
<WorkflowNodeTypeLetter
|
||||
node={{ unifiedJobTemplate: { unified_job_type: 'project_update' } }}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
expect(wrapper.text()).toBe('P');
|
||||
});
|
||||
test('renders I when type=inventory_source', () => {
|
||||
const wrapper = mount(
|
||||
<svg>
|
||||
<WorkflowNodeTypeLetter
|
||||
node={{ unifiedJobTemplate: { type: 'inventory_source' } }}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
expect(wrapper.text()).toBe('I');
|
||||
});
|
||||
test('renders I when unified_job_type=inventory_update', () => {
|
||||
const wrapper = mount(
|
||||
<svg>
|
||||
<WorkflowNodeTypeLetter
|
||||
node={{
|
||||
unifiedJobTemplate: { unified_job_type: 'inventory_update' },
|
||||
}}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
expect(wrapper.text()).toBe('I');
|
||||
});
|
||||
test('renders W when type=workflow_job_template', () => {
|
||||
const wrapper = mount(
|
||||
<svg>
|
||||
<WorkflowNodeTypeLetter
|
||||
node={{ unifiedJobTemplate: { type: 'workflow_job_template' } }}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
expect(wrapper.text()).toBe('W');
|
||||
});
|
||||
test('renders W when unified_job_type=workflow_job', () => {
|
||||
const wrapper = mount(
|
||||
<svg>
|
||||
<WorkflowNodeTypeLetter
|
||||
node={{ unifiedJobTemplate: { unified_job_type: 'workflow_job' } }}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
expect(wrapper.text()).toBe('W');
|
||||
});
|
||||
test('renders puse icon when type=workflow_approval_template', () => {
|
||||
const wrapper = mount(
|
||||
<svg>
|
||||
<WorkflowNodeTypeLetter
|
||||
node={{ unifiedJobTemplate: { type: 'workflow_approval_template' } }}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
expect(wrapper.containsMatchingElement(<PauseIcon />));
|
||||
});
|
||||
test('renders W when unified_job_type=workflow_approval', () => {
|
||||
const wrapper = mount(
|
||||
<svg>
|
||||
<WorkflowNodeTypeLetter
|
||||
node={{
|
||||
unifiedJobTemplate: { unified_job_type: 'workflow_approval' },
|
||||
}}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
expect(wrapper.containsMatchingElement(<PauseIcon />));
|
||||
});
|
||||
});
|
54
awx/ui_next/src/components/Workflow/WorkflowTools.test.jsx
Normal file
54
awx/ui_next/src/components/Workflow/WorkflowTools.test.jsx
Normal file
@ -0,0 +1,54 @@
|
||||
import React from 'react';
|
||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||
import WorkflowTools from './WorkflowTools';
|
||||
|
||||
describe('WorkflowTools', () => {
|
||||
test('renders the expected content', () => {
|
||||
const wrapper = mountWithContexts(
|
||||
<WorkflowTools
|
||||
onFitGraph={() => {}}
|
||||
onPan={() => {}}
|
||||
onPanToMiddle={() => {}}
|
||||
onZoomChange={() => {}}
|
||||
zoomPercentage={100}
|
||||
/>
|
||||
);
|
||||
expect(wrapper).toHaveLength(1);
|
||||
});
|
||||
test('clicking zoom buttons passes callback correctly updated scale', () => {
|
||||
const zoomChange = jest.fn();
|
||||
const wrapper = mountWithContexts(
|
||||
<WorkflowTools
|
||||
onFitGraph={() => {}}
|
||||
onPan={() => {}}
|
||||
onPanToMiddle={() => {}}
|
||||
onZoomChange={zoomChange}
|
||||
zoomPercentage={95.7}
|
||||
/>
|
||||
);
|
||||
wrapper.find('PlusIcon').simulate('click');
|
||||
expect(zoomChange).toHaveBeenCalledWith(1.1);
|
||||
wrapper.find('MinusIcon').simulate('click');
|
||||
expect(zoomChange).toHaveBeenCalledWith(0.8);
|
||||
});
|
||||
test('clicking pan buttons passes callback correct string direction', () => {
|
||||
const pan = jest.fn();
|
||||
const wrapper = mountWithContexts(
|
||||
<WorkflowTools
|
||||
onFitGraph={() => {}}
|
||||
onPan={pan}
|
||||
onPanToMiddle={() => {}}
|
||||
onZoomChange={() => {}}
|
||||
zoomPercentage={100}
|
||||
/>
|
||||
);
|
||||
wrapper.find('CaretLeftIcon').simulate('click');
|
||||
expect(pan).toHaveBeenCalledWith('left');
|
||||
wrapper.find('CaretUpIcon').simulate('click');
|
||||
expect(pan).toHaveBeenCalledWith('up');
|
||||
wrapper.find('CaretRightIcon').simulate('click');
|
||||
expect(pan).toHaveBeenCalledWith('right');
|
||||
wrapper.find('CaretDownIcon').simulate('click');
|
||||
expect(pan).toHaveBeenCalledWith('down');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user