Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[temp] feat: add import taxonomy button #8

Prev Previous commit
Next Next commit
fix: end date error when certificate row not shown (openedx#668)
KristinAoki authored Nov 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 02a683f09a64b46cac0e505f3b226d0ee067f34c
3 changes: 2 additions & 1 deletion src/schedule-and-details/hooks.jsx
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import { validateScheduleAndDetails, updateWithDefaultValues } from './utils';
const useSaveValuesPrompt = (
courseId,
updateDataQuery,
canShowCertificateAvailableDateField,
initialEditedData = {},
) => {
const intl = useIntl();
@@ -28,7 +29,7 @@ const useSaveValuesPrompt = (
}, [initialEditedData]);

useEffect(() => {
const errors = validateScheduleAndDetails(editedValues, intl);
const errors = validateScheduleAndDetails(editedValues, canShowCertificateAvailableDateField, intl);
setErrorFields(errors);
}, [editedValues]);

37 changes: 21 additions & 16 deletions src/schedule-and-details/index.jsx
Original file line number Diff line number Diff line change
@@ -53,22 +53,6 @@ const ScheduleAndDetails = ({ intl, courseId }) => {
const course = useModel('courseDetails', courseId);
document.title = getPageHeadTitle(course?.name, intl.formatMessage(messages.headingTitle));

const {
errorFields,
savingStatus,
editedValues,
isQueryPending,
isEditableState,
showModifiedAlert,
showSuccessfulAlert,
dispatch,
handleResetValues,
handleValuesChange,
handleUpdateValues,
handleQueryProcessing,
handleInternetConnectionFailed,
} = useSaveValuesPrompt(courseId, updateCourseDetailsQuery, courseDetails);

const {
platformName,
isCreditCourse,
@@ -91,6 +75,27 @@ const ScheduleAndDetails = ({ intl, courseId }) => {
canShowCertificateAvailableDateField,
} = courseSettings;

const {
errorFields,
savingStatus,
editedValues,
isQueryPending,
isEditableState,
showModifiedAlert,
showSuccessfulAlert,
dispatch,
handleResetValues,
handleValuesChange,
handleUpdateValues,
handleQueryProcessing,
handleInternetConnectionFailed,
} = useSaveValuesPrompt(
courseId,
updateCourseDetailsQuery,
canShowCertificateAvailableDateField,
courseDetails,
);

const {
org,
courseId: courseNumber,
4 changes: 2 additions & 2 deletions src/schedule-and-details/utils.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ const isDateBeforeOrEqual = (
return new Date(dateFormer) <= new Date(dateLatter);
};

const validateScheduleAndDetails = (courseDetails, intl) => {
const validateScheduleAndDetails = (courseDetails, canShowCertificateAvailableDate, intl) => {
const errors = {};
const {
endDate,
@@ -34,7 +34,7 @@ const validateScheduleAndDetails = (courseDetails, intl) => {
errors.startDate = intl.formatMessage(messages.errorMessage7);
}

if (isDateBeforeOrEqual(certificateAvailableDate, endDate)) {
if (isDateBeforeOrEqual(certificateAvailableDate, endDate) && canShowCertificateAvailableDate) {
errors.certificateAvailableDate = intl.formatMessage(messages.errorMessage6);
}

294 changes: 294 additions & 0 deletions src/schedule-and-details/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
import { CERTIFICATE_DISPLAY_BEHAVIOR } from './schedule-section/certificate-display-row';
import { validateScheduleAndDetails } from './utils';

const intl = { formatMessage: (message) => message };

describe('validateScheduleAndDetails', () => {
describe('startDate', () => {
it('should return without start date errors', () => {
const errors = validateScheduleAndDetails({ startDate: '01/01/1998' }, false, intl);
const hasStartDateError = Object.keys(errors).includes('startDate');

expect(hasStartDateError).toBeFalsy();
});

it('should return with start date error', () => {
const errors = validateScheduleAndDetails({ startDate: null }, false, intl);
const hasStartDateError = Object.keys(errors).includes('startDate');

expect(hasStartDateError).toBeTruthy();
});
});

describe('endDate', () => {
it('should return without end date errors', () => {
const errors = validateScheduleAndDetails(
{ startDate: '01/01/1998', endDate: '01/01/1999' },
false,
intl,
);
const hasEndDateError = Object.keys(errors).includes('endDate');

expect(hasEndDateError).toBeFalsy();
});

it('should return with end date error', () => {
const errors = validateScheduleAndDetails(
{ startDate: '01/01/1998', endDate: '01/01/1997' },
false,
intl,
);
const hasEndDateError = Object.keys(errors).includes('endDate');

expect(hasEndDateError).toBeTruthy();
});
});

describe('enrollmentStart', () => {
it('should return without enrollment start errors when start dates are equal', () => {
const errors = validateScheduleAndDetails(
{ startDate: '01/01/1998', enrollmentStart: '01/01/1998' },
false,
intl,
);
const hasEnrollmentStartError = Object.keys(errors).includes('enrollmentStart');

expect(hasEnrollmentStartError).toBeFalsy();
});

it('should return without enrollment start error when enrollment start is before course start', () => {
const errors = validateScheduleAndDetails(
{ startDate: '01/01/1999', enrollmentStart: '01/01/1998' },
false,
intl,
);
const hasEnrollmentStartError = Object.keys(errors).includes('enrollmentStart');

expect(hasEnrollmentStartError).toBeFalsy();
});

it('should return without enrollment start error when enrollment start is before enrollment end', () => {
const errors = validateScheduleAndDetails(
{ enrollmentEnd: '01/01/1999', enrollmentStart: '01/01/1998' },
false,
intl,
);
const hasEnrollmentStartError = Object.keys(errors).includes('enrollmentStart');

expect(hasEnrollmentStartError).toBeFalsy();
});

it('should return with enrollment start error when enrolllments starts after course start', () => {
const errors = validateScheduleAndDetails(
{ startDate: '01/01/1998', enrollmentStart: '01/02/1998' },
false,
intl,
);
const hasEnrollmentStartError = Object.keys(errors).includes('enrollmentStart');

expect(hasEnrollmentStartError).toBeTruthy();
});

it('should return with enrollment start error when enrolllments starts after enrollment end', () => {
const errors = validateScheduleAndDetails(
{ enrollmentEnd: '01/01/1998', enrollmentStart: '01/02/1998' },
false,
intl,
);
const hasEnrollmentStartError = Object.keys(errors).includes('enrollmentStart');

expect(hasEnrollmentStartError).toBeTruthy();
});
});

describe('enrollmentEnd', () => {
it('should return without enrollment start errors when end dates are equal', () => {
const errors = validateScheduleAndDetails(
{ enrollmentEnd: '01/01/1998', endDate: '01/01/1999' },
false,
intl,
);
const hasEnrollmentEndError = Object.keys(errors).includes('enrollmentEnd');

expect(hasEnrollmentEndError).toBeFalsy();
});

it('should return without enrollment start error when enrollment end is before course end', () => {
const errors = validateScheduleAndDetails(
{ enrollmentEnd: '01/01/1998', endDate: '01/01/1999' },
false,
intl,
);
const hasEnrollmentEndError = Object.keys(errors).includes('enrollmentEnd');

expect(hasEnrollmentEndError).toBeFalsy();
});

it('should return with enrollment date error', () => {
const errors = validateScheduleAndDetails(
{ enrollmentEnd: '01/01/1998', endDate: '01/01/1997' },
false,
intl,
);
const hasEnrollmentEndError = Object.keys(errors).includes('enrollmentEnd');

expect(hasEnrollmentEndError).toBeTruthy();
});
});

describe('certificateAvailableDate', () => {
describe('with canShowCertificateAvailableDate false', () => {
it('should return without certificate available errors when dates are vaild', () => {
const errors = validateScheduleAndDetails(
{ certificateAvailableDate: '01/01/1999', endDate: '01/01/1998' },
false,
intl,
);
const hasCertificateAvailableError = Object.keys(errors).includes('certificateAvailableDate');

expect(hasCertificateAvailableError).toBeFalsy();
});

it('should return without certificate available errors when dates are invaild', () => {
const errors = validateScheduleAndDetails(
{ certificateAvailableDate: '01/01/1997', endDate: '01/01/1998' },
false,
intl,
);
const hasCertificateAvailableError = Object.keys(errors).includes('certificateAvailableDate');

expect(hasCertificateAvailableError).toBeFalsy();
});
});

describe('with canShowCertificateAvailableDate true', () => {
it('should return without certificate available errors when dates are vaild', () => {
const errors = validateScheduleAndDetails(
{ certificateAvailableDate: '01/01/1999', endDate: '01/01/1998' },
true,
intl,
);
const hasCertificateAvailableError = Object.keys(errors).includes('certificateAvailableDate');

expect(hasCertificateAvailableError).toBeFalsy();
});

it('should return with certificate available error', () => {
const errors = validateScheduleAndDetails(
{ certificateAvailableDate: '01/01/1997', endDate: '01/01/1998' },
true,
intl,
);
const hasCertificateAvailableError = Object.keys(errors).includes('certificateAvailableDate');

expect(hasCertificateAvailableError).toBeTruthy();
});
});

describe('with certificatesDisplayBehavior equal to end_with_date', () => {
it('should return without certificate available errors when date has a value', () => {
const errors = validateScheduleAndDetails(
{
certificateAvailableDate: '01/01/1999',
certificatesDisplayBehavior: CERTIFICATE_DISPLAY_BEHAVIOR.endWithDate,
},
true,
intl,
);
const hasCertificateAvailableError = Object.keys(errors).includes('certificateAvailableDate');

expect(hasCertificateAvailableError).toBeFalsy();
});

it('should return with certificate available errors when date is empty', () => {
const errors = validateScheduleAndDetails(
{
certificateAvailableDate: '',
certificatesDisplayBehavior: CERTIFICATE_DISPLAY_BEHAVIOR.endWithDate,
},
true,
intl,
);
const hasCertificateAvailableError = Object.keys(errors).includes('certificateAvailableDate');

expect(hasCertificateAvailableError).toBeTruthy();
});
});

describe('with canShowCertificateAvailableDate not equal to end_with_date', () => {
it('should return without certificate available errors when date is empty', () => {
const errors = validateScheduleAndDetails(
{
certificateAvailableDate: '',
certificatesDisplayBehavior: CERTIFICATE_DISPLAY_BEHAVIOR.end,
},
true,
intl,
);
const hasCertificateAvailableError = Object.keys(errors).includes('certificateAvailableDate');

expect(hasCertificateAvailableError).toBeFalsy();
});

it('should return without certificate available errors when date is empty', () => {
const errors = validateScheduleAndDetails(
{
certificateAvailableDate: '',
certificatesDisplayBehavior: CERTIFICATE_DISPLAY_BEHAVIOR.earlyNoInfo,
},
true,
intl,
);
const hasCertificateAvailableError = Object.keys(errors).includes('certificateAvailableDate');

expect(hasCertificateAvailableError).toBeFalsy();
});
});
});

describe('entranceExamMinimumScore', () => {
it('should return without exam minimum score errors', () => {
const errors = validateScheduleAndDetails(
{ entranceExamMinimumScorePct: '25' },
false,
intl,
);
const hasExamMinimumScoreError = Object.keys(errors).includes('entranceExamMinimumScorePct');

expect(hasExamMinimumScoreError).toBeFalsy();
});

it('should return with exam minimum score error with negative value', () => {
const errors = validateScheduleAndDetails(
{ entranceExamMinimumScorePct: '-1' },
false,
intl,
);
const hasExamMinimumScoreError = Object.keys(errors).includes('entranceExamMinimumScorePct');

expect(hasExamMinimumScoreError).toBeTruthy();
});

it('should return with exam minimum score error with value greater than 100', () => {
const errors = validateScheduleAndDetails(
{ entranceExamMinimumScorePct: '230' },
false,
intl,
);
const hasExamMinimumScoreError = Object.keys(errors).includes('entranceExamMinimumScorePct');

expect(hasExamMinimumScoreError).toBeTruthy();
});

it('should return with exam minimum score error with non-numerical value', () => {
const errors = validateScheduleAndDetails(
{ entranceExamMinimumScorePct: 'test' },
false,
intl,
);
const hasExamMinimumScoreError = Object.keys(errors).includes('entranceExamMinimumScorePct');

expect(hasExamMinimumScoreError).toBeTruthy();
});
});
});