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] Generalize test utils #41175

Merged
merged 7 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion packages/mui-material-next/src/Badge/Badge.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, describeConformance } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
import Badge, { badgeClasses as classes } from '@mui/material-next/Badge';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
import describeConformance from '../../test/describeConformance';

function findBadgeRoot(container: HTMLElement) {
return container?.firstChild;
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-material-next/src/Button/Button.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { describeConformance, createRenderer, fireEvent, act } from '@mui-internal/test-utils';
import { createRenderer, fireEvent, act } from '@mui-internal/test-utils';
import { camelCase } from 'lodash';
import Button, { buttonClasses as classes } from '@mui/material-next/Button';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
import describeConformance from '../../test/describeConformance';

describe('<Button />', () => {
const { render, renderToString } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { expect } from 'chai';
import { spy, stub } from 'sinon';
import userEvent from '@testing-library/user-event';
import {
describeConformance,
act,
createRenderer,
fireEvent,
Expand All @@ -19,6 +18,7 @@ import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
import ButtonBase, { buttonBaseClasses as classes } from '@mui/material-next/ButtonBase';
import { ButtonBaseActions } from './ButtonBase.types';
import { TouchRippleActions } from './TouchRipple.types';
import describeConformance from '../../test/describeConformance';

// TODO v6: initialize @testing-library/user-event using userEvent.setup() instead of directly calling methods e.g. userEvent.click() for all related tests in this file
// currently the setup() method uses the ClipboardEvent constructor which is incompatible with our lowest supported version of iOS Safari (12.2) https://github.com/mui/material-ui/blob/master/.browserslistrc#L44
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { expect } from 'chai';
import { describeConformance, act, createRenderer } from '@mui-internal/test-utils';
import { act, createRenderer } from '@mui-internal/test-utils';
import TouchRipple, { DELAY_RIPPLE } from './TouchRipple';
import describeConformance from '../../test/describeConformance';

const cb = () => {};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, describeConformance, screen } from '@mui-internal/test-utils';
import { createRenderer, screen } from '@mui-internal/test-utils';
import ButtonGroup, { buttonGroupClasses as classes } from '@mui/material-next/ButtonGroup';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
import Button, { buttonClasses } from '@mui/material-next/Button';
import ButtonGroupContext, { ButtonGroupContextType } from './ButtonGroupContext';
import describeConformance from '../../test/describeConformance';

describe('<ButtonGroup />', () => {
const { render } = createRenderer();
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material-next/src/Chip/Chip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { expect } from 'chai';
import { spy, stub } from 'sinon';
import userEvent from '@testing-library/user-event';
import {
describeConformance,
act,
createRenderer,
fireEvent,
Expand All @@ -19,6 +18,7 @@ import Chip, { chipClasses as classes } from '@mui/material-next/Chip';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
import CheckBox from '../internal/svg-icons/CheckBox';
import { ChipProps } from './Chip.types';
import describeConformance from '../../test/describeConformance';

// TODO: remove after migrating SvgIcon to support Material Design 3 colors
const MaterialV5DefaultTheme = createTheme();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, describeConformance } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
import CircularProgress, {
circularProgressClasses as classes,
} from '@mui/material-next/CircularProgress';
import { CssVarsProvider, extendTheme } from '../styles';
import describeConformance from '../../test/describeConformance';

describe('<CircularProgress />', () => {
const { render } = createRenderer();
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-material-next/src/Divider/Divider.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as React from 'react';
import { expect } from 'chai';
import { describeConformance, createRenderer } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
import Divider, { dividerClasses as classes } from '@mui/material-next/Divider';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
import describeConformance from '../../test/describeConformance';

describe('<Divider />', () => {
const { render } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { expect } from 'chai';
import { ClassNames } from '@emotion/react';
import { createRenderer, describeConformance } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
import FilledInput, { filledInputClasses as classes } from '@mui/material-next/FilledInput';
import InputBase from '@mui/material-next/InputBase';
import describeConformance from '../../test/describeConformance';

describe('<FilledInput />', () => {
const { render } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { ClassNames } from '@emotion/react';
import { describeConformance, act, createRenderer, fireEvent } from '@mui-internal/test-utils';
import { act, createRenderer, fireEvent } from '@mui-internal/test-utils';
import FormControl, { formControlClasses as classes } from '@mui/material-next/FormControl';
import FilledInput from '@mui/material-next/FilledInput';
import InputBase from '@mui/material-next/InputBase';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
// TODO v6: replace with material-next/Select
import Select from '@mui/material/Select';
import useFormControl from './useFormControl';
import describeConformance from '../../test/describeConformance';

type TestFormControlledComponent = {
onFilled: () => {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, describeConformance } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
import FormHelperText, {
formHelperTextClasses as classes,
FormHelperTextClasses,
} from '@mui/material-next/FormHelperText';
import FormControl from '@mui/material-next/FormControl';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
import describeConformance from '../../test/describeConformance';

describe('<FormHelperText />', () => {
let originalMatchmedia: typeof window.matchMedia;
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-material-next/src/FormLabel/FormLabel.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import { describeConformance, act, createRenderer } from '@mui-internal/test-utils';
import { act, createRenderer } from '@mui-internal/test-utils';
import FormLabel, { formLabelClasses as classes } from '@mui/material-next/FormLabel';
import FormControl, { useFormControl } from '@mui/material-next/FormControl';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
import describeConformance from '../../test/describeConformance';

describe('<FormLabel />', () => {
let originalMatchmedia: typeof window.matchMedia;
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-material-next/src/IconButton/IconButton.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as React from 'react';
import { expect } from 'chai';
import PropTypes from 'prop-types';
import { createRenderer, describeConformance } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
import { unstable_capitalize as capitalize } from '@mui/utils';
import Icon from '@mui/material/Icon';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import ButtonBase from '@mui/material/ButtonBase';
import { iconButtonClasses as classes } from '@mui/material/IconButton';
import IconButton from '.';
import describeConformance from '../../test/describeConformance';

describe('<IconButton />', () => {
const { render } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import * as React from 'react';
import { expect } from 'chai';
import {
createRenderer,
describeConformance,
strictModeDoubleLoggingSuppressed,
} from '@mui-internal/test-utils';
import { createRenderer, strictModeDoubleLoggingSuppressed } from '@mui-internal/test-utils';
import { typographyClasses } from '@mui/material/Typography';
import InputAdornment, { inputAdornmentClasses as classes } from '@mui/material/InputAdornment';
import TextField from '@mui/material/TextField';
import FormControl from '@mui/material/FormControl';
import Input from '@mui/material/Input';
import describeConformance from '../../test/describeConformance';

describe('<InputAdornment />', () => {
const { render } = createRenderer();
Expand Down
9 changes: 2 additions & 7 deletions packages/mui-material-next/src/InputBase/InputBase.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import * as React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import { spy } from 'sinon';
import {
describeConformance,
act,
createRenderer,
fireEvent,
screen,
} from '@mui-internal/test-utils';
import { act, createRenderer, fireEvent, screen } from '@mui-internal/test-utils';
import FormControl, { useFormControl } from '@mui/material-next/FormControl';
// TODO v6: replace with material-next/InputAdornment
import InputAdornment from '@mui/material/InputAdornment';
Expand All @@ -23,6 +17,7 @@ import {
InputBaseOwnerState,
InputBaseProps,
} from './InputBase.types';
import describeConformance from '../../test/describeConformance';

describe('<InputBase />', () => {
const { render } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import { describeConformance, act, createRenderer } from '@mui-internal/test-utils';
import { act, createRenderer } from '@mui-internal/test-utils';
import { ClassNames } from '@emotion/react';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
import FormControl from '@mui/material-next/FormControl';
import FilledInput from '@mui/material-next/FilledInput';
import FormLabel from '@mui/material-next/FormLabel';
import InputLabel, { inputLabelClasses as classes } from '@mui/material-next/InputLabel';
import describeConformance from '../../test/describeConformance';

describe('<InputLabel />', () => {
let originalMatchmedia: typeof window.matchMedia;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { expect } from 'chai';
import {
createRenderer,
screen,
describeConformance,
strictModeDoubleLoggingSuppressed,
MuiRenderResult,
} from '@mui-internal/test-utils';
import LinearProgress, {
linearProgressClasses as classes,
} from '@mui/material-next/LinearProgress';
import { CssVarsProvider, extendTheme } from '../styles';
import describeConformance from '../../test/describeConformance';

describe('<LinearProgress />', () => {
const { render } = createRenderer();
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-material-next/src/List/List.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as React from 'react';
import { expect } from 'chai';
import { describeConformance, createRenderer } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
import ListSubheader, { listSubheaderClasses } from '@mui/material-next/ListSubheader';
import ListItem, { listItemClasses } from '@mui/material-next/ListItem';
import List, { listClasses as classes } from '@mui/material-next/List';
import describeConformance from '../../test/describeConformance';

describe('<List />', () => {
const { render } = createRenderer();
Expand Down
9 changes: 2 additions & 7 deletions packages/mui-material-next/src/ListItem/ListItem.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import * as React from 'react';
import { expect } from 'chai';
import PropTypes from 'prop-types';
import {
describeConformance,
act,
createRenderer,
fireEvent,
queries,
} from '@mui-internal/test-utils';
import { act, createRenderer, fireEvent, queries } from '@mui-internal/test-utils';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import ListItemText from '@mui/material-next/ListItemText';
import ListItemSecondaryAction from '@mui/material-next/ListItemSecondaryAction';
import ListItem, { listItemClasses as classes } from '@mui/material-next/ListItem';
import ListContext from '../List/ListContext';
import describeConformance from '../../test/describeConformance';

const NoContent = React.forwardRef(() => {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as React from 'react';
import { createRenderer, describeConformance } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
import ListItemAvatar, {
listItemAvatarClasses as classes,
} from '@mui/material-next/ListItemAvatar';
import describeConformance from '../../test/describeConformance';

describe('<ListItemAvatar />', () => {
const { render } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as React from 'react';
import { expect } from 'chai';
import { describeConformance, act, createRenderer, fireEvent } from '@mui-internal/test-utils';
import { act, createRenderer, fireEvent } from '@mui-internal/test-utils';
import ListItemButton, {
listItemButtonClasses as classes,
} from '@mui/material-next/ListItemButton';
import ButtonBase from '@mui/material-next/ButtonBase';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import ListContext from '../List/ListContext';
import describeConformance from '../../test/describeConformance';

describe('<ListItemButton />', () => {
const { render } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { createRenderer, describeConformance } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
import ListItemIcon, { listItemIconClasses as classes } from '@mui/material-next/ListItemIcon';
import describeConformance from '../../test/describeConformance';

describe('<ListItemIcon />', () => {
const { render } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, describeConformance } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
import ListItem from '@mui/material-next/ListItem';
import ListItemSecondaryAction, {
listItemSecondaryActionClasses as classes,
} from '@mui/material-next/ListItemSecondaryAction';
import describeConformance from '../../test/describeConformance';

describe('<ListItemSecondaryAction />', () => {
const { render } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, describeConformance } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
/* TODO: change @mui/material/Typography to @mui/material-next/Typography once Typograpghy is available in @mui/material-next */
import Typography, { typographyClasses } from '@mui/material/Typography';
import ListItemText, { listItemTextClasses as classes } from '@mui/material-next/ListItemText';
import describeConformance from '../../test/describeConformance';

describe('<ListItemText />', () => {
const { render } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { expect } from 'chai';
import { describeConformance, createRenderer } from '@mui-internal/test-utils';
import { createRenderer } from '@mui-internal/test-utils';
import ListSubheader, { listSubheaderClasses as classes } from '@mui/material-next/ListSubheader';
import describeConformance from '../../test/describeConformance';

describe('<ListSubheader />', () => {
const { render } = createRenderer();
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material-next/src/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
act,
createRenderer,
createMount,
describeConformance,
screen,
fireEvent,
strictModeDoubleLoggingSuppressed,
Expand All @@ -17,6 +16,7 @@ import Menu, { menuClasses as classes, MenuProps } from '@mui/material-next/Menu
import Popover from '@mui/material/Popover';
import { extendTheme, CssVarsProvider } from '@mui/material-next/styles';
import { MenuPaper } from './Menu';
import describeConformance from '../../test/describeConformance';

describe('<Menu />', () => {
const { render } = createRenderer({ clock: 'fake' });
Expand Down
9 changes: 2 additions & 7 deletions packages/mui-material-next/src/MenuItem/MenuItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import {
act,
describeConformance,
createRenderer,
fireEvent,
screen,
} from '@mui-internal/test-utils';
import { act, createRenderer, fireEvent, screen } from '@mui-internal/test-utils';
import { MenuProvider } from '@mui/base/useMenu';
import MenuItem, { menuItemClasses as classes } from '@mui/material-next/MenuItem';
import Menu from '@mui/material-next/Menu';
import ButtonBase from '@mui/material-next/ButtonBase';
import describeConformance from '../../test/describeConformance';

const dummyGetItemState = () => ({
disabled: false,
Expand Down
Loading