mirror of
https://github.com/ansible/awx.git
synced 2026-02-16 02:30:01 -03:30
fixes erroneously invalidating responses
This commit is contained in:
@@ -68,12 +68,17 @@ function SurveyQuestionForm({
|
||||
}) {
|
||||
const defaultIsNotAvailable = choices => {
|
||||
return defaultValue => {
|
||||
if (!choices.includes(defaultValue)) {
|
||||
return i18n._(
|
||||
const answerChoices = new Set(choices);
|
||||
const defaultAnswers = new Set(defaultValue);
|
||||
let errorMessage;
|
||||
const found = [...defaultAnswers].every(dA => answerChoices.has(dA));
|
||||
|
||||
if (!found) {
|
||||
errorMessage = i18n._(
|
||||
t`Default choice must be answered from the choices listed.`
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
return errorMessage;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -225,4 +225,67 @@ describe('<SurveyQuestionForm />', () => {
|
||||
wrapper.find('FormField#question-default input').prop('type')
|
||||
).toEqual('number');
|
||||
});
|
||||
test('should not throw validation error', async () => {
|
||||
let wrapper;
|
||||
|
||||
act(() => {
|
||||
wrapper = mountWithContexts(
|
||||
<SurveyQuestionForm
|
||||
question={question}
|
||||
handleSubmit={noop}
|
||||
handleCancel={noop}
|
||||
/>
|
||||
);
|
||||
});
|
||||
await selectType(wrapper, 'multiselect');
|
||||
await act(async () =>
|
||||
wrapper.find('TextArea#question-options').prop('onChange')('a \n b', {
|
||||
target: { value: 'a \n b', name: 'choices' },
|
||||
})
|
||||
);
|
||||
await act(async () =>
|
||||
wrapper.find('TextArea#question-default').prop('onChange')('b \n a', {
|
||||
target: { value: 'b \n a', name: 'default' },
|
||||
})
|
||||
);
|
||||
wrapper.find('FormField#question-default').prop('validate')('b \n a', {});
|
||||
wrapper.update();
|
||||
expect(
|
||||
wrapper
|
||||
.find('FormGroup[fieldId="question-default"]')
|
||||
.prop('helperTextInvalid')
|
||||
).toBe(undefined);
|
||||
});
|
||||
|
||||
test('should throw validation error', async () => {
|
||||
let wrapper;
|
||||
|
||||
act(() => {
|
||||
wrapper = mountWithContexts(
|
||||
<SurveyQuestionForm
|
||||
question={question}
|
||||
handleSubmit={noop}
|
||||
handleCancel={noop}
|
||||
/>
|
||||
);
|
||||
});
|
||||
await selectType(wrapper, 'multiselect');
|
||||
await act(async () =>
|
||||
wrapper.find('TextArea#question-options').prop('onChange')('a \n b', {
|
||||
target: { value: 'a \n b', name: 'choices' },
|
||||
})
|
||||
);
|
||||
await act(async () =>
|
||||
wrapper.find('TextArea#question-default').prop('onChange')('c', {
|
||||
target: { value: 'c', name: 'default' },
|
||||
})
|
||||
);
|
||||
wrapper.find('FormField#question-default').prop('validate')('c', {});
|
||||
wrapper.update();
|
||||
expect(
|
||||
wrapper
|
||||
.find('FormGroup[fieldId="question-default"]')
|
||||
.prop('helperTextInvalid')
|
||||
).toBe('Default choice must be answered from the choices listed.');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user