Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Merge branch 'fix/gutenberg-updated-site-editor-edit-button' of https…
Browse files Browse the repository at this point in the history
…://github.com/woocommerce/woocommerce-blocks into fix/refactor-product-query-e2e-tests
  • Loading branch information
gigitux committed Jan 9, 2023
2 parents f247938 + fd70489 commit 231098d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 32 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/specs/product-query/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import {
findToolsPanelWithTitle,
getFormElementIdByLabel,
insertShortcodeBlock,
setCheckbox,
getToggleIdByLabel,
} from '@woocommerce/blocks-test-utils';
import { ElementHandle } from 'puppeteer';

import { setCheckbox } from '@woocommerce/e2e-utils';
/**
* Internal dependencies
*/
Expand Down
22 changes: 14 additions & 8 deletions tests/e2e/specs/product-query/popular-filters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,20 @@ describeOrSkip( GUTENBERG_EDITOR_CONTEXT === 'gutenberg' )(
filter: 'Newest',
shortcode: '[products orderby="date" order="DESC" limit="9"]',
},
{
filter: 'Best Selling',
shortcode: '[products best_selling="true" limit="9"]',
},
{
filter: 'Top Rated',
shortcode: '[products top_rated="true" limit="9"]',
},
/**
* The following tests are commented out because they are flaky
* due to the lack of orders and reviews in the test environment.
*
* @see https://github.com/woocommerce/woocommerce-blocks/issues/8116
*/
// {
// filter: 'Best Selling',
// shortcode: '[products best_selling="true" limit="9"]',
// },
// {
// filter: 'Top Rated',
// shortcode: '[products top_rated="true" limit="9"]',
// },
] )( '$filter', ( { filter, shortcode } ) => {
beforeEach( async () => {
await selectPopularFilter( filter );
Expand Down
7 changes: 5 additions & 2 deletions tests/e2e/specs/shopper/filter-products-by-attribute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,15 @@ describe( `${ block.name } Block`, () => {
await insertBlock( block.name );
await page.waitForNetworkIdle();

await canvas().waitForSelector(
block.selectors.editor.firstAttributeInTheList
);
// It seems that .click doesn't work well with radio input element.
await page.$eval(
await canvas().$eval(
block.selectors.editor.firstAttributeInTheList,
( el ) => ( el as HTMLInputElement ).click()
);
await page.click( selectors.editor.doneButton );
await canvas().click( selectors.editor.doneButton );
await publishPost();

editorPageUrl = page.url();
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/specs/shopper/filter-products-by-rating.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ describe( `${ block.name } Block`, () => {

it( 'should refresh the page only if the user click on button', async () => {
await page.goto( editorPageUrl );
await waitForCanvas();
await ensureSidebarOpened();
await selectBlockByName( block.slug );
await setCheckbox(
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/specs/shopper/filter-products-by-stock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ describe( `${ block.name } Block`, () => {

it( 'should refresh the page only if the user clicks on button', async () => {
await page.goto( editorPageUrl );
await waitForCanvas();
await ensureSidebarOpened();
await selectBlockByName( block.slug );
await setCheckbox(
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const SELECTORS = {
},
templateEditor: {
editButton:
'.edit-site-layout__edit-button[aria-label="Open the editor"]',
'.edit-site-site-hub__edit-button[aria-label="Open the editor"]',
},
};

Expand Down
7 changes: 1 addition & 6 deletions tests/utils/find-tools-panel-with-title.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
* External dependencies
*/
import { canvas } from '@wordpress/e2e-test-utils';

export const findToolsPanelWithTitle = async ( panelTitle: string ) => {
const panelToggleSelector = `//div[contains(@class, "components-tools-panel-header")]//h2[contains(@class, "components-heading") and contains(text(),"${ panelTitle }")]`;
const panelSelector = `${ panelToggleSelector }/ancestor::*[contains(concat(" ", @class, " "), " components-tools-panel ")]`;
return await canvas().waitForXPath( panelSelector );
return await page.waitForXPath( panelSelector );
};
9 changes: 2 additions & 7 deletions tests/utils/get-form-element-id-by-label.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
/**
* External dependencies
*/
import { canvas } from '@wordpress/e2e-test-utils';

export const getFormElementIdByLabel = async (
text: string,
className: string
) => {
// Remove leading dot if className is passed with it.
className = className.replace( /^\./, '' );

const labelElement = await canvas().waitForXPath(
const labelElement = await page.waitForXPath(
`//label[contains(text(), "${ text }") and contains(@class, "${ className }")]`,
{ visible: true }
);
return await canvas().evaluate(
return await page.evaluate(
( label ) => `#${ label.getAttribute( 'for' ) }`,
labelElement
);
Expand Down
9 changes: 2 additions & 7 deletions tests/utils/get-toggle-id-by-label.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { canvas } from '@wordpress/e2e-test-utils';

/**
* Internal dependencies
*/
Expand All @@ -26,12 +21,12 @@ export const getToggleIdByLabel = async (
): Promise< string > => {
const delay = 1000;
// Wait a bit for toggle to finish rerendering.
await canvas().waitForTimeout( delay );
await page.waitForTimeout( delay );
const checkboxId = await getFormElementIdByLabel(
label,
'components-toggle-control__label'
);
const checkbox = await canvas().$( checkboxId );
const checkbox = await page.$( checkboxId );
if ( ! checkbox ) {
if ( retry * delay < DEFAULT_TIMEOUT ) {
return await getToggleIdByLabel( label, retry + 1 );
Expand Down

0 comments on commit 231098d

Please sign in to comment.