diff --git a/awx/ui_next/src/components/FormField/FormField.jsx b/awx/ui_next/src/components/FormField/FormField.jsx index 19b1b8a0af..49d77cfae3 100644 --- a/awx/ui_next/src/components/FormField/FormField.jsx +++ b/awx/ui_next/src/components/FormField/FormField.jsx @@ -84,6 +84,7 @@ function FormField(props) { isValid={isValid} {...rest} {...field} + type={type} onChange={(value, event) => { field.onChange(event); }} diff --git a/awx/ui_next/src/screens/Template/Survey/SurveyQuestionForm.jsx b/awx/ui_next/src/screens/Template/Survey/SurveyQuestionForm.jsx index 541115d8a4..5f3fdb8258 100644 --- a/awx/ui_next/src/screens/Template/Survey/SurveyQuestionForm.jsx +++ b/awx/ui_next/src/screens/Template/Survey/SurveyQuestionForm.jsx @@ -156,7 +156,7 @@ function SurveyQuestionForm({ )} diff --git a/awx/ui_next/src/screens/Template/Survey/SurveyQuestionForm.test.jsx b/awx/ui_next/src/screens/Template/Survey/SurveyQuestionForm.test.jsx new file mode 100644 index 0000000000..fb7111415f --- /dev/null +++ b/awx/ui_next/src/screens/Template/Survey/SurveyQuestionForm.test.jsx @@ -0,0 +1,228 @@ +import React from 'react'; +import { mountWithContexts } from '@testUtils/enzymeHelpers'; +import { act } from 'react-dom/test-utils'; +import SurveyQuestionForm from './SurveyQuestionForm'; + +const question = { + question_name: 'What is the foo?', + question_description: 'more about the foo', + variable: 'foo', + required: true, + type: 'text', + min: 0, + max: 1024, +}; + +const noop = () => {}; + +async function selectType(wrapper, type) { + await act(async () => { + wrapper.find('AnsibleSelect#question-type').invoke('onChange')({ + target: { + name: 'type', + value: type, + }, + }); + }); + wrapper.update(); +} + +describe('', () => { + test('should render form', () => { + let wrapper; + + act(() => { + wrapper = mountWithContexts( + + ); + }); + + expect(wrapper.find('FormField#question-name input').prop('value')).toEqual( + question.question_name + ); + expect( + wrapper.find('FormField#question-description input').prop('value') + ).toEqual(question.question_description); + expect( + wrapper.find('FormField#question-variable input').prop('value') + ).toEqual(question.variable); + expect( + wrapper.find('CheckboxField#question-required input').prop('checked') + ).toEqual(true); + expect(wrapper.find('AnsibleSelect#question-type').prop('value')).toEqual( + question.type + ); + }); + + test('should provide fields for text question', () => { + let wrapper; + + act(() => { + wrapper = mountWithContexts( + + ); + }); + + expect(wrapper.find('FormField#question-min').prop('type')).toEqual( + 'number' + ); + expect(wrapper.find('FormField#question-max').prop('type')).toEqual( + 'number' + ); + expect(wrapper.find('FormField#question-default').prop('type')).toEqual( + 'text' + ); + }); + + test('should provide fields for textarea question', async () => { + let wrapper; + + act(() => { + wrapper = mountWithContexts( + + ); + }); + await selectType(wrapper, 'textarea'); + + expect(wrapper.find('FormField#question-min').prop('type')).toEqual( + 'number' + ); + expect(wrapper.find('FormField#question-max').prop('type')).toEqual( + 'number' + ); + expect(wrapper.find('FormField#question-default').prop('type')).toEqual( + 'textarea' + ); + }); + + test('should provide fields for password question', async () => { + let wrapper; + + act(() => { + wrapper = mountWithContexts( + + ); + }); + await selectType(wrapper, 'password'); + + expect(wrapper.find('FormField#question-min').prop('type')).toEqual( + 'number' + ); + expect(wrapper.find('FormField#question-max').prop('type')).toEqual( + 'number' + ); + expect( + wrapper.find('PasswordField#question-default input').prop('type') + ).toEqual('password'); + }); + + test('should provide fields for multiple choice question', async () => { + let wrapper; + + act(() => { + wrapper = mountWithContexts( + + ); + }); + await selectType(wrapper, 'multiplechoice'); + + expect(wrapper.find('FormField#question-options').prop('type')).toEqual( + 'textarea' + ); + expect(wrapper.find('FormField#question-default').prop('type')).toEqual( + 'text' + ); + }); + + test('should provide fields for multi-select question', async () => { + let wrapper; + + act(() => { + wrapper = mountWithContexts( + + ); + }); + await selectType(wrapper, 'multiselect'); + + expect(wrapper.find('FormField#question-options').prop('type')).toEqual( + 'textarea' + ); + expect(wrapper.find('FormField#question-default').prop('type')).toEqual( + 'textarea' + ); + }); + + test('should provide fields for integer question', async () => { + let wrapper; + + act(() => { + wrapper = mountWithContexts( + + ); + }); + await selectType(wrapper, 'integer'); + + expect(wrapper.find('FormField#question-min').prop('type')).toEqual( + 'number' + ); + expect(wrapper.find('FormField#question-max').prop('type')).toEqual( + 'number' + ); + expect( + wrapper.find('FormField#question-default input').prop('type') + ).toEqual('number'); + }); + + test('should provide fields for float question', async () => { + let wrapper; + + act(() => { + wrapper = mountWithContexts( + + ); + }); + await selectType(wrapper, 'float'); + + expect(wrapper.find('FormField#question-min').prop('type')).toEqual( + 'number' + ); + expect(wrapper.find('FormField#question-max').prop('type')).toEqual( + 'number' + ); + expect( + wrapper.find('FormField#question-default input').prop('type') + ).toEqual('number'); + }); +}); diff --git a/awx/ui_next/src/screens/Template/shared/data.job_template.json b/awx/ui_next/src/screens/Template/Survey/data.job_template.json similarity index 100% rename from awx/ui_next/src/screens/Template/shared/data.job_template.json rename to awx/ui_next/src/screens/Template/Survey/data.job_template.json