@@ -27,9 +27,12 @@ const returnEmptyResult = (_url, req) => {
27
27
// We have to replace the query (search keywords) in the mock results with the actual query,
28
28
// because otherwise we may have an inconsistent state that causes more queries and unexpected results.
29
29
mockEmptyResult . results [ 0 ] . query = query ;
30
+ mockEmptyResult . results [ 2 ] . query = query ;
30
31
// And fake the required '_formatted' fields; it contains the highlighting <mark>...</mark> around matched words
31
32
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
32
33
mockEmptyResult . results [ 0 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
34
+ // eslint-disable-next-line no-underscore-dangle, no-param-reassign
35
+ mockEmptyResult . results [ 2 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
33
36
return mockEmptyResult ;
34
37
} ;
35
38
@@ -47,10 +50,14 @@ const returnLowNumberResults = (_url, req) => {
47
50
newMockResult . results [ 0 ] . query = query ;
48
51
// Limit number of results to just 2
49
52
newMockResult . results [ 0 ] . hits = mockResult . results [ 0 ] ?. hits . slice ( 0 , 2 ) ;
53
+ newMockResult . results [ 2 ] . hits = mockResult . results [ 2 ] ?. hits . slice ( 0 , 2 ) ;
50
54
newMockResult . results [ 0 ] . estimatedTotalHits = 2 ;
55
+ newMockResult . results [ 2 ] . estimatedTotalHits = 2 ;
51
56
// And fake the required '_formatted' fields; it contains the highlighting <mark>...</mark> around matched words
52
57
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
53
58
newMockResult . results [ 0 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
59
+ // eslint-disable-next-line no-underscore-dangle, no-param-reassign
60
+ newMockResult . results [ 2 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
54
61
return newMockResult ;
55
62
} ;
56
63
@@ -132,42 +139,46 @@ describe('<LibraryAuthoringPage />', () => {
132
139
133
140
// "Recently Modified" header + sort shown
134
141
expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ;
135
- expect ( getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
142
+ expect ( getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
136
143
expect ( getByText ( 'Components (10)' ) ) . toBeInTheDocument ( ) ;
137
144
expect ( ( await findAllByText ( 'Introduction to Testing' ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
138
145
139
146
// Navigate to the components tab
140
147
fireEvent . click ( getByRole ( 'tab' , { name : 'Components' } ) ) ;
141
148
// "Recently Modified" default sort shown
142
149
expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
143
- expect ( queryByText ( 'Collections (0 )' ) ) . not . toBeInTheDocument ( ) ;
150
+ expect ( queryByText ( 'Collections (6 )' ) ) . not . toBeInTheDocument ( ) ;
144
151
expect ( queryByText ( 'Components (10)' ) ) . not . toBeInTheDocument ( ) ;
145
152
146
153
// Navigate to the collections tab
147
154
fireEvent . click ( getByRole ( 'tab' , { name : 'Collections' } ) ) ;
148
155
// "Recently Modified" default sort shown
149
156
expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
150
- expect ( queryByText ( 'Collections (0 )' ) ) . not . toBeInTheDocument ( ) ;
157
+ expect ( queryByText ( 'Collections (6 )' ) ) . not . toBeInTheDocument ( ) ;
151
158
expect ( queryByText ( 'Components (10)' ) ) . not . toBeInTheDocument ( ) ;
152
159
expect ( queryByText ( 'There are 10 components in this library' ) ) . not . toBeInTheDocument ( ) ;
153
- expect ( getByText ( 'Coming soon!' ) ) . toBeInTheDocument ( ) ;
160
+ expect ( ( await findAllByText ( 'Collection 1' ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
154
161
155
162
// Go back to Home tab
156
163
// This step is necessary to avoid the url change leak to other tests
157
164
fireEvent . click ( getByRole ( 'tab' , { name : 'Home' } ) ) ;
158
165
// "Recently Modified" header + sort shown
159
166
expect ( getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ;
160
- expect ( getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
167
+ expect ( getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
161
168
expect ( getByText ( 'Components (10)' ) ) . toBeInTheDocument ( ) ;
162
169
} ) ;
163
170
164
- it ( 'shows a library without components' , async ( ) => {
171
+ it ( 'shows a library without components and collections ' , async ( ) => {
165
172
fetchMock . post ( searchEndpoint , returnEmptyResult , { overwriteRoutes : true } ) ;
166
173
const doc = await renderLibraryPage ( ) ;
167
174
168
175
expect ( await doc . findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
169
176
expect ( ( await doc . findAllByText ( libraryTitle ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
170
177
178
+ fireEvent . click ( doc . getByRole ( 'tab' , { name : 'Collections' } ) ) ;
179
+ expect ( doc . getByText ( 'You have not added any collection to this library yet.' ) ) . toBeInTheDocument ( ) ;
180
+
181
+ fireEvent . click ( doc . getByRole ( 'tab' , { name : 'Home' } ) ) ;
171
182
expect ( doc . getByText ( 'You have not added any content to this library yet.' ) ) . toBeInTheDocument ( ) ;
172
183
} ) ;
173
184
@@ -214,6 +225,14 @@ describe('<LibraryAuthoringPage />', () => {
214
225
// Navigate to the components tab
215
226
fireEvent . click ( doc . getByRole ( 'tab' , { name : 'Components' } ) ) ;
216
227
expect ( doc . getByText ( 'No matching components found in this library.' ) ) . toBeInTheDocument ( ) ;
228
+
229
+ // Navigate to the collections tab
230
+ fireEvent . click ( doc . getByRole ( 'tab' , { name : 'Collections' } ) ) ;
231
+ expect ( getByText ( 'No matching collections found in this library.' ) ) . toBeInTheDocument ( ) ;
232
+
233
+ // Go back to Home tab
234
+ // This step is necessary to avoid the url change leak to other tests
235
+ fireEvent . click ( doc . getByRole ( 'tab' , { name : 'Home' } ) ) ;
217
236
} ) ;
218
237
219
238
it ( 'should open and close new content sidebar' , async ( ) => {
@@ -277,28 +296,37 @@ describe('<LibraryAuthoringPage />', () => {
277
296
expect ( doc . queryByText ( '(Never Published)' ) ) . not . toBeInTheDocument ( ) ;
278
297
} ) ;
279
298
280
- it ( 'show the "View All" button when viewing library with many components' , async ( ) => {
299
+ it ( 'show the "View All" button when viewing library with many components and collections ' , async ( ) => {
281
300
const doc = await renderLibraryPage ( ) ;
282
301
283
302
expect ( doc . getByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
284
303
expect ( ( await doc . findAllByText ( libraryTitle ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
285
304
286
305
// "Recently Modified" header + sort shown
287
306
await waitFor ( ( ) => { expect ( doc . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ; } ) ;
288
- expect ( doc . getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
307
+ expect ( doc . getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
289
308
expect ( doc . getByText ( 'Components (10)' ) ) . toBeInTheDocument ( ) ;
290
309
expect ( doc . getAllByText ( 'Introduction to Testing' ) [ 0 ] ) . toBeInTheDocument ( ) ;
291
310
expect ( doc . queryByText ( 'You have not added any content to this library yet.' ) ) . not . toBeInTheDocument ( ) ;
292
311
293
- // There should only be one "View All" button, since the Components count
312
+ // There should be two "View All" button, since the Components and Collections count
294
313
// are above the preview limit (4)
295
- expect ( doc . getByText ( 'View All' ) ) . toBeInTheDocument ( ) ;
314
+ expect ( doc . getAllByText ( 'View All' ) . length ) . toEqual ( 2 ) ;
296
315
297
- // Clicking on "View All" button should navigate to the Components tab
298
- fireEvent . click ( doc . getByText ( 'View All' ) ) ;
316
+ // Clicking on first "View All" button should navigate to the Collections tab
317
+ fireEvent . click ( doc . getAllByText ( 'View All' ) [ 0 ] ) ;
318
+ // "Recently Modified" default sort shown
319
+ expect ( doc . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
320
+ expect ( doc . queryByText ( 'Collections (6)' ) ) . not . toBeInTheDocument ( ) ;
321
+ expect ( doc . queryByText ( 'Components (10)' ) ) . not . toBeInTheDocument ( ) ;
322
+ expect ( doc . getByText ( 'Collection 1' ) ) . toBeInTheDocument ( ) ;
323
+
324
+ fireEvent . click ( doc . getByRole ( 'tab' , { name : 'Home' } ) ) ;
325
+ // Clicking on second "View All" button should navigate to the Components tab
326
+ fireEvent . click ( doc . getAllByText ( 'View All' ) [ 1 ] ) ;
299
327
// "Recently Modified" default sort shown
300
328
expect ( doc . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
301
- expect ( doc . queryByText ( 'Collections (0 )' ) ) . not . toBeInTheDocument ( ) ;
329
+ expect ( doc . queryByText ( 'Collections (6 )' ) ) . not . toBeInTheDocument ( ) ;
302
330
expect ( doc . queryByText ( 'Components (10)' ) ) . not . toBeInTheDocument ( ) ;
303
331
expect ( doc . getAllByText ( 'Introduction to Testing' ) [ 0 ] ) . toBeInTheDocument ( ) ;
304
332
@@ -307,7 +335,7 @@ describe('<LibraryAuthoringPage />', () => {
307
335
fireEvent . click ( doc . getByRole ( 'tab' , { name : 'Home' } ) ) ;
308
336
// "Recently Modified" header + sort shown
309
337
expect ( doc . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ;
310
- expect ( doc . getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
338
+ expect ( doc . getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
311
339
expect ( doc . getByText ( 'Components (10)' ) ) . toBeInTheDocument ( ) ;
312
340
} ) ;
313
341
@@ -320,7 +348,7 @@ describe('<LibraryAuthoringPage />', () => {
320
348
321
349
// "Recently Modified" header + sort shown
322
350
await waitFor ( ( ) => { expect ( doc . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ; } ) ;
323
- expect ( doc . getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
351
+ expect ( doc . getByText ( 'Collections (2 )' ) ) . toBeInTheDocument ( ) ;
324
352
expect ( doc . getByText ( 'Components (2)' ) ) . toBeInTheDocument ( ) ;
325
353
expect ( doc . getAllByText ( 'Introduction to Testing' ) [ 0 ] ) . toBeInTheDocument ( ) ;
326
354
expect ( doc . queryByText ( 'You have not added any content to this library yet.' ) ) . not . toBeInTheDocument ( ) ;
0 commit comments