Skip to content

E2E Tests: Add test suite for columns block template lock #69089

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

Conversation

himanshupathak95
Copy link
Contributor

@himanshupathak95 himanshupathak95 commented Feb 7, 2025

What?

Closes 49235

Adds end-to-end (E2E) tests for the templateLock attribute functionality on the core/columns block.

Why?

The templateLock attribute was added to the core/columns block in #49132 to provide granular control over inner block manipulation (adding, moving, deleting columns, and inserting blocks within columns). Currently, there are no automated tests to verify this functionality.

This PR adds E2E tests, as suggested in this comment on the original PR, to:

  • Verify that the different templateLock values (all, insert, contentOnly) correctly restrict or allow actions on the inner core/column blocks.
  • Confirm the behavior when templateLock=false is set on the Columns block itself, but it resides within a parent block (Group) that has templateLock="insert".
  • Ensure the feature works as expected and prevent regressions in future updates.

How?

  • New end-to-end tests were added to the existing test suite for the Columns block (core/columns).
  • These tests systematically cover the behavior associated with the templateLock attribute, verifying the expected outcomes for the all, insert, contentOnly, and false lock types.

Testing Instructions

  • Check out this branch.

  • Run the E2E tests specifically for the columns block spec file to confirm that the new tests pass:

    npm run test:e2e -- test/e2e/specs/editor/blocks/columns.spec.js
  • Verify that all tests within the new 'Template Lock' suite pass successfully.

Screenshots or screencast

N/A - This PR adds automated tests, not visual UI changes.

@Mamaduka Mamaduka added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Feb 9, 2025
@Mamaduka
Copy link
Member

@himanshupathak95, let me know when this is ready for review.

@himanshupathak95 himanshupathak95 marked this pull request as ready for review May 5, 2025 08:20
Copy link

github-actions bot commented May 5, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: himanshupathak95 <abcd95@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@himanshupathak95
Copy link
Contributor Author

himanshupathak95 commented May 5, 2025

@Mamaduka, This PR is finally ready for review. Please take a look at your convenience 🙇🏻

@Mamaduka
Copy link
Member

Mamaduka commented May 7, 2025

Thanks for working on this, @himanshupathak95! The new tests look good to me.

One thing to consider: The templateLock value should work the same for all blocks that support it, but adding coverage for all blocks will be just a waste of resources (both human and CI). Maybe we could extract these new tests into a separate file - various/block-template-lock and use it for general coverage.

@t-hamano, what do you think?

@t-hamano
Copy link
Contributor

t-hamano commented May 8, 2025

Maybe we could extract these new tests into a separate file - "various/block-template-lock" and use it for general coverage.

I think it's a good idea. However, the following test might be in the Columns block:

  • templateLock="all" - should hide column count control
  • templateLock="insert" - should hide column count control
  • templateLock="contentOnly" - should hide column count control

I think we can write these tests like this:

Details
test.describe( 'Columns', () => {
	for ( const templateLock of [ 'all', 'insert', 'contentOnly' ] ) {
		test( `templateLock="${ templateLock }" should hide column count control`, async ( {
			editor,
			page,
		} ) => {
			await editor.insertBlock( {
				name: 'core/columns',
				attributes: { templateLock },
				innerBlocks: [
					{
						name: 'core/column',
						innerBlocks: [
							{
								name: 'core/paragraph',
								attributes: { content: 'Col 1' },
							},
						],
					},
					{
						name: 'core/column',
						innerBlocks: [
							{
								name: 'core/paragraph',
								attributes: { content: 'Col 2' },
							},
						],
					},
				],
			} );
			await editor.openDocumentSettingsSidebar();
			await expect(
				page.getByRole( 'slider', { name: 'Columns' } )
			).toBeHidden();
		} );
	}
} );

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM! It would be great if we could add new tests for templateLock in a follow-up PR.

@himanshupathak95 himanshupathak95 force-pushed the add/49235-e2e-test-columns-template-lock branch from e36d837 to af8cdbf Compare May 9, 2025 16:33
@t-hamano t-hamano merged commit 918d152 into WordPress:trunk May 10, 2025
59 checks passed
@github-actions github-actions bot added this to the Gutenberg 20.9 milestone May 10, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…69089)

* E2E: Add test for columns block template lock removal restriction

* E2E: Improve test for templateLock - all

* E2E: Move the tests from post-type-locking.spec.js to columns.spec.js

* E2E: Seperate tests into multiple units

* E2E: Add tests for `templateLock=insert` attribute

* E2E: Add tests for templateLock=contentOnly attribute

* E2E: Add `templateLock=false` test - Ensure columns block deletion prevention

* E2E: Add all remaining tests for `templateLock=false` attribute

* E2E: Use `selectBlocks` to select blocks

* E2E: Remove all `templateLock` tests from `column.spec.js`

* E2E: Keep the column count control tests for `all`, `insert`, and `contentOnly` in `column.spec.js`

* E2E: Test column count control for `templateLock=false` inside locked parent

* E2E: Remove redundant sibling paragraph

* E2E: Remove unnecessary second column

Co-authored-by: himanshupathak95 <abcd95@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E2E Test: Add test for template_lock on columns block
3 participants