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: gate chat visibility by course end date #1270

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/courseware/course/Course.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const Course = ({
courseId={courseId}
contentToolsEnabled={course.showCalculator || course.notes.enabled}
unitId={unitId}
endDate={course.end ? course.end : ''}
/>
{enableNewSidebar === 'true' ? <NewSidebarTriggers /> : <SidebarTriggers /> }
</>
Expand Down
10 changes: 10 additions & 0 deletions src/courseware/course/chat/Chat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Chat = ({
courseId,
contentToolsEnabled,
unitId,
endDate,
}) => {
const VERIFIED_MODES = [
'professional',
Expand All @@ -36,9 +37,17 @@ const Chat = ({
&& [...VERIFIED_MODES, ...AUDIT_MODES].some(mode => mode === enrollmentMode)
);

const endDatePassed = () => {
const date = new Date();
const utcDate = date.toISOString();

return endDate ? utcDate > endDate : false; // evaluate if end date has passed only if course has end date
};

const shouldDisplayChat = (
enabled
&& (isEnrolled || isStaff) // display only to enrolled or staff
&& !endDatePassed()
);

return (
Expand All @@ -59,6 +68,7 @@ Chat.propTypes = {
courseId: PropTypes.string.isRequired,
contentToolsEnabled: PropTypes.bool.isRequired,
unitId: PropTypes.string.isRequired,
endDate: PropTypes.string.isRequired,
};

Chat.defaultProps = {
Expand Down
54 changes: 54 additions & 0 deletions src/courseware/course/chat/Chat.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const enabledModes = [
'paid-executive-education', 'paid-bootcamp', 'audit', 'honor', 'unpaid-executive-education', 'unpaid-bootcamp',
];
const disabledModes = [null, undefined, 'xyz'];
const currentTime = new Date();

describe('Chat', () => {
// Generate test cases.
Expand All @@ -44,6 +45,7 @@ describe('Chat', () => {
enabled
courseId={courseId}
contentToolsEnabled={false}
endDate={new Date(currentTime.getTime() + 10 * 60000).toISOString()}
/>
</BrowserRouter>,
{ store },
Expand Down Expand Up @@ -77,6 +79,7 @@ describe('Chat', () => {
enabled
courseId={courseId}
contentToolsEnabled={false}
endDate={new Date(currentTime.getTime() + 10 * 60000).toISOString()}
/>
</BrowserRouter>,
{ store },
Expand Down Expand Up @@ -138,6 +141,7 @@ describe('Chat', () => {
enabled={test.enabled}
courseId={courseId}
contentToolsEnabled={false}
endDate={new Date(currentTime.getTime() + 10 * 60000).toISOString()}
/>
</BrowserRouter>,
{ store },
Expand All @@ -152,4 +156,54 @@ describe('Chat', () => {
},
);
});

it('if course end date has passed, component should not be visible', async () => {
const store = configureStore({
reducer: {
learningAssistant: learningAssistantReducer,
},
});

render(
<BrowserRouter>
<Chat
enrollmentMode="verified"
isStaff
enabled
courseId={courseId}
contentToolsEnabled={false}
endDate={new Date(currentTime.getTime() - 10 * 60000).toISOString()}
/>
</BrowserRouter>,
{ store },
);

const chat = screen.queryByTestId('toggle-button');
expect(chat).not.toBeInTheDocument();
});

it('if course has no end date, component should be visible', async () => {
const store = configureStore({
reducer: {
learningAssistant: learningAssistantReducer,
},
});

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

const chat = screen.queryByTestId('toggle-button');
expect(chat).toBeInTheDocument();
});
});