@@ -12,6 +12,7 @@ import {
12
12
fireEvent ,
13
13
screen ,
14
14
act ,
15
+ within ,
15
16
} from '@src/testUtils' ;
16
17
import messages from '../messages' ;
17
18
import tabMessages from './messages' ;
@@ -269,7 +270,7 @@ describe('<TabsSection />', () => {
269
270
beforeEach ( async ( ) => {
270
271
await axiosMock . onGet ( courseApiLinkV2 ) . reply ( 200 , generateGetStudioCoursesApiResponseV2 ( ) ) ;
271
272
} ) ;
272
- it ( 'should switch to Legacy Libraries tab and render specific v1 library details ' , async ( ) => {
273
+ it ( 'should switch to Legacy Libraries tab and render - search and filter should work as expected ' , async ( ) => {
273
274
await axiosMock . onGet ( getStudioHomeApiUrl ( ) ) . reply ( 200 , generateGetStudioHomeDataApiResponse ( ) ) ;
274
275
await axiosMock . onGet ( libraryApiLink ) . reply ( 200 , generateGetStudioHomeLibrariesApiResponse ( ) ) ;
275
276
render ( ) ;
@@ -280,12 +281,57 @@ describe('<TabsSection />', () => {
280
281
await user . click ( librariesTab ) ;
281
282
282
283
expect ( librariesTab ) . toHaveClass ( 'active' ) ;
284
+ const panel = await screen . findByRole ( 'tabpanel' , { hidden : false } ) ;
283
285
284
286
expect ( await screen . findByText ( studioHomeMock . libraries [ 0 ] . displayName ) ) . toBeVisible ( ) ;
285
287
286
288
expect (
287
289
await screen . findByText ( `${ studioHomeMock . libraries [ 0 ] . org } / ${ studioHomeMock . libraries [ 0 ] . number } ` ) ,
288
290
) . toBeVisible ( ) ;
291
+
292
+ // Migration info should be displayed
293
+ const migratedContent = generateGetStudioHomeLibrariesApiResponse ( ) . libraries [ 1 ] ;
294
+ expect ( await screen . findByText ( migratedContent . displayName ) ) . toBeVisible ( ) ;
295
+ const newTitleElement = await screen . findAllByText ( migratedContent . migratedToTitle ! ) ;
296
+ expect ( newTitleElement [ 0 ] ) . toBeVisible ( ) ;
297
+ expect ( newTitleElement [ 0 ] ) . toHaveAttribute ( 'href' , `/library/${ migratedContent . migratedToKey } ` ) ;
298
+ expect ( newTitleElement [ 1 ] ) . toHaveAttribute (
299
+ 'href' ,
300
+ `/library/${ migratedContent . migratedToKey } /collection/${ migratedContent . migratedToCollectionKey } ` ,
301
+ ) ;
302
+
303
+ // Check total count display
304
+ expect ( await within ( panel ) . findByText ( 'Showing 3 of 3' ) ) . toBeInTheDocument ( ) ;
305
+
306
+ // Test search functionality
307
+ const searchField = await within ( panel ) . findByPlaceholderText ( 'Search' ) ;
308
+
309
+ fireEvent . change ( searchField , { target : { value : 'Legacy' } } ) ;
310
+ // Should only show 1 result i.e. migratedContent.displayName
311
+ expect ( await within ( panel ) . findByText ( 'Showing 1 of 3' ) ) . toBeInTheDocument ( ) ;
312
+ expect ( await within ( panel ) . findByText ( migratedContent . displayName ) ) . toBeVisible ( ) ;
313
+ // Should not show other items.
314
+ expect ( within ( panel ) . queryByText (
315
+ generateGetStudioHomeLibrariesApiResponse ( ) . libraries [ 0 ] . displayName ,
316
+ ) ) . not . toBeInTheDocument ( ) ;
317
+ // reset search
318
+ fireEvent . change ( searchField , { target : { value : '' } } ) ;
319
+
320
+ // Test migration filter
321
+ const filter = await within ( panel ) . findByRole ( 'button' , { name : 'Any Migration Status' } ) ;
322
+ await user . click ( filter ) ;
323
+ const migratedOption = await within ( panel ) . findByRole ( 'checkbox' , { name : 'Migrated' } ) ;
324
+ // This should uncheck Migrated option as all options are selected by default
325
+ await user . click ( migratedOption ) ;
326
+ // Should only show 2 result i.e. unmigrated libraries
327
+ expect ( await within ( panel ) . findByText ( 'Showing 2 of 3' ) ) . toBeInTheDocument ( ) ;
328
+ const unmigratedOption = await within ( panel ) . findByRole ( 'checkbox' , { name : 'Unmigrated' } ) ;
329
+ // Un-checking both options should reset the state to both checked.
330
+ await user . click ( unmigratedOption ) ;
331
+ expect ( migratedOption ) . toBeChecked ( ) ;
332
+ expect ( unmigratedOption ) . toBeChecked ( ) ;
333
+ // Should only show all 3 results
334
+ expect ( await within ( panel ) . findByText ( 'Showing 3 of 3' ) ) . toBeInTheDocument ( ) ;
289
335
} ) ;
290
336
291
337
it ( 'should switch to Libraries tab and render specific v2 library details' , async ( ) => {
@@ -331,17 +377,6 @@ describe('<TabsSection />', () => {
331
377
expect (
332
378
await screen . findByText ( `${ studioHomeMock . libraries [ 0 ] . org } / ${ studioHomeMock . libraries [ 0 ] . number } ` ) ,
333
379
) . toBeVisible ( ) ;
334
-
335
- // Migration info should be displayed
336
- const migratedContent = generateGetStudioHomeLibrariesApiResponse ( ) . libraries [ 1 ] ;
337
- expect ( await screen . findByText ( migratedContent . displayName ) ) . toBeVisible ( ) ;
338
- const newTitleElement = await screen . findAllByText ( migratedContent . migratedToTitle ! ) ;
339
- expect ( newTitleElement [ 0 ] ) . toBeVisible ( ) ;
340
- expect ( newTitleElement [ 0 ] ) . toHaveAttribute ( 'href' , `/library/${ migratedContent . migratedToKey } ` ) ;
341
- expect ( newTitleElement [ 1 ] ) . toHaveAttribute (
342
- 'href' ,
343
- `/library/${ migratedContent . migratedToKey } /collection/${ migratedContent . migratedToCollectionKey } ` ,
344
- ) ;
345
380
} ) ;
346
381
347
382
it ( 'should switch to Libraries tab and render specific v2 library details ("v2 only" mode)' , async ( ) => {
@@ -402,10 +437,11 @@ describe('<TabsSection />', () => {
402
437
await axiosMock . onGet ( getStudioHomeApiUrl ( ) ) . reply ( 200 , generateGetStudioHomeDataApiResponse ( ) ) ;
403
438
await axiosMock . onGet ( libraryApiLink ) . reply ( 404 ) ;
404
439
render ( ) ;
440
+ const user = userEvent . setup ( ) ;
405
441
await executeThunk ( fetchStudioHomeData ( ) , store . dispatch ) ;
406
442
407
443
const librariesTab = await screen . findByText ( tabMessages . legacyLibrariesTabTitle . defaultMessage ) ;
408
- fireEvent . click ( librariesTab ) ;
444
+ await user . click ( librariesTab ) ;
409
445
410
446
expect ( librariesTab ) . toHaveClass ( 'active' ) ;
411
447
0 commit comments