Skip to content

Commit c13f118

Browse files
committed
feat: update chat component to use PluginSlot and simplify logic
1 parent 3f41d5a commit c13f118

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
@@ -51,6 +51,5 @@ TWITTER_URL=''
5151
USER_INFO_COOKIE_NAME=''
5252
OPTIMIZELY_FULL_STACK_SDK_KEY=''
5353
SHOW_UNGRADED_ASSIGNMENT_PROGRESS=''
54-
FEATURE_ENABLE_CHAT_V2_ENDPOINT=''
5554
# Fallback in local style files
5655
PARAGON_THEME_URLS={}

.env.development

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@ CHAT_RESPONSE_URL='http://localhost:18000/api/learning_assistant/v1/course_id'
5353
PRIVACY_POLICY_URL='http://localhost:18000/privacy'
5454
OPTIMIZELY_FULL_STACK_SDK_KEY=''
5555
SHOW_UNGRADED_ASSIGNMENT_PROGRESS=''
56-
FEATURE_ENABLE_CHAT_V2_ENDPOINT='false'
5756
# Fallback in local style files
5857
PARAGON_THEME_URLS={}

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
@@ -37,7 +37,7 @@
3737
"@edx/browserslist-config": "1.5.0",
3838
"@edx/frontend-component-footer": "^14.6.0",
3939
"@edx/frontend-component-header": "^6.2.0",
40-
"@edx/frontend-lib-learning-assistant": "^2.23.1",
40+
"@edx/frontend-lib-learning-assistant": "^2.24.0",
4141
"@edx/frontend-lib-special-exams": "^4.0.0",
4242
"@edx/frontend-platform": "^8.3.1",
4343
"@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
@@ -9,7 +9,7 @@ import { breakpoints, useWindowSize } from '@openedx/paragon';
99
import { AlertList } from '@src/generic/user-messages';
1010
import { useModel } from '@src/generic/model-store';
1111
import { getCoursewareOutlineSidebarSettings } from '../data/selectors';
12-
import Chat from './chat/Chat';
12+
import { LearnerToolsSlot } from '../../plugin-slots/LearnerToolsSlot';
1313
import SidebarProvider from './sidebar/SidebarContextProvider';
1414
import NewSidebarProvider from './new-sidebar/SidebarContextProvider';
1515
import { NotificationsDiscussionsSidebarTriggerSlot } from '../../plugin-slots/NotificationsDiscussionsSidebarTriggerSlot';
@@ -62,7 +62,7 @@ const Course = ({
6262
const [weeklyGoalCelebrationOpen, setWeeklyGoalCelebrationOpen] = useState(
6363
celebrations && !celebrations.streakLengthToCelebrate && celebrations.weeklyGoal,
6464
);
65-
const shouldDisplayChat = windowWidth >= breakpoints.medium.minWidth;
65+
const shouldDisplayLearnerTools = windowWidth >= breakpoints.medium.minWidth;
6666
const daysPerWeek = course?.courseGoals?.selectedGoal?.daysPerWeek;
6767

6868
useEffect(() => {
@@ -95,17 +95,13 @@ const Course = ({
9595
/>
9696
</>
9797
)}
98-
{shouldDisplayChat && (
99-
<>
100-
<Chat
101-
enabled={course.learningAssistantEnabled}
102-
enrollmentMode={course.enrollmentMode}
103-
isStaff={isStaff}
104-
courseId={courseId}
105-
contentToolsEnabled={course.showCalculator || course.notes.enabled}
106-
unitId={unitId}
107-
/>
108-
</>
98+
{shouldDisplayLearnerTools && (
99+
<LearnerToolsSlot
100+
enrollmentMode={course.enrollmentMode}
101+
isStaff={isStaff}
102+
courseId={courseId}
103+
unitId={unitId}
104+
/>
109105
)}
110106
<div className="w-100 d-flex align-items-center">
111107
<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)