Skip to content

Commit b92ef30

Browse files
committed
Test external state change
1 parent 6429e04 commit b92ef30

1 file changed

Lines changed: 35 additions & 7 deletions

File tree

test/browser/column/resizable.test.tsx

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,28 @@ test('should use columnWidths and onColumnWidthsChange props when provided', asy
260260
onColumnWidthsChangeSpy(newColumnWidths);
261261
}
262262

263+
function changedColumnWidths() {
264+
setColumnWidths(
265+
new Map([
266+
['col1', { width: 101, type: 'measured' }],
267+
['col2', { width: 150, type: 'measured' }]
268+
])
269+
);
270+
}
271+
263272
return (
264-
<DataGrid<Row>
265-
columns={columns}
266-
rows={[]}
267-
columnWidths={columnWidths}
268-
onColumnWidthsChange={onColymnWidthsChange}
269-
onColumnResize={onColumnResizeSpy}
270-
/>
273+
<>
274+
<button type="button" onClick={changedColumnWidths}>
275+
Change widths
276+
</button>
277+
<DataGrid<Row>
278+
columns={columns}
279+
rows={[]}
280+
columnWidths={columnWidths}
281+
onColumnWidthsChange={onColymnWidthsChange}
282+
onColumnResize={onColumnResizeSpy}
283+
/>
284+
</>
271285
);
272286
}
273287

@@ -301,4 +315,18 @@ test('should use columnWidths and onColumnWidthsChange props when provided', asy
301315
expect(onColumnResizeSpy).toHaveBeenNthCalledWith(1, expect.objectContaining(columns[1]), 105);
302316
expect(onColumnResizeSpy).toHaveBeenNthCalledWith(2, expect.objectContaining(columns[1]), 110);
303317
expect(onColumnResizeSpy).toHaveBeenNthCalledWith(3, expect.objectContaining(columns[1]), 115);
318+
onColumnWidthsChangeSpy.mockClear();
319+
onColumnResizeSpy.mockClear();
320+
321+
await userEvent.click(page.getByRole('button', { name: 'Change widths' }));
322+
expect(onColumnWidthsChangeSpy).not.toHaveBeenCalled();
323+
expect(onColumnResizeSpy).not.toHaveBeenCalled();
324+
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '101px 150px' });
325+
await resize({ column: col2, resizeBy: [5, 5] });
326+
expect(onColumnWidthsChangeSpy).toHaveBeenCalledExactlyOnceWith(
327+
new Map([
328+
['col1', { width: 101, type: 'measured' }],
329+
['col2', { width: 160, type: 'resized' }]
330+
])
331+
);
304332
});

0 commit comments

Comments
 (0)