@@ -37,50 +37,61 @@ describe('Breadcrumbs', () => {
3737 jest . clearAllMocks ( ) ;
3838 } ) ;
3939
40- it ( 'renders relevant breadcrumb nodes' , ( ) => {
40+ it ( 'renders all breadcrumb nodes from activePage tree ' , ( ) => {
4141 render ( < Breadcrumbs /> ) ;
4242 expect ( screen . getByText ( 'Home' ) ) . toBeInTheDocument ( ) ;
4343 expect ( screen . getByText ( 'Section 1' ) ) . toBeInTheDocument ( ) ;
44- expect ( screen . queryByText ( 'Subsection 1' ) ) . not . toBeInTheDocument ( ) ;
44+ expect ( screen . getByText ( 'Subsection 1' ) ) . toBeInTheDocument ( ) ;
4545 expect ( screen . getByText ( 'Current Page' ) ) . toBeInTheDocument ( ) ;
4646 } ) ;
4747
4848 it ( 'includes relevant links on the breadcrumb nodes' , ( ) => {
4949 render ( < Breadcrumbs /> ) ;
5050 expect ( screen . getByText ( 'Home' ) ) . toHaveAttribute ( 'href' , '/docs' ) ;
5151 expect ( screen . getByText ( 'Section 1' ) ) . toHaveAttribute ( 'href' , '/section-1' ) ;
52- expect ( screen . queryByText ( 'Subsection 1' ) ) . not . toBeInTheDocument ( ) ;
52+ expect ( screen . getByText ( 'Subsection 1' ) ) . toHaveAttribute ( 'href' , '#' ) ;
5353 expect ( screen . getByText ( 'Current Page' ) ) . toHaveAttribute ( 'href' , '/section-1/subsection-1/page-1' ) ;
5454 } ) ;
5555
56- it ( 'disables the link for the current page' , ( ) => {
56+ it ( 'disables the link for the current page and non-linked nodes ' , ( ) => {
5757 render ( < Breadcrumbs /> ) ;
58+
59+ // Current page (last item) should be disabled
5860 expect ( screen . getByText ( 'Current Page' ) ) . toHaveClass ( 'text-gui-unavailable' ) ;
5961 expect ( screen . getByText ( 'Current Page' ) ) . toHaveClass ( 'pointer-events-none' ) ;
62+
63+ // Non-linked nodes (link='#') should be disabled
64+ expect ( screen . getByText ( 'Subsection 1' ) ) . toHaveClass ( 'text-gui-unavailable' ) ;
65+ expect ( screen . getByText ( 'Subsection 1' ) ) . toHaveClass ( 'pointer-events-none' ) ;
66+
67+ // Active links should not be disabled
68+ expect ( screen . getByText ( 'Section 1' ) ) . not . toHaveClass ( 'text-gui-unavailable' ) ;
69+ expect ( screen . getByText ( 'Section 1' ) ) . not . toHaveClass ( 'pointer-events-none' ) ;
70+ } ) ;
71+
72+ it ( 'shows only the last active node in mobile view' , ( ) => {
73+ render ( < Breadcrumbs /> ) ;
74+
75+ // All items except index 0 should have 'hidden sm:flex' classes
76+ expect ( screen . getByText ( 'Section 1' ) ) . not . toHaveClass ( 'hidden' ) ;
77+ expect ( screen . getByText ( 'Subsection 1' ) ) . toHaveClass ( 'hidden' , 'sm:flex' ) ;
78+ expect ( screen . getByText ( 'Current Page' ) ) . toHaveClass ( 'hidden' , 'sm:flex' ) ;
6079 } ) ;
6180
62- it ( 'removes duplicate links from breadcrumb nodes ' , ( ) => {
81+ it ( 'correctly identifies last active node when current page is non-linked ' , ( ) => {
6382 mockUseLayoutContext . mockReturnValue ( {
6483 activePage : {
6584 tree : [
6685 { page : { name : 'Section 1' , link : '/section-1' } } ,
67- { page : { name : 'Duplicate Section ' , link : '/section-1' } } ,
68- { page : { name : 'Current Page' , link : '/section-1/page-1 ' } } ,
86+ { page : { name : 'Subsection 1 ' , link : '/section-1/subsection -1' } } ,
87+ { page : { name : 'Current Page' , link : '# ' } } ,
6988 ] ,
7089 } ,
7190 } ) ;
7291
7392 render ( < Breadcrumbs /> ) ;
74-
75- // Should only show one instance of the duplicate link
76- const section1Links = screen . getAllByText ( 'Section 1' ) ;
77- expect ( section1Links ) . toHaveLength ( 1 ) ;
78-
79- // Should not render the duplicate with different text
80- expect ( screen . queryByText ( 'Duplicate Section' ) ) . not . toBeInTheDocument ( ) ;
81-
82- // Should still render other breadcrumb elements
83- expect ( screen . getByText ( 'Home' ) ) . toBeInTheDocument ( ) ;
84- expect ( screen . getByText ( 'Current Page' ) ) . toBeInTheDocument ( ) ;
93+ expect ( screen . getByText ( 'Section 1' ) ) . toHaveClass ( 'hidden' , 'sm:flex' ) ;
94+ expect ( screen . getByText ( 'Subsection 1' ) ) . not . toHaveClass ( 'hidden' ) ;
95+ expect ( screen . getByText ( 'Current Page' ) ) . toHaveClass ( 'hidden' , 'sm:flex' ) ;
8596 } ) ;
8697} ) ;
0 commit comments