Skip to content

Commit

Permalink
Merge pull request #241 from edx/mroytman/update-grading-policy-logic
Browse files Browse the repository at this point in the history
fix(checklists): add default grading policy validation
  • Loading branch information
MichaelRoytman authored Aug 1, 2018
2 parents 9512eb6 + 94f4e5c commit 2f1dbc4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/CourseChecklist/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/components/CourseChecklistPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/components/CourseOutlineStatus/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/utils/CourseChecklist/courseChecklistValidators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
28 changes: 23 additions & 5 deletions src/utils/CourseChecklist/courseChecklistValidators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit 2f1dbc4

Please sign in to comment.