Repository navigation
Share the native Site Editor post-type resolver #565
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
Open
jasalt
wants to merge
10
commits into
WordPress:trunk
Choose a base branch
from
jasalt:fix/site-editor-schema-fanout
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
47f71aa
Fix per-block Site Editor schema fetches with shared core-data resolu…
jasalt 86e58c0
Preserve field-format failures as hook error state
jasalt 06d5b43
Share core's native post-type resolver identity for edit schema metadata
jasalt 184fa1c
Preserve stored Site Editor fields during schema refresh
jasalt acc1fb6
Test Site Editor schema sharing with real core-data registries
jasalt d1bbf3b
Preserve hook regression coverage across shared resolution
jasalt 3bd4ac5
Revert accidental name change on lock package-lock.json
jasalt 18b0637
Move real-registry integration tests out of resolver fix
jasalt 40216cd
Add explicit retry for Site Editor field-loading failures
jasalt f6294bc
Merge branch 'trunk' into fix/site-editor-schema-fanout
cbravobernal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /** | ||
| * Inspector recovery from shared Site Editor schema failures. | ||
| */ | ||
| import { fireEvent, render, screen } from '@testing-library/react'; | ||
| import { addFilter } from '@wordpress/hooks'; | ||
| import { | ||
| useSiteEditorContext, | ||
| useSiteEditorFields, | ||
| } from '../../../assets/src/js/bindings/hooks'; | ||
|
|
||
| jest.mock( '@wordpress/hooks', () => ( { addFilter: jest.fn() } ) ); | ||
| jest.mock( '@wordpress/compose', () => ( { | ||
| createHigherOrderComponent: ( callback ) => callback, | ||
| } ) ); | ||
| jest.mock( '@wordpress/block-editor', () => ( { | ||
| InspectorControls: ( { children } ) => <div>{ children }</div>, | ||
| useBlockBindingsUtils: () => ( { | ||
| updateBlockBindings: jest.fn(), | ||
| removeAllBlockBindings: jest.fn(), | ||
| } ), | ||
| } ) ); | ||
| jest.mock( '@wordpress/components', () => ( { | ||
| Notice: ( { children } ) => <div role="alert">{ children }</div>, | ||
| Button: ( { children, onClick, disabled, isBusy } ) => ( | ||
| <button onClick={ onClick } disabled={ disabled } aria-busy={ isBusy }> | ||
| { children } | ||
| </button> | ||
| ), | ||
| ComboboxControl: ( { options } ) => ( | ||
| <ul> | ||
| { options.map( ( option ) => ( | ||
| <li key={ option.value }>{ option.label }</li> | ||
| ) ) } | ||
| </ul> | ||
| ), | ||
| __experimentalToolsPanel: ( { children } ) => <div>{ children }</div>, | ||
| __experimentalToolsPanelItem: ( { children } ) => <div>{ children }</div>, | ||
| } ) ); | ||
| jest.mock( '../../../assets/src/js/bindings/hooks', () => ( { | ||
| useSiteEditorContext: jest.fn(), | ||
| useSiteEditorFields: jest.fn(), | ||
| usePostEditorFields: () => ( { | ||
| field1: { label: 'Field 1', type: 'text' }, | ||
| } ), | ||
| useBoundFields: () => ( { boundFields: {}, setBoundFields: jest.fn() } ), | ||
| } ) ); | ||
|
|
||
| require( '../../../assets/src/js/bindings/block-editor' ); | ||
| const withControls = addFilter.mock.calls[ 0 ][ 2 ]; | ||
| const BlockEdit = () => <div>Block content</div>; | ||
| const EnhancedBlock = withControls( BlockEdit ); | ||
| const renderBlock = () => ( | ||
| <EnhancedBlock name="core/paragraph" attributes={ {} } /> | ||
| ); | ||
|
|
||
| describe( 'Site Editor field recovery', () => { | ||
| let state; | ||
|
|
||
| beforeEach( () => { | ||
| state = { | ||
| fields: {}, | ||
| isLoading: false, | ||
| error: new Error( 'Private REST error details' ), | ||
| refresh: jest.fn(), | ||
| }; | ||
| useSiteEditorFields.mockImplementation( () => state ); | ||
| useSiteEditorContext.mockReturnValue( { | ||
| isSiteEditor: true, | ||
| templatePostType: 'product', | ||
| } ); | ||
| } ); | ||
|
|
||
| it( 'shows a generic error and retries only on user action', () => { | ||
| const { rerender } = render( renderBlock() ); | ||
| expect( screen.getByRole( 'alert' ).textContent ).toContain( | ||
| 'Unable to load custom fields. Please try again.' | ||
| ); | ||
| expect( screen.queryByText( 'Private REST error details' ) ).toBeNull(); | ||
| rerender( renderBlock() ); | ||
| expect( state.refresh ).not.toHaveBeenCalled(); | ||
| fireEvent.click( screen.getByRole( 'button', { name: 'Retry' } ) ); | ||
| expect( state.refresh ).toHaveBeenCalledTimes( 1 ); | ||
| } ); | ||
|
|
||
| it( 'disables retry while loading and keeps cached field options', () => { | ||
| state.isLoading = true; | ||
| state.fields = { field1: { label: 'Field 1', type: 'text' } }; | ||
| render( renderBlock() ); | ||
| const retry = screen.getByRole( 'button', { name: 'Retry' } ); | ||
| expect( retry.disabled ).toBe( true ); | ||
| expect( retry.getAttribute( 'aria-busy' ) ).toBe( 'true' ); | ||
| fireEvent.click( retry ); | ||
| expect( state.refresh ).not.toHaveBeenCalled(); | ||
| expect( screen.getByText( 'Field 1' ) ).toBeTruthy(); | ||
| } ); | ||
|
|
||
| it( 'removes the notice and shows field options after successful recovery', () => { | ||
| const { rerender } = render( renderBlock() ); | ||
| fireEvent.click( screen.getByRole( 'button', { name: 'Retry' } ) ); | ||
| state.error = null; | ||
| state.fields = { field1: { label: 'Field 1', type: 'text' } }; | ||
| rerender( renderBlock() ); | ||
| expect( screen.queryByRole( 'alert' ) ).toBeNull(); | ||
| expect( screen.queryByRole( 'button', { name: 'Retry' } ) ).toBeNull(); | ||
| expect( screen.getByText( 'Field 1' ) ).toBeTruthy(); | ||
| expect( state.refresh ).toHaveBeenCalledTimes( 1 ); | ||
| } ); | ||
|
|
||
| it( 'does not show the Site Editor error in the Post Editor', () => { | ||
| useSiteEditorContext.mockReturnValue( { | ||
| isSiteEditor: false, | ||
| templatePostType: null, | ||
| } ); | ||
| render( renderBlock() ); | ||
| expect( screen.queryByRole( 'alert' ) ).toBeNull(); | ||
| expect( screen.queryByRole( 'button', { name: 'Retry' } ) ).toBeNull(); | ||
| expect( screen.getByText( 'Field 1' ) ).toBeTruthy(); | ||
| expect( state.refresh ).not.toHaveBeenCalled(); | ||
| } ); | ||
| } ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.