Skip to content

Commit

Permalink
Migrate document settings test to playwright (#40258)
Browse files Browse the repository at this point in the history
* Add ported version of site editor document settings test

* Delete old puppeteer test

* Fix test title, not a template part being tested

* Use the spec suffix

* Rename test description

* Remove the EditorTitle utility class

* Remove unnecessary deletion of templates and template parts

* Improve selectors

* use toHaveText

* Select the iframe using its title
  • Loading branch information
talldan authored and adamziel committed Apr 13, 2022
1 parent 4a66af4 commit 7199ec2
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 90 deletions.
2 changes: 2 additions & 0 deletions packages/e2e-test-utils-playwright/src/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { openPreviewPage } from './preview';
import { setBrowserViewport } from './set-browser-viewport';
import { showBlockToolbar } from './show-block-toolbar';
import { visitAdminPage } from './visit-admin-page';
import { visitSiteEditor } from './site-editor';

class PageUtils {
browser: Browser;
Expand All @@ -43,6 +44,7 @@ class PageUtils {
setClipboardData = setClipboardData;
showBlockToolbar = showBlockToolbar;
visitAdminPage = visitAdminPage;
visitSiteEditor = visitSiteEditor;
openDocumentSettingsSidebar = openDocumentSettingsSidebar;
openPreviewPage = openPreviewPage;
setBrowserViewport = setBrowserViewport;
Expand Down
57 changes: 57 additions & 0 deletions packages/e2e-test-utils-playwright/src/page/site-editor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
*/
import type { PageUtils } from './index';

const VISUAL_EDITOR_SELECTOR = 'iframe[title="Editor canvas"i]';

interface SiteEditorQueryParams {
postId: string | number;
postType: string;
}

/**
* Visits the Site Editor main page
*
* By default, it also skips the welcome guide. The option can be disabled if need be.
*
* @param this
* @param query Query params to be serialized as query portion of URL.
* @param skipWelcomeGuide Whether to skip the welcome guide as part of the navigation.
*/
export async function visitSiteEditor(
this: PageUtils,
query: SiteEditorQueryParams,
skipWelcomeGuide = true
) {
const path = addQueryArgs( '', {
page: 'gutenberg-edit-site',
...query,
} ).slice( 1 );

await this.visitAdminPage( 'themes.php', path );
await this.page.waitForSelector( VISUAL_EDITOR_SELECTOR );

if ( skipWelcomeGuide ) {
await this.page.evaluate( () => {
// TODO, type `window.wp`.
// @ts-ignore
window.wp.data
.dispatch( 'core/preferences' )
.set( 'core/edit-site', 'welcomeGuide', false );

// @ts-ignore
window.wp.data
.dispatch( 'core/preferences' )
.toggle( 'core/edit-site', 'welcomeGuideStyles', false );
} );
}
}
90 changes: 0 additions & 90 deletions packages/e2e-tests/specs/site-editor/document-settings.test.js

This file was deleted.

73 changes: 73 additions & 0 deletions test/e2e/specs/site-editor/title.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Site editor title', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'emptytheme' );
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

test( 'displays the selected template name in the title for the index template', async ( {
page,
pageUtils,
} ) => {
// Navigate to a template.
await pageUtils.visitSiteEditor( {
postId: 'emptytheme//index',
postType: 'wp_template',
} );

const title = await page.locator(
'role=region[name="Header"i] >> role=heading[level=1]'
);

await expect( title ).toHaveText( 'Editing template: Index' );
} );

test( 'displays the selected template name in the title for the header template', async ( {
page,
pageUtils,
} ) => {
// Navigate to a template part.
await pageUtils.visitSiteEditor( {
postId: 'emptytheme//header',
postType: 'wp_template_part',
} );

const title = await page.locator(
'role=region[name="Header"i] >> role=heading[level=1]'
);

await expect( title ).toHaveText( 'Editing template part: header' );
} );

test( "displays the selected template part's name in the secondary title when a template part is selected from List View", async ( {
page,
pageUtils,
} ) => {
await pageUtils.visitSiteEditor( {
postId: 'emptytheme//index',
postType: 'wp_template',
} );

// Select the header template part via list view.
await page.click( 'role=button[name="List View"i]' );
const listView = await page.locator(
'role=treegrid[name="Block navigation structure"i]'
);
await listView.locator( 'role=gridcell >> text="header"' ).click();
await page.click( 'role=button[name="Close List View Sidebar"i]' );

// Evaluate the document settings secondary title.
const secondaryTitle = await page.locator(
'.edit-site-document-actions__secondary-item'
);

await expect( secondaryTitle ).toHaveText( 'header' );
} );
} );

0 comments on commit 7199ec2

Please sign in to comment.