From 56caebda55ecafbfb1542cc77ba1a83658a31d84 Mon Sep 17 00:00:00 2001 From: Andrew Cherniavskyi Date: Tue, 3 Dec 2024 01:02:54 +0100 Subject: [PATCH] use correct values in column autosizing assertions --- .../src/tests/columns.DataGridPro.test.tsx | 28 ++++++++----------- .../columnResize/useGridColumnResize.tsx | 2 -- 2 files changed, 11 insertions(+), 19 deletions(-) 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 d18c3fe83a9dc..a8f94fcc4132f 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 @@ -157,11 +157,11 @@ describe(' - Columns', () => { 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 isWidth120Present = widthArgs.some((width) => width === 120); + expect(isWidth120Present).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 isColDefWidth120Present = colDefWidthArgs.some((width) => width === 120); + expect(isColDefWidth120Present).to.equal(true); }); it('should not affect other cell elements that are not part of the main DataGrid instance', () => { @@ -525,7 +525,7 @@ describe(' - Columns', () => { 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 () => { @@ -535,17 +535,17 @@ describe(' - Columns', () => { )[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 () => { 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]); }); - it.only('should work with flex columns', async () => { + it('should work with flex columns', async () => { render( - Columns', () => { const separators = document.querySelectorAll(`.${gridClasses['columnSeparator--resizable']}`); fireEvent.doubleClick(separators[0]); await microtasks(); - expect(columns.map((_, i) => getColumnHeaderCell(i).offsetWidth)).to.deep.equal( - /** - * TODO: Investigate: these values are used to make CI pass. - * The test fails locally for some reason. - */ - [88, 195], - ); + expect(columns.map((_, i) => getColumnHeaderCell(i).offsetWidth)).to.deep.equal([50, 233]); fireEvent.doubleClick(separators[1]); await microtasks(); - expect(columns.map((_, i) => getColumnHeaderCell(i).offsetWidth)).to.deep.equal([88, 114]); + expect(columns.map((_, i) => getColumnHeaderCell(i).offsetWidth)).to.deep.equal([50, 64]); }); describe('options', () => { @@ -584,7 +578,7 @@ describe(' - Columns', () => { }); it('.includeHeaders works', async () => { - await autosize({ includeHeaders: true }, [211, 233]); + await autosize({ includeHeaders: true }, [155, 177]); }); it('.includeOutliers works', async () => { diff --git a/packages/x-data-grid/src/hooks/features/columnResize/useGridColumnResize.tsx b/packages/x-data-grid/src/hooks/features/columnResize/useGridColumnResize.tsx index 3a82b66d8f2f6..75792dd697634 100644 --- a/packages/x-data-grid/src/hooks/features/columnResize/useGridColumnResize.tsx +++ b/packages/x-data-grid/src/hooks/features/columnResize/useGridColumnResize.tsx @@ -234,8 +234,6 @@ function extractColumnWidths( const maxContent = filteredWidths.length === 0 ? 0 : Math.max(...filteredWidths); widthByField[column.field] = clamp(maxContent, min, max); - - console.log(column.field, widthByField[column.field], widths, filteredWidths); }); root.classList.remove(gridClasses.autosizing);