Skip to content

Commit 06c4cb1

Browse files
committed
fix: update tests
1 parent 7b98435 commit 06c4cb1

File tree

4 files changed

+84
-12
lines changed

4 files changed

+84
-12
lines changed

src/courseware/CoursewareContainer.test.jsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ describe('CoursewareContainer', () => {
193193
expect(courseHeader.querySelector('.course-title')).toHaveTextContent(courseHomeMetadata.title);
194194
}
195195

196+
function assertNoSequenceNavigation(container) {
197+
const sequenceNavButtons = container.querySelectorAll('nav.sequence-navigation a, nav.sequence-navigation button');
198+
expect(sequenceNavButtons).toHaveLength(0);
199+
200+
expect(container.querySelector('button, a')).not.toHaveTextContent('Previous');
201+
expect(container.querySelector('svg.fa-tasks')).toBeNull();
202+
expect(container.querySelector('button, a')).not.toHaveTextContent('Next');
203+
}
204+
196205
beforeEach(async () => {
197206
// On page load, SequenceContext attempts to scroll to the top of the page.
198207
global.scrollTo = jest.fn();
@@ -213,6 +222,7 @@ describe('CoursewareContainer', () => {
213222
const container = await loadContainer();
214223

215224
assertLoadedHeader(container);
225+
assertNoSequenceNavigation(container);
216226

217227
expect(container.querySelector('.fake-unit')).toHaveTextContent('Unit Contents');
218228
expect(container.querySelector('.fake-unit')).toHaveTextContent(courseId);
@@ -235,6 +245,7 @@ describe('CoursewareContainer', () => {
235245
const container = await loadContainer();
236246

237247
assertLoadedHeader(container);
248+
assertNoSequenceNavigation(container);
238249

239250
expect(container.querySelector('.fake-unit')).toHaveTextContent('Unit Contents');
240251
expect(container.querySelector('.fake-unit')).toHaveTextContent(courseId);
@@ -266,6 +277,7 @@ describe('CoursewareContainer', () => {
266277
setUrl(sectionTree[1].id);
267278
const container = await loadContainer();
268279
assertLoadedHeader(container);
280+
assertNoSequenceNavigation(container);
269281
assertLocation(container, sequenceTree[1][0].id, unitTree[1][0][0].id);
270282
});
271283
});
@@ -320,6 +332,7 @@ describe('CoursewareContainer', () => {
320332
const container = await loadContainer();
321333

322334
assertLoadedHeader(container);
335+
assertNoSequenceNavigation(container);
323336

324337
expect(container.querySelector('.fake-unit')).toHaveTextContent('Unit Contents');
325338
expect(container.querySelector('.fake-unit')).toHaveTextContent(courseId);
@@ -338,6 +351,7 @@ describe('CoursewareContainer', () => {
338351
const container = await loadContainer();
339352

340353
assertLoadedHeader(container);
354+
assertNoSequenceNavigation(container);
341355

342356
expect(container.querySelector('.fake-unit')).toHaveTextContent('Unit Contents');
343357
expect(container.querySelector('.fake-unit')).toHaveTextContent(courseId);
@@ -354,11 +368,23 @@ describe('CoursewareContainer', () => {
354368
const container = await loadContainer();
355369

356370
assertLoadedHeader(container);
371+
assertNoSequenceNavigation(container);
357372

358373
expect(container.querySelector('.fake-unit')).toHaveTextContent('Unit Contents');
359374
expect(container.querySelector('.fake-unit')).toHaveTextContent(courseId);
360375
expect(container.querySelector('.fake-unit')).toHaveTextContent(unitBlocks[2].id);
361376
});
377+
378+
it('should render the sequence_navigation plugin slot correctly', async () => {
379+
axiosMock
380+
.onPost(`${courseId}/xblock/${sequenceBlock.id}/handler/get_completion`)
381+
.reply(200, { complete: true });
382+
383+
history.push(`/course/${courseId}/${sequenceBlock.id}/${unitBlocks[0].id}`);
384+
await loadContainer();
385+
386+
expect(screen.getByTestId('org.openedx.frontend.learning.sequence_navigation.v1')).toBeInTheDocument();
387+
});
362388
});
363389
});
364390

src/courseware/course/Course.test.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,37 @@ describe('Course', () => {
202202
});
203203
});
204204

205+
it('doesn\'t renders course breadcrumbs by default', async () => {
206+
const courseMetadata = Factory.build('courseMetadata');
207+
const unitBlocks = Array.from({ length: 3 }).map(() => Factory.build(
208+
'block',
209+
{ type: 'vertical' },
210+
{ courseId: courseMetadata.id },
211+
));
212+
const testStore = await initializeTestStore({
213+
courseMetadata, unitBlocks,
214+
}, false);
215+
const { courseware, models } = testStore.getState();
216+
const { courseId, sequenceId } = courseware;
217+
const testData = {
218+
...mockData,
219+
courseId,
220+
sequenceId,
221+
unitId: Object.values(models.units)[1].id, // Corner cases are already covered in `Sequence` tests.
222+
};
223+
render(<Course {...testData} />, { store: testStore, wrapWithRouter: true });
224+
225+
loadUnit();
226+
await waitFor(() => {
227+
expect(screen.queryByText('Loading learning sequence...')).not.toBeInTheDocument();
228+
});
229+
// expect the section and sequence "titles" not to be loaded in as breadcrumb labels.
230+
await waitFor(() => {
231+
expect(screen.queryByText(Object.values(models.sections)[0].title)).not.toBeInTheDocument();
232+
expect(screen.queryByText(Object.values(models.sequences)[0].title)).not.toBeInTheDocument();
233+
});
234+
});
235+
205236
it('passes handlers to the sequence', async () => {
206237
const nextSequenceHandler = jest.fn();
207238
const previousSequenceHandler = jest.fn();

src/courseware/course/sequence/Sequence.jsx

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ const Sequence = ({
8989
sendTrackingLogEvent(eventName, payload);
9090
};
9191

92+
const sequenceNavProps = {
93+
/* istanbul ignore next */
94+
nextHandler: () => {
95+
logEvent('edx.ui.lms.sequence.next_selected', 'top');
96+
handleNext();
97+
},
98+
/* istanbul ignore next */
99+
previousHandler: () => {
100+
logEvent('edx.ui.lms.sequence.previous_selected', 'top');
101+
handlePrevious();
102+
},
103+
/* istanbul ignore next */
104+
onNavigate: (destinationUnitId) => {
105+
logEvent('edx.ui.lms.sequence.tab_selected', 'top', destinationUnitId);
106+
handleNavigate(destinationUnitId);
107+
},
108+
};
109+
92110
useSequenceBannerTextAlert(sequenceId);
93111
useSequenceEntranceExamAlert(courseId, sequenceId, intl);
94112

@@ -170,21 +188,18 @@ const Sequence = ({
170188
<CourseOutlineSidebarSlot />
171189
<div className="sequence w-100">
172190
<div className="sequence-navigation-container">
191+
{/*
192+
SequenceNavigationSlot renders nothing by default.
193+
However, we still pass nextHandler, previousHandler, and onNavigate,
194+
because, as per the slot's contract, if this slot is replaced
195+
with the default SequenceNavigation component, these props are required.
196+
These handlers are excluded from test coverage via istanbul ignore,
197+
since they are not used unless the slot is overridden.
198+
*/}
173199
<SequenceNavigationSlot
174200
sequenceId={sequenceId}
175201
unitId={unitId}
176-
nextHandler={() => {
177-
logEvent('edx.ui.lms.sequence.next_selected', 'top');
178-
handleNext();
179-
}}
180-
onNavigate={(destinationUnitId) => {
181-
logEvent('edx.ui.lms.sequence.tab_selected', 'top', destinationUnitId);
182-
handleNavigate(destinationUnitId);
183-
}}
184-
previousHandler={() => {
185-
logEvent('edx.ui.lms.sequence.previous_selected', 'top');
186-
handlePrevious();
187-
}}
202+
{...sequenceNavProps}
188203
{...{
189204
nextSequenceHandler,
190205
handleNavigate,

webpack.dev-tutor.config.js

Whitespace-only changes.

0 commit comments

Comments
 (0)