@@ -1356,53 +1356,6 @@ test.describe( 'Navigation block', () => {
13561356 await expect ( linkInput ) . toHaveValue ( '' ) ;
13571357 } ) ;
13581358
1359- await test . step ( 'Verify link field validates on submit in Link UI popover' , async ( ) => {
1360- await page . keyboard . type ( 'invalid url string' ) ;
1361-
1362- await page . keyboard . press ( 'Tab' ) ;
1363-
1364- // Verify validation error is not shown on blur
1365- await expect (
1366- page . getByText ( 'Please fill out this field' )
1367- ) . toBeHidden ( ) ;
1368-
1369- // Go back to the link input and press enter to submit
1370- await pageUtils . pressKeys ( 'Shift+Tab' ) ;
1371- await expect ( linkInput ) . toBeFocused ( ) ;
1372- await page . keyboard . press ( 'Enter' ) ;
1373-
1374- // Verify validation error is shown
1375- await expect (
1376- page . getByText ( 'Please enter a valid URL.' )
1377- ) . toBeVisible ( ) ;
1378- } ) ;
1379-
1380- await test . step ( 'Verify focus remains on link input after validation error' , async ( ) => {
1381- // Verify the input is focused and has the correct value
1382- await expect ( linkInput ) . toBeFocused ( ) ;
1383- await expect ( linkInput ) . toHaveValue ( 'invalid url string' ) ;
1384- } ) ;
1385-
1386- // If we type in the link input after a validation error, the validation error should be removed and the input should remain focused
1387- // This checks to make sure the input switching from a base input to validated input does not cause focus loss
1388- await test . step ( 'Verify typing in link input after validation error works' , async ( ) => {
1389- await page . keyboard . press ( 'ArrowRight' ) ;
1390- await page . keyboard . type ( ' after validation error' ) ;
1391-
1392- // Verify the input is still focused
1393- await expect ( linkInput ) . toBeFocused ( ) ;
1394-
1395- // Verify validation error is gone now
1396- await expect (
1397- page . getByText ( 'Please enter a valid URL.' )
1398- ) . toBeHidden ( ) ;
1399-
1400- await expect ( linkInput ) . toHaveValue (
1401- 'invalid url string after validation error'
1402- ) ;
1403- await expect ( linkInput ) . toBeFocused ( ) ;
1404- } ) ;
1405-
14061359 // Cancel to preserve bound state for sidebar tests
14071360 await linkPopover . getByRole ( 'button' , { name : 'Cancel' } ) . click ( ) ;
14081361
@@ -1736,6 +1689,128 @@ test.describe( 'Navigation block', () => {
17361689 } ) ;
17371690 } ) ;
17381691
1692+ test . describe ( 'URL Validation' , ( ) => {
1693+ let testPage1 ;
1694+
1695+ test . beforeEach ( async ( { admin, editor, requestUtils } ) => {
1696+ // Create test pages
1697+ testPage1 = await requestUtils . createPage ( {
1698+ title : 'Test Page 1' ,
1699+ status : 'publish' ,
1700+ } ) ;
1701+
1702+ // Create post and navigation block with pre-populated links
1703+ await admin . createNewPost ( ) ;
1704+
1705+ const menu = await requestUtils . createNavigationMenu ( {
1706+ title : 'Test Menu' ,
1707+ content :
1708+ `<!-- wp:navigation-link {"label":"Test Page 1","type":"page","id":${ testPage1 . id } ,"url":"${ testPage1 . link } ","kind":"post-type"} /-->` +
1709+ '<!-- wp:navigation-link {"label":"wordpress.org","type":"custom","url":"https://wordpress.org","kind":"custom"} /-->' +
1710+ '<!-- wp:navigation-link {"label":"Empty Link"} /-->' ,
1711+ } ) ;
1712+
1713+ await editor . insertBlock ( {
1714+ name : 'core/navigation' ,
1715+ attributes : {
1716+ ref : menu . id ,
1717+ } ,
1718+ } ) ;
1719+ } ) ;
1720+
1721+ test . afterEach ( async ( { requestUtils } ) => {
1722+ await requestUtils . deleteAllPages ( ) ;
1723+ } ) ;
1724+
1725+ test ( 'link field validates on submit in Link UI popover' , async ( {
1726+ editor,
1727+ page,
1728+ admin,
1729+ navigation,
1730+ requestUtils,
1731+ pageUtils,
1732+ } ) => {
1733+ await test . step ( 'Setup - Create menu and navigation block' , async ( ) => {
1734+ await admin . createNewPost ( ) ;
1735+
1736+ // create an empty menu for use - avoids Page List block
1737+ const menu = await requestUtils . createNavigationMenu ( {
1738+ title : 'Test Menu' ,
1739+ content : '' ,
1740+ } ) ;
1741+
1742+ await editor . insertBlock ( {
1743+ name : 'core/navigation' ,
1744+ attributes : {
1745+ ref : menu . id ,
1746+ } ,
1747+ } ) ;
1748+ } ) ;
1749+
1750+ const linkPopover = navigation . getLinkPopover ( ) ;
1751+ const linkInput = linkPopover . getByRole ( 'combobox' , {
1752+ name : 'Search or type URL' ,
1753+ } ) ;
1754+
1755+ await test . step ( 'Open Link inspector' , async ( ) => {
1756+ await expect ( navigation . getNavBlockInserter ( ) ) . toBeVisible ( ) ;
1757+ await pageUtils . pressKeys ( 'ArrowDown' ) ;
1758+ await navigation . useBlockInserter ( ) ;
1759+
1760+ await expect ( linkPopover ) . toBeVisible ( ) ;
1761+ await expect ( linkInput ) . toBeFocused ( ) ;
1762+ await expect ( linkInput ) . toHaveValue ( '' ) ;
1763+ } ) ;
1764+
1765+ await test . step ( 'Verify link field validates on submit in Link UI popover' , async ( ) => {
1766+ await page . keyboard . type ( 'invalid url string' ) ;
1767+
1768+ await page . keyboard . press ( 'Tab' ) ;
1769+
1770+ // Verify validation error is not shown on blur
1771+ await expect (
1772+ page . getByText ( 'Please fill out this field' )
1773+ ) . toBeHidden ( ) ;
1774+
1775+ // Go back to the link input and press enter to submit
1776+ await pageUtils . pressKeys ( 'Shift+Tab' ) ;
1777+ await expect ( linkInput ) . toBeFocused ( ) ;
1778+ await page . keyboard . press ( 'Enter' ) ;
1779+
1780+ // Verify validation error is shown
1781+ await expect (
1782+ page . getByText ( 'Please enter a valid URL.' )
1783+ ) . toBeVisible ( ) ;
1784+ } ) ;
1785+
1786+ await test . step ( 'Verify focus remains on link input after validation error' , async ( ) => {
1787+ // Verify the input is focused and has the correct value
1788+ await expect ( linkInput ) . toBeFocused ( ) ;
1789+ await expect ( linkInput ) . toHaveValue ( 'invalid url string' ) ;
1790+ } ) ;
1791+
1792+ // If we type in the link input after a validation error, the validation error should be removed and the input should remain focused
1793+ // This checks to make sure the input switching from a base input to validated input does not cause focus loss
1794+ await test . step ( 'Verify typing in link input after validation error works' , async ( ) => {
1795+ await page . keyboard . press ( 'ArrowRight' ) ;
1796+ await page . keyboard . type ( ' after validation error' ) ;
1797+
1798+ // Verify the input is still focused
1799+ await expect ( linkInput ) . toBeFocused ( ) ;
1800+
1801+ // Verify validation error is gone now
1802+ await expect (
1803+ page . getByText ( 'Please enter a valid URL.' )
1804+ ) . toBeHidden ( ) ;
1805+
1806+ await expect ( linkInput ) . toHaveValue (
1807+ 'invalid url string after validation error'
1808+ ) ;
1809+ await expect ( linkInput ) . toBeFocused ( ) ;
1810+ } ) ;
1811+ } ) ;
1812+ } ) ;
1813+
17391814 test . describe ( 'Navigation Link Inspector Link Editing' , ( ) => {
17401815 let testPage1 ;
17411816
0 commit comments