Skip to content

Commit

Permalink
feat: gate chat visibility by course end date (#1270)
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto authored Jan 10, 2024
1 parent 486faa5 commit 59a68af
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
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();
});
});

0 comments on commit 59a68af

Please sign in to comment.