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

feat: update gating for chat component #1550

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ export const VERIFIED_MODES = [
'paid-bootcamp',
] as const satisfies readonly string[];

export const AUDIT_MODES = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

'audit',
'honor',
'unpaid-executive-education',
'unpaid-bootcamp',
] as const satisfies readonly string[];

export const WIDGETS = {
DISCUSSIONS: 'DISCUSSIONS',
NOTIFICATIONS: 'NOTIFICATIONS',
Expand Down
26 changes: 21 additions & 5 deletions src/courseware/course/chat/Chat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';

import { Xpert } from '@edx/frontend-lib-learning-assistant';
import { getConfig } from '@edx/frontend-platform';
import { injectIntl } from '@edx/frontend-platform/i18n';

import { VERIFIED_MODES } from '@src/constants';
import { AUDIT_MODES, VERIFIED_MODES } from '@src/constants';
import { useModel } from '../../../generic/model-store';

const Chat = ({
Expand All @@ -21,10 +22,14 @@ const Chat = ({
} = useSelector(state => state.specialExams);
const course = useModel('coursewareMeta', courseId);

const hasVerifiedEnrollment = (
const hasValidEnrollment = (
enrollmentMode !== null
&& enrollmentMode !== undefined
&& VERIFIED_MODES.includes(enrollmentMode)
&& (
VERIFIED_MODES.includes(enrollmentMode)
// audit learners are only eligible if Xpert has been explicitly enabled for audit
|| (AUDIT_MODES.includes(enrollmentMode) && getConfig().ENABLE_XPERT_AUDIT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

)
);

const validDates = () => {
Expand All @@ -42,19 +47,30 @@ const Chat = ({

const shouldDisplayChat = (
enabled
&& (hasVerifiedEnrollment || isStaff) // display only to verified learners or staff
&& (hasValidEnrollment || isStaff)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this rename, makes more sense since what counts as "verified" is kinda blurred by the enrollments we chose to use

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1!

&& validDates()
// it is necessary to check both whether the user is in an exam, and whether or not they are viewing an exam
// this will prevent the learner from interacting with the tool at any point of the exam flow, even at the
// entrance interstitial.
&& !(activeAttempt?.attempt_id || exam?.id)
);

const isUpgradeEligible = (
enrollmentMode !== null
&& enrollmentMode !== undefined
&& AUDIT_MODES.includes(enrollmentMode)
);

return (
<>
{/* Use a portal to ensure that component overlay does not compete with learning MFE styles. */}
{shouldDisplayChat && (createPortal(
<Xpert courseId={courseId} contentToolsEnabled={contentToolsEnabled} unitId={unitId} />,
<Xpert
courseId={courseId}
contentToolsEnabled={contentToolsEnabled}
unitId={unitId}
isUpgradEligible={isUpgradeEligible}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: small typo, guessing you meant to name this isUpgradeEligible?

/>,
document.body,
))}
</>
Expand Down
26 changes: 26 additions & 0 deletions src/courseware/course/chat/Chat.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { BrowserRouter } from 'react-router-dom';
import React from 'react';
import { Factory } from 'rosie';

import { getConfig } from '@edx/frontend-platform';

import {
initializeMockApp,
initializeTestStore,
Expand All @@ -28,6 +30,10 @@ jest.mock('@edx/frontend-lib-learning-assistant', () => {
};
});

jest.mock('@edx/frontend-platform', () => ({
getConfig: jest.fn().mockReturnValue({ ENABLE_XPERT_AUDIT: false }),
}));

initializeMockApp();

const courseId = 'course-v1:edX+DemoX+Demo_Course';
Expand Down Expand Up @@ -225,4 +231,24 @@ describe('Chat', () => {
const chat = screen.queryByTestId(mockXpertTestId);
expect(chat).toBeInTheDocument();
});

it('displays component for audit learner if explicitly enabled', async () => {
getConfig.mockImplementation(() => ({ ENABLE_XPERT_AUDIT: true }));

render(
<BrowserRouter>
<Chat
enrollmentMode="audit"
isStaff={false}
enabled
courseId={courseId}
contentToolsEnabled={false}
/>
</BrowserRouter>,
{ store },
);

const chat = screen.queryByTestId(mockXpertTestId);
expect(chat).toBeInTheDocument();
});
});
1 change: 1 addition & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ initialize({
CHAT_RESPONSE_URL: process.env.CHAT_RESPONSE_URL || null,
PRIVACY_POLICY_URL: process.env.PRIVACY_POLICY_URL || null,
SHOW_UNGRADED_ASSIGNMENT_PROGRESS: process.env.SHOW_UNGRADED_ASSIGNMENT_PROGRESS || false,
ENABLE_XPERT_AUDIT: process.env.ENABLE_XPERT_AUDIT || false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codecov seems to be unhappy with these lines not being covered, not sure we need (or are planning on) testing on these though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't normally tested as part of unit tests!

}, 'LearnerAppConfig');
},
},
Expand Down
Loading