2021-03-24 13:28:11 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-05-05 00:14:07 +00:00
|
|
|
import {
|
|
|
|
findSidebarPanelToggleButtonWithTitle,
|
|
|
|
ensureSidebarOpened,
|
|
|
|
} from '@wordpress/e2e-test-utils';
|
2021-03-24 13:28:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { visitBlockPage } from './visit-block-page';
|
|
|
|
|
2021-04-14 14:50:27 +00:00
|
|
|
const blockPagePermalinks = {};
|
|
|
|
|
2021-03-24 13:28:11 +00:00
|
|
|
/**
|
|
|
|
* Gets the permalink of a page where the block editor is in use.
|
|
|
|
*
|
|
|
|
* @param {string} blockPage The name of the page whose permalink you want to get.
|
|
|
|
* @return {Promise<string>} Returns the permalink of the page.
|
|
|
|
*/
|
|
|
|
export async function getBlockPagePermalink( blockPage ) {
|
2021-04-14 14:50:27 +00:00
|
|
|
if ( blockPagePermalinks[ blockPage ] ) {
|
|
|
|
return blockPagePermalinks[ blockPage ];
|
|
|
|
}
|
2021-03-24 13:28:11 +00:00
|
|
|
await visitBlockPage( blockPage );
|
|
|
|
await ensureSidebarOpened();
|
|
|
|
const panelButton = await findSidebarPanelToggleButtonWithTitle(
|
|
|
|
'Permalink'
|
|
|
|
);
|
|
|
|
const ensureLinkClickable = async ( page ) => {
|
|
|
|
let linkVisible =
|
|
|
|
( await page.$( '.edit-post-post-link__link' ) ) !== null;
|
|
|
|
while ( ! linkVisible ) {
|
|
|
|
await panelButton.click( 'button' );
|
|
|
|
page.waitForTimeout( 300 );
|
|
|
|
linkVisible =
|
|
|
|
( await page.$( '.edit-post-post-link__link' ) ) !== null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
await ensureLinkClickable( page );
|
|
|
|
const link = await page.$eval( '.edit-post-post-link__link', ( el ) => {
|
|
|
|
return el.getAttribute( 'href' );
|
|
|
|
} );
|
2021-04-14 14:50:27 +00:00
|
|
|
blockPagePermalinks[ blockPage ] = link;
|
2021-03-24 13:28:11 +00:00
|
|
|
return link;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default getBlockPagePermalink;
|