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

DataForm: add unit tests #68054

Merged
merged 4 commits into from
Dec 18, 2024
Merged

DataForm: add unit tests #68054

merged 4 commits into from
Dec 18, 2024

Conversation

gigitux
Copy link
Contributor

@gigitux gigitux commented Dec 17, 2024

What?

PR Description

This PR introduces unit tests for the DataForm component, covering the following use cases:

  • Panel mode
  • Regular mode
  • Combined fields
  • Custom Edit component
  • Custom render component
  • onChange callback testing

Also, this PR improves the tsconfig.json to ensure that js test files are skipped.

Why?

How?

Testing Instructions

Ensure that unit test job is green.

Testing Instructions for Keyboard

Screenshots or screencast

Before After

@gigitux gigitux force-pushed the add/unit-test-datafrom branch from a42b3c4 to bc4b839 Compare December 17, 2024 15:39
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied pasted the changes from

@gigitux gigitux changed the title DataForm: add unit test DataForm: add unit tests Dec 17, 2024
@gigitux gigitux self-assigned this Dec 17, 2024
@gigitux gigitux added [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] DataViews /packages/dataviews labels Dec 17, 2024
@gigitux gigitux added the [Type] Code Quality Issues or PRs that relate to code quality label Dec 17, 2024
@gigitux gigitux marked this pull request as ready for review December 17, 2024 17:55
Copy link

github-actions bot commented Dec 17, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: gigitux <gigitux@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

github-actions bot commented Dec 17, 2024

Flaky tests detected in 238f654.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12391474800
📝 Reported issues:

it( 'should display fields', () => {
render(
<Dataform
onChange={ () => void 0 }
Copy link
Member

Choose a reason for hiding this comment

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

Why not just using () => {} as a noop? The void operator is not very common in our codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sense. Fixed with 238f654.

Comment on lines 145 to 160
it( 'should wrap fields in HStack when labelPosition is set to side', async () => {
const { container } = render(
<Dataform
onChange={ () => void 0 }
fields={ fields }
form={ { ...form, labelPosition: 'side' } }
data={ data }
/>
);

expect(
// It is used here to ensure that the fields are wrapped in HStack. This happens when the labelPosition is set to side.
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
container.querySelectorAll( "[data-wp-component='HStack']" )
).toHaveLength( 3 );
} );
Copy link
Member

Choose a reason for hiding this comment

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

This kind test is too implementation-specific in my view. We're testing a specific HTML output that we may need to change. Personally, I find tests more useful when they test the API. Don't feel you need to remove it, but I find it a bit fragile.

Copy link
Contributor Author

@gigitux gigitux Dec 18, 2024

Choose a reason for hiding this comment

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

💯 agree with you, but I didn't find a better way to test this behavior.

Copy link
Member

@oandregal oandregal left a comment

Choose a reason for hiding this comment

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

Thanks. It'd be great to have some e2e tests for the QuickEdit experiment as well :)

@gigitux
Copy link
Contributor Author

gigitux commented Dec 18, 2024

Thanks. It'd be great to have some e2e tests for the QuickEdit experiment as well :)

Thanks for the review! I'm going to work on it! Thanks for the feedback!

@gigitux gigitux enabled auto-merge (squash) December 18, 2024 11:07
@gigitux gigitux merged commit 8ca1bad into trunk Dec 18, 2024
66 of 67 checks passed
@gigitux gigitux deleted the add/unit-test-datafrom branch December 18, 2024 11:29
@github-actions github-actions bot added this to the Gutenberg 20.0 milestone Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] DataViews /packages/dataviews [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants