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] Disable react-transition-group transitions in unit testing #16288

Merged
merged 39 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0c7316d
override react transition group + remove `waitFor` calls
lauri865 Jan 21, 2025
2f5117a
Install missing `react-transition-group` dep in `test` package
LukasTy Jan 22, 2025
cfbdf4e
Always render the transition component - `in` as `false` should rende…
LukasTy Jan 22, 2025
73c71ba
Fix eslint and prettier issues
LukasTy Jan 22, 2025
5546f97
Try built-in `react-transition-group` transition disabling for testing
LukasTy Jan 22, 2025
583b078
Try mocking components instead of using config
LukasTy Jan 23, 2025
1e8be24
prettier & eslint
LukasTy Jan 23, 2025
fd8dccd
Revert back to `config.disabled = "true"` solution
LukasTy Jan 24, 2025
f30868b
Override `config` flag for tests needing transitions
LukasTy Jan 27, 2025
88f8035
Merge branch 'master' into override-react-transition-group-in-tests
LukasTy Jan 27, 2025
e8a289f
Use `waitFor` in relevant cases, where browser tests fail otherwise
LukasTy Jan 27, 2025
b639fa2
Remove `waitFor` where possible
LukasTy Jan 28, 2025
b7c64b8
Merge branch 'master' into override-react-transition-group-in-tests
LukasTy Jan 28, 2025
a6f2d87
Call `beforeAll` hooks to properly setup license and disable transiti…
LukasTy Jan 28, 2025
f4b027b
Fix tests
LukasTy Jan 28, 2025
7c15df7
Fix the fix of tests :D
LukasTy Jan 28, 2025
fcf61b8
brainfart
LukasTy Jan 28, 2025
a30bdc4
Ensure the filter panel is opened before entering filter value
LukasTy Jan 28, 2025
1efc333
Try more assertions
LukasTy Jan 28, 2025
da44c19
Make assertions properly async
LukasTy Jan 28, 2025
d8e765c
Try async expected DOM assertions
LukasTy Jan 28, 2025
2a48064
Keep `waitFor` for a flaky test
LukasTy Jan 28, 2025
40d8eb9
Refactor
LukasTy Jan 28, 2025
e82a695
Try `user.type`
LukasTy Jan 28, 2025
78a49b5
Try assertion for active filter
LukasTy Jan 29, 2025
1daa8c3
Use `findBy` instead of `waitFor`
LukasTy Jan 29, 2025
8a87dbf
Try with `skipClick`
LukasTy Jan 29, 2025
3a97908
Revert test to original behavior
LukasTy Jan 29, 2025
5458de4
Revert test change to maybe avoid flakiness
LukasTy Jan 29, 2025
49ba6d5
Try the failing assertion in async method
LukasTy Jan 29, 2025
52a723f
Merge branch 'master' into override-react-transition-group-in-tests
LukasTy Jan 29, 2025
8f2bff8
Merge branch 'master' into override-react-transition-group-in-tests
LukasTy Jan 29, 2025
6cfb531
Move config to `beforeEach`
LukasTy Jan 30, 2025
4cac57d
Code review: Jan
LukasTy Jan 30, 2025
d92ea56
A few flaky refactors
LukasTy Jan 30, 2025
018956e
Merge branch 'master' into override-react-transition-group-in-tests
LukasTy Jan 30, 2025
6dc1330
Address another flaky test
LukasTy Jan 30, 2025
ee62e4d
Revert change
LukasTy Jan 30, 2025
d05549a
Update packages/x-data-grid-pro/src/tests/editComponents.DataGridPro.…
LukasTy Jan 31, 2025
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, screen, waitFor } from '@mui/internal-test-utils';
import { createRenderer, screen } from '@mui/internal-test-utils';
import { DataGridPro } from '@mui/x-data-grid-pro';
import { LicenseInfo } from '@mui/x-license';

Expand All @@ -14,8 +14,6 @@ describe('<DataGridPro /> - License', () => {
'MUI X: Missing license key.',
]);

await waitFor(() => {
expect(screen.getByText('MUI X Missing license key')).not.to.equal(null);
});
expect(screen.getByText('MUI X Missing license key')).not.to.equal(null);
});
});
100 changes: 36 additions & 64 deletions packages/x-data-grid/src/tests/rows.DataGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
screen,
act,
ErrorBoundary,
waitFor,
reactMajor,
} from '@mui/internal-test-utils';
import clsx from 'clsx';
Expand Down Expand Up @@ -280,9 +279,7 @@ describe('<DataGrid /> - Rows', () => {
render(<TestCase getActions={() => [<GridActionsCellItem label="print" showInMenu />]} />);
expect(screen.queryByText('print')).to.equal(null);
fireEvent.click(screen.getByRole('menuitem', { name: 'more' }));
await waitFor(() => {
expect(screen.queryByText('print')).not.to.equal(null);
});
expect(screen.queryByText('print')).not.to.equal(null);
});

