From 3c7be4c65c7e52c41b6f857966fee834c8b34eea Mon Sep 17 00:00:00 2001 From: Leangseu Kim Date: Thu, 23 Feb 2023 13:18:17 -0500 Subject: [PATCH] fix: disable view course when audit expired --- .../components/CourseCardActions/ViewCourseButton.jsx | 6 ++++-- .../CourseCardActions/ViewCourseButton.test.jsx | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/containers/CourseCard/components/CourseCardActions/ViewCourseButton.jsx b/src/containers/CourseCard/components/CourseCardActions/ViewCourseButton.jsx index 90a4433..9627586 100644 --- a/src/containers/CourseCard/components/CourseCardActions/ViewCourseButton.jsx +++ b/src/containers/CourseCard/components/CourseCardActions/ViewCourseButton.jsx @@ -11,15 +11,17 @@ import messages from './messages'; export const ViewCourseButton = ({ cardId }) => { const { formatMessage } = useIntl(); const { homeUrl } = reduxHooks.useCardCourseRunData(cardId); - const { hasAccess } = reduxHooks.useCardEnrollmentData(cardId); + const { hasAccess, isAudit, isAuditAccessExpired } = reduxHooks.useCardEnrollmentData(cardId); const handleClick = reduxHooks.useTrackCourseEvent( track.course.enterCourseClicked, cardId, homeUrl, ); + // disabled on no access or (is audit track but audit access was expired) + const disabledViewCourseButton = !hasAccess || (isAudit && isAuditAccessExpired); return ( { reduxHooks.useCardCourseRunData.mockReturnValue({ homeUrl }); - reduxHooks.useCardEnrollmentData.mockReturnValueOnce({ hasAccess }); + reduxHooks.useCardEnrollmentData.mockReturnValueOnce({ hasAccess, isAudit, isAuditAccessExpired }); reduxHooks.useCardEntitlementData.mockReturnValueOnce({ isEntitlement, isExpired }); return shallow(); }; @@ -57,6 +59,10 @@ describe('ViewCourseButton', () => { test('link is enabled', () => { expect(wrapper.prop(htmlProps.disabled)).toEqual(false); }); + test('link is disabled when audit access is expired', () => { + wrapper = createWrapper({ hasAccess: true, isAudit: true, isAuditAccessExpired: true }); + expect(wrapper.prop(htmlProps.disabled)).toEqual(true); + }); }); describe('learner does not have access to course', () => { beforeEach(() => { @@ -72,7 +78,7 @@ describe('ViewCourseButton', () => { homeUrl, )); }); - test('link is enabled', () => { + test('link is disabled', () => { expect(wrapper.prop(htmlProps.disabled)).toEqual(true); }); });