mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 23:46:05 -03:30
add tests for array/string survey multi-select
This commit is contained in:
@@ -27,9 +27,6 @@ export default function SurveyQuestionAdd({ survey, updateSurvey }) {
|
|||||||
let defaultAnswers = '';
|
let defaultAnswers = '';
|
||||||
formData.formattedChoices.forEach(({ choice, isDefault }, i) => {
|
formData.formattedChoices.forEach(({ choice, isDefault }, i) => {
|
||||||
choices.push(choice);
|
choices.push(choice);
|
||||||
// i === formData.formattedChoices.length - 1
|
|
||||||
// ? choices.concat(`${choice}`)
|
|
||||||
// : choices.concat(`${choice}\n`);
|
|
||||||
if (isDefault) {
|
if (isDefault) {
|
||||||
defaultAnswers =
|
defaultAnswers =
|
||||||
i === formData.formattedChoices.length - 1
|
i === formData.formattedChoices.length - 1
|
||||||
|
|||||||
@@ -41,18 +41,16 @@ describe('<SurveyQuestionEdit />', () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
updateSurvey = jest.fn();
|
updateSurvey = jest.fn();
|
||||||
act(() => {
|
wrapper = mountWithContexts(
|
||||||
wrapper = mountWithContexts(
|
<Switch>
|
||||||
<Switch>
|
<Route path="/templates/:templateType/:id/survey/edit">
|
||||||
<Route path="/templates/:templateType/:id/survey/edit">
|
<SurveyQuestionEdit survey={survey} updateSurvey={updateSurvey} />
|
||||||
<SurveyQuestionEdit survey={survey} updateSurvey={updateSurvey} />
|
</Route>
|
||||||
</Route>
|
</Switch>,
|
||||||
</Switch>,
|
{
|
||||||
{
|
context: { router: { history } },
|
||||||
context: { router: { history } },
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should render form', () => {
|
test('should render form', () => {
|
||||||
@@ -147,4 +145,164 @@ describe('<SurveyQuestionEdit />', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should handle multiplechoice as array', () => {
|
||||||
|
const survey = {
|
||||||
|
spec: [
|
||||||
|
{
|
||||||
|
question_name: 'What is the foo?',
|
||||||
|
question_description: 'more about the foo',
|
||||||
|
variable: 'foo',
|
||||||
|
required: true,
|
||||||
|
type: 'multiplechoice',
|
||||||
|
choices: ['one', 'two', 'three'],
|
||||||
|
default: '',
|
||||||
|
min: 0,
|
||||||
|
max: 1024,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
history = createMemoryHistory({
|
||||||
|
initialEntries: [
|
||||||
|
'/templates/job_templates/1/survey/edit?question_variable=foo',
|
||||||
|
],
|
||||||
|
});
|
||||||
|
updateSurvey = jest.fn();
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<Switch>
|
||||||
|
<Route path="/templates/:templateType/:id/survey/edit">
|
||||||
|
<SurveyQuestionEdit survey={survey} updateSurvey={updateSurvey} />
|
||||||
|
</Route>
|
||||||
|
</Switch>,
|
||||||
|
{
|
||||||
|
context: { router: { history } },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const inputs = wrapper.find('MultipleChoiceField TextInput');
|
||||||
|
expect(inputs).toHaveLength(3);
|
||||||
|
expect(inputs.at(0).prop('value')).toEqual('one');
|
||||||
|
expect(inputs.at(1).prop('value')).toEqual('two');
|
||||||
|
expect(inputs.at(2).prop('value')).toEqual('three');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle multiplechoice as string', () => {
|
||||||
|
const survey = {
|
||||||
|
spec: [
|
||||||
|
{
|
||||||
|
question_name: 'What is the foo?',
|
||||||
|
question_description: 'more about the foo',
|
||||||
|
variable: 'foo',
|
||||||
|
required: true,
|
||||||
|
type: 'multiplechoice',
|
||||||
|
choices: 'one\ntwo\nthree',
|
||||||
|
default: '',
|
||||||
|
min: 0,
|
||||||
|
max: 1024,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
history = createMemoryHistory({
|
||||||
|
initialEntries: [
|
||||||
|
'/templates/job_templates/1/survey/edit?question_variable=foo',
|
||||||
|
],
|
||||||
|
});
|
||||||
|
updateSurvey = jest.fn();
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<Switch>
|
||||||
|
<Route path="/templates/:templateType/:id/survey/edit">
|
||||||
|
<SurveyQuestionEdit survey={survey} updateSurvey={updateSurvey} />
|
||||||
|
</Route>
|
||||||
|
</Switch>,
|
||||||
|
{
|
||||||
|
context: { router: { history } },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const inputs = wrapper.find('MultipleChoiceField TextInput');
|
||||||
|
expect(inputs).toHaveLength(3);
|
||||||
|
expect(inputs.at(0).prop('value')).toEqual('one');
|
||||||
|
expect(inputs.at(1).prop('value')).toEqual('two');
|
||||||
|
expect(inputs.at(2).prop('value')).toEqual('three');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle multiselect as array', () => {
|
||||||
|
const survey = {
|
||||||
|
spec: [
|
||||||
|
{
|
||||||
|
question_name: 'What is the foo?',
|
||||||
|
question_description: 'more about the foo',
|
||||||
|
variable: 'foo',
|
||||||
|
required: true,
|
||||||
|
type: 'multiselect',
|
||||||
|
choices: ['one', 'two', 'three'],
|
||||||
|
default: '',
|
||||||
|
min: 0,
|
||||||
|
max: 1024,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
history = createMemoryHistory({
|
||||||
|
initialEntries: [
|
||||||
|
'/templates/job_templates/1/survey/edit?question_variable=foo',
|
||||||
|
],
|
||||||
|
});
|
||||||
|
updateSurvey = jest.fn();
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<Switch>
|
||||||
|
<Route path="/templates/:templateType/:id/survey/edit">
|
||||||
|
<SurveyQuestionEdit survey={survey} updateSurvey={updateSurvey} />
|
||||||
|
</Route>
|
||||||
|
</Switch>,
|
||||||
|
{
|
||||||
|
context: { router: { history } },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const inputs = wrapper.find('MultipleChoiceField TextInput');
|
||||||
|
expect(inputs).toHaveLength(3);
|
||||||
|
expect(inputs.at(0).prop('value')).toEqual('one');
|
||||||
|
expect(inputs.at(1).prop('value')).toEqual('two');
|
||||||
|
expect(inputs.at(2).prop('value')).toEqual('three');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle multiselect as string', () => {
|
||||||
|
const survey = {
|
||||||
|
spec: [
|
||||||
|
{
|
||||||
|
question_name: 'What is the foo?',
|
||||||
|
question_description: 'more about the foo',
|
||||||
|
variable: 'foo',
|
||||||
|
required: true,
|
||||||
|
type: 'multiselect',
|
||||||
|
choices: 'one\ntwo\nthree',
|
||||||
|
default: '',
|
||||||
|
min: 0,
|
||||||
|
max: 1024,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
history = createMemoryHistory({
|
||||||
|
initialEntries: [
|
||||||
|
'/templates/job_templates/1/survey/edit?question_variable=foo',
|
||||||
|
],
|
||||||
|
});
|
||||||
|
updateSurvey = jest.fn();
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<Switch>
|
||||||
|
<Route path="/templates/:templateType/:id/survey/edit">
|
||||||
|
<SurveyQuestionEdit survey={survey} updateSurvey={updateSurvey} />
|
||||||
|
</Route>
|
||||||
|
</Switch>,
|
||||||
|
{
|
||||||
|
context: { router: { history } },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const inputs = wrapper.find('MultipleChoiceField TextInput');
|
||||||
|
expect(inputs).toHaveLength(3);
|
||||||
|
expect(inputs.at(0).prop('value')).toEqual('one');
|
||||||
|
expect(inputs.at(1).prop('value')).toEqual('two');
|
||||||
|
expect(inputs.at(2).prop('value')).toEqual('three');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ function SurveyReorderModal({
|
|||||||
let component = null;
|
let component = null;
|
||||||
const choices = Array.isArray(q.choices)
|
const choices = Array.isArray(q.choices)
|
||||||
? q.choices
|
? q.choices
|
||||||
: q.choices.split('\n');
|
: (q.choices || '').split('\n');
|
||||||
switch (q.type) {
|
switch (q.type) {
|
||||||
case 'password':
|
case 'password':
|
||||||
component = (
|
component = (
|
||||||
|
|||||||
Reference in New Issue
Block a user