mirror of
https://github.com/ansible/awx.git
synced 2026-03-08 05:01:09 -02:30
adds tests
This commit is contained in:
@@ -104,4 +104,30 @@ describe('PreviewStep', () => {
|
|||||||
extra_vars: 'one: 1',
|
extra_vars: 'one: 1',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
test('should remove survey with empty array value', async () => {
|
||||||
|
let wrapper;
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<Formik
|
||||||
|
initialValues={{ extra_vars: 'one: 1' }}
|
||||||
|
values={{ extra_vars: 'one: 1', survey_foo: [] }}
|
||||||
|
>
|
||||||
|
<PreviewStep
|
||||||
|
resource={resource}
|
||||||
|
config={{
|
||||||
|
ask_variables_on_launch: true,
|
||||||
|
}}
|
||||||
|
formErrors={formErrors}
|
||||||
|
/>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const detail = wrapper.find('PromptDetail');
|
||||||
|
expect(detail).toHaveLength(1);
|
||||||
|
expect(detail.prop('resource')).toEqual(resource);
|
||||||
|
expect(detail.prop('overrides')).toEqual({
|
||||||
|
extra_vars: 'one: 1',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
import { mountWithContexts } from '../../../../../../testUtils/enzymeHelpers';
|
import {
|
||||||
|
mountWithContexts,
|
||||||
|
waitForElement,
|
||||||
|
} from '../../../../../../testUtils/enzymeHelpers';
|
||||||
import {
|
import {
|
||||||
WorkflowDispatchContext,
|
WorkflowDispatchContext,
|
||||||
WorkflowStateContext,
|
WorkflowStateContext,
|
||||||
@@ -9,10 +12,17 @@ import NodeEditModal from './NodeEditModal';
|
|||||||
|
|
||||||
const dispatch = jest.fn();
|
const dispatch = jest.fn();
|
||||||
|
|
||||||
const nodeResource = {
|
jest.mock('../../../../../api/models/InventorySources');
|
||||||
id: 448,
|
jest.mock('../../../../../api/models/JobTemplates');
|
||||||
type: 'job_template',
|
jest.mock('../../../../../api/models/Projects');
|
||||||
name: 'Test JT',
|
jest.mock('../../../../../api/models/WorkflowJobTemplates');
|
||||||
|
const values = {
|
||||||
|
inventory: undefined,
|
||||||
|
nodeResource: {
|
||||||
|
id: 448,
|
||||||
|
name: 'Test JT',
|
||||||
|
type: 'job_template',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const workflowContext = {
|
const workflowContext = {
|
||||||
@@ -22,27 +32,40 @@ const workflowContext = {
|
|||||||
id: 30,
|
id: 30,
|
||||||
name: 'Foo JT',
|
name: 'Foo JT',
|
||||||
type: 'job_template',
|
type: 'job_template',
|
||||||
|
unified_job_type: 'job',
|
||||||
|
},
|
||||||
|
originalNodeObject: {
|
||||||
|
summary_fields: { unified_job_template: { id: 1, name: 'Job Template' } },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('NodeEditModal', () => {
|
describe('NodeEditModal', () => {
|
||||||
test('Node modal confirmation dispatches as expected', () => {
|
test('Node modal confirmation dispatches as expected', async () => {
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<WorkflowDispatchContext.Provider value={dispatch}>
|
<WorkflowDispatchContext.Provider value={dispatch}>
|
||||||
<WorkflowStateContext.Provider value={workflowContext}>
|
<WorkflowStateContext.Provider value={workflowContext}>
|
||||||
<NodeEditModal />
|
<NodeEditModal
|
||||||
|
onSave={() => {}}
|
||||||
|
askLinkType={false}
|
||||||
|
title="Edit Node"
|
||||||
|
/>
|
||||||
</WorkflowStateContext.Provider>
|
</WorkflowStateContext.Provider>
|
||||||
</WorkflowDispatchContext.Provider>
|
</WorkflowDispatchContext.Provider>
|
||||||
);
|
);
|
||||||
act(() => {
|
waitForElement(
|
||||||
wrapper.find('NodeModal').prop('onSave')(nodeResource);
|
wrapper,
|
||||||
|
'WizardNavItem[content="ContentLoading"]',
|
||||||
|
el => el.length === 0
|
||||||
|
);
|
||||||
|
await act(async () => {
|
||||||
|
wrapper.find('NodeModal').prop('onSave')(values, {});
|
||||||
});
|
});
|
||||||
expect(dispatch).toHaveBeenCalledWith({
|
expect(dispatch).toHaveBeenCalledWith({
|
||||||
type: 'UPDATE_NODE',
|
|
||||||
node: {
|
node: {
|
||||||
nodeResource,
|
nodeResource: { id: 448, name: 'Test JT', type: 'job_template' },
|
||||||
},
|
},
|
||||||
|
type: 'UPDATE_NODE',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -111,7 +111,15 @@ describe('NodeModal', () => {
|
|||||||
data: {
|
data: {
|
||||||
name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
spec: [{ question_name: 'Foo', required: true }],
|
spec: [
|
||||||
|
{
|
||||||
|
question_name: 'Foo',
|
||||||
|
required: true,
|
||||||
|
variable: 'bar',
|
||||||
|
type: 'text',
|
||||||
|
default: 'answer',
|
||||||
|
},
|
||||||
|
],
|
||||||
type: 'text',
|
type: 'text',
|
||||||
variable: 'bar',
|
variable: 'bar',
|
||||||
},
|
},
|
||||||
@@ -254,10 +262,12 @@ describe('NodeModal', () => {
|
|||||||
expect(JobTemplatesAPI.readSurvey).toBeCalledWith(25);
|
expect(JobTemplatesAPI.readSurvey).toBeCalledWith(25);
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
expect(wrapper.find('NodeNextButton').prop('buttonText')).toBe('Next');
|
expect(wrapper.find('NodeNextButton').prop('buttonText')).toBe('Next');
|
||||||
wrapper
|
act(() => {
|
||||||
.find('WizardNavItem[content="Preview"]')
|
wrapper
|
||||||
.find('a')
|
.find('WizardNavItem[content="Preview"]')
|
||||||
.prop('onClick')();
|
.find('a')
|
||||||
|
.prop('onClick')();
|
||||||
|
});
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@@ -469,7 +479,7 @@ describe('NodeModal', () => {
|
|||||||
approvalDescription: 'Test Approval Description',
|
approvalDescription: 'Test Approval Description',
|
||||||
approvalName: 'Test Approval',
|
approvalName: 'Test Approval',
|
||||||
linkType: 'always',
|
linkType: 'always',
|
||||||
nodeResource: undefined,
|
nodeResource: null,
|
||||||
nodeType: 'approval',
|
nodeType: 'approval',
|
||||||
timeout: 330,
|
timeout: 330,
|
||||||
verbosity: undefined,
|
verbosity: undefined,
|
||||||
@@ -573,7 +583,7 @@ describe('NodeModal', () => {
|
|||||||
approvalDescription: 'Test Approval Description',
|
approvalDescription: 'Test Approval Description',
|
||||||
approvalName: 'Test Approval',
|
approvalName: 'Test Approval',
|
||||||
linkType: 'success',
|
linkType: 'success',
|
||||||
nodeResource: undefined,
|
nodeResource: null,
|
||||||
nodeType: 'approval',
|
nodeType: 'approval',
|
||||||
timeout: 330,
|
timeout: 330,
|
||||||
verbosity: undefined,
|
verbosity: undefined,
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ import {
|
|||||||
|
|
||||||
import NodeTypeStep from './NodeTypeStep';
|
import NodeTypeStep from './NodeTypeStep';
|
||||||
|
|
||||||
jest.mock('../../../../api/models/InventorySources');
|
jest.mock('../../../../../../api/models/InventorySources');
|
||||||
jest.mock('../../../../api/models/JobTemplates');
|
jest.mock('../../../../../../api/models/JobTemplates');
|
||||||
jest.mock('../../../../api/models/Projects');
|
jest.mock('../../../../../../api/models/Projects');
|
||||||
jest.mock('../../../../api/models/WorkflowJobTemplates');
|
jest.mock('../../../../../../api/models/WorkflowJobTemplates');
|
||||||
|
|
||||||
describe('NodeTypeStep', () => {
|
describe('NodeTypeStep', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user