-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Navigation: Add integration tests for NavigationMenuSelector component #47825
Conversation
Size Change: +1.19 kB (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
Flaky tests detected in 710b682. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4122909054
|
b82a195
to
0685b3d
Compare
@@ -93,10 +93,10 @@ function NavigationMenuSelector( { | |||
hasResolvedNavigationMenus && currentMenuId === null; | |||
|
|||
useEffect( () => { | |||
if ( ! hasResolvedNavigationMenus ) { | |||
if ( ! hasResolvedNavigationMenus && ! canUserCreateNavigationMenu ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug fix: should show option to create even if menu items have no resolved.
setSelectorLabel( __( 'Loading …' ) ); | ||
} else if ( noMenuSelected || noBlockMenus || menuUnavailable ) { | ||
setSelectorLabel( __( 'Choose a Navigation menu' ) ); | ||
setSelectorLabel( __( 'Choose or create a Navigation menu' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix: sometimes the "Create" option can show even if there are no menus. We should make the label clearer.
@@ -56,7 +56,7 @@ function NavigationMenuSelector( { | |||
return ( | |||
navigationMenus?.map( ( { id, title }, index ) => { | |||
const label = | |||
decodeEntities( title.rendered ) || | |||
decodeEntities( title?.rendered ) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug fix: if there is no rendered
property at all we need to handle that and ensure we get a fallback title.
252b410
to
49b797e
Compare
@glendaviesnz I've tagged you into this one as I know you are keen to explore integration testing. This is an example of such an approach. It's very simple but it provides confidence. |
Seems broken on @scruffian How would you feel about merging this "as is" and then following up with a fix and a test. Reason being this PR is getting large. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is broken on trunk too, I'm happy for us to merge it.
Nice - we need a lot more of this style of test across the blocks - thanks for the ping. |
What?
Adds a suite of integration/component level tests for the
<NavigationMenuSelector>
component in the Nav block.Also fixes a few bugs discovered along the way.
Why?
This component has suffered from a number of regressions. Moreover it has a number of states and potential edge cases that are too difficult for humans to manually test. This makes the component brittle and difficult to change.
Adding these tests provides an intial measure of confidence in the component's behaviour. After this it will be necessary to refactor the component to remove some of the unusual patterns that are in evidence (e.g. setState on render). This should help to simplify it but should not be done without the backing of tests.
How?
Adds integration tests that assert on all the states of the component. Various hooks are mocked to control the state of the component. That's ok. We sacrifice some certainty/accuracy for speed and ease of use. It's gets us 80% of the coverage with 20% of the effort relative to e2e tests.
Testing Instructions
It's critical we try and verify the original behaviour from
trunk
is maintained:With that checked you can run the test suite:
Testing Instructions for Keyboard
Screenshots or screencast