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] Scope the tests to just Material UI components #35219

Merged
merged 24 commits into from Nov 29, 2022

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Nov 21, 2022

The current conformance test suite makes it hard to test slots prop on Joy UI components #34997 because it is used in Material UI tests.

This PR moves the slots to components so that it reflects only Material UI components. This will make the transition to slots prop easier for Material UI because, in v6, the slots prop will behave the same as Joy UI.

Changes

// mui-material/src/Alert/Alert.test.js
describeConformance({
   ...
-   slots: { root: { ... } } 
+   components: { root: { ... } }
})

The future

#34997

Joy UI will run the slots prop tests which are separate from the current Material UI tests, allow them to coexist in the same describeConformance.

// describeConformance.js
function testSlotsProp() {
  ...test Joy UI and Material UI v6 (in the future)
}

function testSlotPropsProp() {
  ...test Joy UI and Material UI v6 (in the future)
}
// mui-joy/src/Alert/Alert.test.tsx
describeConformance({
   ...
+   slots: { root: { ... } } 
})

v6

Material UI: add slots key to conformance which runs the same tests as Joy UI. components tests remain the same.

describeConformance({
   ...
+   slots: { root: { ... } } 
})

v7

Material UI: remove components tests because it is removed from the prop.

describeConformance({
   ...
-   components: { root: { ... } } 
})

@mui-bot
Copy link

mui-bot commented Nov 21, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-35219--material-ui.netlify.app/

No bundle size changes

Generated by 🚫 dangerJS against 0faa8b3

});
} else {
// eslint-disable-next-line react/prop-types
const CustomComponent = React.forwardRef(({ className }, ref) => (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below are the same tests from #34873

@zannager zannager added the test label Nov 21, 2022
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 22, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 23, 2022
@siriwatknp
Copy link
Member Author

@michaldudak Could you take a quick look at this? The change might be hard to review but it is all about moving the tests to Material UI scope so that I can add similar tests for Joy UI.

The idea is to have a smooth transition for Material UI tests in v6, v7.

@hbjORbj
Copy link
Member

hbjORbj commented Nov 23, 2022

I agree with the idea completely. Does this PR change slots back to components in conformance test suite for all material components?


if (!components) {
// if `components` are not defined, do not run tests that depend on them
filteredTests = filteredTests.filter((testKey) => !['componentsPropsProp'].includes(testKey));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about componentsProp?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those tests are in function testMaterialUIComponentsPropsProp().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we will need another big refactoring but that can be done in a separate PR.

@@ -41,6 +41,7 @@ export interface InputConformanceOptions {
mount: (node: React.ReactNode) => ReactWrapper,
) => (node: React.ReactNode) => ReactWrapper;
slots?: Record<string, SlotTestingOptions>;
components?: Record<string, SlotTestingOptions>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave a comment explaining the current usage of components and slots?
e.g.,
slots are for Material UI v6 and Joy UI
components are for Material UI v6; Expected to be removed from v7

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

Copy link
Member

@hbjORbj hbjORbj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments.

Signed-off-by: Siriwat K <siriwatkunaporn@gmail.com>
@michaldudak
Copy link
Member

This will make the transition to slots prop easier for Material UI because, in v6, the slots prop will behave the same as Joy UI.

What's the difference between Material UI v5 and Joy in terms of the slots prop currently?

@siriwatknp
Copy link
Member Author

siriwatknp commented Nov 25, 2022

This will make the transition to slots prop easier for Material UI because, in v6, the slots prop will behave the same as Joy UI.

What's the difference between Material UI v5 and Joy in terms of the slots prop currently?

For slots prop, the name of the slot is in camel case for Joy UI, but Material UI uses PascalCase.

For slotProps prop:

  1. Joy UI supports callback (ownerState) => ... whereas Material UI does not.
  2. Joy UI supports slotProps: { $slot: { component: '...' }} whereas Material UI does not.

With the above conditions, mixing both packages in the same test suite would create a lot of if-else which is not good for maintainability and transition for Material UI.

@michaldudak
Copy link
Member

The idea for the slots/slotProps is to be as similar between products as possible, even today.

For slots prop, the name of the slot is in camel case for Joy UI, but Material UI uses PascalCase.

That's not true. Material UI components use camelCase as well:

https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Alert/Alert.d.ts#L114-L116
https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Backdrop/Backdrop.d.ts#L73-L75
etc.

Joy UI supports callback (ownerState) => ... whereas Material UI does not.
Joy UI supports slotProps: { $slot: { component: '...' }} whereas Material UI does not.

This isn't something that needs v6 to be implemented.
We can add a separate test that verifies if the callback work and add them to the skip array in components that don't have it implemented yet. This would allow us to easily spot which Material UI components do not conform with the standard yet and what needs to be done to make them conformant (it would be finer-grained control).

@siriwatknp
Copy link
Member Author

That's not true. Material UI components use camelCase as well:

My bad, I meant Material UI components prop.

This isn't something that needs v6 to be implemented.
We can add a separate test that verifies if the callback work and add them to the skip array in components that don't have it implemented yet. This would allow us to easily spot which Material UI components do not conform with the standard yet and what needs to be done to make them conformant (it would be finer-grained control).

Okay, I got your point. Will update the PR but won't include implementation to support callback, is this align with you?

@michaldudak
Copy link
Member

I'd say we should leave the slots prop in conformance tests as they were previously, add a test that verifies the slotProps as callbacks (and skip them in Material UI components), and perhaps add a flag testLegacyComponentsProp that would determine if the tests should take into consideration the older components/componentsProps prop (this could be false by default and only set in Material UI tests).

@siriwatknp
Copy link
Member Author

I'd say we should leave the slots prop in conformance tests as they were previously, add a test that verifies the slotProps as callbacks (and skip them in Material UI components), and perhaps add a flag testLegacyComponentsProp that would determine if the tests should take into consideration the older components/componentsProps prop (this could be false by default and only set in Material UI tests).

Updated!

'componentsProp',
'slotsProp',
'reactTestRenderer',
'slotPropsCallback',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a comment to explain why this is skipped (for all instances)? // not supported yet should be enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks for asking.

});
}

function testSlotPropsCallback(element: React.ReactElement, getOptions: () => ConformanceOptions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@siriwatknp siriwatknp merged commit 0c7a5cb into mui:master Nov 29, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
feliperli pushed a commit to jesrodri/material-ui that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants