Skip to content

Commit

Permalink
[test] Do not enforce the presence of ownerState.className in `desc…
Browse files Browse the repository at this point in the history
…ribeConformance` (#44479)
  • Loading branch information
flaviendelangle authored Nov 22, 2024
1 parent 7be6a2e commit 6894dfa
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 2 deletions.
35 changes: 34 additions & 1 deletion packages-internal/test-utils/src/describeConformance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,33 @@ function testSlotPropsCallback(

forEachSlot(slots, (slotName) => {
it(`sets custom properties on the ${slotName} slot's element with the slotProps.${slotName} callback`, async () => {
const slotProps = {
[slotName]: () => ({
'data-testid': 'custom',
}),
};

const { queryByTestId } = await render(
React.cloneElement(element, { slotProps, className: 'custom' }),
);
const slotComponent = queryByTestId('custom');
expect(slotComponent).not.to.equal(null);
});
});
}

function testSlotPropsCallbackWithPropsAsOwnerState(
element: React.ReactElement<any>,
getOptions: () => ConformanceOptions,
) {
const { render, slots } = getOptions();

if (!render) {
throwMissingPropError('render');
}

forEachSlot(slots, (slotName) => {
it(`sets custom properties on the ${slotName} slot's element with the slotProps.${slotName} callback using the ownerState`, async () => {
const slotProps = {
[slotName]: (ownerState: Record<string, any>) => ({
'data-testid': ownerState.className,
Expand Down Expand Up @@ -1068,6 +1095,7 @@ const fullSuite = {
rootClass: testRootClass,
slotPropsProp: testSlotPropsProp,
slotPropsCallback: testSlotPropsCallback,
slotPropsCallbackWithPropsAsOwnerState: testSlotPropsCallbackWithPropsAsOwnerState,
slotsProp: testSlotsProp,
themeDefaultProps: testThemeDefaultProps,
themeStyleOverrides: testThemeStyleOverrides,
Expand Down Expand Up @@ -1120,7 +1148,12 @@ function describeConformance(
(testKey) => only.includes(testKey) && !skip.includes(testKey as keyof typeof fullSuite),
) as (keyof typeof fullSuite)[];

const slotBasedTests = ['slotsProp', 'slotPropsProp', 'slotPropsCallback'];
const slotBasedTests = [
'slotsProp',
'slotPropsProp',
'slotPropsCallback',
'slotPropsCallbackWithPropsAsOwnerState',
];

if (!slots) {
// if `slots` are not defined, do not run tests that depend on them
Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/FilledInput/FilledInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('<FilledInput />', () => {
'componentProp',
'componentsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Input/Input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('<Input />', () => {
'componentProp',
'componentsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/InputBase/InputBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('<InputBase />', () => {
skip: [
'componentProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/ListItem/ListItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('<ListItem />', () => {
skip: [
'componentsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('<OutlinedInput />', () => {
'componentProp',
'componentsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('<PaginationItem />', () => {
'slotsProp',
'slotPropsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Popper/Popper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('<Popper />', () => {
'themeStyleOverrides',
'themeVariants',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}));

Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Slider/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('<Slider />', () => {
},
skip: [
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}),
);
Expand Down
7 changes: 6 additions & 1 deletion packages/mui-material/src/TextField/TextField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ describe('<TextField />', () => {
testWithElement: null,
},
},
only: ['slotsProp', 'slotPropsProp', 'slotPropsCallback'],
only: [
'slotsProp',
'slotPropsProp',
'slotPropsCallback', // not supported yet
'slotPropsCallbackWithPropsAsOwnerState', // not supported yet
],
}),
);

Expand Down

0 comments on commit 6894dfa

Please sign in to comment.