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 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
3 changes: 2 additions & 1 deletion packages/mui-base/src/Badge/Badge.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { createRenderer, createMount, describeConformanceUnstyled } from '@mui-internal/test-utils';
import { createRenderer, createMount } from '@mui-internal/test-utils';
import { Badge, badgeClasses as classes } from '@mui/base/Badge';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<Badge />', () => {
const { render } = createRenderer();
Expand Down
9 changes: 2 additions & 7 deletions packages/mui-base/src/Button/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import * as React from 'react';
import {
act,
createMount,
createRenderer,
describeConformanceUnstyled,
fireEvent,
} from '@mui-internal/test-utils';
import { act, createMount, createRenderer, fireEvent } from '@mui-internal/test-utils';
import { expect } from 'chai';
import { spy } from 'sinon';
import { Button, buttonClasses } from '@mui/base/Button';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<Button />', () => {
const mount = createMount();
Expand Down
8 changes: 2 additions & 6 deletions packages/mui-base/src/FormControl/FormControl.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
fireEvent,
} from '@mui-internal/test-utils';
import { createMount, createRenderer, fireEvent } from '@mui-internal/test-utils';
import { FormControl, formControlClasses, useFormControlContext } from '@mui/base/FormControl';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<FormControl />', () => {
const mount = createMount();
Expand Down
10 changes: 2 additions & 8 deletions packages/mui-base/src/Input/Input.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
fireEvent,
screen,
act,
} from '@mui-internal/test-utils';
import { createMount, createRenderer, fireEvent, screen, act } from '@mui-internal/test-utils';
import { expect } from 'chai';
import { spy } from 'sinon';
import { Input, inputClasses, InputOwnerState } from '@mui/base/Input';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<Input />', () => {
const mount = createMount();
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { spy } from 'sinon';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
fireEvent,
act,
MuiRenderResult,
Expand All @@ -16,6 +15,7 @@ import { MenuItem, MenuItemRootSlotProps } from '@mui/base/MenuItem';
import { DropdownContext, DropdownContextValue } from '@mui/base/useDropdown';
import { Popper } from '@mui/base/Popper';
import { MenuProvider, useMenu } from '@mui/base/useMenu';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

