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