@@ -28,9 +28,12 @@ const returnEmptyResult = (_url, req) => {
28
28
// We have to replace the query (search keywords) in the mock results with the actual query,
29
29
// because otherwise we may have an inconsistent state that causes more queries and unexpected results.
30
30
mockEmptyResult . results [ 0 ] . query = query ;
31
+ mockEmptyResult . results [ 2 ] . query = query ;
31
32
// And fake the required '_formatted' fields; it contains the highlighting <mark>...</mark> around matched words
32
33
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
33
34
mockEmptyResult . results [ 0 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
35
+ // eslint-disable-next-line no-underscore-dangle, no-param-reassign
36
+ mockEmptyResult . results [ 2 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
34
37
return mockEmptyResult ;
35
38
} ;
36
39
@@ -48,10 +51,14 @@ const returnLowNumberResults = (_url, req) => {
48
51
newMockResult . results [ 0 ] . query = query ;
49
52
// Limit number of results to just 2
50
53
newMockResult . results [ 0 ] . hits = mockResult . results [ 0 ] ?. hits . slice ( 0 , 2 ) ;
54
+ newMockResult . results [ 2 ] . hits = mockResult . results [ 2 ] ?. hits . slice ( 0 , 2 ) ;
51
55
newMockResult . results [ 0 ] . estimatedTotalHits = 2 ;
56
+ newMockResult . results [ 2 ] . estimatedTotalHits = 2 ;
52
57
// And fake the required '_formatted' fields; it contains the highlighting <mark>...</mark> around matched words
53
58
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
54
59
newMockResult . results [ 0 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
60
+ // eslint-disable-next-line no-underscore-dangle, no-param-reassign
61
+ newMockResult . results [ 2 ] ?. hits . forEach ( ( hit ) => { hit . _formatted = { ...hit } ; } ) ;
55
62
return newMockResult ;
56
63
} ;
57
64
@@ -129,42 +136,46 @@ describe('<LibraryAuthoringPage />', () => {
129
136
130
137
// "Recently Modified" header + sort shown
131
138
expect ( screen . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ;
132
- expect ( screen . getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
139
+ expect ( screen . getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
133
140
expect ( screen . getByText ( 'Components (10)' ) ) . toBeInTheDocument ( ) ;
134
141
expect ( ( await screen . findAllByText ( 'Introduction to Testing' ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
135
142
136
143
// Navigate to the components tab
137
144
fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Components' } ) ) ;
138
145
// "Recently Modified" default sort shown
139
146
expect ( screen . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
140
- expect ( screen . queryByText ( 'Collections (0 )' ) ) . not . toBeInTheDocument ( ) ;
147
+ expect ( screen . queryByText ( 'Collections (6 )' ) ) . not . toBeInTheDocument ( ) ;
141
148
expect ( screen . queryByText ( 'Components (10)' ) ) . not . toBeInTheDocument ( ) ;
142
149
143
150
// Navigate to the collections tab
144
151
fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Collections' } ) ) ;
145
152
// "Recently Modified" default sort shown
146
153
expect ( screen . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
147
- expect ( screen . queryByText ( 'Collections (0 )' ) ) . not . toBeInTheDocument ( ) ;
154
+ expect ( screen . queryByText ( 'Collections (6 )' ) ) . not . toBeInTheDocument ( ) ;
148
155
expect ( screen . queryByText ( 'Components (10)' ) ) . not . toBeInTheDocument ( ) ;
149
156
expect ( screen . queryByText ( 'There are 10 components in this library' ) ) . not . toBeInTheDocument ( ) ;
150
- expect ( screen . getByText ( 'Coming soon!' ) ) . toBeInTheDocument ( ) ;
157
+ expect ( ( await screen . findAllByText ( 'Collection 1' ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
151
158
152
159
// Go back to Home tab
153
160
// This step is necessary to avoid the url change leak to other tests
154
161
fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Home' } ) ) ;
155
162
// "Recently Modified" header + sort shown
156
163
expect ( screen . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ;
157
- expect ( screen . getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
164
+ expect ( screen . getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
158
165
expect ( screen . getByText ( 'Components (10)' ) ) . toBeInTheDocument ( ) ;
159
166
} ) ;
160
167
161
- it ( 'shows a library without components' , async ( ) => {
168
+ it ( 'shows a library without components and collections ' , async ( ) => {
162
169
fetchMock . post ( searchEndpoint , returnEmptyResult , { overwriteRoutes : true } ) ;
163
170
await renderLibraryPage ( ) ;
164
171
165
172
expect ( await screen . findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
166
173
expect ( ( await screen . findAllByText ( libraryTitle ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
167
174
175
+ fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Collections' } ) ) ;
176
+ expect ( screen . getByText ( 'You have not added any collection to this library yet.' ) ) . toBeInTheDocument ( ) ;
177
+
178
+ fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Home' } ) ) ;
168
179
expect ( screen . getByText ( 'You have not added any content to this library yet.' ) ) . toBeInTheDocument ( ) ;
169
180
} ) ;
170
181
@@ -211,6 +222,14 @@ describe('<LibraryAuthoringPage />', () => {
211
222
// Navigate to the components tab
212
223
fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Components' } ) ) ;
213
224
expect ( screen . getByText ( 'No matching components found in this library.' ) ) . toBeInTheDocument ( ) ;
225
+
226
+ // Navigate to the collections tab
227
+ fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Collections' } ) ) ;
228
+ expect ( screen . getByText ( 'No matching collections found in this library.' ) ) . toBeInTheDocument ( ) ;
229
+
230
+ // Go back to Home tab
231
+ // This step is necessary to avoid the url change leak to other tests
232
+ fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Home' } ) ) ;
214
233
} ) ;
215
234
216
235
it ( 'should open and close new content sidebar' , async ( ) => {
@@ -282,20 +301,29 @@ describe('<LibraryAuthoringPage />', () => {
282
301
283
302
// "Recently Modified" header + sort shown
284
303
await waitFor ( ( ) => { expect ( screen . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ; } ) ;
285
- expect ( screen . getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
304
+ expect ( screen . getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
286
305
expect ( screen . getByText ( 'Components (10)' ) ) . toBeInTheDocument ( ) ;
287
306
expect ( screen . getAllByText ( 'Introduction to Testing' ) [ 0 ] ) . toBeInTheDocument ( ) ;
288
307
expect ( screen . queryByText ( 'You have not added any content to this library yet.' ) ) . not . toBeInTheDocument ( ) ;
289
308
290
- // There should only be one "View All" button, since the Components count
309
+ // There should be two "View All" button, since the Components and Collections count
291
310
// are above the preview limit (4)
292
- expect ( screen . getByText ( 'View All' ) ) . toBeInTheDocument ( ) ;
311
+ expect ( screen . getAllByText ( 'View All' ) . length ) . toEqual ( 2 ) ;
293
312
294
- // Clicking on "View All" button should navigate to the Components tab
295
- fireEvent . click ( screen . getByText ( 'View All' ) ) ;
313
+ // Clicking on first "View All" button should navigate to the Collections tab
314
+ fireEvent . click ( screen . getAllByText ( 'View All' ) [ 0 ] ) ;
296
315
// "Recently Modified" default sort shown
297
316
expect ( screen . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
298
- expect ( screen . queryByText ( 'Collections (0)' ) ) . not . toBeInTheDocument ( ) ;
317
+ expect ( screen . queryByText ( 'Collections (6)' ) ) . not . toBeInTheDocument ( ) ;
318
+ expect ( screen . queryByText ( 'Components (10)' ) ) . not . toBeInTheDocument ( ) ;
319
+ expect ( screen . getByText ( 'Collection 1' ) ) . toBeInTheDocument ( ) ;
320
+
321
+ fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Home' } ) ) ;
322
+ // Clicking on second "View All" button should navigate to the Components tab
323
+ fireEvent . click ( screen . getAllByText ( 'View All' ) [ 1 ] ) ;
324
+ // "Recently Modified" default sort shown
325
+ expect ( screen . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 1 ) ;
326
+ expect ( screen . queryByText ( 'Collections (6)' ) ) . not . toBeInTheDocument ( ) ;
299
327
expect ( screen . queryByText ( 'Components (10)' ) ) . not . toBeInTheDocument ( ) ;
300
328
expect ( screen . getAllByText ( 'Introduction to Testing' ) [ 0 ] ) . toBeInTheDocument ( ) ;
301
329
@@ -304,7 +332,7 @@ describe('<LibraryAuthoringPage />', () => {
304
332
fireEvent . click ( screen . getByRole ( 'tab' , { name : 'Home' } ) ) ;
305
333
// "Recently Modified" header + sort shown
306
334
expect ( screen . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ;
307
- expect ( screen . getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
335
+ expect ( screen . getByText ( 'Collections (6 )' ) ) . toBeInTheDocument ( ) ;
308
336
expect ( screen . getByText ( 'Components (10)' ) ) . toBeInTheDocument ( ) ;
309
337
} ) ;
310
338
@@ -317,7 +345,7 @@ describe('<LibraryAuthoringPage />', () => {
317
345
318
346
// "Recently Modified" header + sort shown
319
347
await waitFor ( ( ) => { expect ( screen . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ; } ) ;
320
- expect ( screen . getByText ( 'Collections (0 )' ) ) . toBeInTheDocument ( ) ;
348
+ expect ( screen . getByText ( 'Collections (2 )' ) ) . toBeInTheDocument ( ) ;
321
349
expect ( screen . getByText ( 'Components (2)' ) ) . toBeInTheDocument ( ) ;
322
350
expect ( screen . getAllByText ( 'Introduction to Testing' ) [ 0 ] ) . toBeInTheDocument ( ) ;
323
351
expect ( screen . queryByText ( 'You have not added any content to this library yet.' ) ) . not . toBeInTheDocument ( ) ;
@@ -405,8 +433,8 @@ describe('<LibraryAuthoringPage />', () => {
405
433
await renderLibraryPage ( ) ;
406
434
407
435
// Click on the first component
408
- waitFor ( ( ) => expect ( screen . queryByText ( displayName ) ) . toBeInTheDocument ( ) ) ;
409
- fireEvent . click ( screen . getAllByText ( displayName ) [ 0 ] ) ;
436
+ expect ( ( await screen . findAllByText ( displayName ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
437
+ fireEvent . click ( ( await screen . findAllByText ( displayName ) ) [ 0 ] ) ;
410
438
411
439
const sidebar = screen . getByTestId ( 'library-sidebar' ) ;
412
440
@@ -518,4 +546,20 @@ describe('<LibraryAuthoringPage />', () => {
518
546
519
547
expect ( screen . getByText ( / n o m a t c h i n g c o m p o n e n t s / i) ) . toBeInTheDocument ( ) ;
520
548
} ) ;
549
+
550
+ it ( 'shows both components and collections in recently modified section' , async ( ) => {
551
+ await renderLibraryPage ( ) ;
552
+
553
+ expect ( await screen . findByText ( 'Content library' ) ) . toBeInTheDocument ( ) ;
554
+ expect ( ( await screen . findAllByText ( libraryTitle ) ) [ 0 ] ) . toBeInTheDocument ( ) ;
555
+
556
+ // "Recently Modified" header + sort shown
557
+ expect ( screen . getAllByText ( 'Recently Modified' ) . length ) . toEqual ( 2 ) ;
558
+ const recentModifiedContainer = ( await screen . findAllByText ( 'Recently Modified' ) ) [ 1 ] . parentElement ?. parentElement ?. parentElement ;
559
+ expect ( recentModifiedContainer ) . toBeTruthy ( ) ;
560
+
561
+ const container = within ( recentModifiedContainer ! ) ;
562
+ expect ( container . queryAllByText ( 'Text' ) . length ) . toBeGreaterThan ( 0 ) ;
563
+ expect ( container . queryAllByText ( 'Collection' ) . length ) . toBeGreaterThan ( 0 ) ;
564
+ } ) ;
521
565
} ) ;
0 commit comments