Skip to content

Commit 5cf5b9f

Browse files
[code-infra] Remove components and componentsProps test from describeConformance for Material UI v9 (#1244)
Co-authored-by: Jan Potoms <2109932+Janpot@users.noreply.github.com>
1 parent 8041849 commit 5cf5b9f

1 file changed

Lines changed: 2 additions & 206 deletions

File tree

packages/test-utils/src/describeConformance.tsx

Lines changed: 2 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import createDescribe from './createDescribe';
55
import { MuiRenderResult } from './createRenderer';
66
import { isJsdom } from './env';
77

8-
function capitalize(string: string): string {
9-
return string.charAt(0).toUpperCase() + string.slice(1);
10-
}
11-
128
interface DataProps {
139
[key: `data-${string}`]: string;
1410
}
@@ -65,7 +61,6 @@ export interface ConformanceOptions {
6561
testStateOverrides?: { prop?: string; value?: any; styleKey: string };
6662
testCustomVariant?: boolean;
6763
testVariantProps?: object;
68-
testLegacyComponentsProp?: boolean | string[];
6964
slots?: Record<string, SlotTestingOptions>;
7065
ThemeProvider?: React.ElementType;
7166
/**
@@ -303,26 +298,13 @@ function testSlotsProp(
303298
} & React.RefAttributes<HTMLDivElement>
304299
>;
305300
};
306-
components?: {
307-
[x: string]:
308-
| SlotTestingOptions['testWithComponent']
309-
| keyof React.JSX.IntrinsicElements
310-
| React.ForwardRefExoticComponent<
311-
{
312-
children: React.ReactNode;
313-
} & React.RefAttributes<HTMLDivElement>
314-
>;
315-
};
316301
slotProps: {
317302
[x: string]: DataProps;
318303
};
319-
componentsProps?: {
320-
[x: string]: DataProps;
321-
};
322304
}>,
323305
getOptions: () => ConformanceOptions,
324306
) {
325-
const { render, slots, testLegacyComponentsProp } = getOptions();
307+
const { render, slots } = getOptions();
326308

327309
const CustomComponent = React.forwardRef<
328310
HTMLElement,
@@ -386,127 +368,16 @@ function testSlotsProp(
386368
}
387369
});
388370
}
389-
390-
// For testing Material UI components v5, and v6. Likely to be removed in a future major release.
391-
if (
392-
testLegacyComponentsProp === true ||
393-
(Array.isArray(testLegacyComponentsProp) && testLegacyComponentsProp.includes(slotName))
394-
) {
395-
it(`allows overriding the ${slotName} slot with a component using the components.${capitalize(
396-
slotName,
397-
)} prop`, async () => {
398-
if (!render) {
399-
throwMissingPropError('render');
400-
}
401-
402-
const slotComponent = slotOptions.testWithComponent ?? CustomComponent;
403-
404-
const components = {
405-
[capitalize(slotName)]: slotComponent,
406-
};
407-
408-
const { queryByTestId } = await render(React.cloneElement(element, { components }));
409-
const renderedElement = queryByTestId('custom');
410-
expect(renderedElement).not.to.equal(null);
411-
if (slotOptions.expectedClassName) {
412-
expect(renderedElement).to.have.class(slotOptions.expectedClassName);
413-
}
414-
});
415-
416-
it(`prioritizes the 'slots.${slotName}' over components.${capitalize(
417-
slotName,
418-
)} if both are defined`, async () => {
419-
if (!render) {
420-
throwMissingPropError('render');
421-
}
422-
423-
const ComponentForComponentsProp = React.forwardRef<
424-
HTMLDivElement,
425-
{ children: React.ReactNode }
426-
>(({ children }, ref) => {
427-
const SlotComponent = slotOptions.testWithComponent ?? 'div';
428-
return (
429-
<SlotComponent ref={ref} data-testid="from-components">
430-
{children}
431-
</SlotComponent>
432-
);
433-
});
434-
435-
const ComponentForSlotsProp = React.forwardRef<
436-
HTMLDivElement,
437-
{ children: React.ReactNode }
438-
>(({ children }, ref) => {
439-
const SlotComponent = slotOptions.testWithComponent ?? 'div';
440-
return (
441-
<SlotComponent ref={ref} data-testid="from-slots">
442-
{children}
443-
</SlotComponent>
444-
);
445-
});
446-
447-
const components = {
448-
[capitalize(slotName)]: ComponentForComponentsProp,
449-
};
450-
451-
const slotOverrides = {
452-
[slotName]: ComponentForSlotsProp,
453-
};
454-
455-
const { queryByTestId } = await render(
456-
React.cloneElement(element, { components, slots: slotOverrides }),
457-
);
458-
459-
expect(queryByTestId('from-slots')).not.to.equal(null);
460-
expect(queryByTestId('from-components')).to.equal(null);
461-
});
462-
463-
if (slotOptions.testWithElement !== null) {
464-
it(`allows overriding the ${slotName} slot with an element using the components.${capitalize(
465-
slotName,
466-
)} prop`, async () => {
467-
if (!render) {
468-
throwMissingPropError('render');
469-
}
470-
471-
const slotElement = slotOptions.testWithElement ?? 'i';
472-
473-
const components = {
474-
[capitalize(slotName)]: slotElement,
475-
};
476-
477-
const componentsProps = {
478-
[slotName]: {
479-
'data-testid': 'customized',
480-
},
481-
};
482-
483-
const { queryByTestId } = await render(
484-
React.cloneElement(element, { components, componentsProps }),
485-
);
486-
487-
const renderedElement = queryByTestId('customized');
488-
expect(renderedElement).not.to.equal(null);
489-
490-
if (typeof slotElement === 'string') {
491-
expect(renderedElement!.nodeName.toLowerCase()).to.equal(slotElement);
492-
}
493-
if (slotOptions.expectedClassName) {
494-
expect(renderedElement).to.have.class(slotOptions.expectedClassName);
495-
}
496-
});
497-
}
498-
}
499371
});
500372
}
501373

502374
function testSlotPropsProp(
503375
element: React.ReactElement<{
504-
componentsProps?: Record<string, DataProps>;
505376
slotProps: Record<string, DataProps>;
506377
}>,
507378
getOptions: () => ConformanceOptions,
508379
) {
509-
const { render, slots, testLegacyComponentsProp } = getOptions();
380+
const { render, slots } = getOptions();
510381

511382
if (!render) {
512383
throwMissingPropError('render');
@@ -544,50 +415,6 @@ function testSlotPropsProp(
544415
expect(getByTestId('custom')).to.have.class(slotProps[slotName].className);
545416
});
546417
}
547-
548-
if (
549-
testLegacyComponentsProp === true ||
550-
(Array.isArray(testLegacyComponentsProp) && testLegacyComponentsProp.includes(slotName))
551-
) {
552-
it(`sets custom properties on the ${slotName} slot's element with the componentsProps.${slotName} prop`, async () => {
553-
const componentsProps = {
554-
[slotName]: {
555-
'data-testid': 'custom',
556-
},
557-
};
558-
559-
const { queryByTestId } = await render(React.cloneElement(element, { componentsProps }));
560-
const slotComponent = queryByTestId('custom');
561-
expect(slotComponent).not.to.equal(null);
562-
563-
if (slotOptions.expectedClassName) {
564-
expect(slotComponent).to.have.class(slotOptions.expectedClassName);
565-
}
566-
});
567-
568-
it(`prioritizes the 'slotProps.${slotName}' over componentsProps.${slotName} if both are defined`, async () => {
569-
const componentsProps = {
570-
[slotName]: {
571-
'data-testid': 'custom',
572-
'data-from-components-props': 'true',
573-
},
574-
};
575-
576-
const slotProps = {
577-
[slotName]: {
578-
'data-testid': 'custom',
579-
'data-from-slot-props': 'true',
580-
},
581-
};
582-
583-
const { queryByTestId } = await render(
584-
React.cloneElement(element, { componentsProps, slotProps }),
585-
);
586-
const slotComponent = queryByTestId('custom');
587-
expect(slotComponent).to.have.attribute('data-from-slot-props', 'true');
588-
expect(slotComponent).not.to.have.attribute('data-from-components-props');
589-
});
590-
}
591418
});
592419
}
593420

@@ -651,36 +478,6 @@ function testSlotPropsCallbackWithPropsAsOwnerState(
651478
});
652479
}
653480

654-
/**
655-
* MUI components have a `components` prop that allows rendering a different
656-
* Components from @inheritComponent
657-
*/
658-
function testComponentsProp(
659-
element: React.ReactElement<
660-
{
661-
components?: Record<string, string>;
662-
} & DataProps
663-
>,
664-
getOptions: () => ConformanceOptions,
665-
) {
666-
describe('prop components:', () => {
667-
it('can render another root component with the `components` prop', async () => {
668-
const { render, testComponentsRootPropWith: component = 'em' } = getOptions();
669-
if (!render) {
670-
throwMissingPropError('render');
671-
}
672-
673-
const testId = randomStringValue();
674-
675-
const { getByTestId } = await render(
676-
React.cloneElement(element, { components: { Root: component }, 'data-testid': testId }),
677-
);
678-
expect(getByTestId(testId)).not.to.equal(null);
679-
expect(getByTestId(testId).nodeName.toLowerCase()).to.eq(component);
680-
});
681-
});
682-
}
683-
684481
/**
685482
* MUI theme has a components section that allows specifying default props.
686483
* Components from @inheritComponent
@@ -1142,7 +939,6 @@ function testThemeCustomPalette(
1142939

1143940
const fullSuite = {
1144941
componentProp: testComponentProp,
1145-
componentsProp: testComponentsProp,
1146942
mergeClassName: testClassName,
1147943
propsSpread: testPropsSpread,
1148944
refForwarding: describeRef,

0 commit comments

Comments
 (0)