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

Block bindings: allow the field types matching attribute types in bindings. #66174

Merged
merged 11 commits into from
Oct 18, 2024
64 changes: 64 additions & 0 deletions packages/e2e-tests/plugins/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function gutenberg_test_block_bindings_registration() {
'post',
'text_custom_field',
array(
'label' => 'Text custom field',
'default' => 'Value of the text custom field',
'show_in_rest' => true,
'single' => true,
Expand All @@ -106,6 +107,69 @@ function gutenberg_test_block_bindings_registration() {
'type' => 'string',
)
);
register_meta(
'post',
'object_custom_field',
array(
'label' => 'Object custom field',
'show_in_rest' => true,
'single' => true,
'type' => 'object',
'default' => json_decode( json_encode( array( 'foo' => 'bar' ) ), false ),
)
);
register_meta(
'post',
'array_custom_field',
array(
'label' => 'Array custom field',
'show_in_rest' => array(
'schema' => array(
'type' => 'array',
'items' => array(
'type' => 'string',
),
),
),
'single' => true,
'type' => 'array',
'default' => array(),
)
);
register_meta(
'post',
'number',
array(
'label' => 'Number custom field',
'type' => 'number',
'show_in_rest' => true,
'single' => true,
'default' => 5.5,
)
);
register_meta(
'post',
'integer',
array(
'label' => 'Integer custom field',
'type' => 'integer',
'show_in_rest' => true,
'single' => true,
'default' => 5,
)
);
register_meta(
'post',
'boolean',
array(
'label' => 'Boolean custom field',
'type' => 'boolean',
'show_in_rest' => true,
'single' => true,
'default' => true,
)
);

// Register CPT custom fields.
register_meta(
'post',
Expand Down
10 changes: 8 additions & 2 deletions packages/editor/src/bindings/post-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ function getPostMetaFields( select, context ) {
const registeredFields = getRegisteredPostMeta( context?.postType );
const metaFields = {};
Object.entries( registeredFields || {} ).forEach( ( [ key, props ] ) => {
// Don't include footnotes or private fields.
if ( key !== 'footnotes' && key.charAt( 0 ) !== '_' ) {
if (
// Don't include footnotes.
key !== 'footnotes' &&
// Don't include private fields.
key.charAt( 0 ) !== '_' &&
// Only support string types.
typeof entityMetaValues?.[ key ] === 'string'
Copy link
Contributor

Choose a reason for hiding this comment

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

We could add the filter here:

const metaProperties =
				options?.schema?.properties?.meta?.properties;
			const stringMetaProperties = Object.fromEntries(
				Object.entries( metaProperties ).filter(
					( [ , value ] ) => value.type === 'string'
				)
			);
			dispatch.receiveRegisteredPostMeta(
				postType,
				stringMetaProperties
			);

https://github.com/WordPress/gutenberg/blob/0010f6355a37b647f2246ddbd88bba886a84a9cb/packages/core-data/src/resolvers.js#L1011-L1018

Copy link
Contributor

@artemiomorales artemiomorales Oct 16, 2024

Choose a reason for hiding this comment

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

Hmm, I think it makes more sense to have the check here in packages/editor/src/bindings/post-meta.js. That makes the check more specific to bindings and keeps the related exceptions together, whereas getRegisteredPostMeta seems better to me conceptually as a more agnostic function.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the conditional should look like this, adding some handling for default values, otherwise valid fields will get skipped over in templates where entityMetaFields is undefined due to postId being undefined. Consequently, this also fixes some broken tests.

It might cause other things to break, though — I haven't been able to confirm that yet:

if (
	// Don't include footnotes.
	key !== 'footnotes' &&
	// Don't include private fields.
	key.charAt( 0 ) !== '_' &&
	// Only support string types.
	(typeof entityMetaValues?.[ key ] === 'string' || typeof props.default === 'string')
) { // logic here }

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 agree getRegisteredPostMeta should be agnostic to bindings and in other case an object or an array could be a valid value. I want to explore if it should happen in the bindings hooks instead of just post meta.

And it's true that we can't just check against string because undefined is also a valid value. I'll spend some time today exploring the best way to handle this.

) {
metaFields[ key ] = {
label: props.title || key,
value:
Expand Down
49 changes: 49 additions & 0 deletions test/e2e/specs/editor/various/block-bindings/post-meta.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
const paragraphBlock = editor.canvas.getByRole( 'document', {
name: 'Block: Paragraph',
} );
await expect( paragraphBlock ).toHaveText(

Check failure on line 84 in test/e2e/specs/editor/various/block-bindings/post-meta.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-bindings/post-meta.spec.js:62:4 › Post Meta source › Movie CPT template › Block attributes values › should show the default value if it is defined

1) [chromium] › editor/various/block-bindings/post-meta.spec.js:62:4 › Post Meta source › Movie CPT template › Block attributes values › should show the default value if it is defined Error: Timed out 5000ms waiting for expect(locator).toHaveText(expected) Locator: frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) Expected string: "Movie field default value" Received string: "movie_field" Call log: - expect.toHaveText with timeout 5000ms - waiting for frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-be691c8f-2e81-4b5e-b873-cc5a98c2876f" data-block="be691c8f-2e81-4b5e-b873-cc5a98c2876f" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-be691c8f-2e81-4b5e-b873-cc5a98c2876f" data-block="be691c8f-2e81-4b5e-b873-cc5a98c2876f" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-be691c8f-2e81-4b5e-b873-cc5a98c2876f" data-block="be691c8f-2e81-4b5e-b873-cc5a98c2876f" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-be691c8f-2e81-4b5e-b873-cc5a98c2876f" data-block="be691c8f-2e81-4b5e-b873-cc5a98c2876f" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-be691c8f-2e81-4b5e-b873-cc5a98c2876f" data-block="be691c8f-2e81-4b5e-b873-cc5a98c2876f" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-be691c8f-2e81-4b5e-b873-cc5a98c2876f" data-block="be691c8f-2e81-4b5e-b873-cc5a98c2876f" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Bloc

Check failure on line 84 in test/e2e/specs/editor/various/block-bindings/post-meta.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-bindings/post-meta.spec.js:62:4 › Post Meta source › Movie CPT template › Block attributes values › should show the default value if it is defined

1) [chromium] › editor/various/block-bindings/post-meta.spec.js:62:4 › Post Meta source › Movie CPT template › Block attributes values › should show the default value if it is defined Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveText(expected) Locator: frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) Expected string: "Movie field default value" Received string: "movie_field" Call log: - expect.toHaveText with timeout 5000ms - waiting for frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-fcf50a0a-f089-41b8-8d93-4af619760281" data-block="fcf50a0a-f089-41b8-8d93-4af619760281" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-fcf50a0a-f089-41b8-8d93-4af619760281" data-block="fcf50a0a-f089-41b8-8d93-4af619760281" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-fcf50a0a-f089-41b8-8d93-4af619760281" data-block="fcf50a0a-f089-41b8-8d93-4af619760281" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-fcf50a0a-f089-41b8-8d93-4af619760281" data-block="fcf50a0a-f089-41b8-8d93-4af619760281" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-fcf50a0a-f089-41b8-8d93-4af619760281" data-block="fcf50a0a-f089-41b8-8d93-4af619760281" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-fcf50a0a-f089-41b8-8d93-4af619760281" data-block="fcf50a0a-f089-41b8-8d93-4af619760281" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multi

Check failure on line 84 in test/e2e/specs/editor/various/block-bindings/post-meta.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-bindings/post-meta.spec.js:62:4 › Post Meta source › Movie CPT template › Block attributes values › should show the default value if it is defined

1) [chromium] › editor/various/block-bindings/post-meta.spec.js:62:4 › Post Meta source › Movie CPT template › Block attributes values › should show the default value if it is defined Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveText(expected) Locator: frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) Expected string: "Movie field default value" Received string: "movie_field" Call log: - expect.toHaveText with timeout 5000ms - waiting for frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-eed76ed7-76a4-467a-a1ff-54c7dce7444a" data-block="eed76ed7-76a4-467a-a1ff-54c7dce7444a" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-eed76ed7-76a4-467a-a1ff-54c7dce7444a" data-block="eed76ed7-76a4-467a-a1ff-54c7dce7444a" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-eed76ed7-76a4-467a-a1ff-54c7dce7444a" data-block="eed76ed7-76a4-467a-a1ff-54c7dce7444a" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-eed76ed7-76a4-467a-a1ff-54c7dce7444a" data-block="eed76ed7-76a4-467a-a1ff-54c7dce7444a" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-eed76ed7-76a4-467a-a1ff-54c7dce7444a" data-block="eed76ed7-76a4-467a-a1ff-54c7dce7444a" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-eed76ed7-76a4-467a-a1ff-54c7dce7444a" data-block="eed76ed7-76a4-467a-a1ff-54c7dce7444a" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">movie_field</p> - unexpected value "movie_field" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multi
'Movie field default value'
);
} );
Expand All @@ -107,7 +107,7 @@
const paragraphBlock = editor.canvas.getByRole( 'document', {
name: 'Block: Paragraph',
} );
await expect( paragraphBlock ).toHaveText(

Check failure on line 110 in test/e2e/specs/editor/various/block-bindings/post-meta.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-bindings/post-meta.spec.js:88:4 › Post Meta source › Movie CPT template › Block attributes values › should fall back to the field label if the default value is not defined

2) [chromium] › editor/various/block-bindings/post-meta.spec.js:88:4 › Post Meta source › Movie CPT template › Block attributes values › should fall back to the field label if the default value is not defined Error: Timed out 5000ms waiting for expect(locator).toHaveText(expected) Locator: frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) Expected string: "Field with only label" Received string: "field_with_only_label" Call log: - expect.toHaveText with timeout 5000ms - waiting for frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-14e47890-1c3e-4c86-b044-185d12e01f32" data-block="14e47890-1c3e-4c86-b044-185d12e01f32" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-14e47890-1c3e-4c86-b044-185d12e01f32" data-block="14e47890-1c3e-4c86-b044-185d12e01f32" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-14e47890-1c3e-4c86-b044-185d12e01f32" data-block="14e47890-1c3e-4c86-b044-185d12e01f32" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-14e47890-1c3e-4c86-b044-185d12e01f32" data-block="14e47890-1c3e-4c86-b044-185d12e01f32" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-14e47890-1c3e-4c86-b044-185d12e01f32" data-block="14e47890-1c3e-4c86-b044-185d12e01f32" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-14e47890-1c3e-4c86-b044-185d12e01f32" data-block="14e47890-1c3e-4c86-b044-185d12e01f32" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" d

