@@ -12,6 +12,7 @@ import {
1212 fireEvent ,
1313 screen ,
1414 act ,
15+ within ,
1516} from '@src/testUtils' ;
1617import messages from '../messages' ;
1718import tabMessages from './messages' ;
@@ -269,7 +270,7 @@ describe('<TabsSection />', () => {
269270 beforeEach ( async ( ) => {
270271 await axiosMock . onGet ( courseApiLinkV2 ) . reply ( 200 , generateGetStudioCoursesApiResponseV2 ( ) ) ;
271272 } ) ;
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 ( ) => {
273274 await axiosMock . onGet ( getStudioHomeApiUrl ( ) ) . reply ( 200 , generateGetStudioHomeDataApiResponse ( ) ) ;
274275 await axiosMock . onGet ( libraryApiLink ) . reply ( 200 , generateGetStudioHomeLibrariesApiResponse ( ) ) ;
275276 render ( ) ;
@@ -280,12 +281,70 @@ describe('<TabsSection />', () => {
280281 await user . click ( librariesTab ) ;
281282
282283 expect ( librariesTab ) . toHaveClass ( 'active' ) ;
284+ const panel = await screen . findByRole ( 'tabpanel' , { hidden : false } ) ;
283285
284286 expect ( await screen . findByText ( studioHomeMock . libraries [ 0 ] . displayName ) ) . toBeVisible ( ) ;
285287
286288 expect (
287289 await screen . findByText ( `${ studioHomeMock . libraries [ 0 ] . org } / ${ studioHomeMock . libraries [ 0 ] . number } ` ) ,
288290 ) . 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+ let 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+ // test clearing filter
329+ const clearFilter = await within ( panel ) . findByRole ( 'button' , { name : 'Clear Filter' } ) ;
330+ await user . click ( clearFilter ) ;
331+ // Should show all 3 results
332+ expect ( await within ( panel ) . findByText ( 'Showing 3 of 3' ) ) . toBeInTheDocument ( ) ;
333+ // Open the filter again
334+ await user . click ( filter ) ;
335+ // Reload migratedOption as clearing and opening the filter again creates a new modal
336+ migratedOption = await within ( panel ) . findByRole ( 'checkbox' , { name : 'Migrated' } ) ;
337+ const unmigratedOption = await within ( panel ) . findByRole ( 'checkbox' , { name : 'Unmigrated' } ) ;
338+ // both options should be selected by default - even after clearing
339+ expect ( migratedOption ) . toBeChecked ( ) ;
340+ expect ( unmigratedOption ) . toBeChecked ( ) ;
341+ // Un-checking both options should reset the state to both checked.
342+ await user . click ( unmigratedOption ) ;
343+ await user . click ( migratedOption ) ;
344+ expect ( migratedOption ) . toBeChecked ( ) ;
345+ expect ( unmigratedOption ) . toBeChecked ( ) ;
346+ // Should show all 3 results
347+ expect ( await within ( panel ) . findByText ( 'Showing 3 of 3' ) ) . toBeInTheDocument ( ) ;
289348 } ) ;
290349
291350 it ( 'should switch to Libraries tab and render specific v2 library details' , async ( ) => {
@@ -331,17 +390,6 @@ describe('<TabsSection />', () => {
331390 expect (
332391 await screen . findByText ( `${ studioHomeMock . libraries [ 0 ] . org } / ${ studioHomeMock . libraries [ 0 ] . number } ` ) ,
333392 ) . 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- ) ;
345393 } ) ;
346394
347395 it ( 'should switch to Libraries tab and render specific v2 library details ("v2 only" mode)' , async ( ) => {
@@ -402,10 +450,11 @@ describe('<TabsSection />', () => {
402450 await axiosMock . onGet ( getStudioHomeApiUrl ( ) ) . reply ( 200 , generateGetStudioHomeDataApiResponse ( ) ) ;
403451 await axiosMock . onGet ( libraryApiLink ) . reply ( 404 ) ;
404452 render ( ) ;
453+ const user = userEvent . setup ( ) ;
405454 await executeThunk ( fetchStudioHomeData ( ) , store . dispatch ) ;
406455
407456 const librariesTab = await screen . findByText ( tabMessages . legacyLibrariesTabTitle . defaultMessage ) ;
408- fireEvent . click ( librariesTab ) ;
457+ await user . click ( librariesTab ) ;
409458
410459 expect ( librariesTab ) . toHaveClass ( 'active' ) ;
411460
0 commit comments