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 all 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
2 changes: 2 additions & 0 deletions packages/x-data-grid-premium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@
"@mui/material": "^5.16.14",
"@mui/system": "^5.16.14",
"@types/prop-types": "^15.7.14",
"@types/react-transition-group": "^4.4.12",
"date-fns": "^4.1.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-transition-group": "^4.4.5",
"rimraf": "^6.0.1"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import { createRenderer, act, waitFor } from '@mui/internal-test-utils';
import { createRenderer, act } from '@mui/internal-test-utils';
import { expect } from 'chai';
import {
DataGridPremium as DataGrid,
Expand Down Expand Up @@ -104,6 +104,6 @@ describe('<DataGrid /> - Quick filter', () => {
},
});

await waitFor(() => expect(getColumnValues(0)).to.deep.equal(['20th Century Fox (1)', '']));
expect(getColumnValues(0)).to.deep.equal(['20th Century Fox (1)', '']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('<DataGridPremium /> - Data source aggregation', () => {
expect(fetchRowsSpy.callCount).to.be.greaterThan(0);
});
await user.click(within(getColumnHeaderCell(0)).getByLabelText('Menu'));
expect(screen.queryByLabelText('Aggregation')).not.to.equal(null);
expect(await screen.findByLabelText('Aggregation')).not.to.equal(null);
});

it('should not show aggregation option in the column menu when no aggregation function is defined', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { addYears } from 'date-fns/addYears';
import { expect } from 'chai';
import { createRenderer, screen, waitFor } from '@mui/internal-test-utils';
import { createRenderer, screen } from '@mui/internal-test-utils';
import { DataGridPremium } from '@mui/x-data-grid-premium';
import { generateLicense, LicenseInfo } from '@mui/x-license';

Expand All @@ -23,15 +23,13 @@ describe('<DataGridPremium /> - License', () => {
]);
});

