From 94f4e5cab08cf82fefe1792a5f27797c65df9159 Mon Sep 17 00:00:00 2001 From: Michael Roytman Date: Tue, 31 Jul 2018 16:51:36 -0400 Subject: [PATCH] fix(checklists): add default grading policy validation --- src/components/CourseChecklist/index.jsx | 1 + src/components/CourseChecklistPage/index.jsx | 1 + src/components/CourseOutlineStatus/index.jsx | 1 + .../courseChecklistValidators.js | 1 + .../courseChecklistValidators.test.js | 28 +++++++++++++++---- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/components/CourseChecklist/index.jsx b/src/components/CourseChecklist/index.jsx index 407afd4c..c4300f9f 100644 --- a/src/components/CourseChecklist/index.jsx +++ b/src/components/CourseChecklist/index.jsx @@ -426,6 +426,7 @@ CourseChecklist.propTypes = { has_certificate: PropTypes.bool, }), grades: PropTypes.shape({ + has_grading_policy: PropTypes.bool, sum_of_weights: PropTypes.number, }), is_self_paced: PropTypes.bool, diff --git a/src/components/CourseChecklistPage/index.jsx b/src/components/CourseChecklistPage/index.jsx index dccf2334..9d1a2047 100644 --- a/src/components/CourseChecklistPage/index.jsx +++ b/src/components/CourseChecklistPage/index.jsx @@ -119,6 +119,7 @@ CourseChecklistPage.propTypes = { has_certificate: PropTypes.bool, }), grades: PropTypes.shape({ + has_grading_policy: PropTypes.bool, sum_of_weights: PropTypes.number, }), is_self_paced: PropTypes.bool, diff --git a/src/components/CourseOutlineStatus/index.jsx b/src/components/CourseOutlineStatus/index.jsx index bf9a6f8e..17c6caaf 100644 --- a/src/components/CourseOutlineStatus/index.jsx +++ b/src/components/CourseOutlineStatus/index.jsx @@ -277,6 +277,7 @@ CourseOutlineStatus.propTypes = { has_certificate: PropTypes.bool, }), grades: PropTypes.shape({ + has_grading_policy: PropTypes.bool, sum_of_weights: PropTypes.number, }), is_self_paced: PropTypes.bool, diff --git a/src/utils/CourseChecklist/courseChecklistValidators.js b/src/utils/CourseChecklist/courseChecklistValidators.js index d9d125d5..de843b55 100644 --- a/src/utils/CourseChecklist/courseChecklistValidators.js +++ b/src/utils/CourseChecklist/courseChecklistValidators.js @@ -3,6 +3,7 @@ export const hasWelcomeMessage = updates => ( ); export const hasGradingPolicy = grades => ( + grades.has_grading_policy && parseFloat(grades.sum_of_weights.toPrecision(2), 10) === 1.0 ); diff --git a/src/utils/CourseChecklist/courseChecklistValidators.test.js b/src/utils/CourseChecklist/courseChecklistValidators.test.js index f8da88d0..ff95693a 100644 --- a/src/utils/CourseChecklist/courseChecklistValidators.test.js +++ b/src/utils/CourseChecklist/courseChecklistValidators.test.js @@ -13,15 +13,33 @@ describe('courseCheckValidators utility functions', () => { describe('hasGradingPolicy', () => { it('returns true when sum of weights is 1', () => { - expect(validators.hasGradingPolicy({ sum_of_weights: 1 })).toEqual(true); + expect(validators.hasGradingPolicy( + { has_grading_policy: true, sum_of_weights: 1 }, + )).toEqual(true); }); it('returns true when sum of weights is not 1 due to floating point approximation (1.00004)', () => { - expect(validators.hasGradingPolicy({ sum_of_weights: 1.00004 })).toEqual(true); + expect(validators.hasGradingPolicy( + { has_grading_policy: true, sum_of_weights: 1.00004 }, + )).toEqual(true); }); it('returns false when sum of weights is not 1', () => { - expect(validators.hasGradingPolicy({ sum_of_weights: 2 })).toEqual(false); + expect(validators.hasGradingPolicy( + { has_grading_policy: true, sum_of_weights: 2 }, + )).toEqual(false); + }); + + it('returns true when has_grading_policy is true', () => { + expect(validators.hasGradingPolicy( + { has_grading_policy: true, sum_of_weights: 1 }, + )).toEqual(true); + }); + + it('returns false when has_grading_policy is false', () => { + expect(validators.hasGradingPolicy( + { has_grading_policy: false, sum_of_weights: 1 }, + )).toEqual(false); }); }); @@ -97,8 +115,8 @@ describe('courseCheckValidators utility functions', () => { total_number: 0, }, { - has_start_date: false, - has_end_date: false, + has_start_date: true, + has_end_date: true, }, )).toEqual(false); });