From 02ab2e50bb27520bec552c54d47723a675f7372f Mon Sep 17 00:00:00 2001 From: Eason Su Date: Tue, 9 Apr 2024 17:14:50 +0800 Subject: [PATCH 01/17] Set the variable product tour of classic product editor to not display. --- tests/e2e/bin/test-env-setup.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/e2e/bin/test-env-setup.sh b/tests/e2e/bin/test-env-setup.sh index d849cd7c46..9cab2e369d 100755 --- a/tests/e2e/bin/test-env-setup.sh +++ b/tests/e2e/bin/test-env-setup.sh @@ -22,3 +22,6 @@ wp-env run tests-cli wp wc payment_gateway update cod --enabled=1 --user=admin echo -e 'Set the tour of product block editor to not display \n' wp-env run tests-cli wp option update woocommerce_block_product_tour_shown 'yes' + +echo -e 'Set the variable product tour of classic product editor to not display \n' +wp-env run tests-cli wp user meta update admin woocommerce_admin_variable_product_tour_shown '"yes"' From 466489510b08f1d77fff6f4751fa3774ba8a7b02 Mon Sep 17 00:00:00 2001 From: Eason Su Date: Tue, 9 Apr 2024 17:16:48 +0800 Subject: [PATCH 02/17] Classic product editor E2E test: Prompt to Get Started when not yet finished onboarding --- .../classic-integration.test.js | 53 +++++++++++++++++++ tests/e2e/utils/product-editor.js | 28 ++++++++++ 2 files changed, 81 insertions(+) create mode 100644 tests/e2e/specs/product-editor/classic-integration.test.js diff --git a/tests/e2e/specs/product-editor/classic-integration.test.js b/tests/e2e/specs/product-editor/classic-integration.test.js new file mode 100644 index 0000000000..3e3ffe516d --- /dev/null +++ b/tests/e2e/specs/product-editor/classic-integration.test.js @@ -0,0 +1,53 @@ +/** + * External dependencies + */ +import { expect, test, Page } from '@playwright/test'; + +/** + * Internal dependencies + */ +import * as api from '../../utils/api'; +import { getClassicProductEditorUtils } from '../../utils/product-editor'; + +test.use( { storageState: process.env.ADMINSTATE } ); +test.describe.configure( { mode: 'serial' } ); + +test.describe( 'Classic Product Editor integration', () => { + /** + * @type {Page} + */ + let page = null; + let editorUtils = null; + + test.beforeAll( async ( { browser } ) => { + page = await browser.newPage(); + editorUtils = getClassicProductEditorUtils( page ); + + await api.setOnboardedMerchant(); + } ); + + test( 'Prompt to Get Started when not yet finished onboarding', async () => { + await api.clearOnboardedMerchant(); + await editorUtils.gotoAddProductPage(); + + await expect( editorUtils.getPluginTab() ).toBeHidden(); + + const link = editorUtils + .getChannelVisibilityMetaBox() + .getByRole( 'link', { name: 'Complete setup' } ); + + await expect( link ).toBeVisible(); + await expect( link ).toHaveAttribute( + 'href', + /\/wp-admin\/admin\.php\?page=wc-admin&path=\/google\/start/ + ); + + // Resume the plugin to onboarded status so that the next test can carry over. + await api.setOnboardedMerchant(); + } ); + + test.afterAll( async () => { + await api.clearOnboardedMerchant(); + await page.close(); + } ); +} ); diff --git a/tests/e2e/utils/product-editor.js b/tests/e2e/utils/product-editor.js index 28f80d8fc5..eb75f8faf0 100644 --- a/tests/e2e/utils/product-editor.js +++ b/tests/e2e/utils/product-editor.js @@ -10,6 +10,34 @@ import * as api from './api'; const REGEX_URL_PRODUCTS = /\/wc\/v3\/products\/\d+(\/variations\/\d+)?\?/; +/** + * Gets E2E test utils for facilitating writing tests for the classic product editor. + * + * @param {Page} page Playwright page object. + */ +export function getClassicProductEditorUtils( page ) { + const locators = { + getPluginTab() { + return page.locator( '.gla_attributes_tab' ); + }, + + getChannelVisibilityMetaBox() { + return page.locator( '#channel_visibility' ); + }, + }; + + const asyncActions = { + gotoAddProductPage() { + return page.goto( '/wp-admin/post-new.php?post_type=product' ); + }, + }; + + return { + ...locators, + ...asyncActions, + }; +} + /** * Gets E2E test utils for facilitating writing tests for Product Block Editor. * From 9a5e5b0cb32bf4705ff0872b4dd4784225cb8fcb Mon Sep 17 00:00:00 2001 From: Eason Su Date: Tue, 9 Apr 2024 17:17:23 +0800 Subject: [PATCH 03/17] Classic product editor E2E test: Hide plugin tab and meta box for unsupported product types --- .../classic-integration.test.js | 28 +++++++++++++++++++ tests/e2e/utils/product-editor.js | 20 +++++++++++++ 2 files changed, 48 insertions(+) diff --git a/tests/e2e/specs/product-editor/classic-integration.test.js b/tests/e2e/specs/product-editor/classic-integration.test.js index 3e3ffe516d..2411064a26 100644 --- a/tests/e2e/specs/product-editor/classic-integration.test.js +++ b/tests/e2e/specs/product-editor/classic-integration.test.js @@ -46,6 +46,34 @@ test.describe( 'Classic Product Editor integration', () => { await api.setOnboardedMerchant(); } ); + test( 'Hide plugin tab and meta box for unsupported product types', async () => { + await editorUtils.gotoAddProductPage(); + + const channelVisibilityMetaBox = + editorUtils.getChannelVisibilityMetaBox(); + + const pluginTab = editorUtils.getPluginTab(); + + await expect( channelVisibilityMetaBox ).toBeVisible(); + await expect( pluginTab ).toBeVisible(); + + await editorUtils.changeToGroupedProduct(); + await expect( channelVisibilityMetaBox ).toBeHidden(); + await expect( pluginTab ).toBeHidden(); + + await editorUtils.changeToSimpleProduct(); + await expect( channelVisibilityMetaBox ).toBeVisible(); + await expect( pluginTab ).toBeVisible(); + + await editorUtils.changeToExternalProduct(); + await expect( channelVisibilityMetaBox ).toBeHidden(); + await expect( pluginTab ).toBeHidden(); + + await editorUtils.changeToVariableProduct(); + await expect( channelVisibilityMetaBox ).toBeVisible(); + await expect( pluginTab ).toBeVisible(); + } ); + test.afterAll( async () => { await api.clearOnboardedMerchant(); await page.close(); diff --git a/tests/e2e/utils/product-editor.js b/tests/e2e/utils/product-editor.js index eb75f8faf0..1fe9ff2811 100644 --- a/tests/e2e/utils/product-editor.js +++ b/tests/e2e/utils/product-editor.js @@ -30,6 +30,26 @@ export function getClassicProductEditorUtils( page ) { gotoAddProductPage() { return page.goto( '/wp-admin/post-new.php?post_type=product' ); }, + + async changeProductType( type ) { + await page.locator( '#product-type' ).selectOption( type ); + }, + + changeToSimpleProduct() { + return this.changeProductType( 'simple' ); + }, + + changeToGroupedProduct() { + return this.changeProductType( 'grouped' ); + }, + + changeToExternalProduct() { + return this.changeProductType( 'external' ); + }, + + changeToVariableProduct() { + return this.changeProductType( 'variable' ); + }, }; return { From 2369b1929b83d865f04496f780fa87f3a23c5ee7 Mon Sep 17 00:00:00 2001 From: Eason Su Date: Tue, 9 Apr 2024 18:30:30 +0800 Subject: [PATCH 04/17] Classic product editor E2E test: Check existence and availability of fields for simple product --- .../classic-integration.test.js | 139 ++++++++++++++++++ tests/e2e/utils/product-editor.js | 20 +++ 2 files changed, 159 insertions(+) diff --git a/tests/e2e/specs/product-editor/classic-integration.test.js b/tests/e2e/specs/product-editor/classic-integration.test.js index 2411064a26..2b21e92e2c 100644 --- a/tests/e2e/specs/product-editor/classic-integration.test.js +++ b/tests/e2e/specs/product-editor/classic-integration.test.js @@ -74,6 +74,145 @@ test.describe( 'Classic Product Editor integration', () => { await expect( pluginTab ).toBeVisible(); } ); + test( 'Check existence and availability of fields for simple product', async () => { + await editorUtils.gotoAddProductPage(); + await editorUtils.clickPluginTab(); + + const panel = editorUtils.getPluginPanel(); + + /* + * 2 Headings + */ + await expect( editorUtils.getChannelVisibilityHeading() ).toBeVisible(); + await expect( editorUtils.getProductAttributesHeading() ).toBeVisible(); + + /* + * 1 + 8 : + * - GTIN + * - MPN + * - Size + * - Color + * - Material + * - Pattern + * - Availability date + * - Availability time + */ + await expect( panel.getByRole( 'textbox' ) ).toHaveCount( 8 ); + + /* + * 1 : + * - Multipack + */ + await expect( panel.getByRole( 'spinbutton' ) ).toHaveCount( 1 ); + + /* + * 16 pairs of