Check failure on line 110 in test/e2e/specs/editor/various/block-bindings/post-meta.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-bindings/post-meta.spec.js:88:4 › Post Meta source › Movie CPT template › Block attributes values › should fall back to the field label if the default value is not defined

2) [chromium] › editor/various/block-bindings/post-meta.spec.js:88:4 › Post Meta source › Movie CPT template › Block attributes values › should fall back to the field label if the default value is not defined Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveText(expected) Locator: frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) Expected string: "Field with only label" Received string: "field_with_only_label" Call log: - expect.toHaveText with timeout 5000ms - waiting for frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-1a793b67-4792-4dab-9855-667e4a9869b1" data-block="1a793b67-4792-4dab-9855-667e4a9869b1" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-1a793b67-4792-4dab-9855-667e4a9869b1" data-block="1a793b67-4792-4dab-9855-667e4a9869b1" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-1a793b67-4792-4dab-9855-667e4a9869b1" data-block="1a793b67-4792-4dab-9855-667e4a9869b1" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-1a793b67-4792-4dab-9855-667e4a9869b1" data-block="1a793b67-4792-4dab-9855-667e4a9869b1" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-1a793b67-4792-4dab-9855-667e4a9869b1" data-block="1a793b67-4792-4dab-9855-667e4a9869b1" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-1a793b67-4792-4dab-9855-667e4a9869b1" data-block="1a793b67-4792-4dab-9855-667e4a9869b1" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - un