it('should not select the row when clicking in an action', async () => {
Expand All @@ -291,8 +288,7 @@ describe('<DataGrid /> - Rows', () => {
);
expect(getRow(0)).not.to.have.class('Mui-selected');
fireEvent.click(screen.getByRole('menuitem', { name: 'print' }));

await waitFor(() => expect(getRow(0)).not.to.have.class('Mui-selected'));
expect(getRow(0)).not.to.have.class('Mui-selected');
});

it('should not select the row when clicking in a menu action', async () => {
Expand All @@ -303,28 +299,23 @@ describe('<DataGrid /> - Rows', () => {
);
expect(getRow(0)).not.to.have.class('Mui-selected');
fireEvent.click(screen.getByRole('menuitem', { name: 'more' }));
await waitFor(() => {
expect(screen.queryByText('print')).not.to.equal(null);
});
expect(screen.queryByText('print')).not.to.equal(null);

fireEvent.click(screen.getByText('print'));
await waitFor(() => {
expect(getRow(0)).not.to.have.class('Mui-selected');
});
expect(getRow(0)).not.to.have.class('Mui-selected');

await microtasks();
});

it('should not select the row when opening the menu', async () => {
render(<TestCase getActions={() => [<GridActionsCellItem label="print" showInMenu />]} />);
expect(getRow(0)).not.to.have.class('Mui-selected');
fireEvent.click(screen.getByRole('menuitem', { name: 'more' }));
await waitFor(() => {
expect(getRow(0)).not.to.have.class('Mui-selected');
});
expect(getRow(0)).not.to.have.class('Mui-selected');
});

it('should close other menus before opening a new one', async () => {
render(
const { user } = render(
<TestCase
rows={[{ id: 1 }, { id: 2 }]}
getActions={() => [<GridActionsCellItem label="print" showInMenu />]}
Expand All @@ -333,18 +324,12 @@ describe('<DataGrid /> - Rows', () => {
expect(screen.queryAllByRole('menu')).to.have.length(2);

const more1 = screen.getAllByRole('menuitem', { name: 'more' })[0];
fireEvent.mouseDown(more1);
fireEvent.click(more1);
await waitFor(() => {
expect(screen.queryAllByRole('menu')).to.have.length(2 + 1);
});
await user.click(more1);
expect(screen.queryAllByRole('menu')).to.have.length(2 + 1);

const more2 = screen.getAllByRole('menuitem', { name: 'more' })[1];
fireEvent.mouseDown(more2);
fireEvent.click(more2);
await waitFor(() => {
expect(screen.queryAllByRole('menu')).to.have.length(2 + 1);
});
await user.click(more2);
expect(screen.queryAllByRole('menu')).to.have.length(2 + 1);
});

it('should allow to move focus to another cell with the arrow keys', () => {
Expand Down Expand Up @@ -375,10 +360,8 @@ describe('<DataGrid /> - Rows', () => {
const moreButton = screen.getByRole('menuitem', { name: 'more' });
fireUserEvent.mousePress(moreButton);

await waitFor(() => {
const printButton = screen.queryByRole('menuitem', { name: 'print' });
expect(printButton).toHaveFocus();
});
const printButton = screen.queryByRole('menuitem', { name: 'print' });
expect(printButton).toHaveFocus();
});

it('should allow to navigate between actions using the arrow keys', () => {
Expand Down Expand Up @@ -642,9 +625,9 @@ describe('<DataGrid /> - Rows', () => {
'.MuiDataGrid-virtualScrollerContent',
);
const expectedHeight = baselineProps.rows.length * (contentHeight + border);
await waitFor(() => {
expect(virtualScrollerContent).toHaveComputedStyle({ height: `${expectedHeight}px` });
});

expect(virtualScrollerContent).toHaveComputedStyle({ height: `${expectedHeight}px` });

expect(virtualScrollerContent).toHaveInlineStyle({ width: 'auto' });
});

Expand All @@ -669,9 +652,9 @@ describe('<DataGrid /> - Rows', () => {
measuredRowHeight +
border + // Measured rows also include the border
(baselineProps.rows.length - 1) * defaultRowHeight;
await waitFor(() => {
expect(virtualScrollerContent).toHaveComputedStyle({ height: `${expectedHeight}px` });
});

expect(virtualScrollerContent).toHaveComputedStyle({ height: `${expectedHeight}px` });

expect(virtualScrollerContent).toHaveInlineStyle({ width: 'auto' });
});

Expand All @@ -696,9 +679,9 @@ describe('<DataGrid /> - Rows', () => {
const firstRowHeight = measuredRowHeight + border; // Measured rows also include the border
const expectedHeight =
firstRowHeight + (baselineProps.rows.length - 1) * estimatedRowHeight;
await waitFor(() => {
expect(virtualScrollerContent).toHaveComputedStyle({ height: `${expectedHeight}px` });
});

expect(virtualScrollerContent).toHaveComputedStyle({ height: `${expectedHeight}px` });

expect(virtualScrollerContent).toHaveInlineStyle({ width: 'auto' });
});

Expand All @@ -714,14 +697,12 @@ describe('<DataGrid /> - Rows', () => {
const virtualScrollerContent = document.querySelector(
'.MuiDataGrid-virtualScrollerContent',
);
await waitFor(() => {
expect(virtualScrollerContent).toHaveComputedStyle({ height: '101px' });
});

expect(virtualScrollerContent).toHaveComputedStyle({ height: '101px' });
expect(virtualScrollerContent).toHaveInlineStyle({ width: 'auto' });
setProps({ rows: [{ clientId: 'c1', expanded: true }] });
await waitFor(() => {
expect(virtualScrollerContent).toHaveComputedStyle({ height: '201px' });
});
expect(virtualScrollerContent).toHaveComputedStyle({ height: '201px' });

expect(virtualScrollerContent).toHaveInlineStyle({ width: 'auto' });
});

Expand Down Expand Up @@ -764,20 +745,16 @@ describe('<DataGrid /> - Rows', () => {
/>,
);
const virtualScroller = grid('virtualScroller')!;
await waitFor(() =>
expect(virtualScroller.scrollHeight).to.equal(columnHeaderHeight + 101 + 52 + 52),
);

expect(virtualScroller.scrollHeight).to.equal(columnHeaderHeight + 101 + 52 + 52);
virtualScroller.scrollTop = 101; // Scroll to measure the 2nd cell
virtualScroller.dispatchEvent(new Event('scroll'));

await waitFor(() =>
expect(virtualScroller.scrollHeight).to.equal(columnHeaderHeight + 101 + 101 + 52),
);
expect(virtualScroller.scrollHeight).to.equal(columnHeaderHeight + 101 + 101 + 52);
virtualScroller.scrollTop = 10e6; // Scroll to measure all cells
virtualScroller.dispatchEvent(new Event('scroll'));
await waitFor(() =>
expect(virtualScroller.scrollHeight).to.equal(columnHeaderHeight + 101 + 101 + 101),
);

expect(virtualScroller.scrollHeight).to.equal(columnHeaderHeight + 101 + 101 + 101);
});

it('should allow to mix rows with dynamic row height and default row height', async () => {
Expand All @@ -800,10 +777,9 @@ describe('<DataGrid /> - Rows', () => {
const virtualScrollerContent = document.querySelector(
'.MuiDataGrid-virtualScrollerContent',
)!;
await waitFor(() => {
expect(virtualScrollerContent).toHaveComputedStyle({
height: `${Math.floor(expectedHeight)}px`,
});

expect(virtualScrollerContent).toHaveComputedStyle({
height: `${Math.floor(expectedHeight)}px`,
});
expect(virtualScrollerContent).toHaveInlineStyle({ width: 'auto' });
});
Expand Down Expand Up @@ -833,9 +809,7 @@ describe('<DataGrid /> - Rows', () => {

fireEvent.click(screen.getByRole('button', { name: /next page/i }));

await waitFor(() => {
expect(gridOffsetTop()).to.equal(0);
});
expect(gridOffsetTop()).to.equal(0);
},
);

Expand Down Expand Up @@ -895,9 +869,7 @@ describe('<DataGrid /> - Rows', () => {
setProps({ pageSize: 10 });
fireEvent.click(screen.getByRole('button', { name: /next page/i }));

await waitFor(() => {
expect(gridOffsetTop()).to.equal(0);
});
expect(gridOffsetTop()).to.equal(0);
},
);
});
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-router-dom": "^6.28.2",
"react-transition-group": "^4.4.5",
"semver": "^7.6.3",
"stylis": "^4.3.5",
"stylis-plugin-rtl": "^2.1.1"
Expand Down
6 changes: 6 additions & 0 deletions test/utils/mochaHooks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as React from 'react';
import { config } from 'react-transition-group';
import sinon from 'sinon';
import { unstable_resetCleanupTracking as unstable_resetCleanupTrackingDataGrid } from '@mui/x-data-grid';
import { unstable_resetCleanupTracking as unstable_resetCleanupTrackingDataGridPro } from '@mui/x-data-grid-pro';
Expand All @@ -7,6 +9,10 @@ import { clearWarningsCache } from '@mui/x-internals/warning';
import { generateTestLicenseKey, setupTestLicenseKey } from './testLicense';

export function createXMochaHooks(coreMochaHooks = {}) {
// disable "react-transition-group" transitions
// https://reactcommunity.org/react-transition-group/testing/
config.disabled = true;

const mochaHooks = {
beforeAll: [...(coreMochaHooks.beforeAll ?? [])],
afterAll: [...(coreMochaHooks.afterAll ?? [])],
Expand Down
Loading