1
1
import { getConfig , history } from '@edx/frontend-platform' ;
2
2
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
3
3
import { AppProvider } from '@edx/frontend-platform/react' ;
4
- import { waitForElementToBeRemoved , fireEvent } from '@testing-library/dom' ;
4
+ import { waitForElementToBeRemoved } from '@testing-library/dom' ;
5
5
import '@testing-library/jest-dom' ;
6
6
import { render , screen } from '@testing-library/react' ;
7
7
import React from 'react' ;
@@ -193,15 +193,13 @@ describe('CoursewareContainer', () => {
193
193
expect ( courseHeader . querySelector ( '.course-title' ) ) . toHaveTextContent ( courseHomeMetadata . title ) ;
194
194
}
195
195
196
- function assertSequenceNavigation ( container , expectedUnitCount = 3 ) {
197
- // Ensure we had appropriate sequence navigation buttons. We should only have one unit.
196
+ function assertNoSequenceNavigation ( container ) {
198
197
const sequenceNavButtons = container . querySelectorAll ( 'nav.sequence-navigation a, nav.sequence-navigation button' ) ;
199
- expect ( sequenceNavButtons ) . toHaveLength ( expectedUnitCount + 2 ) ;
198
+ expect ( sequenceNavButtons ) . toHaveLength ( 0 ) ;
200
199
201
- expect ( sequenceNavButtons [ 0 ] ) . toHaveTextContent ( 'Previous' ) ;
202
- // Prove this button is rendering an SVG tasks icon, meaning it's a unit/vertical.
203
- expect ( sequenceNavButtons [ 1 ] . querySelector ( 'svg' ) ) . toHaveClass ( 'fa-tasks' ) ;
204
- expect ( sequenceNavButtons [ sequenceNavButtons . length - 1 ] ) . toHaveTextContent ( 'Next' ) ;
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' ) ;
205
203
}
206
204
207
205
beforeEach ( async ( ) => {
@@ -224,7 +222,7 @@ describe('CoursewareContainer', () => {
224
222
const container = await loadContainer ( ) ;
225
223
226
224
assertLoadedHeader ( container ) ;
227
- assertSequenceNavigation ( container ) ;
225
+ assertNoSequenceNavigation ( container ) ;
228
226
229
227
expect ( container . querySelector ( '.fake-unit' ) ) . toHaveTextContent ( 'Unit Contents' ) ;
230
228
expect ( container . querySelector ( '.fake-unit' ) ) . toHaveTextContent ( courseId ) ;
@@ -247,7 +245,7 @@ describe('CoursewareContainer', () => {
247
245
const container = await loadContainer ( ) ;
248
246
249
247
assertLoadedHeader ( container ) ;
250
- assertSequenceNavigation ( container ) ;
248
+ assertNoSequenceNavigation ( container ) ;
251
249
252
250
expect ( container . querySelector ( '.fake-unit' ) ) . toHaveTextContent ( 'Unit Contents' ) ;
253
251
expect ( container . querySelector ( '.fake-unit' ) ) . toHaveTextContent ( courseId ) ;
@@ -274,29 +272,12 @@ describe('CoursewareContainer', () => {
274
272
setUpMockRequests ( { courseBlocks } ) ;
275
273
} ) ;
276
274
277
- // describe('when the URL contains a unit ID', () => {
278
- // it('should ignore the section ID and redirect based on the unit ID', async () => {
279
- // const urlUnit = unitTree[1][1][1];
280
- // setUrl(sectionTree[1].id, urlUnit.id);
281
- // const container = await loadContainer();
282
- // assertLoadedHeader(container);
283
- // assertSequenceNavigation(container, 2);
284
- // assertLocation(container, sequenceTree[1][1].id, urlUnit.id);
285
- // });
286
-
287
- // it('should ignore invalid unit IDs and redirect to the course root', async () => {
288
- // setUrl(sectionTree[1].id, 'foobar');
289
- // await loadContainer();
290
- // expect(global.location.href).toEqual(`http://localhost/course/${courseId}`);
291
- // });
292
- // });
293
-
294
275
describe ( 'when the URL does not contain a unit ID' , ( ) => {
295
276
it ( 'should choose a unit within the section\'s first sequence' , async ( ) => {
296
277
setUrl ( sectionTree [ 1 ] . id ) ;
297
278
const container = await loadContainer ( ) ;
298
279
assertLoadedHeader ( container ) ;
299
- assertSequenceNavigation ( container , 2 ) ;
280
+ assertNoSequenceNavigation ( container ) ;
300
281
assertLocation ( container , sequenceTree [ 1 ] [ 0 ] . id , unitTree [ 1 ] [ 0 ] [ 0 ] . id ) ;
301
282
} ) ;
302
283
} ) ;
@@ -342,27 +323,6 @@ describe('CoursewareContainer', () => {
342
323
} ) ;
343
324
} ) ;
344
325
345
- // describe('when the URL only contains a unit ID', () => {
346
- // const { courseBlocks, unitTree, sequenceTree } = buildBinaryCourseBlocks(courseId, courseMetadata.name);
347
-
348
- // beforeEach(async () => {
349
- // setUpMockRequests({ courseBlocks });
350
- // });
351
-
352
- // it('should insert the sequence ID into the URL', async () => {
353
- // const unit = unitTree[1][0][1];
354
- // history.push(`/course/${courseId}/${unit.id}`);
355
- // const container = await loadContainer();
356
-
357
- // assertLoadedHeader(container);
358
- // assertSequenceNavigation(container, 2);
359
- // const expectedSequenceId = sequenceTree[1][0].id;
360
- // const expectedUrl = `http://localhost/course/${courseId}/${expectedSequenceId}/${unit.id}`;
361
- // expect(global.location.href).toEqual(expectedUrl);
362
- // expect(container.querySelector('.fake-unit')).toHaveTextContent(unit.id);
363
- // });
364
- // });
365
-
366
326
describe ( 'when the URL contains a course ID and sequence ID' , ( ) => {
367
327
const sequenceBlock = defaultSequenceBlock ;
368
328
const unitBlocks = defaultUnitBlocks ;
@@ -372,7 +332,7 @@ describe('CoursewareContainer', () => {
372
332
const container = await loadContainer ( ) ;
373
333
374
334
assertLoadedHeader ( container ) ;
375
- assertSequenceNavigation ( container ) ;
335
+ assertNoSequenceNavigation ( container ) ;
376
336
377
337
expect ( container . querySelector ( '.fake-unit' ) ) . toHaveTextContent ( 'Unit Contents' ) ;
378
338
expect ( container . querySelector ( '.fake-unit' ) ) . toHaveTextContent ( courseId ) ;
@@ -391,7 +351,7 @@ describe('CoursewareContainer', () => {
391
351
const container = await loadContainer ( ) ;
392
352
393
353
assertLoadedHeader ( container ) ;
394
- assertSequenceNavigation ( container ) ;
354
+ assertNoSequenceNavigation ( container ) ;
395
355
396
356
expect ( container . querySelector ( '.fake-unit' ) ) . toHaveTextContent ( 'Unit Contents' ) ;
397
357
expect ( container . querySelector ( '.fake-unit' ) ) . toHaveTextContent ( courseId ) ;
@@ -408,44 +368,24 @@ describe('CoursewareContainer', () => {
408
368
const container = await loadContainer ( ) ;
409
369
410
370
assertLoadedHeader ( container ) ;
411
- assertSequenceNavigation ( container ) ;
371
+ assertNoSequenceNavigation ( container ) ;
412
372
413
373
expect ( container . querySelector ( '.fake-unit' ) ) . toHaveTextContent ( 'Unit Contents' ) ;
414
374
expect ( container . querySelector ( '.fake-unit' ) ) . toHaveTextContent ( courseId ) ;
415
375
expect ( container . querySelector ( '.fake-unit' ) ) . toHaveTextContent ( unitBlocks [ 2 ] . id ) ;
416
376
} ) ;
417
377
418
- it ( 'should navigate between units and check block completion ' , async ( ) => {
419
- axiosMock . onPost ( ` ${ courseId } /xblock/ ${ sequenceBlock . id } /handler/get_completion` ) . reply ( 200 , {
420
- complete : true ,
421
- } ) ;
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 } ) ;
422
382
423
383
history . push ( `/course/${ courseId } /${ sequenceBlock . id } /${ unitBlocks [ 0 ] . id } ` ) ;
424
- const container = await loadContainer ( ) ;
425
-
426
- const sequenceNavButtons = container . querySelectorAll ( 'nav.sequence-navigation a, nav.sequence-navigation button' ) ;
427
- const sequenceNextButton = sequenceNavButtons [ 4 ] ;
428
- expect ( sequenceNextButton ) . toHaveTextContent ( 'Next' ) ;
429
- fireEvent . click ( sequenceNextButton ) ;
384
+ await loadContainer ( ) ;
430
385
431
- expect ( global . location . href ) . toEqual ( `http://localhost/course/ ${ courseId } / ${ sequenceBlock . id } / ${ unitBlocks [ 1 ] . id } ` ) ;
386
+ expect ( screen . getByTestId ( 'org.openedx.frontend.learning.sequence_navigation.v1' ) ) . toBeInTheDocument ( ) ;
432
387
} ) ;
433
388
} ) ;
434
-
435
- // describe('when the current sequence is an exam', () => {
436
- // const { location } = window;
437
-
438
- // beforeEach(() => {
439
- // delete window.location;
440
- // window.location = {
441
- // assign: jest.fn(),
442
- // };
443
- // });
444
-
445
- // afterEach(() => {
446
- // window.location = location;
447
- // });
448
- // });
449
389
} ) ;
450
390
451
391
describe ( 'when receiving a course_access error_code' , ( ) => {
0 commit comments