Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[E2E test coverage]: Disable block product editor #39493

Merged
merged 46 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
295161a
Remove ENABLE_NEW_PRODUCT_EDITOR
octaedro Jul 27, 2023
b3cf2ce
add block-product-editor.spec.js
octaedro Jul 27, 2023
acad50f
Remove old editor tests
octaedro Jul 27, 2023
40a92ce
Add changelog
octaedro Jul 27, 2023
fc5bd5b
Improve `isNewProductEditorEnabled`
octaedro Jul 27, 2023
a2fc765
Refactor enable-block-product-editor
octaedro Jul 31, 2023
5b7633b
Fix enabling
octaedro Jul 31, 2023
3f877ef
Fix NEW_EDITOR_ADD_PRODUCT_URL
octaedro Aug 4, 2023
84f9009
Add test disable new product editor
octaedro Jul 31, 2023
b604410
Add changelog
octaedro Jul 31, 2023
f8d9fde
Clean code
octaedro Jul 31, 2023
732a9dc
Fix disabling
octaedro Jul 31, 2023
77068cc
Moved methods
octaedro Aug 1, 2023
7feed0f
Fix comment
octaedro Aug 4, 2023
496e27b
Fix url
octaedro Aug 4, 2023
2ccfdab
Add `clickOnTab` function
octaedro Aug 2, 2023
b4e7863
Add "general-tab"
octaedro Aug 2, 2023
9e254ce
Add changelog
octaedro Aug 2, 2023
cbfc6a4
Add sale price
octaedro Aug 2, 2023
1e3c1c4
Rename file
octaedro Aug 3, 2023
9605745
Rename file
octaedro Aug 3, 2023
2bc01d3
rename file again
octaedro Aug 3, 2023
6de25cd
Fix product creation tests
octaedro Aug 4, 2023
ed2e54c
Fix test
octaedro Aug 4, 2023
6d115b8
add block-product-editor.spec.js
octaedro Jul 27, 2023
99b4a06
Improve `isNewProductEditorEnabled`
octaedro Jul 27, 2023
2b6c11d
Refactor enable-block-product-editor
octaedro Jul 31, 2023
d08c8ce
Fix enabling
octaedro Jul 31, 2023
b9c217b
Add test disable new product editor
octaedro Jul 31, 2023
7ee799b
Add changelog
octaedro Jul 31, 2023
6adf413
Clean code
octaedro Jul 31, 2023
6c3a38f
Fix disabling
octaedro Jul 31, 2023
e08322e
Moved methods
octaedro Aug 1, 2023
4a2e791
Fix comment
octaedro Aug 4, 2023
df1ce80
Fix url
octaedro Aug 4, 2023
498f193
Add `clickOnTab` function
octaedro Aug 2, 2023
700f493
Add "general-tab"
octaedro Aug 2, 2023
eefddfd
Add changelog
octaedro Aug 2, 2023
6076235
Add sale price
octaedro Aug 2, 2023
08c7841
Rename file
octaedro Aug 3, 2023
6519105
Rename file
octaedro Aug 3, 2023
32cfdb7
rename file again
octaedro Aug 3, 2023
0f5bdaf
Fix product creation tests
octaedro Aug 4, 2023
4bbce3d
Fix test
octaedro Aug 4, 2023
eb1e9af
Merge branch 'add/39411_tests_to_general_tab' into add/39417_disable_…
octaedro Aug 8, 2023
07cd6f3
Remove expect not used
octaedro Aug 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/add-39411_tests_to_general_tab
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

[E2E test coverage]: General tab #39411
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

[E2E test coverage]: Disable block product editor #39417
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
const { test, expect } = require( '@playwright/test' );

const {
clickOnTab,
isBlockProductEditorEnabled,
toggleBlockProductEditor,
} = require( '../../../../utils/simple-products' );

const NEW_EDITOR_ADD_PRODUCT_URL =
'wp-admin/admin.php?page=wc-admin&path=%2Fadd-product';

let isNewProductEditorEnabled = false;

const isTrackingSupposedToBeEnabled = !! process.env.ENABLE_TRACKING;

const productData = {
name: `Simple product Name ${ new Date().getTime().toString() }`,
summary: 'This is a product summary',
productPrice: '100',
salePrice: '90',
};

