Skip to content

Commit

Permalink
Fix E2E tests (woocommerce#52909)
Browse files Browse the repository at this point in the history
* Fix E2E test suite with WordPress 6.6

* improve selector
  • Loading branch information
gigitux authored Nov 22, 2024
1 parent 5724707 commit 636e5b7
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ test.describe( 'Product Collection: Register Product Collection', () => {
} );

test( `Registered collections should be available in Collection chooser`, async ( {
page,
pageObject,
editor,
admin,
page,
} ) => {
await admin.createNewPost();
await editor.insertBlockUsingGlobalInserter( pageObject.BLOCK_NAME );
Expand All @@ -74,14 +74,22 @@ test.describe( 'Product Collection: Register Product Collection', () => {
} )
.click();

// This viewport size is required to ensure that the selectors are visible.
// For smaller viewports, a different DOM structure is rendered, which may cause the selectors to be hidden or not interactable.
await page.setViewportSize( {
width: 1920,
height: 1080,
} );

for ( const myCollection of Object.values(
MY_REGISTERED_COLLECTIONS
) ) {
await expect(
page.getByRole( 'button', {
name: myCollection.name,
exact: true,
} )
editor.canvas
.locator(
`.wc-blocks-product-collection__collection-button-title`
)
.getByText( myCollection.name, { exact: true } )
).toBeVisible();
}
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ test.describe( 'Template customization', () => {
await editor.saveSiteEditorEntities( {
isOnlyCurrentEntityDirty: true,
} );

// Verify template name didn't change.
// See: https://github.com/woocommerce/woocommerce/issues/42221
await expect(
page.getByRole( 'heading', {
name: `${ testData.templateName } · ${ templateTypeName }`,
name: templateTypeName,
} )
).toBeVisible();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ test.describe( 'Template customization', () => {
await editor.saveSiteEditorEntities( {
isOnlyCurrentEntityDirty: true,
} );

// Verify template name didn't change.
// See: https://github.com/woocommerce/woocommerce/issues/42221
await expect(
page.getByRole( 'heading', {
name: `${ testData.templateName } · ${ templateTypeName }`,
name: templateTypeName,
} )
).toBeVisible();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ test.describe( 'Template part customization', () => {
await editor.saveSiteEditorEntities( {
isOnlyCurrentEntityDirty: true,
} );

// Verify template name didn't change.
// See: https://github.com/woocommerce/woocommerce/issues/42221
await expect(
page.getByRole( 'heading', {
name: `${ templateName } · Template Part`,
name: templateName,
} )
).toBeVisible();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ test.describe( 'Template part customization', () => {
await editor.saveSiteEditorEntities( {
isOnlyCurrentEntityDirty: true,
} );

// Verify template name didn't change.
// See: https://github.com/woocommerce/woocommerce/issues/42221
await expect(
page.getByRole( 'heading', {
name: `${ templateName } · Template Part`,
name: templateName,
} )
).toBeVisible();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,28 @@ export class Editor extends CoreEditor {

async revertTemplate( { templateName }: { templateName: string } ) {
await this.page.getByPlaceholder( 'Search' ).fill( templateName );
// WP 6.7 issue: https://github.com/WordPress/gutenberg/issues/66585.
// Template-parts have aria-label="[object Object]" hence switching
// from using label to button.
await this.page
.getByRole( 'button', { name: templateName, exact: true } )
.click();

// Depending on the context, we need to click either on a link (in the template page)
// or a button (in the template-parts/patterns page) to visit the template.
const link = this.page.getByRole( 'link', {
name: templateName,
exact: true,
} );

if ( await link.isVisible() ) {
await link.click();
}

const button = this.page
.getByRole( 'button', {
name: templateName,
exact: true,
} )
.and( this.page.locator( '.is-link' ) );

if ( await button.isVisible() ) {
await button.click();
}

await this.page.getByLabel( 'Actions' ).click();
await this.page
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: tweak
Comment: Fix E2E test suite to support WordPress 6.6

0 comments on commit 636e5b7

Please sign in to comment.