mirror of
https://github.com/ansible/awx.git
synced 2026-02-04 19:18:13 -03:30
Adds tests
This commit is contained in:
@@ -15,9 +15,11 @@ jest.mock('@api/models/Inventories');
|
||||
describe('<WorkflowJobTemplateAdd/>', () => {
|
||||
let wrapper;
|
||||
let history;
|
||||
const handleSubmit = jest.fn();
|
||||
const handleCancel = jest.fn();
|
||||
beforeEach(async () => {
|
||||
WorkflowJobTemplatesAPI.create.mockResolvedValue({ data: { id: 1 } });
|
||||
OrganizationsAPI.read.mockResolvedValue({ results: [{ id: 1 }] });
|
||||
OrganizationsAPI.read.mockResolvedValue({ data: { results: [{ id: 1 }] } });
|
||||
LabelsAPI.read.mockResolvedValue({
|
||||
data: {
|
||||
results: [
|
||||
@@ -36,7 +38,12 @@ describe('<WorkflowJobTemplateAdd/>', () => {
|
||||
wrapper = mountWithContexts(
|
||||
<Route
|
||||
path="/templates/workflow_job_template/add"
|
||||
component={() => <WorkflowJobTemplateAdd />}
|
||||
component={() => (
|
||||
<WorkflowJobTemplateAdd
|
||||
handleSubmit={handleSubmit}
|
||||
handleCancel={handleCancel}
|
||||
/>
|
||||
)}
|
||||
/>,
|
||||
{
|
||||
context: {
|
||||
@@ -63,16 +70,49 @@ describe('<WorkflowJobTemplateAdd/>', () => {
|
||||
|
||||
test('calls workflowJobTemplatesAPI with correct information on submit', async () => {
|
||||
await act(async () => {
|
||||
await wrapper.find('WorkflowJobTemplateForm').invoke('handleSubmit')({
|
||||
name: 'Alex',
|
||||
labels: [{ name: 'Foo', id: 1 }, { name: 'bar', id: 2 }],
|
||||
organizationId: 1,
|
||||
wrapper.find('input#wfjt-name').simulate('change', {
|
||||
target: { value: 'Alex', name: 'name' },
|
||||
});
|
||||
|
||||
wrapper
|
||||
.find('LabelSelect')
|
||||
.find('SelectToggle')
|
||||
.simulate('click');
|
||||
});
|
||||
expect(WorkflowJobTemplatesAPI.create).toHaveBeenCalledWith({
|
||||
|
||||
wrapper.update();
|
||||
|
||||
act(() => {
|
||||
wrapper
|
||||
.find('SelectOption')
|
||||
.find('button')
|
||||
.at(2)
|
||||
.prop('onClick')();
|
||||
});
|
||||
|
||||
wrapper.update();
|
||||
await act(async () => {
|
||||
wrapper.find('form').simulate('submit');
|
||||
});
|
||||
await expect(WorkflowJobTemplatesAPI.create).toHaveBeenCalledWith({
|
||||
name: 'Alex',
|
||||
allow_simultaneous: false,
|
||||
ask_inventory_on_launch: false,
|
||||
ask_limit_on_launch: false,
|
||||
ask_scm_branch_on_launch: false,
|
||||
ask_variables_on_launch: false,
|
||||
description: '',
|
||||
extra_vars: '---',
|
||||
inventory: undefined,
|
||||
limit: '',
|
||||
organization: undefined,
|
||||
scm_branch: '',
|
||||
webhook_credential: undefined,
|
||||
webhook_service: '',
|
||||
webhook_url: '',
|
||||
});
|
||||
expect(WorkflowJobTemplatesAPI.associateLabel).toHaveBeenCalledTimes(2);
|
||||
|
||||
expect(WorkflowJobTemplatesAPI.associateLabel).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('handleCancel navigates the user to the /templates', async () => {
|
||||
@@ -95,10 +135,16 @@ describe('<WorkflowJobTemplateAdd/>', () => {
|
||||
|
||||
WorkflowJobTemplatesAPI.create.mockRejectedValue(error);
|
||||
await act(async () => {
|
||||
wrapper.find('WorkflowJobTemplateForm').invoke('handleSubmit')({
|
||||
name: 'Foo',
|
||||
wrapper.find('input#wfjt-name').simulate('change', {
|
||||
target: { value: 'Alex', name: 'name' },
|
||||
});
|
||||
});
|
||||
|
||||
wrapper.update();
|
||||
await act(async () => {
|
||||
wrapper.find('form').simulate('submit');
|
||||
});
|
||||
|
||||
expect(WorkflowJobTemplatesAPI.create).toHaveBeenCalled();
|
||||
wrapper.update();
|
||||
expect(wrapper.find('WorkflowJobTemplateForm').prop('submitError')).toEqual(
|
||||
|
||||
@@ -29,10 +29,15 @@ const mockTemplate = {
|
||||
describe('<WorkflowJobTemplateEdit/>', () => {
|
||||
let wrapper;
|
||||
let history;
|
||||
|
||||
beforeEach(async () => {
|
||||
LabelsAPI.read.mockResolvedValue({
|
||||
data: {
|
||||
results: [{ name: 'Label 1', id: 1 }, { name: 'Label 2', id: 2 }],
|
||||
results: [
|
||||
{ name: 'Label 1', id: 1 },
|
||||
{ name: 'Label 2', id: 2 },
|
||||
{ name: 'Label 3', id: 3 },
|
||||
],
|
||||
},
|
||||
});
|
||||
OrganizationsAPI.read.mockResolvedValue({ results: [{ id: 1 }] });
|
||||
@@ -71,29 +76,67 @@ describe('<WorkflowJobTemplateEdit/>', () => {
|
||||
});
|
||||
|
||||
test('api is called to properly to save the updated template.', async () => {
|
||||
await act(async () => {
|
||||
await wrapper.find('WorkflowJobTemplateForm').invoke('handleSubmit')({
|
||||
id: 6,
|
||||
name: 'Alex',
|
||||
description: 'Apollo and Athena',
|
||||
inventory: 1,
|
||||
organization: 1,
|
||||
labels: [{ name: 'Label 2', id: 2 }, { name: 'Generated Label' }],
|
||||
scm_branch: 'master',
|
||||
limit: '5000',
|
||||
variables: '---',
|
||||
act(() => {
|
||||
wrapper.find('input#wfjt-name').simulate('change', {
|
||||
target: { value: 'Alex', name: 'name' },
|
||||
});
|
||||
wrapper.find('input#wfjt-description').simulate('change', {
|
||||
target: { value: 'Apollo and Athena', name: 'description' },
|
||||
});
|
||||
wrapper.find('input#wfjt-description').simulate('change', {
|
||||
target: { value: 'master', name: 'scm_branch' },
|
||||
});
|
||||
wrapper.find('input#wfjt-description').simulate('change', {
|
||||
target: { value: '5000', name: 'limit' },
|
||||
});
|
||||
wrapper
|
||||
.find('LabelSelect')
|
||||
.find('SelectToggle')
|
||||
.simulate('click');
|
||||
});
|
||||
|
||||
wrapper.update();
|
||||
|
||||
act(() => {
|
||||
wrapper
|
||||
.find('SelectOption')
|
||||
.find('button')
|
||||
.at(2)
|
||||
.prop('onClick')();
|
||||
});
|
||||
|
||||
wrapper.update();
|
||||
|
||||
act(() =>
|
||||
wrapper
|
||||
.find('SelectOption')
|
||||
.find('button')
|
||||
.at(0)
|
||||
.prop('onClick')()
|
||||
);
|
||||
|
||||
wrapper.update();
|
||||
|
||||
await act(async () => {
|
||||
wrapper.find('WorkflowJobTemplateForm').invoke('handleSubmit')();
|
||||
});
|
||||
|
||||
expect(WorkflowJobTemplatesAPI.update).toHaveBeenCalledWith(6, {
|
||||
id: 6,
|
||||
name: 'Alex',
|
||||
description: 'Apollo and Athena',
|
||||
inventory: 1,
|
||||
organization: 1,
|
||||
scm_branch: 'master',
|
||||
limit: '5000',
|
||||
variables: '---',
|
||||
extra_vars: '---',
|
||||
webhook_credential: null,
|
||||
webhook_url: '',
|
||||
webhook_service: '',
|
||||
allow_simultaneous: false,
|
||||
ask_inventory_on_launch: false,
|
||||
ask_limit_on_launch: false,
|
||||
ask_scm_branch_on_launch: false,
|
||||
ask_variables_on_launch: false,
|
||||
});
|
||||
wrapper.update();
|
||||
await expect(WorkflowJobTemplatesAPI.disassociateLabel).toBeCalledWith(6, {
|
||||
|
||||
@@ -74,7 +74,7 @@ describe('<WorkflowJobTemplateForm/>', () => {
|
||||
template={mockTemplate}
|
||||
handleCancel={handleCancel}
|
||||
handleSubmit={handleSubmit}
|
||||
webhook_key="sdfghjklmnbvcdsew435678iokjhgfd"
|
||||
webhookKey="sdfghjklmnbvcdsew435678iokjhgfd"
|
||||
/>
|
||||
)}
|
||||
/>,
|
||||
@@ -106,13 +106,14 @@ describe('<WorkflowJobTemplateForm/>', () => {
|
||||
const fields = [
|
||||
'FormField[name="name"]',
|
||||
'FormField[name="description"]',
|
||||
'Field[name="organization"]',
|
||||
'Field[name="inventory"]',
|
||||
'FormGroup[label="Organization"]',
|
||||
'FormGroup[label="Inventory"]',
|
||||
'FormField[name="limit"]',
|
||||
'FormField[name="scm_branch"]',
|
||||
'Field[name="labels"]',
|
||||
'FormGroup[label="Labels"]',
|
||||
'VariablesField',
|
||||
];
|
||||
|
||||
const assertField = field => {
|
||||
expect(wrapper.find(`${field}`).length).toBe(1);
|
||||
};
|
||||
@@ -191,7 +192,7 @@ describe('<WorkflowJobTemplateForm/>', () => {
|
||||
).toBe('sdfghjklmnbvcdsew435678iokjhgfd');
|
||||
await act(() =>
|
||||
wrapper
|
||||
.find('FormGroup[name="webhook_key"]')
|
||||
.find('FormGroup[name="webhookKey"]')
|
||||
.find('Button[variant="tertiary"]')
|
||||
.prop('onClick')()
|
||||
);
|
||||
@@ -201,8 +202,7 @@ describe('<WorkflowJobTemplateForm/>', () => {
|
||||
).toContain('/api/v2/workflow_job_templates/57/gitlab/');
|
||||
|
||||
wrapper.update();
|
||||
|
||||
expect(wrapper.find('Field[name="webhook_service"]').length).toBe(1);
|
||||
expect(wrapper.find('FormGroup[name="webhook_service"]').length).toBe(1);
|
||||
|
||||
act(() => wrapper.find('AnsibleSelect').prop('onChange')({}, 'gitlab'));
|
||||
wrapper.update();
|
||||
|
||||
Reference in New Issue
Block a user