diff --git a/packages/x-data-grid-pro/src/tests/columns.DataGridPro.test.tsx b/packages/x-data-grid-pro/src/tests/columns.DataGridPro.test.tsx
index 3d6e0567771d6..8cdac39175f0f 100644
--- a/packages/x-data-grid-pro/src/tests/columns.DataGridPro.test.tsx
+++ b/packages/x-data-grid-pro/src/tests/columns.DataGridPro.test.tsx
@@ -165,12 +165,13 @@ describe(' - Columns', () => {
fireEvent.doubleClick(separator);
await microtasks();
expect(onColumnWidthChange.callCount).to.be.at.least(2);
- const widthArgs = onColumnWidthChange.args.map((arg) => arg[0].width);
- const isWidth114Present = widthArgs.some((width) => width === 114);
- expect(isWidth114Present).to.equal(true);
- const colDefWidthArgs = onColumnWidthChange.args.map((arg) => arg[0].colDef.width);
- const isColDefWidth114Present = colDefWidthArgs.some((width) => width === 114);
- expect(isColDefWidth114Present).to.equal(true);
+ const widthArgs = onColumnWidthChange.args.map((arg) => Math.round(arg[0].width));
+ expect(widthArgs).to.deep.equal([120, 64]);
+ const colDefWidthArgs = onColumnWidthChange.args.map((arg) =>
+ Math.round(arg[0].colDef.width),
+ );
+ const isColDefWidth64Present = colDefWidthArgs.some((width) => width === 64);
+ expect(isColDefWidth64Present).to.equal(true);
});
it('should not affect other cell elements that are not part of the main DataGrid instance', () => {
@@ -449,52 +450,57 @@ describe(' - Columns', () => {
},
{
id: 1,
- brand: 'Adidas',
- },
- {
- id: 2,
brand: 'Puma',
},
{
- id: 3,
+ id: 2,
brand: 'Lululemon Athletica',
},
];
- const columns = [
- { field: 'id', headerName: 'This is the ID column' },
- { field: 'brand', headerName: 'This is the brand column' },
- ];
-
- const getWidths = () => {
- return columns.map((_, i) => parseInt(getColumnHeaderCell(i).style.width, 10));
+ const buildColumns = () => {
+ const columns = [
+ { field: 'id', headerName: 'This is the ID column' },
+ { field: 'brand', headerName: 'This is the brand column' },
+ ];
+ const getWidths = () => {
+ return columns.map((_, i) => parseInt(getColumnHeaderCell(i).style.width, 10));
+ };
+ return {
+ columns,
+ getWidths,
+ };
};
it('should work through the API', async () => {
+ const { columns, getWidths } = buildColumns();
render();
await apiRef.current.autosizeColumns();
await microtasks();
- expect(getWidths()).to.deep.equal([211, 233]);
+ expect(getWidths()).to.deep.equal([155, 177]);
});
it('should work through double-clicking the separator', async () => {
+ const { columns, getWidths } = buildColumns();
render();
const separator = document.querySelectorAll(
`.${gridClasses['columnSeparator--resizable']}`,
)[1];
fireEvent.doubleClick(separator);
await microtasks();
- expect(getWidths()).to.deep.equal([100, 233]);
+ expect(getWidths()).to.deep.equal([100, 177]);
});
it('should work on mount', async () => {
+ const { columns, getWidths } = buildColumns();
render();
await microtasks(); /* first effect after render */
await microtasks(); /* async autosize operation */
- expect(getWidths()).to.deep.equal([211, 233]);
+ expect(getWidths()).to.deep.equal([155, 177]);
});
describe('options', () => {
const autosize = async (options: GridAutosizeOptions | undefined, widths: number[]) => {
+ const { columns, getWidths } = buildColumns();
render();
await apiRef.current.autosizeColumns({ includeHeaders: false, ...options });
await microtasks();
@@ -502,11 +508,11 @@ describe(' - Columns', () => {
};
it('.columns works', async () => {
- await autosize({ columns: [columns[0].field] }, [50, 100]);
+ await autosize({ columns: ['id'] }, [50, 100]);
});
it('.includeHeaders works', async () => {
- await autosize({ includeHeaders: true }, [211, 233]);
+ await autosize({ includeHeaders: true }, [155, 177]);
});
it('.includeOutliers works', async () => {
@@ -518,7 +524,7 @@ describe(' - Columns', () => {
});
it('.expand works', async () => {
- await autosize({ expand: true }, [134, 148]);
+ await autosize({ expand: true }, [101, 196]);
});
});
});
@@ -536,6 +542,7 @@ describe(' - Columns', () => {
act(() => apiRef.current.setColumnWidth('brand', 300));
expect(gridColumnLookupSelector(apiRef).brand.computedWidth).to.equal(300);
+ // @ts-expect-error privateApi is not defined
act(() => privateApi.current.requestPipeProcessorsApplication('hydrateColumns'));
expect(gridColumnLookupSelector(apiRef).brand.computedWidth).to.equal(300);
});
@@ -557,6 +564,7 @@ describe(' - Columns', () => {
expect(gridColumnFieldsSelector(apiRef).indexOf('brand')).to.equal(2);
act(() => apiRef.current.setColumnIndex('brand', 1));
expect(gridColumnFieldsSelector(apiRef).indexOf('brand')).to.equal(1);
+ // @ts-expect-error privateApi is not defined
act(() => privateApi.current.requestPipeProcessorsApplication('hydrateColumns'));
expect(gridColumnFieldsSelector(apiRef).indexOf('brand')).to.equal(1);
});
@@ -571,6 +579,7 @@ describe(' - Columns', () => {
act(() => apiRef.current.updateColumns([{ field: 'id' }]));
expect(gridColumnFieldsSelector(apiRef)).to.deep.equal(['__check__', 'brand', 'id']);
+ // @ts-expect-error privateApi is not defined
act(() => privateApi.current.requestPipeProcessorsApplication('hydrateColumns'));
expect(gridColumnFieldsSelector(apiRef)).to.deep.equal(['__check__', 'brand', 'id']);
});