11import { useState } from 'react' ;
2- import { page , userEvent } from '@ vitest/browser/context ' ;
2+ import { page , userEvent } from 'vitest/browser' ;
33
44import type { Column } from '../../src' ;
55import { SelectColumn , textEditor , TreeDataGrid } from '../../src' ;
@@ -136,7 +136,7 @@ function rowGrouper(rows: readonly Row[], columnKey: string) {
136136}
137137
138138function setup ( groupBy : string [ ] , groupIdGetter ?: ( groupKey : string , parentId ?: string ) => string ) {
139- page . render ( < TestGrid groupBy = { groupBy } groupIdGetter = { groupIdGetter } /> ) ;
139+ return page . render ( < TestGrid groupBy = { groupBy } groupIdGetter = { groupIdGetter } /> ) ;
140140}
141141
142142async function testHeaderCellsContent ( expected : readonly string [ ] ) {
@@ -147,27 +147,27 @@ async function testHeaderCellsContent(expected: readonly string[]) {
147147}
148148
149149test ( 'should not group if groupBy is empty' , async ( ) => {
150- setup ( [ ] ) ;
150+ await setup ( [ ] ) ;
151151 await expect . element ( getTreeGrid ( ) ) . toHaveAttribute ( 'aria-rowcount' , '7' ) ;
152152 await testHeaderCellsContent ( [ '' , 'Sport' , 'Country' , 'Year' , 'Id' ] ) ;
153153 await testRowCount ( 7 ) ;
154154} ) ;
155155
156156test ( 'should not group if column does not exist' , async ( ) => {
157- setup ( [ 'abc' ] ) ;
157+ await setup ( [ 'abc' ] ) ;
158158 await expect . element ( getTreeGrid ( ) ) . toHaveAttribute ( 'aria-rowcount' , '7' ) ;
159159 await testRowCount ( 7 ) ;
160160} ) ;
161161
162162test ( 'should group by single column' , async ( ) => {
163- setup ( [ 'country' ] ) ;
163+ await setup ( [ 'country' ] ) ;
164164 await expect . element ( getTreeGrid ( ) ) . toHaveAttribute ( 'aria-rowcount' , '9' ) ;
165165 await testHeaderCellsContent ( [ '' , 'Country' , 'Sport' , 'Year' , 'Id' ] ) ;
166166 await testRowCount ( 5 ) ;
167167} ) ;
168168
169169test ( 'should group by multiple columns' , async ( ) => {
170- setup ( [ 'country' , 'year' ] ) ;
170+ await setup ( [ 'country' , 'year' ] ) ;
171171 await expect . element ( getTreeGrid ( ) ) . toHaveAttribute ( 'aria-rowcount' , '13' ) ;
172172 await testHeaderCellsContent ( [ '' , 'Country' , 'Year' , 'Sport' , 'Id' ] ) ;
173173 await testRowCount ( 5 ) ;
@@ -177,7 +177,7 @@ test('should use groupIdGetter when provided', async () => {
177177 const groupIdGetter = vi . fn ( ( groupKey : string , parentId ?: string ) =>
178178 parentId !== undefined ? `${ groupKey } #${ parentId } ` : groupKey
179179 ) ;
180- setup ( [ 'country' , 'year' ] , groupIdGetter ) ;
180+ await setup ( [ 'country' , 'year' ] , groupIdGetter ) ;
181181 expect ( groupIdGetter ) . toHaveBeenCalled ( ) ;
182182 await expect . element ( getTreeGrid ( ) ) . toHaveAttribute ( 'aria-rowcount' , '13' ) ;
183183 await testHeaderCellsContent ( [ '' , 'Country' , 'Year' , 'Sport' , 'Id' ] ) ;
@@ -193,20 +193,20 @@ test('should use groupIdGetter when provided', async () => {
193193} ) ;
194194
195195test ( 'should ignore duplicate groupBy columns' , async ( ) => {
196- setup ( [ 'year' , 'year' , 'year' ] ) ;
196+ await setup ( [ 'year' , 'year' , 'year' ] ) ;
197197 await expect . element ( getTreeGrid ( ) ) . toHaveAttribute ( 'aria-rowcount' , '10' ) ;
198198 await testRowCount ( 6 ) ;
199199} ) ;
200200
201201test ( 'should use groupBy order while grouping' , async ( ) => {
202- setup ( [ 'year' , 'country' ] ) ;
202+ await setup ( [ 'year' , 'country' ] ) ;
203203 await expect . element ( getTreeGrid ( ) ) . toHaveAttribute ( 'aria-rowcount' , '14' ) ;
204204 await testHeaderCellsContent ( [ '' , 'Year' , 'Country' , 'Sport' , 'Id' ] ) ;
205205 await testRowCount ( 6 ) ;
206206} ) ;
207207
208208test ( 'should toggle group when group cell is clicked' , async ( ) => {
209- setup ( [ 'year' ] ) ;
209+ await setup ( [ 'year' ] ) ;
210210 await testRowCount ( 6 ) ;
211211 const groupCell = getCell ( '2021' ) ;
212212 await userEvent . click ( groupCell ) ;
@@ -216,7 +216,7 @@ test('should toggle group when group cell is clicked', async () => {
216216} ) ;
217217
218218test ( 'should toggle group using keyboard' , async ( ) => {
219- setup ( [ 'year' ] ) ;
219+ await setup ( [ 'year' ] ) ;
220220 await testRowCount ( 6 ) ;
221221 const groupCell = getCell ( '2021' ) ;
222222 await userEvent . click ( groupCell ) ;
@@ -231,7 +231,7 @@ test('should toggle group using keyboard', async () => {
231231} ) ;
232232
233233test ( 'should set aria-attributes' , async ( ) => {
234- setup ( [ 'year' , 'country' ] ) ;
234+ await setup ( [ 'year' , 'country' ] ) ;
235235
236236 const groupRow1 = getRowByCellName ( '2020' ) ;
237237 await expect . element ( groupRow1 ) . toHaveAttribute ( 'aria-level' , '1' ) ;
@@ -264,7 +264,7 @@ test('should set aria-attributes', async () => {
264264} ) ;
265265
266266test ( 'should select rows in a group' , async ( ) => {
267- setup ( [ 'year' , 'country' ] ) ;
267+ await setup ( [ 'year' , 'country' ] ) ;
268268
269269 const headerCheckbox = getSelectAllCheckbox ( ) ;
270270 await expect . element ( headerCheckbox ) . not . toBeChecked ( ) ;
@@ -316,7 +316,7 @@ test('should select rows in a group', async () => {
316316} ) ;
317317
318318test ( 'cell navigation in a treegrid' , async ( ) => {
319- setup ( [ 'country' , 'year' ] ) ;
319+ await setup ( [ 'country' , 'year' ] ) ;
320320 await testRowCount ( 5 ) ;
321321 const focusSink = page . getBySelector ( `.${ focusSinkClassname } ` ) ;
322322
@@ -399,7 +399,7 @@ test('cell navigation in a treegrid', async () => {
399399} ) ;
400400
401401test ( 'copy/paste when grouping is enabled' , async ( ) => {
402- setup ( [ 'year' ] ) ;
402+ await setup ( [ 'year' ] ) ;
403403 await userEvent . click ( getCell ( '2021' ) ) ;
404404 await userEvent . copy ( ) ;
405405 expect ( onCellCopySpy ) . not . toHaveBeenCalled ( ) ;
@@ -434,7 +434,7 @@ test('copy/paste when grouping is enabled', async () => {
434434} ) ;
435435
436436test ( 'update row using cell renderer' , async ( ) => {
437- setup ( [ 'year' ] ) ;
437+ await setup ( [ 'year' ] ) ;
438438 await userEvent . click ( getCell ( '2021' ) ) ;
439439 await userEvent . click ( getCell ( 'USA' ) ) ;
440440 await userEvent . keyboard ( '{arrowright}{arrowright}' ) ;
@@ -444,7 +444,7 @@ test('update row using cell renderer', async () => {
444444} ) ;
445445
446446test ( 'custom renderGroupCell' , async ( ) => {
447- setup ( [ 'country' ] ) ;
447+ await setup ( [ 'country' ] ) ;
448448 await expect . element ( getRowByCellName ( 'USA' ) . getByRole ( 'gridcell' ) . nth ( 4 ) ) . toHaveTextContent ( '1' ) ;
449449 await expect
450450 . element ( getRowByCellName ( 'Canada' ) . getByRole ( 'gridcell' ) . nth ( 4 ) )
0 commit comments