-
Notifications
You must be signed in to change notification settings - Fork 67
feat: use a direct URL input in Stackable link controls #3756
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
Arukuen
wants to merge
3
commits into
develop
Choose a base branch
from
feat/unrestricted-url-setting
base: develop
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.
+376
−66
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { | ||
| test, | ||
| expect, | ||
| waitForBlockEditor, | ||
| } from 'e2e/test-utils' | ||
|
|
||
| test.describe( 'Link control URL input', () => { | ||
| const createdPostIds: Array<string | number> = [] | ||
|
|
||
| test.afterEach( async ( { requestUtils } ) => { | ||
| for ( const id of createdPostIds.splice( 0 ) ) { | ||
| await requestUtils.deletePost( id ).catch( () => undefined ) | ||
| } | ||
| } ) | ||
|
|
||
| test( 'accepts URLs, shortcodes, and other non-URL values', async ( { | ||
| page, | ||
| admin, | ||
| editor, | ||
| stackable, | ||
| } ) => { | ||
| await admin.createNewPost( { title: 'Link Control URL Input' } ) | ||
| await editor.saveDraft() | ||
| const postQuery = new URL( editor.page.url() ).search | ||
| const postId = new URLSearchParams( postQuery ).get( 'post' ) | ||
| if ( postId ) { | ||
| createdPostIds.push( postId ) | ||
| } | ||
|
|
||
| await stackable.dismissToursAndNotices() | ||
| await waitForBlockEditor( editor ) | ||
|
|
||
| await editor.insertBlock( { name: 'stackable/button-group' } ) | ||
| await stackable.pickDefaultLayout( editor ) | ||
| await stackable.selectBlockByName( editor, 'stackable/button' ) | ||
|
|
||
| await stackable.openInspectorTab( 'Style' ) | ||
|
|
||
| const inspector = page.getByRole( 'region', { name: 'Editor settings' } ) | ||
| const linkPanel = inspector.locator( '.ugb-toggle-panel-body.ugb-panel--link' ) | ||
| await expect( linkPanel ).toBeVisible() | ||
| if ( ! ( await linkPanel.getAttribute( 'class' ) || '' ).includes( 'is-opened' ) ) { | ||
| await linkPanel.locator( '.components-panel__body-toggle' ).click() | ||
| } | ||
| await expect( linkPanel ).toHaveClass( /is-opened/ ) | ||
|
|
||
| const linkControl = linkPanel.locator( '.stk-link-control' ).filter( { | ||
| has: page.locator( '.stk-control-label', { hasText: /Link \/ URL/ } ), | ||
| } ) | ||
| const input = linkControl.getByRole( 'combobox', { name: 'URL' } ) | ||
| await expect( input ).toBeVisible() | ||
|
|
||
| const buttonBlock = editor.canvas.locator( '[data-type="stackable/button"]' ).first() | ||
| const clientId = await buttonBlock.getAttribute( 'data-block' ) | ||
|
|
||
| const setLinkValue = async ( value: string ) => { | ||
| await input.click() | ||
| await input.fill( value ) | ||
| await page.keyboard.press( 'Escape' ) | ||
| await input.blur() | ||
| } | ||
|
|
||
| await setLinkValue( 'https://example.com' ) | ||
| await expect.poll( async () => { | ||
| const attributes = await editor.getBlockAttributes( clientId ) | ||
| return attributes.linkUrl | ||
| } ).toBe( 'https://example.com' ) | ||
| await expect( linkControl ).not.toContainText( 'Please enter a valid URL.' ) | ||
|
|
||
| await setLinkValue( 'example.com' ) | ||
| await expect.poll( async () => { | ||
| const attributes = await editor.getBlockAttributes( clientId ) | ||
| return attributes.linkUrl | ||
| } ).toBe( 'https://example.com' ) | ||
|
|
||
| await setLinkValue( '[my_shortcode]' ) | ||
| await expect.poll( async () => { | ||
| const attributes = await editor.getBlockAttributes( clientId ) | ||
| return attributes.linkUrl | ||
| } ).toBe( '[my_shortcode]' ) | ||
| await expect( linkControl ).not.toContainText( 'Please enter a valid URL.' ) | ||
|
|
||
| await setLinkValue( '!#stk_dynamic/current-page/url!#' ) | ||
| await expect.poll( async () => { | ||
| const attributes = await editor.getBlockAttributes( clientId ) | ||
| return attributes.linkUrl | ||
| } ).toBe( '!#stk_dynamic/current-page/url!#' ) | ||
| await expect( linkControl ).not.toContainText( 'Please enter a valid URL.' ) | ||
|
|
||
| await setLinkValue( '{{permalink}}' ) | ||
| await expect.poll( async () => { | ||
| const attributes = await editor.getBlockAttributes( clientId ) | ||
| return attributes.linkUrl | ||
| } ).toBe( '{{permalink}}' ) | ||
| await expect( linkControl ).not.toContainText( 'Please enter a valid URL.' ) | ||
|
|
||
| await setLinkValue( 'https://' ) | ||
| await expect.poll( async () => { | ||
| const attributes = await editor.getBlockAttributes( clientId ) | ||
| return attributes.linkUrl | ||
| } ).toBe( 'https://' ) | ||
| await expect( linkControl ).toContainText( 'Please enter a valid URL.' ) | ||
| } ) | ||
| } ) | ||
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,71 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { | ||
| isPassThroughLinkValue, | ||
| isUrlLike, | ||
| isValidLinkValue, | ||
| normalizeLinkValue, | ||
| } from '../validate' | ||
|
|
||
| describe( 'link-control validation', () => { | ||
| it( 'treats empty values as pass-through', () => { | ||
| expect( isPassThroughLinkValue( '' ) ).toBe( true ) | ||
| expect( isPassThroughLinkValue( ' ' ) ).toBe( true ) | ||
| expect( isPassThroughLinkValue( undefined ) ).toBe( true ) | ||
| expect( isValidLinkValue( '' ) ).toBe( true ) | ||
| } ) | ||
|
|
||
| it( 'allows shortcodes without treating them as URLs', () => { | ||
| expect( isPassThroughLinkValue( '[my_shortcode]' ) ).toBe( true ) | ||
| expect( isPassThroughLinkValue( '[contact-form-7 id="1"]' ) ).toBe( true ) | ||
| expect( isPassThroughLinkValue( '[site.url]' ) ).toBe( true ) | ||
| expect( isValidLinkValue( '[my_shortcode]' ) ).toBe( true ) | ||
| expect( normalizeLinkValue( '[my_shortcode]' ) ).toBe( '[my_shortcode]' ) | ||
| } ) | ||
|
|
||
| it( 'allows dynamic content tokens', () => { | ||
| const token = '!#stk_dynamic/current-page/url!#' | ||
| expect( isPassThroughLinkValue( token ) ).toBe( true ) | ||
| expect( isValidLinkValue( token ) ).toBe( true ) | ||
| expect( normalizeLinkValue( token ) ).toBe( token ) | ||
| } ) | ||
|
|
||
| it( 'allows other non-URL strings', () => { | ||
| expect( isPassThroughLinkValue( '{{permalink}}' ) ).toBe( true ) | ||
| expect( isPassThroughLinkValue( '%post_url%' ) ).toBe( true ) | ||
| expect( isPassThroughLinkValue( 'hello' ) ).toBe( true ) | ||
| expect( isValidLinkValue( 'hello' ) ).toBe( true ) | ||
| expect( isUrlLike( 'hello' ) ).toBe( false ) | ||
| } ) | ||
|
|
||
| it( 'recognizes URL-like values', () => { | ||
| expect( isUrlLike( 'https://example.com' ) ).toBe( true ) | ||
| expect( isUrlLike( 'example.com' ) ).toBe( true ) | ||
| expect( isUrlLike( 'www.example.com' ) ).toBe( true ) | ||
| expect( isUrlLike( '#section' ) ).toBe( true ) | ||
| expect( isUrlLike( '/about' ) ).toBe( true ) | ||
| expect( isUrlLike( 'mailto:hi@example.com' ) ).toBe( true ) | ||
| } ) | ||
|
|
||
| it( 'accepts valid URLs, anchors, and relative paths', () => { | ||
| expect( isValidLinkValue( 'https://example.com' ) ).toBe( true ) | ||
| expect( isValidLinkValue( '#section' ) ).toBe( true ) | ||
| expect( isValidLinkValue( '/about' ) ).toBe( true ) | ||
| expect( isValidLinkValue( '../parent' ) ).toBe( true ) | ||
| expect( isValidLinkValue( 'mailto:hi@example.com' ) ).toBe( true ) | ||
| } ) | ||
|
|
||
| it( 'rejects incomplete URL-like values', () => { | ||
| expect( isValidLinkValue( 'https://' ) ).toBe( false ) | ||
| expect( isValidLinkValue( 'http://' ) ).toBe( false ) | ||
| } ) | ||
|
|
||
| it( 'prepends https to bare domains on normalize', () => { | ||
| expect( normalizeLinkValue( 'example.com' ) ).toBe( 'https://example.com' ) | ||
| expect( normalizeLinkValue( ' example.com ' ) ).toBe( 'https://example.com' ) | ||
| expect( normalizeLinkValue( 'https://example.com' ) ).toBe( 'https://example.com' ) | ||
| expect( normalizeLinkValue( '#section' ) ).toBe( '#section' ) | ||
| expect( normalizeLinkValue( '/about' ) ).toBe( '/about' ) | ||
| } ) | ||
| } ) |
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
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.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: gambitph/Stackable
Length of output: 5129
🏁 Script executed:
Repository: gambitph/Stackable
Length of output: 20994
🏁 Script executed:
Repository: gambitph/Stackable
Length of output: 1087
Assert a distinct normalized bare-domain value. The test enters
example.comafter storinghttps://example.com, then expects the samelinkUrl. If the bare-domain update is ignored, the previous value remains and the test still passes. Use a different domain, such asexample.org, and expecthttps://example.org.LinkControlpasses the blur-normalized value throughupdateAttributeHandler('url')to the button’slinkUrl, so this assertion directly detects the regression.🤖 Prompt for AI Agents