Check failure on line 110 in test/e2e/specs/editor/various/block-bindings/post-meta.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-bindings/post-meta.spec.js:88:4 › Post Meta source › Movie CPT template › Block attributes values › should fall back to the field label if the default value is not defined

2) [chromium] › editor/various/block-bindings/post-meta.spec.js:88:4 › Post Meta source › Movie CPT template › Block attributes values › should fall back to the field label if the default value is not defined Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: Timed out 5000ms waiting for expect(locator).toHaveText(expected) Locator: frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) Expected string: "Field with only label" Received string: "field_with_only_label" Call log: - expect.toHaveText with timeout 5000ms - waiting for frameLocator('[name="editor-canvas"]').getByRole('document', { name: 'Block: Paragraph' }) - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-72f7a309-d27b-4fef-a007-190b85b2aa64" data-block="72f7a309-d27b-4fef-a007-190b85b2aa64" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-72f7a309-d27b-4fef-a007-190b85b2aa64" data-block="72f7a309-d27b-4fef-a007-190b85b2aa64" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-72f7a309-d27b-4fef-a007-190b85b2aa64" data-block="72f7a309-d27b-4fef-a007-190b85b2aa64" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-72f7a309-d27b-4fef-a007-190b85b2aa64" data-block="72f7a309-d27b-4fef-a007-190b85b2aa64" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-72f7a309-d27b-4fef-a007-190b85b2aa64" data-block="72f7a309-d27b-4fef-a007-190b85b2aa64" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - unexpected value "field_with_only_label" - locator resolved to <p tabindex="0" role="document" data-empty="false" aria-readonly="true" aria-multiline="true" data-title="Paragraph" contenteditable="false" data-type="core/paragraph" aria-label="Block: Paragraph" data-wp-block-attribute-key="content" id="block-72f7a309-d27b-4fef-a007-190b85b2aa64" data-block="72f7a309-d27b-4fef-a007-190b85b2aa64" class="block-editor-rich-text__editable block-editor-block-list__block wp-block is-selected wp-block-paragraph rich-text">field_with_only_label</p> - un
'Field with only label'
);
} );
Expand Down Expand Up @@ -166,7 +166,7 @@
await page
.getByRole( 'menuitemradio' )
.filter( { hasText: 'Movie field label' } )
.click();