it('should render watermark when the license is missing', async () => {
it('should render watermark when the license is missing', () => {
LicenseInfo.setLicenseKey('');

expect(() => render(<DataGridPremium columns={[]} rows={[]} autoHeight />)).toErrorDev([
'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);
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import * as React from 'react';
import { config } from 'react-transition-group';
import { RefObject } from '@mui/x-internals/types';
import {
createRenderer,
fireEvent,
screen,
act,
waitFor,
reactMajor,
} from '@mui/internal-test-utils';
import { createRenderer, fireEvent, screen, act, reactMajor } from '@mui/internal-test-utils';
import {
microtasks,
getColumnHeaderCell,
Expand Down Expand Up @@ -1792,6 +1786,10 @@ describe('<DataGridPremium /> - Row grouping', () => {
});

it('should add a "Stop grouping {field}" menu item for each grouping criteria on the grouping column when prop.rowGroupingColumnMode = "single"', () => {
const restoreDisabledConfig = config.disabled;
// enable `react-transition-group` transitions for this test
config.disabled = false;
Copy link
Member

Choose a reason for hiding this comment

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

This test needs animations or refactoring.


render(
<Test
columns={[
Expand Down Expand Up @@ -1826,6 +1824,9 @@ describe('<DataGridPremium /> - Row grouping', () => {
});
fireEvent.click(menuItemCategory2);
expect(apiRef.current?.state.rowGrouping.model).to.deep.equal([]);

// restore previous config
config.disabled = restoreDisabledConfig;
});

it('should add a "Stop grouping {field}" menu item for each grouping criteria with colDef.groupable = false but it should be disabled', () => {
Expand Down Expand Up @@ -2891,29 +2892,31 @@ describe('<DataGridPremium /> - Row grouping', () => {
/>,
);

act(() => apiRef.current?.updateRows([{ id: 1, group: 'A', username: 'username 2' }]));
await act(async () => {
apiRef.current?.updateRows([{ id: 1, group: 'A', username: 'username 2' }]);
});

await waitFor(() => expect(getCell(1, 3).textContent).to.equal('username 2'));
expect(getCell(1, 3).textContent).to.equal('username 2');
});

// See https://github.com/mui/mui-x/issues/8580
it('should not collapse expanded groups after `updateRows`', async () => {
render(
const { user } = render(
<Test
columns={[{ field: 'id' }, { field: 'group' }, { field: 'username', width: 150 }]}
rows={[{ id: 1, group: 'A', username: 'username' }]}
rowGroupingModel={['group']}
/>,
);

fireEvent.click(screen.getByRole('button', { name: 'see children' }));
await user.click(screen.getByRole('button', { name: 'see children' }));

act(() => apiRef.current?.updateRows([{ id: 1, group: 'A', username: 'username 2' }]));

await waitFor(() => {
expect(screen.getByRole('button', { name: 'hide children' })).toBeVisible();
await act(async () => {
apiRef.current?.updateRows([{ id: 1, group: 'A', username: 'username 2' }]);
});
await waitFor(() => expect(getCell(1, 3).textContent).to.equal('username 2'));

expect(screen.getByRole('button', { name: 'hide children' })).toBeVisible();
expect(getCell(1, 3).textContent).to.equal('username 2');
});

// See https://github.com/mui/mui-x/issues/8853
Expand All @@ -2933,10 +2936,10 @@ describe('<DataGridPremium /> - Row grouping', () => {
expect(getColumnValues(3)).to.deep.equal(['', 'username1', 'username2']);

// trigger row update without any changes in row data
act(() => apiRef.current?.updateRows([{ id: 1 }]));

await waitFor(() => {
expect(getColumnValues(3)).to.deep.equal(['', 'username1', 'username2']);
await act(async () => {
apiRef.current?.updateRows([{ id: 1 }]);
});

expect(getColumnValues(3)).to.deep.equal(['', 'username1', 'username2']);
});
});
2 changes: 2 additions & 0 deletions packages/x-data-grid-pro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@
"@mui/material": "^5.16.14",
"@mui/system": "^5.16.14",
"@types/prop-types": "^15.7.14",
"@types/react-transition-group": "^4.4.12",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-transition-group": "^4.4.5",
"rimraf": "^6.0.1"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
GridColDef,
} from '@mui/x-data-grid-pro';
import { getBasicGridData } from '@mui/x-data-grid-generator';
import { createRenderer, fireEvent, act, waitFor } from '@mui/internal-test-utils';
import { createRenderer, fireEvent, act } from '@mui/internal-test-utils';
import { getCell, spyApi } from 'test/utils/helperFn';
import { fireUserEvent } from 'test/utils/fireUserEvent';

Expand Down Expand Up @@ -906,15 +906,13 @@ describe('<DataGridPro /> - Cell editing', () => {

it('should call preProcessEditCellProps', async () => {
const preProcessEditCellProps = spy(({ props }: GridPreProcessEditCellProps) => props);
render(<TestCase columnProps={{ preProcessEditCellProps }} />);
const { user } = render(<TestCase columnProps={{ preProcessEditCellProps }} />);

const cell = getCell(0, 1);
fireUserEvent.mousePress(cell);
fireEvent.keyDown(cell, { key: 'Delete' });
await user.click(cell);
await user.keyboard('{Delete}');

await waitFor(() => {
expect(preProcessEditCellProps.callCount).to.equal(1);
});
expect(preProcessEditCellProps.callCount).to.equal(1);

expect(preProcessEditCellProps.lastCall.args[0].props).to.deep.equal({
value: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { config } from 'react-transition-group';
import { createRenderer, fireEvent, screen } from '@mui/internal-test-utils';
import { expect } from 'chai';
import { gridClasses, DataGridPro, DataGridProProps } from '@mui/x-data-grid-pro';
Expand Down Expand Up @@ -198,6 +199,10 @@ describe('<DataGridPro /> - Column headers', () => {
});

it('should remove the MuiDataGrid-menuOpen CSS class only after the transition has ended', () => {
const restoreDisabledConfig = config.disabled;
// enable `react-transition-group` transitions for this test
config.disabled = false;
Copy link
Member

Choose a reason for hiding this comment

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

This test needs animations with timeouts or a complete refactor/removal


render(
<div style={{ width: 300, height: 500 }}>
<DataGridPro {...baselineProps} columns={[{ field: 'brand' }]} />
Expand All @@ -212,6 +217,9 @@ describe('<DataGridPro /> - Column headers', () => {
expect(menuIconButton?.parentElement).to.have.class(gridClasses.menuOpen);
clock.runToLast(); // Wait for the transition to run
expect(menuIconButton?.parentElement).not.to.have.class(gridClasses.menuOpen);

// restore previous config
config.disabled = restoreDisabledConfig;
});

it('should restore focus to the column header when dismissing the menu by selecting any item', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('<DataGridPro /> - Detail panel', () => {
);
}
const rowHeight = 50;
render(
const { user } = render(
<TestCase
nbRows={1}
rowHeight={rowHeight}
Expand All @@ -131,23 +131,19 @@ describe('<DataGridPro /> - Detail panel', () => {
/>,
);
const virtualScrollerContent = grid('virtualScrollerContent')!;
fireEvent.click(screen.getByRole('button', { name: 'Expand' }));
await user.click(screen.getByRole('button', { name: 'Expand' }));

await waitFor(() => {
expect(getRow(0).className).to.include(gridClasses['row--detailPanelExpanded']);
});
expect(getRow(0).className).to.include(gridClasses['row--detailPanelExpanded']);

await waitFor(() => {
expect(virtualScrollerContent).toHaveComputedStyle({ height: `${rowHeight + 100}px` });
});
expect(virtualScrollerContent).toHaveComputedStyle({ height: `${rowHeight + 100}px` });
expect(virtualScrollerContent).toHaveInlineStyle({ width: 'auto' });

const detailPanels = $$('.MuiDataGrid-detailPanel');
expect(detailPanels[0]).toHaveComputedStyle({
height: `100px`,
});

fireEvent.click(screen.getByRole('button', { name: 'Increase' }));
await user.click(screen.getByRole('button', { name: 'Increase' }));

await waitFor(() => {
expect(virtualScrollerContent).toHaveComputedStyle({ height: `${rowHeight + 200}px` });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ describe('<DataGridPro /> - Edit components', () => {
const cell = getCell(0, 0);
await user.dblClick(cell);
await user.click(screen.queryAllByRole('option')[1]);
await waitFor(() => expect(screen.queryByRole('listbox')).to.equal(null));
await act(() => {
expect(screen.queryByRole('listbox')).to.equal(null);
await act(async () => {
screen.getByRole('combobox').focus();
});
await user.keyboard('{Enter}');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
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';

describe('<DataGridPro /> - License', () => {
const { render } = createRenderer();

it('should render watermark when the license is missing', async () => {
it('should render watermark when the license is missing', () => {
LicenseInfo.setLicenseKey('');

expect(() => render(<DataGridPro columns={[]} rows={[]} autoHeight />)).toErrorDev([
'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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@mui/x-data-grid-pro';
import Portal from '@mui/material/Portal';
import { getBasicGridData } from '@mui/x-data-grid-generator';
import { createRenderer, fireEvent, act, screen, waitFor } from '@mui/internal-test-utils';
import { createRenderer, fireEvent, act, screen } from '@mui/internal-test-utils';
import { getCell, getRow, spyApi } from 'test/utils/helperFn';
import { fireUserEvent } from 'test/utils/fireUserEvent';

Expand Down Expand Up @@ -910,15 +910,13 @@ describe('<DataGridPro /> - Row editing', () => {

it('should call preProcessEditCellProps', async () => {
const preProcessEditCellProps = spy(({ props }: GridPreProcessEditCellProps) => props);
render(<TestCase column1Props={{ preProcessEditCellProps }} />);
const { user } = render(<TestCase column1Props={{ preProcessEditCellProps }} />);

const cell = getCell(0, 1);
fireUserEvent.mousePress(cell);
fireEvent.keyDown(cell, { key: 'Delete' });
await user.click(cell);
await user.keyboard('{Delete}');

await waitFor(() => {
expect(preProcessEditCellProps.callCount).to.equal(1);
});
expect(preProcessEditCellProps.callCount).to.equal(1);

expect(preProcessEditCellProps.lastCall.args[0].props).to.deep.equal({
value: '',
Expand Down
32 changes: 17 additions & 15 deletions packages/x-data-grid-pro/src/tests/rowPinning.DataGridPro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
GridColDef,
} from '@mui/x-data-grid-pro';
import { getBasicGridData } from '@mui/x-data-grid-generator';
import { createRenderer, fireEvent, screen, act, waitFor } from '@mui/internal-test-utils';
import { createRenderer, fireEvent, screen, act } from '@mui/internal-test-utils';
import {
$,
grid,
Expand Down Expand Up @@ -733,7 +733,7 @@ describe('<DataGridPro /> - Row pinning', () => {
testSkipIf(isJSDOM)('should support cell editing', async () => {
const processRowUpdate = spy((row) => ({ ...row, currencyPair: 'USD-GBP' }));
const columns: GridColDef[] = [{ field: 'id' }, { field: 'name', editable: true }];
render(
const { user } = render(
<div style={{ width: 400, height: 400 }}>
<DataGridPro
rows={[
Expand All @@ -752,15 +752,16 @@ describe('<DataGridPro /> - Row pinning', () => {
);

const cell = getCell(0, 1);
fireEvent.doubleClick(cell);
await user.dblClick(cell);

const input = cell.querySelector('input')!;
fireEvent.change(input, { target: { value: 'Marcus' } });
fireEvent.keyDown(input, { key: 'Enter' });
// remove the previous value before typing in the new one
// was "fireEvent.change(input, { target: { value: 'Marcus' } })"
await user.clear(input);
await user.type(input, 'Marcus');
await user.keyboard('{Enter}');

await waitFor(() => {
expect(cell.textContent).to.equal('Marcus');
});
expect(cell.textContent).to.equal('Marcus');
expect(processRowUpdate.callCount).to.equal(1);
expect(processRowUpdate.lastCall.args[0]).to.deep.equal({ id: 3, name: 'Marcus' });
});
Expand All @@ -769,7 +770,7 @@ describe('<DataGridPro /> - Row pinning', () => {
testSkipIf(isJSDOM)('should support row editing', async () => {
const processRowUpdate = spy((row) => ({ ...row, currencyPair: 'USD-GBP' }));
const columns: GridColDef[] = [{ field: 'id' }, { field: 'name', editable: true }];
render(
const { user } = render(
<div style={{ width: 400, height: 400 }}>
<DataGridPro
rows={[
Expand All @@ -789,15 +790,16 @@ describe('<DataGridPro /> - Row pinning', () => {
);

const cell = getCell(0, 1);
fireEvent.doubleClick(cell);
await user.dblClick(cell);

const input = cell.querySelector('input')!;
fireEvent.change(input, { target: { value: 'Marcus' } });
fireEvent.keyDown(input, { key: 'Enter' });
// remove the previous value before typing in the new one
// was "fireEvent.change(input, { target: { value: 'Marcus' } })"
await user.clear(input);
await user.type(input, 'Marcus');
await user.keyboard('{Enter}');

await waitFor(() => {
expect(cell.textContent).to.equal('Marcus');
});
expect(cell.textContent).to.equal('Marcus');
expect(processRowUpdate.callCount).to.equal(1);
expect(processRowUpdate.lastCall.args[0]).to.deep.equal({ id: 3, name: 'Marcus' });
});
Expand Down
Loading