Skip to content

Commit

Permalink
fix(coursechecklist): add ora date validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanford Student committed Jul 26, 2018
1 parent e1de3ab commit ec67308
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/components/CourseChecklist/CourseChecklist.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const testData = {
assignments: {
assignments_with_dates_after_end: [],
assignments_with_dates_before_start: [],
assignments_with_ora_dates_after_end: [],
assignments_with_ora_dates_before_start: [],
},
is_self_paced: true,
grades: {
Expand Down
22 changes: 20 additions & 2 deletions src/components/CourseChecklist/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,23 @@ class CourseChecklist extends React.Component {
);

getAssignmentDeadlineCommentSection = () => {
const gradedAssignmentsOutsideDateRange = [].concat(
const allGradedAssignmentsOutsideDateRange = [].concat(
this.props.data.assignments.assignments_with_dates_before_start,
this.props.data.assignments.assignments_with_dates_after_end,
this.props.data.assignments.assignments_with_ora_dates_before_start,
this.props.data.assignments.assignments_with_ora_dates_after_end,
);

// de-dupe in case one assignment has multiple violations
const assignmentsMap = new Map();
allGradedAssignmentsOutsideDateRange.forEach(
(assignment) => { assignmentsMap.set(assignment.id, assignment); },
);
const gradedAssignmentsOutsideDateRange = [];
assignmentsMap.forEach(
(value) => {
gradedAssignmentsOutsideDateRange.push(value);
},
);

const message = (
Expand Down Expand Up @@ -297,7 +311,9 @@ class CourseChecklist extends React.Component {
Object.keys(this.props.data).length > 0 &&
(
this.props.data.assignments.assignments_with_dates_before_start.length > 0 ||
this.props.data.assignments.assignments_with_dates_after_end.length > 0
this.props.data.assignments.assignments_with_dates_after_end.length > 0 ||
this.props.data.assignments.assignments_with_ora_dates_before_start.length > 0 ||
this.props.data.assignments.assignments_with_ora_dates_after_end.length > 0
)
)

Expand Down Expand Up @@ -395,6 +411,8 @@ CourseChecklist.propTypes = {
total_visible: PropTypes.number,
assignments_with_dates_before_start: PropTypes.array,
assignments_with_dates_after_end: PropTypes.array,
assignments_with_ora_dates_before_start: PropTypes.array,
assignments_with_ora_dates_after_end: PropTypes.array,
}),
dates: PropTypes.shape({
has_start_date: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ describe('CourseChecklistPage', () => {

expect(getCourseValidationSpy).toHaveBeenCalledTimes(1);
expect(getCourseValidationSpy).toHaveBeenCalledWith(
{ graded_only: true },
{ graded_only: true, validate_oras: true },
defaultProps.studioDetails.course,
);
});
Expand Down
5 changes: 4 additions & 1 deletion src/components/CourseChecklistPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import WrappedMessage from '../../utils/i18n/formattedMessageWrapper';
export default class CourseChecklistPage extends React.Component {
componentDidMount() {
this.props.getCourseBestPractices({ exclude_graded: true }, this.props.studioDetails.course);
this.props.getCourseLaunch({ graded_only: true }, this.props.studioDetails.course);
this.props.getCourseLaunch(
{ graded_only: true, validate_oras: true },
this.props.studioDetails.course,
);
}

getAriaLiveRegion = (isCourseLaunchChecklistLoading, isCourseBestPracticeChecklistLoading) => {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/CourseChecklist/courseChecklistValidators.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const hasAssignmentDeadlines = (assignments, dates) => {
return false;
} else if (assignments.assignments_with_dates_after_end.length > 0) {
return false;
} else if (assignments.assignments_with_ora_dates_before_start.length > 0) {
return false;
} else if (assignments.assignments_with_ora_dates_after_end.length > 0) {
return false;
}

return true;
Expand Down
42 changes: 42 additions & 0 deletions src/utils/CourseChecklist/courseChecklistValidators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ describe('courseCheckValidators utility functions', () => {
{
assignments_with_dates_before_start: 0,
assignments_with_dates_after_end: 0,
assignments_with_ora_dates_after_end: 0,
assignments_with_ora_dates_before_start: 0,
},
{
has_start_date: true,
Expand Down Expand Up @@ -106,6 +108,8 @@ describe('courseCheckValidators utility functions', () => {
{
assignments_with_dates_before_start: ['test'],
assignments_with_dates_after_end: 0,
assignments_with_ora_dates_after_end: 0,
assignments_with_ora_dates_before_start: 0,
},
{
has_start_date: true,
Expand All @@ -119,6 +123,8 @@ describe('courseCheckValidators utility functions', () => {
{
assignments_with_dates_before_start: 0,
assignments_with_dates_after_end: ['test'],
assignments_with_ora_dates_after_end: 0,
assignments_with_ora_dates_before_start: 0,
},
{
has_start_date: true,
Expand All @@ -128,6 +134,42 @@ describe('courseCheckValidators utility functions', () => {
});
});

it(
'returns false when a course run has start and end date and an ora with a date before start',
() => {
expect(validators.hasAssignmentDeadlines(
{
assignments_with_dates_before_start: 0,
assignments_with_dates_after_end: 0,
assignments_with_ora_dates_after_end: 0,
assignments_with_ora_dates_before_start: ['test'],
},
{
has_start_date: true,
has_end_date: true,
},
)).toEqual(false);
},
);

it(
'returns false when a course run has start and end date and an ora with a date after end',
() => {
expect(validators.hasAssignmentDeadlines(
{
assignments_with_dates_before_start: 0,
assignments_with_dates_after_end: 0,
assignments_with_ora_dates_after_end: ['test'],
assignments_with_ora_dates_before_start: 0,
},
{
has_start_date: true,
has_end_date: true,
},
)).toEqual(false);
},
);

describe('hasShortVideoDuration', () => {
it('returns true if course run has no videos', () => {
expect(validators.hasShortVideoDuration({ total_number: 0 })).toEqual(true);
Expand Down

0 comments on commit ec67308

Please sign in to comment.