test.describe( 'General tab', () => {
test.describe.serial( 'Create product', () => {
let productId;
test.use( { storageState: process.env.ADMINSTATE } );

test.skip(
isTrackingSupposedToBeEnabled,
'The block product editor is not being tested'
);

test.beforeEach( async ( { browser } ) => {
const context = await browser.newContext();
const page = await context.newPage();
isNewProductEditorEnabled = await isBlockProductEditorEnabled(
page
);
if ( ! isNewProductEditorEnabled ) {
await toggleBlockProductEditor( 'enable', page );
}
} );

test.afterEach( async ( { browser } ) => {
const context = await browser.newContext();
const page = await context.newPage();
isNewProductEditorEnabled = await isBlockProductEditorEnabled(
page
);
if ( isNewProductEditorEnabled ) {
await toggleBlockProductEditor( 'disable', page );
}
} );

test( 'can create a simple product', async ( { page } ) => {
await page.goto( NEW_EDITOR_ADD_PRODUCT_URL );
await clickOnTab( 'General', page );
await page
.getByPlaceholder( 'e.g. 12 oz Coffee Mug' )
.fill( productData.name );
await page
.locator( '.components-summary-control' )
.fill( productData.summary );
await page
.locator(
'[id^="wp-block-woocommerce-product-regular-price-field"]'
)
.first()
.fill( productData.productPrice );
await page
.locator(
'[id^="wp-block-woocommerce-product-sale-price-field"]'
)
.first()
.fill( productData.salePrice );

await page
.locator( '.woocommerce-product-header__actions' )
.getByRole( 'button', {
name: 'Add',
} )
.click();

const element = await page.locator(
'div.components-snackbar__content'
);
const textContent = await element.innerText();

await expect( textContent ).toMatch( /Product added/ );

const title = await page.locator(
'.woocommerce-product-header__title'
);

// Save product ID
const productIdRegex = /product%2F(\d+)/;
const url = await page.url();
const productIdMatch = productIdRegex.exec( url );
productId = productIdMatch ? productIdMatch[ 1 ] : null;

await expect( productId ).toBeDefined();
await expect( title ).toHaveText( productData.name );
} );
test( 'can not create a product with duplicated SKU', async ( {
page,
} ) => {
await page.goto( NEW_EDITOR_ADD_PRODUCT_URL );
await clickOnTab( 'General', page );
await page
.locator( '//input[@placeholder="e.g. 12 oz Coffee Mug"]' )
.fill( productData.name );
await page
.locator( '.components-summary-control' )
.fill( productData.summary );
await page
.locator(
'[id^="wp-block-woocommerce-product-regular-price-field"]'
)
.first()
.fill( productData.productPrice );
await page
.locator( '.woocommerce-product-header__actions' )
.getByRole( 'button', {
name: 'Add',
} )
.click();

const element = await page.locator(
'div.components-snackbar__content'
);
const textContent = await element.innerText();

await expect( textContent ).toMatch( /Invalid or duplicated SKU./ );
} );
test( 'can a shopper add the simple product to the cart', async ( {
page,
} ) => {
await page.goto( `/?post_type=product&p=${ productId }`, {
waitUntil: 'networkidle',
} );
await expect( page.locator( '.product_title' ) ).toHaveText(
productData.name
);
const productPriceElements = await page
.locator( '.summary .woocommerce-Price-amount' )
.all();

let foundProductPrice = false;
let foundSalePrice = false;
for ( const element of productPriceElements ) {
const textContent = await element.innerText();
if ( textContent.includes( productData.productPrice ) ) {
foundProductPrice = true;
}
if ( textContent.includes( productData.salePrice ) ) {
foundSalePrice = true;
}
}
await expect( foundProductPrice && foundSalePrice ).toBeTruthy();

await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await page.getByRole( 'link', { name: 'View cart' } ).click();
await expect(
page.locator( 'td[data-title=Product]' ).first()
).toContainText( productData.name );
await page
.locator( `a.remove[data-product_id='${ productId }']` )
.click();
await page.waitForLoadState( 'networkidle' );
await expect(
page.locator( `a.remove[data-product_id='${ productId }']` )
).not.toBeVisible();
} );
} );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const { test } = require( '@playwright/test' );
const {
clickAddNewMenuItem,
expectBlockProductEditor,
expectOldProductEditor,
isBlockProductEditorEnabled,
toggleBlockProductEditor,
} = require( '../../../../utils/simple-products' );

const ALL_PRODUCTS_URL = 'wp-admin/edit.php?post_type=product';
const NEW_EDITOR_ADD_PRODUCT_URL =
'wp-admin/admin.php?page=wc-admin&path=%2Fadd-product';
const SETTINGS_URL =
'wp-admin/admin.php?page=wc-settings&tab=advanced&section=features';

let isNewProductEditorEnabled = false;

const isTrackingSupposedToBeEnabled = !! process.env.ENABLE_TRACKING;

async function dismissFeedbackModalIfShown( page ) {
if ( ! isTrackingSupposedToBeEnabled ) {
// no modal should be shown, so don't even look for button
return;
}

try {
await page
.locator( '.woocommerce-product-mvp-feedback-modal' )
.getByRole( 'button', { name: 'Skip' } )
.click( { timeout: 5000 } );
} catch ( error ) {}
}

test.describe.serial( 'Disable block product editor', () => {
test.use( { storageState: process.env.ADMINSTATE } );

test.beforeEach( async ( { page } ) => {
isNewProductEditorEnabled = await isBlockProductEditorEnabled( page );
if ( ! isNewProductEditorEnabled ) {
await toggleBlockProductEditor( 'enable', page );
}
} );

test.afterEach( async ( { browser } ) => {
const context = await browser.newContext();
const page = await context.newPage();
isNewProductEditorEnabled = await isBlockProductEditorEnabled( page );
if ( isNewProductEditorEnabled ) {
await toggleBlockProductEditor( 'disable', page );
}
} );

test.skip(
isNewProductEditorEnabled && isTrackingSupposedToBeEnabled,
'The block product editor is not being tested'
);

test( 'is hooked up to sidebar "Add New"', async ( { page } ) => {
await page.goto( ALL_PRODUCTS_URL );
await clickAddNewMenuItem( page );
await expectBlockProductEditor( page );
} );

test( 'can be disabled from the header', async ( { page } ) => {
await page.goto( NEW_EDITOR_ADD_PRODUCT_URL );

// turn off block product editor from the header
await page
.locator( '.components-dropdown-menu' )
.getByRole( 'button', { name: 'Options' } )
.click();
await page
.getByRole( 'menuitem', {
name: 'Turn off the new product form',
} )
.click();
await dismissFeedbackModalIfShown( page );
await expectOldProductEditor( page );
} );
test( 'can be disabled from settings', async ( { page } ) => {
await toggleBlockProductEditor( 'disable', page );
await page.goto( ALL_PRODUCTS_URL );
await clickAddNewMenuItem( page );
await expectOldProductEditor( page );
} );
} );
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { test, expect } = require( '@playwright/test' );
const {
clickAddNewMenuItem,
expectBlockProductEditor,
expectOldProductEditor,
isBlockProductEditorEnabled,
toggleBlockProductEditor,
} = require( '../../../../utils/simple-products' );
Expand All @@ -13,18 +15,6 @@ let isNewProductEditorEnabled = false;

const isTrackingSupposedToBeEnabled = !! process.env.ENABLE_TRACKING;

async function expectOldProductEditor( page ) {
await expect(
page.locator( '#woocommerce-product-data h2' )
).toContainText( 'Product data' );
}

async function expectBlockProductEditor( page ) {
await expect(
page.locator( '.woocommerce-product-header__inner h1' )
).toContainText( 'Add new product' );
}

async function disableNewEditorIfEnabled( browser ) {
const context = await browser.newContext();
const page = await context.newPage();
Expand Down
41 changes: 41 additions & 0 deletions plugins/woocommerce/tests/e2e-pw/utils/simple-products.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { expect } = require( '@playwright/test' );

const SETTINGS_URL =
'wp-admin/admin.php?page=wc-settings&tab=advanced&section=features';

Expand Down Expand Up @@ -54,8 +56,47 @@ async function clickAddNewMenuItem( page ) {
.click();
}

/**
* This function checks if the old product editor is visible.
*
* @param {Page} page
*/
async function expectOldProductEditor( page ) {
await expect(
page.locator( '#woocommerce-product-data h2' )
).toContainText( 'Product data' );
}

/**
* This function checks if the block product editor is visible.
*
* @param {Page} page
*/
async function expectBlockProductEditor( page ) {
await expect(
page.locator( '.woocommerce-product-header__inner h1' )
).toContainText( 'Add new product' );
}

/**
* Click on a block editor tab.
*
* @param {Page} page
* @param {string} tabName
*/
async function clickOnTab( tabName, page ) {
await page
// .locator( '.woocommerce-product-tab__general-content' )
.locator( '.woocommerce-product-tabs' )
.getByRole( 'button', { name: tabName } )
.click();
}

module.exports = {
expectBlockProductEditor,
expectOldProductEditor,
clickAddNewMenuItem,
clickOnTab,
isBlockProductEditorEnabled,
toggleBlockProductEditor,
};