Skip to content

Commit

Permalink
use correct values in column autosizing assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii committed Dec 3, 2024
1 parent 1fbe2f0 commit 56caebd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
28 changes: 11 additions & 17 deletions packages/x-data-grid-pro/src/tests/columns.DataGridPro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ describe('<DataGridPro /> - 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', () => {
Expand Down Expand Up @@ -525,7 +525,7 @@ describe('<DataGridPro /> - Columns', () => {
render(<Test rows={rows} columns={columns} />);
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 () => {
Expand All @@ -535,17 +535,17 @@ describe('<DataGridPro /> - 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(<Test rows={rows} columns={columns} autosizeOnMount />);
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(
<Test
rows={rows}
Expand All @@ -558,17 +558,11 @@ describe('<DataGridPro /> - 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', () => {
Expand All @@ -584,7 +578,7 @@ describe('<DataGridPro /> - Columns', () => {
});

it('.includeHeaders works', async () => {
await autosize({ includeHeaders: true }, [211, 233]);
await autosize({ includeHeaders: true }, [155, 177]);
});

it('.includeOutliers works', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 56caebd

Please sign in to comment.