From a07d6f9b8072d40f1076f28ff2dff33b47913d24 Mon Sep 17 00:00:00 2001 From: Leangseu Kim Date: Mon, 5 Jun 2023 12:43:30 -0400 Subject: [PATCH] fix: when there is no options, the validation should be valid --- src/data/redux/grading/selectors/validation.js | 2 +- src/data/redux/grading/selectors/validation.test.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/data/redux/grading/selectors/validation.js b/src/data/redux/grading/selectors/validation.js index 6ed033e0..db6603ff 100644 --- a/src/data/redux/grading/selectors/validation.js +++ b/src/data/redux/grading/selectors/validation.js @@ -32,7 +32,7 @@ validation.criteria = createSelector( criterion.feedback === feedbackRequirement.required && gradingData.criteria[index].feedback === '' ), - selectedOption: gradingData.criteria[index].selectedOption !== '', + selectedOption: rubricConfig.criteria[index].options.length === 0 || gradingData.criteria[index].selectedOption !== '', })), ); diff --git a/src/data/redux/grading/selectors/validation.test.js b/src/data/redux/grading/selectors/validation.test.js index 1b4c4984..80526c88 100644 --- a/src/data/redux/grading/selectors/validation.test.js +++ b/src/data/redux/grading/selectors/validation.test.js @@ -64,8 +64,8 @@ describe('validation grading selectors unit tests', () => { expect(preSelectors).toEqual([selected.gradingData, appSelectors.rubric.config]); }); describe('returned object', () => { - const feedbackOptional = { feedback: feedbackRequirement.optional }; - const feedbackRequired = { feedback: feedbackRequirement.required }; + const feedbackOptional = { feedback: feedbackRequirement.optional, options: [1] }; + const feedbackRequired = { feedback: feedbackRequirement.required, options: [1] }; describe('feedback', () => { const validFeedback = { feedback: 'Fair' }; const emptyFeedback = { feedback: '' }; @@ -85,6 +85,14 @@ describe('validation grading selectors unit tests', () => { ); expect(output.map(({ selectedOption }) => selectedOption)).toEqual([true, false]); }); + it('returns true criteria options are empty', () => { + const emptyOptionsFeedback = { ...feedbackOptional, options: [] }; + const output = cb( + { criteria: [{ selectedOption: '' }, { selectedOption: 'Invalid' }] }, + { criteria: [emptyOptionsFeedback, emptyOptionsFeedback] }, + ); + expect(output.map(({ selectedOption }) => selectedOption)).toEqual([true, true]); + }); }); }); });