Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Fix failing dynamic row height tests on Edge #5707

Merged
merged 2 commits into from
Aug 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m4theushw
This test also fails in Chrome and Firefox sometimes:

https://app.circleci.com/pipelines/github/mui/mui-x/21944/workflows/5b674c92-8ba9-427e-a902-d1a516513cd6/jobs/126695

Firefox 78.0 (Windows 10) <DataGrid /> - Rows prop: getRowHeight dynamic row height should position correctly the render zone when the 2nd page has less rows than the 1st page FAILED
	expected inline style of <div …(2)>…(1)</div> did not match
	Expected:
	{
	  "transform": "translate3d(0px, 0px, 0px)"
	}
	Actual:
	{
	  "transform": "translate3d(0px, 988px, 0px)"
	}

https://app.circleci.com/pipelines/github/mui/mui-x/21943/workflows/4ec09158-5c2c-4fb8-b994-52816ab953e1/jobs/126682

Chrome 87.0.4280.66 (Mac OS 10.15.6) <DataGrid /> - Rows prop: getRowHeight dynamic row height should position correctly the render zone when the 2nd page has less rows than the 1st page FAILED
	AssertionError: expected inline style of <div …(2)></div> did not match
	Expected:
	{
	  "transform": "translate3d(0px, 0px, 0px)"
	}
	Actual:
	{
	  "transform": "translate3d(0px, 1040px, 0px)"
	}

I can reproduce it locally using Chrome instead of ChromeHeadless.
Test fails only when browser window is in background.

diff --git a/test/karma.conf.js b/test/karma.conf.js
index 2ea932985..f40b51137 100644
--- a/test/karma.conf.js
+++ b/test/karma.conf.js
@@ -44,7 +44,7 @@ const MAX_CIRCLE_CI_CONCURRENCY = 83;
 module.exports = function setKarmaConfig(config) {
   const baseConfig = {
     basePath: '../',
-    browsers: ['chromeHeadless'],
+    browsers: ['Chrome'],
     browserDisconnectTimeout: 3 * 60 * 1000, // default 2000
     browserDisconnectTolerance: 1, // default 0
     browserNoActivityTimeout: 6 * 60 * 1000, // default 10000

Any ideas?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any clue of why they fail. When I did this PR, I only had problems with Edge so ignoring this browser in this specific test solved the problem. https://app.circleci.com/pipelines/github/mui/mui-x/21728/workflows/12ccc593-a493-414b-9484-79cb96b8a991/jobs/125448 is from a7eef9e

I think we'll need to skip all tests related to dynamic row height since they are too flacky.

}
const data = getData(120, 3);
const headerHeight = 50;
const measuredRowHeight = 100;
Expand Down