Check failure on line 169 in test/e2e/specs/editor/various/block-bindings/post-meta.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-bindings/post-meta.spec.js:143:4 › Post Meta source › Movie CPT template › Attributes panel › should show the field label if it is defined

3) [chromium] › editor/various/block-bindings/post-meta.spec.js:143:4 › Post Meta source › Movie CPT template › Attributes panel › should show the field label if it is defined TimeoutError: locator.click: Timeout 10000ms exceeded. Call log: - waiting for getByRole('menuitemradio').filter({ hasText: 'Movie field label' }) 167 | .getByRole( 'menuitemradio' ) 168 | .filter( { hasText: 'Movie field label' } ) > 169 | .click(); | ^ 170 | await expect( contentBinding ).toContainText( 171 | 'Movie field label' 172 | ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/block-bindings/post-meta.spec.js:169:7

Check failure on line 169 in test/e2e/specs/editor/various/block-bindings/post-meta.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-bindings/post-meta.spec.js:143:4 › Post Meta source › Movie CPT template › Attributes panel › should show the field label if it is defined

3) [chromium] › editor/various/block-bindings/post-meta.spec.js:143:4 › Post Meta source › Movie CPT template › Attributes panel › should show the field label if it is defined Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.click: Timeout 10000ms exceeded. Call log: - waiting for getByRole('menuitemradio').filter({ hasText: 'Movie field label' }) 167 | .getByRole( 'menuitemradio' ) 168 | .filter( { hasText: 'Movie field label' } ) > 169 | .click(); | ^ 170 | await expect( contentBinding ).toContainText( 171 | 'Movie field label' 172 | ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/block-bindings/post-meta.spec.js:169:7

Check failure on line 169 in test/e2e/specs/editor/various/block-bindings/post-meta.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-bindings/post-meta.spec.js:143:4 › Post Meta source › Movie CPT template › Attributes panel › should show the field label if it is defined

3) [chromium] › editor/various/block-bindings/post-meta.spec.js:143:4 › Post Meta source › Movie CPT template › Attributes panel › should show the field label if it is defined Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.click: Timeout 10000ms exceeded. Call log: - waiting for getByRole('menuitemradio').filter({ hasText: 'Movie field label' }) 167 | .getByRole( 'menuitemradio' ) 168 | .filter( { hasText: 'Movie field label' } ) > 169 | .click(); | ^ 170 | await expect( contentBinding ).toContainText( 171 | 'Movie field label' 172 | ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/block-bindings/post-meta.spec.js:169:7
await expect( contentBinding ).toContainText(
'Movie field label'
);
Expand Down Expand Up @@ -197,7 +197,7 @@
await page
.getByRole( 'menuitemradio' )
.filter( { hasText: 'field_without_label_or_default' } )
.click();

Check failure on line 200 in test/e2e/specs/editor/various/block-bindings/post-meta.spec.js

View workflow job for this annotation

GitHub Actions / Playwright - 3

[chromium] › editor/various/block-bindings/post-meta.spec.js:174:4 › Post Meta source › Movie CPT template › Attributes panel › should fall back to the field key if the field label is not defined

4) [chromium] › editor/various/block-bindings/post-meta.spec.js:174:4 › Post Meta source › Movie CPT template › Attributes panel › should fall back to the field key if the field label is not defined TimeoutError: locator.click: Timeout 10000ms exceeded. Call log: - waiting for getByRole('menuitemradio').filter({ hasText: 'field_without_label_or_default' }) 198 | .getByRole( 'menuitemradio' ) 199 | .filter( { hasText: 'field_without_label_or_default' } ) > 200 | .click(); | ^ 201 | await expect( contentBinding ).toContainText( 202 | 'field_without_label_or_default' 203 | ); at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/block-bindings/post-meta.spec.js:200:7
await expect( contentBinding ).toContainText(
'field_without_label_or_default'
);
Expand Down Expand Up @@ -547,5 +547,54 @@
.filter( { hasText: 'Movie field label' } );
await expect( movieField ).toBeVisible();
} );
test( 'should not be possible to connect non-supported fields through the attributes panel', async ( {
editor,
page,
} ) => {
await editor.insertBlock( {
name: 'core/paragraph',
} );
await page.getByLabel( 'Attributes options' ).click();
await page
.getByRole( 'menuitemcheckbox', {
name: 'Show content',
} )
.click();
await page
.getByRole( 'button', {
name: 'content',
} )
.click();
await expect(
page.getByRole( 'menuitemradio', {
name: 'Text custom field',
} )
).toBeVisible();
await expect(
page.getByRole( 'menuitemradio', {
name: 'Number custom field',
} )
).toBeVisible();
await expect(
page.getByRole( 'menuitemradio', {
name: 'Integer custom field',
} )
).toBeVisible();
await expect(
page.getByRole( 'menuitemradio', {
name: 'Boolean custom field',
} )
).toBeHidden();
await expect(
page.getByRole( 'menuitemradio', {
name: 'Object custom field',
} )
).toBeHidden();
await expect(
page.getByRole( 'menuitemradio', {
name: 'Array custom field',
} )
).toBeHidden();
} );
} );
} );
Loading