@@ -48,9 +48,12 @@ const returnEmptyResult = (_url, req) => {
48
48
// We have to replace the query (search keywords) in the mock results with the actual query,
49
49
// because otherwise we may have an inconsistent state that causes more queries and unexpected results.
50
50
mockEmptyResult . results [ 0 ] . query = query ;
51
+ mockEmptyResult . results [ 2 ] . query = query ;
51
52
// And fake the required '_formatted' fields; it contains the highlighting <mark>...</mark> around matched words
52
53
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
53
54
mockEmptyResult . results [ 0 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
55
+ // eslint-disable-next-line no-underscore-dangle, no-param-reassign
56
+ mockEmptyResult . results [ 2 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
54
57
return mockEmptyResult ;
55
58
} ;
56
59
@@ -68,10 +71,14 @@ const returnLowNumberResults = (_url, req) => {
68
71
newMockResult . results [ 0 ] . query = query ;
69
72
// Limit number of results to just 2
70
73
newMockResult . results [ 0 ] . hits = mockResult . results [ 0 ] ?. hits . slice ( 0 , 2 ) ;
74
+ newMockResult . results [ 2 ] . hits = mockResult . results [ 2 ] ?. hits . slice ( 0 , 2 ) ;
71
75
newMockResult . results [ 0 ] . estimatedTotalHits = 2 ;
76
+ newMockResult . results [ 2 ] . estimatedTotalHits = 2 ;
72
77
// And fake the required '_formatted' fields; it contains the highlighting <mark>...</mark> around matched words
73
78
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
74
79
newMockResult . results [ 0 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
80
+ // eslint-disable-next-line no-underscore-dangle, no-param-reassign
81
+ newMockResult . results [ 2 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
75
82
return newMockResult ;
76
83
} ;
77
84
@@ -220,47 +227,52 @@ describe('<LibraryAuthoringPage />', () => {
220
227
221
228
// "Recently Modified" header + sort shown
222
229
expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ;
223
- expect ( getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
230
+ expect ( getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
224
231
expect ( getByText ( 'Components (6)' ) ) . toBeInTheDocument ( ) ;
225
232
expect ( ( await findAllByText ( 'Test HTML Block' ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
226
233
227
234
// Navigate to the components tab
228
235
fireEvent . click ( getByRole ( 'tab' , { name : 'Components' } ) ) ;
229
236
// "Recently Modified" default sort shown
230
237
expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
231
- expect ( queryByText ( 'Collections (0 )' ) ) . not . toBeInTheDocument ( ) ;
238
+ expect ( queryByText ( 'Collections (6 )' ) ) . not . toBeInTheDocument ( ) ;
232
239
expect ( queryByText ( 'Components (6)' ) ) . not . toBeInTheDocument ( ) ;
233
240
234
241
// Navigate to the collections tab
235
242
fireEvent . click ( getByRole ( 'tab' , { name : 'Collections' } ) ) ;
236
243
// "Recently Modified" default sort shown
237
244
expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
238
- expect ( queryByText ( 'Collections (0 )' ) ) . not . toBeInTheDocument ( ) ;
245
+ expect ( queryByText ( 'Collections (6 )' ) ) . not . toBeInTheDocument ( ) ;
239
246
expect ( queryByText ( 'Components (6)' ) ) . not . toBeInTheDocument ( ) ;
240
- expect ( queryByText ( 'There are 6 components in this library' ) ) . not . toBeInTheDocument ( ) ;
241
- expect ( getByText ( 'Coming soon!' ) ) . toBeInTheDocument ( ) ;
247
+ expect ( ( await findAllByText ( 'Collection 1' ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
242
248
243
249
// Go back to Home tab
244
250
// This step is necessary to avoid the url change leak to other tests
245
251
fireEvent . click ( getByRole ( 'tab' , { name : 'Home' } ) ) ;
246
252
// "Recently Modified" header + sort shown
247
253
expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ;
248
- expect ( getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
254
+ expect ( getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
249
255
expect ( getByText ( 'Components (6)' ) ) . toBeInTheDocument ( ) ;
250
256
} ) ;
251
257
252
- it ( 'show library without components' , async ( ) => {
258
+ it ( 'show library without components and collections ' , async ( ) => {
253
259
mockUseParams . mockReturnValue ( { libraryId : libraryData . id } ) ;
254
260
axiosMock . onGet ( getContentLibraryApiUrl ( libraryData . id ) ) . reply ( 200 , libraryData ) ;
255
261
fetchMock . post ( searchEndpoint , returnEmptyResult , { overwriteRoutes : true } ) ;
256
262
257
- const { findByText, getByText, findAllByText } = render ( < RootWrapper /> ) ;
263
+ const {
264
+ findByText, findAllByText, getByText, getByRole,
265
+ } = render ( < RootWrapper /> ) ;
258
266
259
267
expect ( await findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
260
268
expect ( ( await findAllByText ( libraryData . title ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
261
269
262
270
await waitFor ( ( ) => { expect ( fetchMock ) . toHaveFetchedTimes ( 1 , searchEndpoint , 'post' ) ; } ) ;
263
271
272
+ fireEvent . click ( getByRole ( 'tab' , { name : 'Collections' } ) ) ;
273
+ expect ( getByText ( 'You have not added any collection to this library yet.' ) ) . toBeInTheDocument ( ) ;
274
+
275
+ fireEvent . click ( getByRole ( 'tab' , { name : 'Home' } ) ) ;
264
276
expect ( getByText ( 'You have not added any content to this library yet.' ) ) . toBeInTheDocument ( ) ;
265
277
} ) ;
266
278
@@ -332,6 +344,10 @@ describe('<LibraryAuthoringPage />', () => {
332
344
fireEvent . click ( getByRole ( 'tab' , { name : 'Components' } ) ) ;
333
345
expect ( getByText ( 'No matching components found in this library.' ) ) . toBeInTheDocument ( ) ;
334
346
347
+ // Navigate to the collections tab
348
+ fireEvent . click ( getByRole ( 'tab' , { name : 'Collections' } ) ) ;
349
+ expect ( getByText ( 'No matching collections found in this library.' ) ) . toBeInTheDocument ( ) ;
350
+
335
351
// Go back to Home tab
336
352
// This step is necessary to avoid the url change leak to other tests
337
353
fireEvent . click ( getByRole ( 'tab' , { name : 'Home' } ) ) ;
@@ -395,7 +411,7 @@ describe('<LibraryAuthoringPage />', () => {
395
411
expect ( screen . queryByText ( '(Never Published)' ) ) . not . toBeInTheDocument ( ) ;
396
412
} ) ;
397
413
398
- it ( 'show the "View All" button when viewing library with many components' , async ( ) => {
414
+ it ( 'show the "View All" button when viewing library with many components and collections ' , async ( ) => {
399
415
const {
400
416
getByRole, getByText, queryByText, getAllByText, findAllByText,
401
417
} = await renderLibraryPage ( ) ;
@@ -405,20 +421,29 @@ describe('<LibraryAuthoringPage />', () => {
405
421
406
422
// "Recently Modified" header + sort shown
407
423
await waitFor ( ( ) => { expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ; } ) ;
408
- expect ( getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
424
+ expect ( getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
409
425
expect ( getByText ( 'Components (6)' ) ) . toBeInTheDocument ( ) ;
410
426
expect ( getAllByText ( 'Test HTML Block' ) [ 0 ] ) . toBeInTheDocument ( ) ;
411
427
expect ( queryByText ( 'You have not added any content to this library yet.' ) ) . not . toBeInTheDocument ( ) ;
412
428
413
- // There should only be one "View All" button, since the Components count
429
+ // There should be two "View All" button, since the Components and Collections count
414
430
// are above the preview limit (4)
415
- expect ( getByText ( 'View All' ) ) . toBeInTheDocument ( ) ;
431
+ expect ( getAllByText ( 'View All' ) . length ) . toEqual ( 2 ) ;
416
432
417
- // Clicking on "View All" button should navigate to the Components tab
418
- fireEvent . click ( getByText ( 'View All' ) ) ;
433
+ // Clicking on first "View All" button should navigate to the Collections tab
434
+ fireEvent . click ( getAllByText ( 'View All' ) [ 0 ] ) ;
435
+ // "Recently Modified" default sort shown
436
+ expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
437
+ expect ( queryByText ( 'Collections (6)' ) ) . not . toBeInTheDocument ( ) ;
438
+ expect ( queryByText ( 'Components (6)' ) ) . not . toBeInTheDocument ( ) ;
439
+ expect ( getByText ( 'Collection 1' ) ) . toBeInTheDocument ( ) ;
440
+
441
+ fireEvent . click ( getByRole ( 'tab' , { name : 'Home' } ) ) ;
442
+ // Clicking on second "View All" button should navigate to the Components tab
443
+ fireEvent . click ( getAllByText ( 'View All' ) [ 1 ] ) ;
419
444
// "Recently Modified" default sort shown
420
445
expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
421
- expect ( queryByText ( 'Collections (0 )' ) ) . not . toBeInTheDocument ( ) ;
446
+ expect ( queryByText ( 'Collections (6 )' ) ) . not . toBeInTheDocument ( ) ;
422
447
expect ( queryByText ( 'Components (6)' ) ) . not . toBeInTheDocument ( ) ;
423
448
expect ( getAllByText ( 'Test HTML Block' ) [ 0 ] ) . toBeInTheDocument ( ) ;
424
449
@@ -427,7 +452,7 @@ describe('<LibraryAuthoringPage />', () => {
427
452
fireEvent . click ( getByRole ( 'tab' , { name : 'Home' } ) ) ;
428
453
// "Recently Modified" header + sort shown
429
454
expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ;
430
- expect ( getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
455
+ expect ( getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
431
456
expect ( getByText ( 'Components (6)' ) ) . toBeInTheDocument ( ) ;
432
457
} ) ;
433
458
@@ -447,7 +472,7 @@ describe('<LibraryAuthoringPage />', () => {
447
472
448
473
// "Recently Modified" header + sort shown
449
474
await waitFor ( ( ) => { expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ; } ) ;
450
- expect ( getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
475
+ expect ( getByText ( 'Collections (2 )' ) ) . toBeInTheDocument ( ) ;
451
476
expect ( getByText ( 'Components (2)' ) ) . toBeInTheDocument ( ) ;
452
477
expect ( getAllByText ( 'Test HTML Block' ) [ 0 ] ) . toBeInTheDocument ( ) ;
453
478
expect ( queryByText ( 'You have not added any content to this library yet.' ) ) . not . toBeInTheDocument ( ) ;
0 commit comments