@@ -10,7 +10,7 @@ describe("Grid", () => {
1010 let mountedCells : Map < string , CellComponentProps < object > > = new Map ( ) ;
1111
1212 const CellComponent = vi . fn ( function Cell ( props : CellComponentProps < object > ) {
13- const { columnIndex, rowIndex, style } = props ;
13+ const { ariaAttributes , columnIndex, rowIndex, style } = props ;
1414
1515 const key = `${ rowIndex } ,${ columnIndex } ` ;
1616
@@ -22,7 +22,7 @@ describe("Grid", () => {
2222 } ) ;
2323
2424 return (
25- < div role = "listitem" style = { style } >
25+ < div { ... ariaAttributes } style = { style } >
2626 Cell { key }
2727 </ div >
2828 ) ;
@@ -49,7 +49,7 @@ describe("Grid", () => {
4949 />
5050 ) ;
5151
52- const items = screen . queryAllByRole ( "listitem " ) ;
52+ const items = screen . queryAllByRole ( "gridcell " ) ;
5353 expect ( items ) . toHaveLength ( 0 ) ;
5454 } ) ;
5555
@@ -67,7 +67,7 @@ describe("Grid", () => {
6767 ) ;
6868
6969 // 4 columns (+2) by 2 rows (+2)
70- const items = screen . queryAllByRole ( "listitem " ) ;
70+ const items = screen . queryAllByRole ( "gridcell " ) ;
7171 expect ( items ) . toHaveLength ( 24 ) ;
7272 } ) ;
7373
@@ -86,7 +86,7 @@ describe("Grid", () => {
8686 ) ;
8787
8888 // 4 columns by 2 rows
89- expect ( container . querySelectorAll ( '[role="listitem "]' ) ) . toHaveLength ( 8 ) ;
89+ expect ( container . querySelectorAll ( '[role="gridcell "]' ) ) . toHaveLength ( 8 ) ;
9090 } ) ;
9191
9292 test ( "type: function (px)" , ( ) => {
@@ -106,7 +106,7 @@ describe("Grid", () => {
106106 ) ;
107107
108108 // 2 columns by 2 rows
109- expect ( container . querySelectorAll ( '[role="listitem "]' ) ) . toHaveLength ( 4 ) ;
109+ expect ( container . querySelectorAll ( '[role="gridcell "]' ) ) . toHaveLength ( 4 ) ;
110110 } ) ;
111111
112112 test ( "type: string (%)" , ( ) => {
@@ -123,7 +123,7 @@ describe("Grid", () => {
123123 ) ;
124124
125125 // 4 columns by 4 rows
126- expect ( container . querySelectorAll ( '[role="listitem "]' ) ) . toHaveLength ( 16 ) ;
126+ expect ( container . querySelectorAll ( '[role="gridcell "]' ) ) . toHaveLength ( 16 ) ;
127127 } ) ;
128128 } ) ;
129129
@@ -253,4 +253,43 @@ describe("Grid", () => {
253253 // TODO
254254 } ) ;
255255 } ) ;
256+
257+ describe ( "aria attributes" , ( ) => {
258+ test ( "should adhere to the best recommended practices" , ( ) => {
259+ render (
260+ < Grid
261+ cellComponent = { CellComponent }
262+ cellProps = { EMPTY_OBJECT }
263+ columnCount = { 2 }
264+ columnWidth = { 25 }
265+ overscanCount = { 0 }
266+ rowCount = { 2 }
267+ rowHeight = { 20 }
268+ />
269+ ) ;
270+
271+ expect ( screen . queryAllByRole ( "grid" ) ) . toHaveLength ( 1 ) ;
272+
273+ const rows = screen . queryAllByRole ( "row" ) ;
274+ expect ( rows ) . toHaveLength ( 2 ) ;
275+ expect ( rows [ 0 ] . getAttribute ( "aria-rowindex" ) ) . toBe ( "1" ) ;
276+ expect ( rows [ 1 ] . getAttribute ( "aria-rowindex" ) ) . toBe ( "2" ) ;
277+
278+ expect ( screen . queryAllByRole ( "gridcell" ) ) . toHaveLength ( 4 ) ;
279+
280+ {
281+ const cells = rows [ 0 ] . querySelectorAll ( '[role="gridcell"]' ) ;
282+ expect ( cells ) . toHaveLength ( 2 ) ;
283+ expect ( cells [ 0 ] . getAttribute ( "aria-colindex" ) ) . toBe ( "1" ) ;
284+ expect ( cells [ 1 ] . getAttribute ( "aria-colindex" ) ) . toBe ( "2" ) ;
285+ }
286+
287+ {
288+ const cells = rows [ 1 ] . querySelectorAll ( '[role="gridcell"]' ) ;
289+ expect ( cells ) . toHaveLength ( 2 ) ;
290+ expect ( cells [ 0 ] . getAttribute ( "aria-colindex" ) ) . toBe ( "1" ) ;
291+ expect ( cells [ 1 ] . getAttribute ( "aria-colindex" ) ) . toBe ( "2" ) ;
292+ }
293+ } ) ;
294+ } ) ;
256295} ) ;
0 commit comments