Skip to content

Commit

Permalink
refactor: Replace PDF course certificate view code (#946)
Browse files Browse the repository at this point in the history
Co-authored-by: ruzniaievdm <[email protected]>
  • Loading branch information
ruzniaievdm and ruzniaievdm authored Jun 13, 2022
1 parent 792d9eb commit 6257cb4
Show file tree
Hide file tree
Showing 17 changed files with 4 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Factory.define('outlineTabData')
cert_status: null,
cert_web_view_url: null,
certificate_available_date: null,
download_url: null,
},
course_goals: {
goal_options: [],
Expand Down
1 change: 0 additions & 1 deletion src/course-home/data/__snapshots__/redux.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ Object {
"certStatus": null,
"certWebViewUrl": null,
"certificateAvailableDate": null,
"downloadUrl": null,
},
"courseBlocks": Object {
"courses": Object {
Expand Down
78 changes: 1 addition & 77 deletions src/course-home/outline-tab/OutlineTab.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ describe('Outline Tab', () => {
cert_status: CERT_STATUS_TYPE.EARNED_NOT_AVAILABLE,
cert_web_view_url: null,
certificate_available_date: tomorrow.toISOString(),
download_url: null,
},
}, {
date_blocks: [
Expand Down Expand Up @@ -670,7 +669,6 @@ describe('Outline Tab', () => {
cert_data: {
cert_status: CERT_STATUS_TYPE.UNVERIFIED,
cert_web_view_url: null,
download_url: null,
},
}, {
date_blocks: [
Expand Down Expand Up @@ -739,7 +737,6 @@ describe('Outline Tab', () => {
cert_data: {
cert_status: CERT_STATUS_TYPE.REQUESTING,
cert_web_view_url: null,
download_url: null,
},
}, {
date_blocks: [
Expand Down Expand Up @@ -773,50 +770,7 @@ describe('Outline Tab', () => {
org_key: 'edX',
});
});
it('tracks download cert button', async () => {
sendTrackEvent.mockClear();
const now = new Date();
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
const tomorrow = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
setMetadata({ is_enrolled: true });
setTabData({
cert_data: {
cert_status: CERT_STATUS_TYPE.DOWNLOADABLE,
cert_web_view_url: null,
download_url: null,
},
}, {
date_blocks: [
{
date_type: 'course-end-date',
date: yesterday.toISOString(),
title: 'End',
},
{
date_type: 'certificate-available-date',
date: tomorrow.toISOString(),
title: 'Cert Available',
},
{
date_type: 'verification-deadline-date',
date: tomorrow.toISOString(),
link_text: 'Verify',
title: 'Verification Upgrade Deadline',
},
],
});
await fetchAndRender();
sendTrackEvent.mockClear();
const requestingButton = screen.getByRole('button', { name: 'View my certificate' });
fireEvent.click(requestingButton);
expect(sendTrackEvent).toHaveBeenCalledTimes(1);
expect(sendTrackEvent).toHaveBeenCalledWith('edx.ui.lms.course_outline.certificate_alert_downloadable_button.clicked',
{
courserun_key: courseId,
is_staff: false,
org_key: 'edX',
});
});

it('tracks unverified cert button', async () => {
sendTrackEvent.mockClear();
const now = new Date();
Expand All @@ -827,7 +781,6 @@ describe('Outline Tab', () => {
cert_data: {
cert_status: CERT_STATUS_TYPE.UNVERIFIED,
cert_web_view_url: null,
download_url: null,
},
}, {
date_blocks: [
Expand Down Expand Up @@ -915,7 +868,6 @@ describe('Outline Tab', () => {
cert_status: CERT_STATUS_TYPE.DOWNLOADABLE,
cert_web_view_url: 'certificate/testuuid',
certificate_available_date: null,
download_url: null,
},
}, {
date_blocks: [
Expand All @@ -941,7 +893,6 @@ describe('Outline Tab', () => {
cert_status: CERT_STATUS_TYPE.REQUESTING,
cert_web_view_url: null,
certificate_available_date: null,
download_url: null,
},
}, {
date_blocks: [
Expand All @@ -958,33 +909,6 @@ describe('Outline Tab', () => {
});
});

describe('Certificate (pdf) Complete Alert', () => {
it('appears', async () => {
const now = new Date();
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
setMetadata({ is_enrolled: true });
setTabData({
cert_data: {
cert_status: CERT_STATUS_TYPE.DOWNLOADABLE,
cert_web_view_url: null,
certificate_available_date: null,
download_url: 'download/url',
},
}, {
date_blocks: [
{
date_type: 'course-end-date',
date: yesterday.toISOString(),
title: 'End',
},
],
});
await fetchAndRender();
expect(screen.queryByText('Congratulations! Your certificate is ready.')).toBeInTheDocument();
expect(screen.queryByRole('link', { name: 'Download my certificate' })).toBeInTheDocument();
});
});

describe('Proctoring Info Panel', () => {
const onboardingReleaseDate = new Date();
onboardingReleaseDate.setDate(new Date().getDate() - 7);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function CertificateStatusAlert({ intl, payload }) {
courseEndDate,
courseId,
certURL,
isWebCert,
userTimezone,
org,
notPassingCourseEnded,
Expand Down Expand Up @@ -79,11 +78,7 @@ function CertificateStatusAlert({ intl, payload }) {
);
} else if (certStatus === CERT_STATUS_TYPE.DOWNLOADABLE) {
alertProps.header = intl.formatMessage(certMessages.certStatusDownloadableHeader);
if (isWebCert) {
alertProps.buttonMessage = intl.formatMessage(certStatusMessages.viewableButton);
} else {
alertProps.buttonMessage = intl.formatMessage(certStatusMessages.downloadableButton);
}
alertProps.buttonMessage = intl.formatMessage(certStatusMessages.viewableButton);
alertProps.buttonVisible = true;
alertProps.buttonLink = certURL;
alertProps.buttonAction = () => {
Expand Down Expand Up @@ -204,7 +199,6 @@ CertificateStatusAlert.propTypes = {
courseEndDate: PropTypes.string,
courseId: PropTypes.string,
certURL: PropTypes.string,
isWebCert: PropTypes.bool,
userTimezone: PropTypes.string,
org: PropTypes.string,
notPassingCourseEnded: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ function useCertificateStatusAlert(courseId) {
certStatus,
certWebViewUrl,
certificateAvailableDate,
downloadUrl,
} = certData || {};
const endBlock = courseDateBlocks.find(b => b.dateType === 'course-end-date');
const isWebCert = downloadUrl === null;
const isVerifiedEnrollmentMode = (
enrollmentMode !== null
&& enrollmentMode !== undefined
Expand All @@ -63,9 +61,6 @@ function useCertificateStatusAlert(courseId) {
let certURL = '';
if (certWebViewUrl) {
certURL = `${getConfig().LMS_BASE_URL}${certWebViewUrl}`;
} else if (downloadUrl) {
// PDF Certificate
certURL = downloadUrl;
}
const hasAlertingCertStatus = verifyCertStatusType(certStatus);

Expand All @@ -87,7 +82,6 @@ function useCertificateStatusAlert(courseId) {
courseId,
courseEndDate: endBlock && endBlock.date,
userTimezone,
isWebCert,
org,
notPassingCourseEnded,
tabs,
Expand Down
43 changes: 0 additions & 43 deletions src/course-home/progress-tab/ProgressTab.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -959,49 +959,6 @@ describe('Progress Tab', () => {
});
});

it('Displays download link', async () => {
setTabData({
certificate_data: {
cert_status: 'downloadable',
download_url: 'fake.download.url',
},
user_has_passing_grade: true,
});
await fetchAndRender();
expect(screen.getByRole('link', { name: 'Download my certificate' })).toBeInTheDocument();
});

it('sends events on view of progress tab and on click of downloadable certificate link', async () => {
setTabData({
certificate_data: {
cert_status: 'downloadable',
download_url: 'fake.download.url',
},
user_has_passing_grade: true,
});
await fetchAndRender();
expect(sendTrackEvent).toHaveBeenCalledTimes(1);
expect(sendTrackEvent).toHaveBeenCalledWith('edx.ui.lms.course_progress.visited', {
org_key: 'edX',
courserun_key: courseId,
is_staff: false,
track_variant: 'audit',
grade_variant: 'passing',
certificate_status_variant: 'earned_downloadable',
});

const downloadCertificateLink = screen.getByRole('link', { name: 'Download my certificate' });
fireEvent.click(downloadCertificateLink);

expect(sendTrackEvent).toHaveBeenCalledTimes(2);
expect(sendTrackEvent).toHaveBeenNthCalledWith(2, 'edx.ui.lms.course_progress.certificate_status.clicked', {
org_key: 'edX',
courserun_key: courseId,
is_staff: false,
certificate_status_variant: 'earned_downloadable',
});
});

it('Displays webview link', async () => {
setTabData({
certificate_data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ function CertificateStatus({ intl }) {

let certStatus;
let certWebViewUrl;
let downloadUrl;
const timezoneFormatArgs = userTimezone ? { timeZone: userTimezone } : {};

if (certificateData) {
certStatus = certificateData.certStatus;
certWebViewUrl = certificateData.certWebViewUrl;
downloadUrl = certificateData.downloadUrl;
}

let certCase;
Expand Down Expand Up @@ -143,15 +141,10 @@ function CertificateStatus({ intl }) {
values={{ dashboardLink, profileLink }}
/>
);

if (certWebViewUrl) {
certEventName = 'earned_viewable';
buttonLocation = `${getConfig().LMS_BASE_URL}${certWebViewUrl}`;
buttonText = intl.formatMessage(messages.viewableButton);
} else if (downloadUrl) {
certEventName = 'earned_downloadable';
buttonLocation = downloadUrl;
buttonText = intl.formatMessage(messages.downloadableButton);
}
break;

Expand Down
5 changes: 0 additions & 5 deletions src/course-home/progress-tab/certificate-status/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ const messages = defineMessages({
defaultMessage: 'Showcase your accomplishment on LinkedIn or your resumé today. You can download your certificate now and access it any time from your Dashboard and Profile.',
description: 'Recommending an action for learner when course certificate is available',
},
downloadableButton: {
id: 'progress.certificateStatus.downloadableButton',
defaultMessage: 'Download my certificate',
description: 'Button text when learner certifcate status is downloadable',
},
viewableButton: {
id: 'progress.certificateStatus.viewableButton',
defaultMessage: 'View my certificate',
Expand Down
4 changes: 0 additions & 4 deletions src/courseware/course/course-exit/CourseCelebration.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function CourseCelebration({ intl }) {
const {
certStatus,
certWebViewUrl,
downloadUrl,
certificateAvailableDate,
} = certificateData || {};

Expand Down Expand Up @@ -104,9 +103,6 @@ function CourseCelebration({ intl }) {
if (certWebViewUrl) {
buttonLocation = `${getConfig().LMS_BASE_URL}${certWebViewUrl}`;
buttonText = intl.formatMessage(messages.viewCertificateButton);
} else if (downloadUrl) {
buttonLocation = downloadUrl;
buttonText = intl.formatMessage(messages.downloadButton);
}
if (linkedinAddToProfileUrl) {
buttonPrefix = (
Expand Down
11 changes: 0 additions & 11 deletions src/courseware/course/course-exit/CourseExit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ describe('Course Exit Pages', () => {
});

describe('Course Celebration Experience', () => {
it('Displays download link', async () => {
setMetadata({
certificate_data: {
cert_status: 'downloadable',
download_url: 'fake.download.url',
},
});
await fetchAndRender(<CourseCelebration />);
expect(screen.getByRole('link', { name: 'Download my certificate' })).toBeInTheDocument();
});

it('Displays webview link', async () => {
setMetadata({
certificate_data: {
Expand Down
5 changes: 0 additions & 5 deletions src/courseware/course/course-exit/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ const messages = defineMessages({
defaultMessage: 'Dashboard',
description: 'Link to user’s dashboard',
},
downloadButton: {
id: 'courseCelebration.downloadButton',
defaultMessage: 'Download my certificate',
description: 'Button to download the course certificate',
},
endOfCourseDescription: {
id: 'courseExit.endOfCourseDescription',
defaultMessage: 'Unfortunately, you are not currently eligible for a certificate. You need to receive a passing grade to be eligible for a certificate.',
Expand Down
3 changes: 1 addition & 2 deletions src/courseware/data/pact-tests/lmsPact.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ describe('Courseware Service', () => {
user_has_passing_grade: boolean(false),
course_exit_page_is_active: boolean(false),
certificate_data: {
cert_status: string('audit_passing'), cert_web_view_url: null, download_url: null, certificate_available_date: null,
cert_status: string('audit_passing'), cert_web_view_url: null, certificate_available_date: null,
},
verify_identity_url: null,
verification_status: string('none'),
Expand Down Expand Up @@ -328,7 +328,6 @@ describe('Courseware Service', () => {
certificateData: {
certStatus: 'audit_passing',
certWebViewUrl: null,
downloadUrl: null,
certificateAvailableDate: null,
},
timeOffsetMillis: 0,
Expand Down
2 changes: 0 additions & 2 deletions src/i18n/messages/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
"progress.certificateStatus.unverifiedButton": "التحقق من الهوية",
"progress.certificateStatus.courseCelebration.verificationPending": "عملية التحقق من المعرّف الخاص بك معلّقة وستتوفر شهادتك بمجرد الموافقة.",
"progress.certificateStatus.downloadableHeader": "!شهادتك جاهزة",
"progress.certificateStatus.downloadableButton": "تحميل شهاداتي",
"progress.certificateStatus.viewableButton": "عرض شهاداتي",
"progress.certificateStatus.notAvailableHeader": "حالة الشهادة",
"progress.certificateBody.notAvailable.endDate": "Final grades and any earned certificates are scheduled to be available after {endDate}.",
Expand Down Expand Up @@ -288,7 +287,6 @@
"courseExit.courseInProgressDescription": "يبدو أن هناك المزيد من المحتوى في هذه الدورة والذي سيتم إصداره في المستقبل. ابقى على اطلاع بتحديثات البريد الإلكتروني أو تحقق مرة أخرى من الدورة التدريبية الخاصة بك لمعرفة وقت توفر هذا المحتوى.",
"courseExit.courseInProgressHeader": "المزيد من المحتوى قريبا!",
"courseExit.dashboardLink": "لوحة المعلومات",
"courseCelebration.downloadButton": "تحميل شهاداتي",
"courseExit.endOfCourseDescription": "لسوء الحظ، لست مؤهلًا الآن للحصول على شهادة. تحتاج إلى تحقيق درجة الاجتياز تؤهلك للحصول على شهادة.",
"courseExit.endOfCourseHeader": "لقد أتممت المساق!",
"courseExit.endOfCourseTitle": "نهاية المساق",
Expand Down
2 changes: 0 additions & 2 deletions src/i18n/messages/es_419.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
"progress.certificateStatus.unverifiedButton": "Verificar tu identidad",
"progress.certificateStatus.courseCelebration.verificationPending": "Su verificación de ID está pendiente y su certificado estará disponible una vez que se haya aprobado.",
"progress.certificateStatus.downloadableHeader": "¡Tu certificado está disponible!",
"progress.certificateStatus.downloadableButton": "Descargar mi certificado",
"progress.certificateStatus.viewableButton": "Ver mi certificado",
"progress.certificateStatus.notAvailableHeader": "Estado del certificado",
"progress.certificateBody.notAvailable.endDate": "Final grades and any earned certificates are scheduled to be available after {endDate}.",
Expand Down Expand Up @@ -288,7 +287,6 @@
"courseExit.courseInProgressDescription": "Parece que hay más contenido en este curso que se publicará en el futuro. Presta atención a las novedades por correo electrónico o consulta tu curso para saber cuándo estará disponible este contenido.",
"courseExit.courseInProgressHeader": "¡Pronto habrá más contenido!",
"courseExit.dashboardLink": "Panel de Control",
"courseCelebration.downloadButton": "Descargar mi certificado",
"courseExit.endOfCourseDescription": "Lamentablemente, no puedes obtener un certificado en este momento. Debes recibir una calificación aprobatoria para poder obtener un certificado.",
"courseExit.endOfCourseHeader": "¡Has llegado al fin del curso!",
"courseExit.endOfCourseTitle": "Fin del curso",
Expand Down
Loading

0 comments on commit 6257cb4

Please sign in to comment.