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

Fix available bindings using incorrect block name #5

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix available bindings using incorrect block name
chriszarate committed Aug 20, 2024
commit 87780607f9aae7977f453a228fcabebf73b26d21
2 changes: 1 addition & 1 deletion src/blocks/context-container/hooks/with-block-binding.tsx
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ export const withBlockBinding = createHigherOrderComponent( BlockEdit => {
return ( props: BlockEditProps< ContextInnerBlockAttributes > ) => {
const { attributes, context, name, setAttributes } = props;
const remoteData = context[ REMOTE_DATA_CONTEXT_KEY ] as RemoteData | undefined;
const availableBindings = getBlockAvailableBindings( name );
const availableBindings = getBlockAvailableBindings( remoteData?.blockName ?? '' );
const hasAvailableBindings = Boolean( Object.keys( availableBindings ).length );

// If the block does not have a remote data context, render it as usual.

Unchanged files with check annotations Beta

await vi.runAllTimersAsync();
expect( screen.getByTestId( 'mock-block-edit' ) ).toBeDefined();
expect( screen.getByTestId( 'inspector-controls' ) ).toBeDefined();

Check failure on line 92 in tests/src/blocks/context-container/hooks/with-block-bindings.test.tsx

GitHub Actions / vitest

tests/src/blocks/context-container/hooks/with-block-bindings.test.tsx > withBlockBinding > renders BoundBlockEdit when remote data is available

TestingLibraryElementError: Unable to find an element by: [data-testid="inspector-controls"] Ignored nodes: comments, script, style <body> <div> <div data-testid="mock-block-edit" /> </div> </body> ❯ Object.getElementError node_modules/@testing-library/dom/dist/config.js:37:19 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:76:38 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:52:17 ❯ node_modules/@testing-library/dom/dist/query-helpers.js:95:19 ❯ tests/src/blocks/context-container/hooks/with-block-bindings.test.tsx:92:18
expect( screen.getByTestId( 'panel-body' ) ).toBeDefined();
} );
render( <WrappedComponent { ...props } /> );
expect( MockBlockEdit ).toHaveBeenCalledTimes( 1 );
expect( MockBlockEdit ).toHaveBeenCalledWith(

Check failure on line 148 in tests/src/blocks/context-container/hooks/with-block-bindings.test.tsx

GitHub Actions / vitest

tests/src/blocks/context-container/hooks/with-block-bindings.test.tsx > withBlockBinding > updates attributes when mismatches are found

AssertionError: expected "spy" to be called with arguments: [ { attributes: { …(2) }, …(6) }, {} ] Received: 1st spy call: Array [ Object { "attributes": Object { - "content": "New Title", + "content": "Old Title", "metadata": Object { "bindings": Object { "content": Object { "args": Object { "field": "title", }, "source": "remote-data/binding", }, }, }, }, "className": "", "clientId": "test-client-id", "context": Object { "remote-data-blocks/remoteData": Object { "results": Array [ Object { "title": "New Title", }, ], }, }, "isSelected": false, "name": "test-block", "setAttributes": [Function spy], }, Object {}, ] Number of calls: 1 ❯ tests/src/blocks/context-container/hooks/with-block-bindings.test.tsx:148:27
{
...props,
attributes: { ...props.attributes, content: 'New Title' },