Skip to content

Commit 992ab48

Browse files
authored
feat: show chat for desktop only (openedx#1286)
1 parent 5d2aa5e commit 992ab48

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/courseware/course/Course.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const Course = ({
5454
celebrations && !celebrations.streakLengthToCelebrate && celebrations.weeklyGoal,
5555
);
5656
const shouldDisplayTriggers = windowWidth >= breakpoints.small.minWidth;
57+
const shouldDisplayChat = windowWidth >= breakpoints.medium.minWidth;
5758
const daysPerWeek = course?.courseGoals?.selectedGoal?.daysPerWeek;
5859

5960
useEffect(() => {
@@ -82,7 +83,7 @@ const Course = ({
8283
isStaff={isStaff}
8384
unitId={unitId}
8485
/>
85-
{shouldDisplayTriggers && (
86+
{shouldDisplayChat && (
8687
<>
8788
<Chat
8889
enabled={course.learningAssistantEnabled}
@@ -93,6 +94,10 @@ const Course = ({
9394
unitId={unitId}
9495
endDate={course.end ? course.end : ''}
9596
/>
97+
</>
98+
)}
99+
{shouldDisplayTriggers && (
100+
<>
96101
{enableNewSidebar === 'true' ? <NewSidebarTriggers /> : <SidebarTriggers /> }
97102
</>
98103
)}

src/courseware/course/Course.test.jsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ jest.mock('@edx/frontend-lib-special-exams/dist/data/thunks.js', () => ({
1717
...jest.requireActual('@edx/frontend-lib-special-exams/dist/data/thunks.js'),
1818
checkExamEntry: () => jest.fn(),
1919
}));
20+
const mockChatTestId = 'fake-chat';
21+
jest.mock(
22+
'./chat/Chat',
23+
// eslint-disable-next-line react/prop-types
24+
() => function ({ courseId }) {
25+
return <div className="fake-chat" data-testid={mockChatTestId}>Chat contents {courseId} </div>;
26+
},
27+
);
2028

2129
const recordFirstSectionCelebration = jest.fn();
2230
// eslint-disable-next-line no-import-assign
@@ -317,4 +325,41 @@ describe('Course', () => {
317325
await waitFor(() => expect(screen.getByText('To access course materials, you must score 70% or higher on this exam. Your current score is 30%.')).toBeInTheDocument());
318326
});
319327
});
328+
329+
it('displays chat when screen is wide enough (browser)', async () => {
330+
const courseMetadata = Factory.build('courseMetadata', {
331+
learning_assistant_enabled: true,
332+
enrollment: { mode: 'verified' },
333+
});
334+
const testStore = await initializeTestStore({ courseMetadata }, false);
335+
const { courseware } = testStore.getState();
336+
const { courseId, sequenceId } = courseware;
337+
const testData = {
338+
...mockData,
339+
courseId,
340+
sequenceId,
341+
};
342+
render(<Course {...testData} />, { store: testStore, wrapWithRouter: true });
343+
const chat = screen.queryByTestId(mockChatTestId);
344+
await expect(chat).toBeInTheDocument();
345+
});
346+
347+
it('does not display chat when screen is too narrow (mobile)', async () => {
348+
global.innerWidth = breakpoints.extraSmall.minWidth;
349+
const courseMetadata = Factory.build('courseMetadata', {
350+
learning_assistant_enabled: true,
351+
enrollment: { mode: 'verified' },
352+
});
353+
const testStore = await initializeTestStore({ courseMetadata }, false);
354+
const { courseware } = testStore.getState();
355+
const { courseId, sequenceId } = courseware;
356+
const testData = {
357+
...mockData,
358+
courseId,
359+
sequenceId,
360+
};
361+
render(<Course {...testData} />, { store: testStore, wrapWithRouter: true });
362+
const chat = screen.queryByTestId(mockChatTestId);
363+
await expect(chat).not.toBeInTheDocument();
364+
});
320365
});

0 commit comments

Comments
 (0)