fix: disable view course when audit expired
This commit is contained in:
committed by
leangseu-edx
parent
7ccf049edb
commit
3c7be4c65c
@@ -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 (
|
||||
<ActionButton
|
||||
disabled={!hasAccess}
|
||||
disabled={disabledViewCourseButton}
|
||||
as="a"
|
||||
href="#"
|
||||
onClick={handleClick}
|
||||
|
||||
@@ -29,12 +29,14 @@ const homeUrl = 'homeUrl';
|
||||
|
||||
const createWrapper = ({
|
||||
hasAccess = false,
|
||||
isAudit = false,
|
||||
isAuditAccessExpired = false,
|
||||
isEntitlement = false,
|
||||
isExpired = false,
|
||||
propsOveride = {},
|
||||
}) => {
|
||||
reduxHooks.useCardCourseRunData.mockReturnValue({ homeUrl });
|
||||
reduxHooks.useCardEnrollmentData.mockReturnValueOnce({ hasAccess });
|
||||
reduxHooks.useCardEnrollmentData.mockReturnValueOnce({ hasAccess, isAudit, isAuditAccessExpired });
|
||||
reduxHooks.useCardEntitlementData.mockReturnValueOnce({ isEntitlement, isExpired });
|
||||
return shallow(<ViewCourseButton {...defaultProps} {...propsOveride} />);
|
||||
};
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user