Skip to content

Commit b282bc0

Browse files
authored
feat: update chat component to use PluginSlot and simplify logic (#1810)
1 parent d987aed commit b282bc0

File tree

13 files changed

+220
-408
lines changed

13 files changed

+220
-408
lines changed

.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,3 @@ OPTIMIZELY_FULL_STACK_SDK_KEY=''
5353
SHOW_UNGRADED_ASSIGNMENT_PROGRESS=''
5454
# Fallback in local style files
5555
PARAGON_THEME_URLS={}
56-
FEATURE_ENABLE_CHAT_V2_ENDPOINT=''

.env.development

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,3 @@ OPTIMIZELY_FULL_STACK_SDK_KEY=''
5555
SHOW_UNGRADED_ASSIGNMENT_PROGRESS=''
5656
# Fallback in local style files
5757
PARAGON_THEME_URLS={}
58-
FEATURE_ENABLE_CHAT_V2_ENDPOINT='false'

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@edx/browserslist-config": "1.5.0",
3737
"@edx/frontend-component-footer": "^14.6.0",
3838
"@edx/frontend-component-header": "^8.0.0",
39-
"@edx/frontend-lib-learning-assistant": "^2.23.1",
39+
"@edx/frontend-lib-learning-assistant": "^2.24.0",
4040
"@edx/frontend-lib-special-exams": "^4.0.0",
4141
"@edx/frontend-platform": "^8.4.0",
4242
"@edx/openedx-atlas": "^0.7.0",

src/courseware/course/Course.jsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { breakpoints, useWindowSize } from '@openedx/paragon';
88

99
import { AlertList } from '@src/generic/user-messages';
1010
import { useModel } from '@src/generic/model-store';
11-
import Chat from './chat/Chat';
11+
import { LearnerToolsSlot } from '../../plugin-slots/LearnerToolsSlot';
1212
import SidebarProvider from './sidebar/SidebarContextProvider';
1313
import NewSidebarProvider from './new-sidebar/SidebarContextProvider';
1414
import { NotificationsDiscussionsSidebarTriggerSlot } from '../../plugin-slots/NotificationsDiscussionsSidebarTriggerSlot';
@@ -59,7 +59,7 @@ const Course = ({
5959
const [weeklyGoalCelebrationOpen, setWeeklyGoalCelebrationOpen] = useState(
6060
celebrations && !celebrations.streakLengthToCelebrate && celebrations.weeklyGoal,
6161
);
62-
const shouldDisplayChat = windowWidth >= breakpoints.medium.minWidth;
62+
const shouldDisplayLearnerTools = windowWidth >= breakpoints.medium.minWidth;
6363
const daysPerWeek = course?.courseGoals?.selectedGoal?.daysPerWeek;
6464

6565
useEffect(() => {
@@ -88,17 +88,13 @@ const Course = ({
8888
isStaff={isStaff}
8989
unitId={unitId}
9090
/>
91-
{shouldDisplayChat && (
92-
<>
93-
<Chat
94-
enabled={course.learningAssistantEnabled}
95-
enrollmentMode={course.enrollmentMode}
96-
isStaff={isStaff}
97-
courseId={courseId}
98-
contentToolsEnabled={course.showCalculator || course.notes.enabled}
99-
unitId={unitId}
100-
/>
101-
</>
91+
{shouldDisplayLearnerTools && (
92+
<LearnerToolsSlot
93+
enrollmentMode={course.enrollmentMode}
94+
isStaff={isStaff}
95+
courseId={courseId}
96+
unitId={unitId}
97+
/>
10298
)}
10399
<div className="w-100 d-flex align-items-center">
104100
<CourseOutlineMobileSidebarTriggerSlot />

src/courseware/course/Course.test.jsx

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,25 @@ import Course from './Course';
1313
import setupDiscussionSidebar from './test-utils';
1414

1515
jest.mock('@edx/frontend-platform/analytics');
16-
jest.mock('@edx/frontend-lib-special-exams/dist/data/thunks.js', () => ({
17-
...jest.requireActual('@edx/frontend-lib-special-exams/dist/data/thunks.js'),
18-
checkExamEntry: () => jest.fn(),
19-
}));
20-
const mockChatTestId = 'fake-chat';
16+
jest.mock('@edx/frontend-lib-special-exams', () => {
17+
const actual = jest.requireActual('@edx/frontend-lib-special-exams');
18+
return {
19+
...actual,
20+
__esModule: true,
21+
// Mock the default export (SequenceExamWrapper) to just render children
22+
// eslint-disable-next-line react/prop-types
23+
default: ({ children }) => <div data-testid="sequence-exam-wrapper">{children}</div>,
24+
};
25+
});
26+
const mockLearnerToolsTestId = 'fake-learner-tools';
2127
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-
},
28+
'../../plugin-slots/LearnerToolsSlot',
29+
() => ({
30+
// eslint-disable-next-line react/prop-types
31+
LearnerToolsSlot({ courseId }) {
32+
return <div className="fake-learner-tools" data-testid={mockLearnerToolsTestId}>LearnerTools contents {courseId} </div>;
33+
},
34+
}),
2735
);
2836

2937
const recordFirstSectionCelebration = jest.fn();
@@ -360,28 +368,27 @@ describe('Course', () => {
360368
});
361369
});
362370

363-
it('displays chat when screen is wide enough (browser)', async () => {
371+
it('displays learner tools when screen is wide enough (browser)', async () => {
364372
const courseMetadata = Factory.build('courseMetadata', {
365-
learning_assistant_enabled: true,
366373
enrollment: { mode: 'verified' },
367374
});
368375
const testStore = await initializeTestStore({ courseMetadata }, false);
369-
const { courseware } = testStore.getState();
376+
const { courseware, models } = testStore.getState();
370377
const { courseId, sequenceId } = courseware;
371378
const testData = {
372379
...mockData,
373380
courseId,
374381
sequenceId,
382+
unitId: Object.values(models.units)[0].id,
375383
};
376384
render(<Course {...testData} />, { store: testStore, wrapWithRouter: true });
377-
const chat = screen.queryByTestId(mockChatTestId);
378-
waitFor(() => expect(chat).toBeInTheDocument());
385+
const learnerTools = screen.queryByTestId(mockLearnerToolsTestId);
386+
await waitFor(() => expect(learnerTools).toBeInTheDocument());
379387
});
380388

381-
it('does not display chat when screen is too narrow (mobile)', async () => {
389+
it('does not display learner tools when screen is too narrow (mobile)', async () => {
382390
global.innerWidth = breakpoints.extraSmall.minWidth;
383391
const courseMetadata = Factory.build('courseMetadata', {
384-
learning_assistant_enabled: true,
385392
enrollment: { mode: 'verified' },
386393
});
387394
const testStore = await initializeTestStore({ courseMetadata }, false);
@@ -393,7 +400,7 @@ describe('Course', () => {
393400
sequenceId,
394401
};
395402
render(<Course {...testData} />, { store: testStore, wrapWithRouter: true });
396-
const chat = screen.queryByTestId(mockChatTestId);
397-
await expect(chat).not.toBeInTheDocument();
403+
const learnerTools = screen.queryByTestId(mockLearnerToolsTestId);
404+
await expect(learnerTools).not.toBeInTheDocument();
398405
});
399406
});

src/courseware/course/chat/Chat.jsx

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)