@@ -30,13 +30,6 @@ Subject.propTypes = {
3030 fixture : PropTypes . object , // eslint-disable-line react/forbid-prop-types
3131} ;
3232
33- vi . mock (
34- 'react-virtualized-auto-sizer' ,
35- ( ) => ( {
36- default : ( { children } ) => children ( { height : 600 , width : 600 } ) ,
37- } ) ,
38- ) ;
39-
4033describe ( 'ThumbnailNavigation' , ( ) => {
4134 it ( 'renders the component' , async ( ) => {
4235 render ( < Subject /> ) ;
@@ -49,29 +42,49 @@ describe('ThumbnailNavigation', () => {
4942 expect ( screen . getAllByRole ( 'gridcell' ) . length ) . toEqual ( 3 ) ;
5043 } ) ;
5144
45+ it ( 'uses Grid component for horizontal (far-bottom) layout' , ( ) => {
46+ render ( < Subject position = "far-bottom" /> ) ;
47+ // Grid component renders with role="grid" inside the Thumbnails wrapper
48+ const thumbnailWrapper = screen . getByLabelText ( 'Thumbnails' ) ;
49+ const grid = thumbnailWrapper . querySelector ( '[role="grid"]' ) ;
50+ expect ( grid ) . toBeInTheDocument ( ) ;
51+ // Grid should have 3 gridcells (all in one row)
52+ expect ( screen . getAllByRole ( 'gridcell' ) ) . toHaveLength ( 3 ) ;
53+ } ) ;
54+
55+ it ( 'uses List component for vertical (far-right) layout' , ( ) => {
56+ render ( < Subject position = "far-right" /> ) ;
57+ // List component renders with role="list" inside the Thumbnails wrapper
58+ const thumbnailWrapper = screen . getByLabelText ( 'Thumbnails' ) ;
59+ const list = thumbnailWrapper . querySelector ( '[role="list"]' ) ;
60+ expect ( list ) . toBeInTheDocument ( ) ;
61+ // List should have 3 gridcells (each as a separate item)
62+ expect ( screen . getAllByRole ( 'gridcell' ) ) . toHaveLength ( 3 ) ;
63+ } ) ;
64+
5265 // TODO: Test that we recalculate dimensions when the view changes (resetAfterIndex)
5366 // TODO: Test that the window scrolls when the canvasIndex prop changes (scorllToItem)
5467
5568 it ( 'gives the grid a size' , ( ) => {
5669 const { rerender } = render ( < Subject /> ) ;
57- expect ( screen . getByRole ( 'grid ') ) . toHaveStyle ( { height : '150px' , width : '100%' } ) ;
70+ expect ( screen . getByLabelText ( 'Thumbnails ') ) . toHaveStyle ( { height : '150px' , width : '100%' } ) ;
5871
5972 rerender ( < Subject position = "far-right" /> ) ;
60- expect ( screen . getByRole ( 'grid ') ) . toHaveStyle ( { height : '100%' , minHeight : 0 , width : '123px ' } ) ;
73+ expect ( screen . getByLabelText ( 'Thumbnails ') ) . toHaveStyle ( { height : '100%' , minHeight : 0 , width : '127px ' } ) ;
6174 } ) ;
6275
6376 it ( 'roughly doubles the width of the grid in book view' , ( ) => {
6477 const { rerender } = render ( < Subject position = "far-right" /> ) ;
65- expect ( screen . getByRole ( 'grid ') ) . toHaveStyle ( { width : '123px ' } ) ;
78+ expect ( screen . getByLabelText ( 'Thumbnails ') ) . toHaveStyle ( { width : '127px ' } ) ;
6679
6780 rerender ( < Subject position = "far-right" view = "book" /> ) ;
68- expect ( screen . getByRole ( 'grid ') ) . toHaveStyle ( { width : '223px ' } ) ;
81+ expect ( screen . getByLabelText ( 'Thumbnails ') ) . toHaveStyle ( { width : '227px ' } ) ;
6982 } ) ;
7083
7184 it ( 'calculates the scaled width of each cell' , ( ) => {
7285 render ( < Subject /> ) ;
7386
74- expect ( screen . getAllByRole ( 'gridcell' ) [ 0 ] ) . toHaveStyle ( { width : '74px ' } ) ;
87+ expect ( screen . getAllByRole ( 'gridcell' ) [ 0 ] ) . toHaveStyle ( { width : '111px ' } ) ;
7588 } ) ;
7689
7790 it ( 'calculates the scaled height of each cell when on the right' , ( ) => {
@@ -82,7 +95,7 @@ describe('ThumbnailNavigation', () => {
8295 it ( 'keeps a minimum size for each cell' , ( ) => {
8396 render ( < Subject fixture = { zeroWidthFixture } /> ) ;
8497
85- expect ( screen . getAllByRole ( 'gridcell' ) [ 0 ] ) . toHaveStyle ( { width : '100px ' } ) ;
98+ expect ( screen . getAllByRole ( 'gridcell' ) [ 0 ] ) . toHaveStyle ( { width : '111px ' } ) ;
8699 } ) ;
87100
88101 it ( 'keeps a minimum size for each cell when on the right' , ( ) => {
@@ -106,22 +119,22 @@ describe('ThumbnailNavigation', () => {
106119 it ( 'handles down arrow by advancing the current canvas when the canvas is on the right' , ( ) => {
107120 render ( < Subject canvasIndex = { 1 } hasNextCanvas position = "far-right" setNextCanvas = { setNextCanvas } /> ) ;
108121
109- screen . getByRole ( 'grid ') . focus ( ) ;
110- fireEvent . keyDown ( screen . getByRole ( 'grid ') , { code : 'ArrowDown' , key : 'ArrowDown' } ) ;
122+ screen . getByLabelText ( 'Thumbnails ') . focus ( ) ;
123+ fireEvent . keyDown ( screen . getByLabelText ( 'Thumbnails ') , { code : 'ArrowDown' , key : 'ArrowDown' } ) ;
111124 expect ( setNextCanvas ) . toHaveBeenCalled ( ) ;
112125 } ) ;
113126 it ( 'handles left arrow by selecting the previous canvas' , ( ) => {
114127 render ( < Subject canvasIndex = { 2 } hasPreviousCanvas setPreviousCanvas = { setPreviousCanvas } /> ) ;
115128
116- screen . getByRole ( 'grid ') . focus ( ) ;
117- fireEvent . keyDown ( screen . getByRole ( 'grid ') , { code : 'ArrowLeft' , key : 'ArrowLeft' } ) ;
129+ screen . getByLabelText ( 'Thumbnails ') . focus ( ) ;
130+ fireEvent . keyDown ( screen . getByLabelText ( 'Thumbnails ') , { code : 'ArrowLeft' , key : 'ArrowLeft' } ) ;
118131 expect ( setPreviousCanvas ) . toHaveBeenCalled ( ) ;
119132 } ) ;
120133 it ( 'handles up arrow by selecting the previous canvas when the canvas is on the right' , ( ) => {
121134 render ( < Subject canvasIndex = { 2 } hasPreviousCanvas position = "far-right" setPreviousCanvas = { setPreviousCanvas } /> ) ;
122135
123- screen . getByRole ( 'grid ') . focus ( ) ;
124- fireEvent . keyDown ( screen . getByRole ( 'grid ') , { code : 'ArrowUp' , key : 'ArrowUp' } ) ;
136+ screen . getByLabelText ( 'Thumbnails ') . focus ( ) ;
137+ fireEvent . keyDown ( screen . getByLabelText ( 'Thumbnails ') , { code : 'ArrowUp' , key : 'ArrowUp' } ) ;
125138 expect ( setPreviousCanvas ) . toHaveBeenCalled ( ) ;
126139 } ) ;
127140 } ) ;
0 commit comments