const testContext: DropdownContextValue = {
dispatch: () => {},
Expand Down
8 changes: 2 additions & 6 deletions packages/mui-base/src/MenuButton/MenuButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import userEvent from '@testing-library/user-event';
import {
act,
createMount,
createRenderer,
describeConformanceUnstyled,
} from '@mui-internal/test-utils';
import { act, createMount, createRenderer } from '@mui-internal/test-utils';
import { MenuButton, menuButtonClasses } from '@mui/base/MenuButton';
import { DropdownContext, DropdownContextValue, DropdownActionTypes } from '@mui/base/useDropdown';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

// 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
3 changes: 2 additions & 1 deletion packages/mui-base/src/MenuItem/MenuItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from '@mui-internal/test-utils';
import { createMount, createRenderer } from '@mui-internal/test-utils';
import { MenuItem, menuItemClasses } from '@mui/base/MenuItem';
import { MenuProvider } from '@mui/base/useMenu';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

const dummyGetItemState = () => ({
disabled: false,
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-base/src/Modal/Modal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { expect } from 'chai';
import { createMount, createRenderer, describeConformanceUnstyled } from '@mui-internal/test-utils';
import { createMount, createRenderer } from '@mui-internal/test-utils';
import { Modal, modalClasses as classes, ModalRootSlotProps } from '@mui/base/Modal';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<Modal />', () => {
const mount = createMount();
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-base/src/Option/Option.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from '@mui-internal/test-utils';
import { createMount, createRenderer } from '@mui-internal/test-utils';
import { Option, optionClasses } from '@mui/base/Option';
import { SelectProvider } from '../useSelect/SelectProvider';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

const dummyGetItemState = () => ({
highlighted: false,
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-base/src/OptionGroup/OptionGroup.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from '@mui-internal/test-utils';
import { createMount, createRenderer } from '@mui-internal/test-utils';
import { OptionGroup, optionGroupClasses } from '@mui/base/OptionGroup';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<OptionGroup />', () => {
const mount = createMount();
Expand Down
8 changes: 2 additions & 6 deletions packages/mui-base/src/Popper/Popper.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import * as React from 'react';
import { expect } from 'chai';
import {
createRenderer,
createMount,
describeConformanceUnstyled,
screen,
} from '@mui-internal/test-utils';
import { createRenderer, createMount, screen } from '@mui-internal/test-utils';
import { Popper, popperClasses } from '@mui/base/Popper';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<Popper />', () => {
const { render } = createRenderer();
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { spy } from 'sinon';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
fireEvent,
act,
screen,
Expand All @@ -17,6 +16,7 @@ import { Select, SelectListboxSlotProps, selectClasses } from '@mui/base/Select'
import { SelectOption } from '@mui/base/useOption';
import { Option, OptionProps, OptionRootSlotProps, optionClasses } from '@mui/base/Option';
import { OptionGroup } from '@mui/base/OptionGroup';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

// 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
10 changes: 2 additions & 8 deletions packages/mui-base/src/Slider/Slider.test.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { expect } from 'chai';
import * as React from 'react';
import { spy, stub } from 'sinon';
import {
act,
createRenderer,
createMount,
describeConformanceUnstyled,
fireEvent,
screen,
} from '@mui-internal/test-utils';
import { act, createRenderer, createMount, fireEvent, screen } from '@mui-internal/test-utils';
import {
Slider,
sliderClasses as classes,
SliderRootSlotProps,
SliderValueLabelSlotProps,
} from '@mui/base/Slider';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

type Touches = Array<Pick<Touch, 'identifier' | 'clientX' | 'clientY'>>;

Expand Down
9 changes: 2 additions & 7 deletions packages/mui-base/src/Snackbar/Snackbar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import {
act,
createRenderer,
createMount,
describeConformanceUnstyled,
fireEvent,
} from '@mui-internal/test-utils';
import { act, createRenderer, createMount, fireEvent } from '@mui-internal/test-utils';
import { Snackbar, snackbarClasses as classes } from '@mui/base/Snackbar';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<Snackbar />', () => {
const { clock, render: clientRender } = createRenderer({ clock: 'fake' });
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-base/src/Switch/Switch.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from '@mui-internal/test-utils';
import { createMount, createRenderer } from '@mui-internal/test-utils';
import { expect } from 'chai';
import { Switch, SwitchOwnerState, switchClasses } from '@mui/base/Switch';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<Switch />', () => {
const mount = createMount();
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-base/src/Tab/Tab.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from '@mui-internal/test-utils';
import { createMount, createRenderer } from '@mui-internal/test-utils';
import { Tab, tabClasses } from '@mui/base/Tab';
import { TabsListProvider, TabsListProviderValue } from '../useTabsList';
import { TabsContext } from '../Tabs';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<Tab />', () => {
const mount = createMount();
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-base/src/TabPanel/TabPanel.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from '@mui-internal/test-utils';
import { createMount, createRenderer } from '@mui-internal/test-utils';
import { TabPanel, tabPanelClasses } from '@mui/base/TabPanel';
import { TabsProvider, TabsProviderValue } from '../useTabs';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<TabPanel />', () => {
const mount = createMount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import PropTypes from 'prop-types';
import {
describeConformanceUnstyled,
fireEvent,
createRenderer,
createMount,
} from '@mui-internal/test-utils';
import { fireEvent, createRenderer, createMount } from '@mui-internal/test-utils';
import {
TablePagination,
tablePaginationClasses as classes,
LabelDisplayedRowsArgs,
} from '@mui/base/TablePagination';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

interface WithClassName {
className: string;
Expand Down
10 changes: 2 additions & 8 deletions packages/mui-base/src/Tabs/Tabs.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import {
describeConformanceUnstyled,
act,
createRenderer,
fireEvent,
screen,
createMount,
} from '@mui-internal/test-utils';
import { act, createRenderer, fireEvent, screen, createMount } from '@mui-internal/test-utils';
import { Tab } from '@mui/base/Tab';
import { Tabs, tabsClasses as classes, TabsProps } from '@mui/base/Tabs';
import { TabsList } from '@mui/base/TabsList';
import { TabPanel } from '@mui/base/TabPanel';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<Tabs />', () => {
const mount = createMount();
Expand Down
8 changes: 2 additions & 6 deletions packages/mui-base/src/TabsList/TabsList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import * as React from 'react';
import {
act,
createMount,
createRenderer,
describeConformanceUnstyled,
} from '@mui-internal/test-utils';
import { act, createMount, createRenderer } from '@mui-internal/test-utils';
import { Tab } from '@mui/base/Tab';
import { Tabs, TabsContext } from '@mui/base/Tabs';
import { TabsList, tabsListClasses } from '@mui/base/TabsList';
import { expect } from 'chai';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

describe('<TabsList />', () => {
const { render } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';
import { expect } from 'chai';
import sinon, { spy, stub } from 'sinon';
import {
describeConformanceUnstyled,
act,
screen,
waitFor,
Expand All @@ -11,6 +10,7 @@ import {
fireEvent,
} from '@mui-internal/test-utils';
import { TextareaAutosize } from '@mui/base/TextareaAutosize';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

function getStyleValue(value: string) {
return parseInt(value, 10) || 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import userEvent from '@testing-library/user-event';
import {
act,
createMount,
createRenderer,
describeConformanceUnstyled,
fireEvent,
} from '@mui-internal/test-utils';
import { act, createMount, createRenderer, fireEvent } from '@mui-internal/test-utils';
import {
Unstable_NumberInput as NumberInput,
numberInputClasses,
NumberInputOwnerState,
NumberInputIncrementButtonSlotProps,
NumberInputDecrementButtonSlotProps,
} from '@mui/base/Unstable_NumberInput';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

// 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
10 changes: 2 additions & 8 deletions packages/mui-base/src/Unstable_Popup/Popup.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import * as React from 'react';
import { expect } from 'chai';
import {
act,
createRenderer,
createMount,
describeConformanceUnstyled,
screen,
fireEvent,
} from '@mui-internal/test-utils';
import { act, createRenderer, createMount, screen, fireEvent } from '@mui-internal/test-utils';
import { Unstable_Popup as Popup, popupClasses, PopupProps } from '@mui/base/Unstable_Popup';
import { PopupContext } from './PopupContext';
import { useTransitionStateManager } from '../useTransition';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

const TRANSITION_DURATION = 100;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import * as React from 'react';
import { expect } from 'chai';
import { ClassNameConfigurator } from '@mui/base/utils';
import { MuiRenderResult, RenderOptions, screen } from './createRenderer';
import createDescribe from './createDescribe';
import {
MuiRenderResult,
RenderOptions,
screen,
createDescribe,
ConformanceOptions,
SlotTestingOptions,
describeRef,
randomStringValue,
testClassName,
testComponentProp,
testReactTestRenderer,
} from './describeConformance';
} from '@mui-internal/test-utils';
import { ClassNameConfigurator } from '@mui/base/utils';

export interface UnstyledConformanceOptions
extends Omit<Partial<ConformanceOptions>, 'render' | 'skip' | 'classes'> {
Expand Down Expand Up @@ -391,7 +393,7 @@ const fullSuite = {
disableClassGeneration: testDisablingClassGeneration,
};

function describeConformanceUnstyled(
function describeConformance(
minimalElement: React.ReactElement,
getOptions: () => UnstyledConformanceOptions,
) {
Expand All @@ -410,4 +412,6 @@ function describeConformanceUnstyled(
});
}

export default createDescribe('MUI unstyled component API', describeConformanceUnstyled);
const describeConformanceUnstyled = createDescribe('Base UI component API', describeConformance);

export { describeConformanceUnstyled };
Loading
Loading