Skip to content

Commit

Permalink
[test] Fix failing dynamic row height tests on Edge (mui#5707)
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw authored and alexfauquette committed Aug 26, 2022
1 parent 179f083 commit ebeda48
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions packages/grid/x-data-grid/src/tests/rows.DataGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import { COMPACT_DENSITY_FACTOR } from '../hooks/features/density/useGridDensity

const isJSDOM = /jsdom/.test(window.navigator.userAgent);

const nativeSetTimeout = setTimeout;
const nativeClearTimeout = clearTimeout;

describe('<DataGrid /> - Rows', () => {
const { render, clock } = createRenderer({ clock: 'fake' });

Expand Down Expand Up @@ -500,12 +497,12 @@ describe('<DataGrid /> - Rows', () => {
return {
observe: (element: HTMLElement) => {
// Simulates the async behavior of the native ResizeObserver
timeout = nativeSetTimeout(() => {
timeout = setTimeout(() => {
callback([{ borderBoxSize: [{ blockSize: element.clientHeight }] }]);
});
},
disconnect: () => {
nativeClearTimeout(timeout);
clearTimeout(timeout);
},
};
}
Expand Down Expand Up @@ -568,7 +565,8 @@ describe('<DataGrid /> - Rows', () => {
);
const expectedHeight = baselineProps.rows.length * (contentHeight + border);
await act(() => Promise.resolve());
clock.runToLast();
clock.runToLast(); // Run timers in the mocked ResizeObserver
clock.runToLast(); // Run the debounce timeout that triggers the rerender
expect(virtualScrollerContent).toHaveInlineStyle({
width: 'auto',
height: `${expectedHeight}px`,
Expand Down Expand Up @@ -597,7 +595,8 @@ describe('<DataGrid /> - Rows', () => {
border + // Measured rows also include the border
(baselineProps.rows.length - 1) * defaultRowHeight;
await act(() => Promise.resolve());
clock.runToLast();
clock.runToLast(); // Run timers in the mocked ResizeObserver
clock.runToLast(); // Run the debounce timeout that triggers the rerender
expect(virtualScrollerContent).toHaveInlineStyle({
width: 'auto',
height: `${expectedHeight}px`,
Expand Down Expand Up @@ -626,7 +625,8 @@ describe('<DataGrid /> - Rows', () => {
const expectedHeight =
firstRowHeight + (baselineProps.rows.length - 1) * estimatedRowHeight;
await act(() => Promise.resolve());
clock.runToLast();
clock.runToLast(); // Run timers in the mocked ResizeObserver
clock.runToLast(); // Run the debounce timeout that triggers the rerender
expect(virtualScrollerContent).toHaveInlineStyle({
width: 'auto',
height: `${expectedHeight}px`,
Expand All @@ -646,14 +646,16 @@ describe('<DataGrid /> - Rows', () => {
'.MuiDataGrid-virtualScrollerContent',
);
await act(() => Promise.resolve()); // Wait for ResizeObserver to send dimensions
clock.runToLast();
clock.runToLast(); // Run timers in the mocked ResizeObserver
clock.runToLast(); // Run the debounce timeout that triggers the rerender
expect(virtualScrollerContent).toHaveInlineStyle({
width: 'auto',
height: '101px',
});
setProps({ rows: [{ clientId: 'c1', expanded: true }] });
await act(() => Promise.resolve()); // Wait for ResizeObserver to send dimensions
clock.runToLast();
clock.runToLast(); // Run timers in the mocked ResizeObserver
clock.runToLast(); // Run the debounce timeout that triggers the rerender
expect(virtualScrollerContent).toHaveInlineStyle({
width: 'auto',
height: '201px',
Expand Down Expand Up @@ -702,17 +704,20 @@ describe('<DataGrid /> - Rows', () => {
);
const virtualScroller = document.querySelector('.MuiDataGrid-virtualScroller')!;
await act(() => Promise.resolve());
clock.runToLast();
clock.runToLast(); // Run timers in the mocked ResizeObserver
clock.runToLast(); // Run the debounce timeout that triggers the rerender
expect(virtualScroller.scrollHeight).to.equal(101 + 52 + 52);
virtualScroller.scrollTop = 101; // Scroll to measure the 2nd cell
virtualScroller.dispatchEvent(new Event('scroll'));
await act(() => Promise.resolve());
clock.runToLast();
clock.runToLast(); // Run timers in the mocked ResizeObserver
clock.runToLast(); // Run the debounce timeout that triggers the rerender
expect(virtualScroller.scrollHeight).to.equal(101 + 101 + 52);
virtualScroller.scrollTop = 10e6; // Scroll to measure all cells
virtualScroller.dispatchEvent(new Event('scroll'));
await act(() => Promise.resolve());
clock.runToLast();
clock.runToLast(); // Run timers in the mocked ResizeObserver
clock.runToLast(); // Run the debounce timeout that triggers the rerender
expect(virtualScroller.scrollHeight).to.equal(101 + 101 + 101); // Ensure that all rows before the last were measured
});

Expand All @@ -738,14 +743,18 @@ describe('<DataGrid /> - Rows', () => {
'.MuiDataGrid-virtualScrollerContent',
)!;
await act(() => Promise.resolve());
clock.runToLast();
clock.runToLast(); // Run timers in the mocked ResizeObserver
clock.runToLast(); // Run the debounce timeout that triggers the rerender
expect(virtualScrollerContent).toHaveInlineStyle({
width: 'auto',
height: `${Math.floor(expectedHeight)}px`,
});
});

it('should position correctly the render zone when the 2nd page has less rows than the 1st page', async () => {
it('should position correctly the render zone when the 2nd page has less rows than the 1st page', async function test() {
if (/edg/i.test(window.navigator.userAgent)) {
this.skip(); // FIXME: We need a waitFor that works with fake clock
}
const data = getData(120, 3);
const headerHeight = 50;
const measuredRowHeight = 100;
Expand Down

0 comments on commit ebeda48

Please sign in to comment.