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

File structure and components refactoring and test update #215

Merged

Conversation

renintw
Copy link
Contributor

@renintw renintw commented Jun 8, 2023

Fixes #210

This PR refactors the items mentioned in #210 as well as the following ones

  1. Add renderHook for useUser test.

In testing, using renderHook is recommended as it simulates a true React environment for Hooks. While some Hooks like useSelect and useEntityRecord may work outside a true React environment because their functions aren't tied to the React lifecycle, it's not guaranteed. For lifecycle-dependent Hooks like useEffect, a real React environment is necessary. Therefore, always use tools like renderHook in tests for accurate simulations, even if some tests pass without them.

This is an issue discovered in #205.

  1. Extract ScreenNavigation for better readability and improved maintainability.
  2. Add navigateToScreen as dependency

This is an issue discovered in #205.

  1. Bump version of @wordpress/scripts to 25.5.1

3. makes me wonder why there's no warning/error for not adding required dependencies to a hook, then I found that the rule was added later in WordPress/gutenberg#24914 (In this PR, there are some discussions about whether to enable the rule). Since our version of @wordpress/scripts is pinned to 24, it can't reflect the update on Gutenberg side. The latest version of @wordpress/scripts is 26.6.0 at the moment, but it wasn't upgraded to that version in this PR as there'd be failures when doing js testing. The root cause of it might come from the older version of @wordpress/core-data. At the moment, I guess it's not absolutely necessary to bump the version to 26.6.0, as the rule I really want to introduce is 'react-hooks/exhaustive-deps': 'warn', which still exists in the latest version. We could address it when it really needs to.

@renintw renintw requested review from iandunn and adamwoodnz June 8, 2023 17:15
@renintw renintw self-assigned this Jun 8, 2023
@renintw renintw linked an issue Jun 8, 2023 that may be closed by this pull request
4 tasks
@renintw renintw force-pushed the add/handle-revalidation-error-in-a-single-place branch 2 times, most recently from 5add378 to 7107688 Compare June 9, 2023 14:41
Base automatically changed from add/handle-revalidation-error-in-a-single-place to trunk June 9, 2023 14:51
@renintw renintw force-pushed the refactor/structure-components-refactoring-and-test-update branch 2 times, most recently from 760debf to 6e16e3c Compare June 9, 2023 14:57
Copy link
Member

@iandunn iandunn left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏻

renintw added 9 commits June 15, 2023 10:43
Hook should be called by a component. In test, renderHook would do that for us.
navigateToScreen should be added as the hook dependency, or hasEdits might not be the latest value when calling the function. In fact, due to the property of how hasEdits is updated, the navigateToScreen would always get the latest value of hasEdits, but it's best practice to add state and props that are used in the hook as its dependency, or it might get harder to develop new feature or maintain the code someday in the future.
@renintw renintw force-pushed the refactor/structure-components-refactoring-and-test-update branch from 6e16e3c to d755597 Compare June 15, 2023 02:51
@renintw renintw merged commit 2f6c51e into trunk Jun 15, 2023
@renintw renintw deleted the refactor/structure-components-refactoring-and-test-update branch June 15, 2023 02:58
@renintw renintw restored the refactor/structure-components-refactoring-and-test-update branch June 22, 2023 18:48
@renintw renintw deleted the refactor/structure-components-refactoring-and-test-update branch June 22, 2023 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor utilities, tests out of components folder
2 participants