Skip to content

Commit

Permalink
Remove mount from describeConformance
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoAndai committed May 30, 2024
1 parent 9bb12bf commit b711d40
Show file tree
Hide file tree
Showing 16 changed files with 1 addition and 111 deletions.
32 changes: 1 addition & 31 deletions packages-internal/test-utils/src/describeConformance.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/* eslint-env mocha */
import * as React from 'react';
import { expect } from 'chai';
import { ReactWrapper } from 'enzyme';
import ReactTestRenderer from 'react-test-renderer';
import createMount from './createMount';
import createDescribe from './createDescribe';
import findOutermostIntrinsic from './findOutermostIntrinsic';
import { MuiRenderResult } from './createRenderer';

function capitalize(string: string): string {
Expand Down Expand Up @@ -46,7 +43,6 @@ export interface ConformanceOptions {
after?: () => void;
inheritComponent?: React.ElementType;
render: (node: React.ReactElement<any>) => MuiRenderResult;
mount?: (node: React.ReactElement<any>) => ReactWrapper;
only?: Array<keyof typeof fullSuite>;
skip?: Array<keyof typeof fullSuite | 'classesRoot'>;
testComponentsRootPropWith?: string;
Expand All @@ -66,9 +62,6 @@ export interface ConformanceOptions {
testCustomVariant?: boolean;
testVariantProps?: object;
testLegacyComponentsProp?: boolean;
wrapMount?: (
mount: (node: React.ReactElement<any>) => ReactWrapper,
) => (node: React.ReactElement<any>) => ReactWrapper;
slots?: Record<string, SlotTestingOptions>;
ThemeProvider?: React.ElementType;
createTheme?: (arg: any) => any;
Expand All @@ -83,18 +76,6 @@ export interface ConformanceOptions {
* - has the type of `inheritComponent`
*/

/**
* Returns the component with the same constructor as `component` that renders
* the outermost host
*/
export function findRootComponent(wrapper: ReactWrapper, component: string | React.ElementType) {
const outermostHostElement = findOutermostIntrinsic(wrapper).getElement();

return wrapper.find(component as string).filterWhere((componentWrapper) => {
return componentWrapper.contains(outermostHostElement);
});
}

export function randomStringValue() {
return `s${Math.random().toString(36).slice(2)}`;
}
Expand Down Expand Up @@ -1076,7 +1057,6 @@ function describeConformance(
only = Object.keys(fullSuite),
slots,
skip = [],
wrapMount,
} = getOptions();

let filteredTests = Object.keys(fullSuite).filter(
Expand All @@ -1091,21 +1071,11 @@ function describeConformance(
filteredTests = filteredTests.filter((testKey) => !slotBasedTests.includes(testKey));
}

const baseMount = createMount();
const mount = wrapMount !== undefined ? wrapMount(baseMount) : baseMount;

after(runAfterHook);

function getTestOptions(): ConformanceOptions {
return {
...getOptions(),
mount,
};
}

filteredTests.forEach((testKey) => {
const test = fullSuite[testKey];
test(minimalElement, getTestOptions);
test(minimalElement, getOptions);
});
}

Expand Down
6 changes: 0 additions & 6 deletions packages/mui-joy/src/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ describe('Joy <Menu />', () => {
<DropdownContext.Provider value={testContext}>{node}</DropdownContext.Provider>,
);
},
wrapMount: (mount) => (node: React.ReactNode) => {
const wrapper = mount(
<DropdownContext.Provider value={testContext}>{node}</DropdownContext.Provider>,
);
return wrapper.childAt(0);
},
ThemeProvider,
muiName: 'JoyMenu',
refInstanceof: window.HTMLUListElement,
Expand Down
6 changes: 0 additions & 6 deletions packages/mui-joy/src/MenuButton/MenuButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ describe('<MenuButton />', () => {
describeConformance(<MenuButton />, () => ({
classes,
inheritComponent: 'button',
wrapMount: (mount) => (node: React.ReactNode) => {
const wrapper = mount(
<DropdownContext.Provider value={testContext}>{node}</DropdownContext.Provider>,
);
return wrapper.childAt(0);
},
muiName: 'JoyMenuButton',
refInstanceof: window.HTMLButtonElement,
render: (node) => {
Expand Down
4 changes: 0 additions & 4 deletions packages/mui-joy/src/MenuItem/MenuItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ describe('Joy <MenuItem />', () => {
classes,
inheritComponent: ListItemButton,
render: (node) => render(<MenuProvider value={testContext}>{node}</MenuProvider>),
wrapMount: (mount) => (node) => {
const wrapper = mount(<MenuProvider value={testContext}>{node}</MenuProvider>);
return wrapper.childAt(0);
},
ThemeProvider,
refInstanceof: window.HTMLLIElement,
testComponentPropWith: 'a',
Expand Down
1 change: 0 additions & 1 deletion packages/mui-joy/src/Tab/Tab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('Joy <Tab />', () => {
classes,
inheritComponent: 'button',
render: (node) => render(<TabsProvider defaultValue={0}>{node}</TabsProvider>),
wrapMount: (mount) => (node) => mount(<TabsProvider defaultValue={0}>{node}</TabsProvider>),
ThemeProvider,
muiName: 'JoyTab',
refInstanceof: window.HTMLButtonElement,
Expand Down
1 change: 0 additions & 1 deletion packages/mui-joy/src/TabList/TabList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('Joy <TabList />', () => {
classes,
inheritComponent: 'div',
render: (node) => render(<TabsProvider defaultValue={0}>{node}</TabsProvider>),
wrapMount: (mount) => (node) => mount(<TabsProvider defaultValue={0}>{node}</TabsProvider>),
ThemeProvider,
muiName: 'JoyTabList',
refInstanceof: window.HTMLDivElement,
Expand Down
1 change: 0 additions & 1 deletion packages/mui-joy/src/TabPanel/TabPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('Joy <TabPanel />', () => {
classes,
inheritComponent: 'div',
render: (node) => render(<TabsProvider defaultValue={0}>{node}</TabsProvider>),
wrapMount: (mount) => (node) => mount(<TabsProvider defaultValue={0}>{node}</TabsProvider>),
ThemeProvider,
muiName: 'JoyTabPanel',
refInstanceof: window.HTMLDivElement,
Expand Down
4 changes: 0 additions & 4 deletions packages/mui-lab/src/TabList/TabList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ describe('<TabList />', () => {
* @param {React.ReactNode} node
*/
render: (node) => render(<TabContext value="0">{node}</TabContext>),
wrapMount: (mount) => (node) => {
const wrapper = mount(<TabContext value="0">{node}</TabContext>);
return wrapper.childAt(0);
},
refInstanceof: window.HTMLDivElement,
// TODO: no idea why reactTestRenderer fails
skip: [
Expand Down
1 change: 0 additions & 1 deletion packages/mui-lab/src/TabPanel/TabPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('<TabPanel />', () => {
classes,
inheritComponent: 'div',
render: (node) => render(<TabContext value="0">{node}</TabContext>),
wrapMount: (mount) => (node) => mount(<TabContext value="0">{node}</TabContext>),
refInstanceof: window.HTMLDivElement,
muiName: 'MuiTabPanel',
skip: [
Expand Down
16 changes: 0 additions & 16 deletions packages/mui-material/src/StepContent/StepContent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@ describe('<StepContent />', () => {
describeConformance(<StepContent />, () => ({
classes,
inheritComponent: 'div',
wrapMount: (mount) => (node) => {
const wrapper = mount(
<Stepper orientation="vertical">
<Step>{node}</Step>
</Stepper>,
);
// `wrapper.find(Step)` tree.
// "->" indicates the path we want
// "n:" indicates the index
// <ForwardRef(Step)>
// -> 0: <MuiStepRoot>
// 0: <Noop /> // from Emotion
// -> 1: <div className="MuiStep-root">
// -> 0: <MuiStepContentRoot />
return wrapper.find(Step).childAt(0).childAt(1).childAt(0);
},
muiName: 'MuiStepContent',
refInstanceof: window.HTMLDivElement,
render: (node) => {
Expand Down
4 changes: 0 additions & 4 deletions packages/mui-material/src/TableBody/TableBody.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ describe('<TableBody />', () => {
describeConformance(<TableBody />, () => ({
classes,
inheritComponent: 'tbody',
wrapMount: (mount) => (node) => {
const wrapper = mount(<table>{node}</table>);
return wrapper.find('table').childAt(0);
},
render: (node) => {
const { container, ...other } = render(<table>{node}</table>);
return { container: container.firstChild, ...other };
Expand Down
10 changes: 0 additions & 10 deletions packages/mui-material/src/TableCell/TableCell.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ describe('<TableCell />', () => {
);
return { container: container.firstChild.firstChild.firstChild, ...other };
},
wrapMount: (mount) => (node) => {
const wrapper = mount(
<table>
<tbody>
<tr>{node}</tr>
</tbody>
</table>,
);
return wrapper.find('tr').childAt(0);
},
muiName: 'MuiTableCell',
testVariantProps: { variant: 'body' },
refInstanceof: window.HTMLTableCellElement,
Expand Down
4 changes: 0 additions & 4 deletions packages/mui-material/src/TableFooter/TableFooter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ describe('<TableFooter />', () => {
const { container, ...other } = render(<table>{node}</table>);
return { container: container.firstChild, ...other };
},
wrapMount: (mount) => (node) => {
const wrapper = mount(<table>{node}</table>);
return wrapper.find('table').childAt(0);
},
muiName: 'MuiTableFooter',
testVariantProps: { variant: 'foo' },
refInstanceof: window.HTMLTableSectionElement,
Expand Down
4 changes: 0 additions & 4 deletions packages/mui-material/src/TableHead/TableHead.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ describe('<TableHead />', () => {
describeConformance(<TableHead />, () => ({
classes,
inheritComponent: 'thead',
wrapMount: (mount) => (node) => {
const wrapper = mount(<table>{node}</table>);
return wrapper.find('table').childAt(0);
},
render: (node) => {
const { container, ...other } = render(<table>{node}</table>);
return { container: container.firstChild, ...other };
Expand Down
10 changes: 0 additions & 10 deletions packages/mui-material/src/TablePagination/TablePagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ describe('<TablePagination />', () => {
);
return { container: container.firstChild.firstChild.firstChild, ...other };
},
wrapMount: (mount) => (node) => {
const wrapper = mount(
<table>
<tbody>
<tr>{node}</tr>
</tbody>
</table>,
);
return wrapper.find('tr').childAt(0);
},
muiName: 'MuiTablePagination',
refInstanceof: window.HTMLTableCellElement,
testComponentPropWith: 'td',
Expand Down
8 changes: 0 additions & 8 deletions packages/mui-material/src/TableRow/TableRow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ describe('<TableRow />', () => {
);
return { container: container.firstChild.firstChild, ...other };
},
wrapMount: (mount) => (node) => {
const wrapper = mount(
<table>
<tbody>{node}</tbody>
</table>,
);
return wrapper.find('tbody').childAt(0);
},
muiName: 'MuiTableRow',
testVariantProps: { variant: 'foo' },
refInstanceof: window.HTMLTableRowElement,
Expand Down

0 comments on commit b711d40

Please sign in to comment.