Skip to content

Commit 6def666

Browse files
authored
feat: update chat visibility (openedx#1297)
1 parent 8335dec commit 6def666

File tree

3 files changed

+26
-36
lines changed

3 files changed

+26
-36
lines changed

src/courseware/course/Course.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ const Course = ({
7070

7171
const SidebarProviderComponent = enableNewSidebar === 'true' ? NewSidebarProvider : SidebarProvider;
7272

73+
const chatValidDates = () => {
74+
const date = new Date();
75+
const utcDate = date.toISOString();
76+
77+
const enrollmentStartDate = course.enrollmentStart || utcDate;
78+
const startDate = course.start || enrollmentStartDate;
79+
const enrollmentEndDate = course.enrollmentEnd || utcDate;
80+
const endDate = course.end || enrollmentEndDate;
81+
82+
return (
83+
startDate <= enrollmentStartDate
84+
&& enrollmentStartDate <= utcDate
85+
&& utcDate <= enrollmentEndDate
86+
&& enrollmentEndDate <= endDate
87+
);
88+
};
89+
7390
return (
7491
<SidebarProviderComponent courseId={courseId} unitId={unitId}>
7592
<Helmet>
@@ -92,7 +109,7 @@ const Course = ({
92109
courseId={courseId}
93110
contentToolsEnabled={course.showCalculator || course.notes.enabled}
94111
unitId={unitId}
95-
endDate={course.end ? course.end : ''}
112+
validDates={chatValidDates()}
96113
/>
97114
</>
98115
)}

src/courseware/course/chat/Chat.jsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Chat = ({
1212
courseId,
1313
contentToolsEnabled,
1414
unitId,
15-
endDate,
15+
validDates,
1616
}) => {
1717
const {
1818
activeAttempt, exam,
@@ -35,17 +35,10 @@ const Chat = ({
3535
&& [...VERIFIED_MODES].some(mode => mode === enrollmentMode)
3636
);
3737

38-
const endDatePassed = () => {
39-
const date = new Date();
40-
const utcDate = date.toISOString();
41-
42-
return endDate ? utcDate > endDate : false; // evaluate if end date has passed only if course has end date
43-
};
44-
4538
const shouldDisplayChat = (
4639
enabled
4740
&& (hasVerifiedEnrollment || isStaff) // display only to verified learners or staff
48-
&& !endDatePassed()
41+
&& validDates
4942
// it is necessary to check both whether the user is in an exam, and whether or not they are viewing an exam
5043
// this will prevent the learner from interacting with the tool at any point of the exam flow, even at the
5144
// entrance interstitial.
@@ -70,7 +63,7 @@ Chat.propTypes = {
7063
courseId: PropTypes.string.isRequired,
7164
contentToolsEnabled: PropTypes.bool.isRequired,
7265
unitId: PropTypes.string.isRequired,
73-
endDate: PropTypes.string.isRequired,
66+
validDates: PropTypes.bool.isRequired,
7467
};
7568

7669
Chat.defaultProps = {

src/courseware/course/chat/Chat.test.jsx

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const enabledModes = [
3838
'paid-executive-education', 'paid-bootcamp',
3939
];
4040
const disabledModes = [null, undefined, 'xyz', 'audit', 'honor', 'unpaid-executive-education', 'unpaid-bootcamp'];
41-
const currentTime = new Date();
4241

4342
describe('Chat', () => {
4443
let store;
@@ -73,7 +72,7 @@ describe('Chat', () => {
7372
enabled
7473
courseId={courseId}
7574
contentToolsEnabled={false}
76-
endDate={new Date(currentTime.getTime() + 10 * 60000).toISOString()}
75+
validDates
7776
/>
7877
</BrowserRouter>,
7978
{ store },
@@ -101,7 +100,7 @@ describe('Chat', () => {
101100
enabled
102101
courseId={courseId}
103102
contentToolsEnabled={false}
104-
endDate={new Date(currentTime.getTime() + 10 * 60000).toISOString()}
103+
validDates
105104
/>
106105
</BrowserRouter>,
107106
{ store },
@@ -157,7 +156,7 @@ describe('Chat', () => {
157156
enabled={test.enabled}
158157
courseId={courseId}
159158
contentToolsEnabled={false}
160-
endDate={new Date(currentTime.getTime() + 10 * 60000).toISOString()}
159+
validDates
161160
/>
162161
</BrowserRouter>,
163162
{ store },
@@ -182,7 +181,7 @@ describe('Chat', () => {
182181
enabled
183182
courseId={courseId}
184183
contentToolsEnabled={false}
185-
endDate={new Date(currentTime.getTime() - 10 * 60000).toISOString()}
184+
validDates={false}
186185
/>
187186
</BrowserRouter>,
188187
{ store },
@@ -192,25 +191,6 @@ describe('Chat', () => {
192191
expect(chat).not.toBeInTheDocument();
193192
});
194193

195-
it('if course has no end date, component should be visible', async () => {
196-
render(
197-
<BrowserRouter>
198-
<Chat
199-
enrollmentMode="verified"
200-
isStaff
201-
enabled
202-
courseId={courseId}
203-
contentToolsEnabled={false}
204-
endDate={null}
205-
/>
206-
</BrowserRouter>,
207-
{ store },
208-
);
209-
210-
const chat = screen.queryByTestId(mockXpertTestId);
211-
expect(chat).toBeInTheDocument();
212-
});
213-
214194
it('if learner has active exam attempt, component should not be visible', async () => {
215195
store = await initializeTestStore({
216196
specialExams: {
@@ -228,7 +208,7 @@ describe('Chat', () => {
228208
enabled
229209
courseId={courseId}
230210
contentToolsEnabled={false}
231-
endDate={null}
211+
validDates
232212
/>
233213
</BrowserRouter>,
234214
{ store },

0 commit comments

Comments
 (0)