[e2e tests] Add tests for product inventory in product block editor (#44699)

* Remove describe blocks and duplicated page fixture

* Add test `can update sku`

* Add changelog

* Finish test 'can update sku'

* Add test 'can update stock status'

* Add test 'can track stock quantity'

* Add test 'can limit purchases'

* Remove extra whitespace

* Disable product editor tour

* Revert timeout update
This commit is contained in:
Adrian Moldovan 2024-02-21 00:25:16 +02:00 committed by GitHub
parent 487f230f0a
commit f4f4d798fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 516 additions and 310 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
E2E tests: add tests for product inventory in product block editor

View File

@ -18,5 +18,15 @@ exports.test = base.test.extend( {
await use( api );
},
wcAdminApi: async ( { baseURL }, use ) => {
const wcAdminApi = new wcApi( {
url: baseURL,
consumerKey: process.env.CONSUMER_KEY,
consumerSecret: process.env.CONSUMER_SECRET,
version: 'wc-admin', // Use wc-admin namespace
} );
await use( wcAdminApi );
},
} );
exports.expect = base.expect;

View File

@ -1,7 +1,8 @@
const { test } = require( '../../../../fixtures' );
exports.test = test.extend( {
page: async ( { page, api }, use ) => {
page: async ( { page, api, wcAdminApi }, use ) => {
// Enable product block editor
await api.put(
'settings/advanced/woocommerce_feature_product_block_editor_enabled',
{
@ -9,8 +10,14 @@ exports.test = test.extend( {
}
);
// Disable the product editor tour
await wcAdminApi.post( 'options', {
woocommerce_block_product_tour_shown: 'yes',
} );
await use( page );
// Disable product block editor
await api.put(
'settings/advanced/woocommerce_feature_product_block_editor_enabled',
{

View File

@ -1,7 +1,7 @@
const { test: baseTest } = require( './block-editor-fixtures' );
const { expect } = require( '../../../../fixtures' );
baseTest.describe( 'Products > Edit Product', () => {
const test = baseTest.extend( {
const test = baseTest.extend( {
product: async ( { api }, use ) => {
let product;
@ -23,29 +23,12 @@ baseTest.describe( 'Products > Edit Product', () => {
// Cleanup
await api.delete( `products/${ product.id }`, { force: true } );
},
page: async ( { page, api }, use ) => {
await api.put(
'settings/advanced/woocommerce_feature_product_block_editor_enabled',
{
value: 'yes',
}
);
} );
await use( page );
await api.put(
'settings/advanced/woocommerce_feature_product_block_editor_enabled',
{
value: 'no',
}
);
},
} );
test( 'can update the general information of a product', async ( {
test( 'can update the general information of a product', async ( {
page,
product,
} ) => {
} ) => {
await page.goto( `wp-admin/post.php?post=${ product.id }&action=edit` );
const updatedProduct = {
@ -91,9 +74,9 @@ baseTest.describe( 'Products > Edit Product', () => {
await test.step( 'publish the updated product', async () => {
await page.getByRole( 'button', { name: 'Update' } ).click();
await expect(
page.getByLabel( 'Dismiss this notice' )
).toContainText( 'Product updated' );
await expect( page.getByLabel( 'Dismiss this notice' ) ).toContainText(
'Product updated'
);
} );
await test.step( 'verify the changes', async () => {
@ -114,5 +97,4 @@ baseTest.describe( 'Products > Edit Product', () => {
.soft( salePriceTextbox )
.toHaveValue( updatedProduct.salePrice );
} );
} );
} );

View File

@ -23,8 +23,7 @@ async function selectImagesInLibrary( page, imagesNames ) {
return dataIds;
}
baseTest.describe( 'Products > Edit Product', () => {
const test = baseTest.extend( {
const test = baseTest.extend( {
product: async ( { api }, use ) => {
let product;
@ -67,15 +66,13 @@ baseTest.describe( 'Products > Edit Product', () => {
await use( productWithGallery );
},
} );
} );
test( 'can add images', async ( { page, product } ) => {
test( 'can add images', async ( { page, product } ) => {
const images = [ 'image-01', 'image-02' ];
await test.step( 'navigate to product edit page', async () => {
await page.goto(
`wp-admin/post.php?post=${ product.id }&action=edit`
);
await page.goto( `wp-admin/post.php?post=${ product.id }&action=edit` );
} );
await test.step( 'add images', async () => {
@ -98,9 +95,9 @@ baseTest.describe( 'Products > Edit Product', () => {
await test.step( 'update the product', async () => {
await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify product was updated
await expect(
page.getByLabel( 'Dismiss this notice' )
).toContainText( 'Product updated' );
await expect( page.getByLabel( 'Dismiss this notice' ) ).toContainText(
'Product updated'
);
} );
await test.step( 'verify product image was set', async () => {
@ -111,9 +108,9 @@ baseTest.describe( 'Products > Edit Product', () => {
await expect( page.getByTitle( image ) ).toBeVisible();
}
} );
} );
} );
test( 'can replace an image', async ( { page, productWithGallery } ) => {
test( 'can replace an image', async ( { page, productWithGallery } ) => {
const initialImagesCount = productWithGallery.images.length;
const newImageName = 'image-01';
const replacedImgLocator = page
@ -145,9 +142,9 @@ baseTest.describe( 'Products > Edit Product', () => {
await test.step( 'update the product', async () => {
await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify product was updated
await expect(
page.getByLabel( 'Dismiss this notice' )
).toContainText( 'Product updated' );
await expect( page.getByLabel( 'Dismiss this notice' ) ).toContainText(
'Product updated'
);
} );
await test.step( 'verify product image was set', async () => {
@ -160,9 +157,9 @@ baseTest.describe( 'Products > Edit Product', () => {
await page.goto( productWithGallery.permalink );
await expect( page.getByTitle( newImageName ) ).toBeVisible();
} );
} );
} );
test( 'can remove an image', async ( { page, productWithGallery } ) => {
test( 'can remove an image', async ( { page, productWithGallery } ) => {
const initialImagesCount = productWithGallery.images.length;
const removedImgLocator = page
.getByLabel( 'Block: Product images' )
@ -191,9 +188,9 @@ baseTest.describe( 'Products > Edit Product', () => {
await test.step( 'update the product', async () => {
await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify product was updated
await expect(
page.getByLabel( 'Dismiss this notice' )
).toContainText( 'Product updated' );
await expect( page.getByLabel( 'Dismiss this notice' ) ).toContainText(
'Product updated'
);
} );
await test.step( 'verify product image was set', async () => {
@ -207,12 +204,9 @@ baseTest.describe( 'Products > Edit Product', () => {
page.locator( `#product-${ productWithGallery.id } ol img` )
).toHaveCount( initialImagesCount - 1 );
} );
} );
} );
test( 'can set an image as cover', async ( {
page,
productWithGallery,
} ) => {
test( 'can set an image as cover', async ( { page, productWithGallery } ) => {
const newCoverImgLocator = page
.getByLabel( 'Block: Product images' )
.locator( 'img' )
@ -238,9 +232,9 @@ baseTest.describe( 'Products > Edit Product', () => {
await test.step( 'update the product', async () => {
await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify product was updated
await expect(
page.getByLabel( 'Dismiss this notice' )
).toContainText( 'Product updated' );
await expect( page.getByLabel( 'Dismiss this notice' ) ).toContainText(
'Product updated'
);
} );
await test.step( 'verify product image was set', async () => {
@ -248,5 +242,4 @@ baseTest.describe( 'Products > Edit Product', () => {
page.getByRole( 'button', { name: 'Cover' } ).locator( 'img' )
).toHaveId( newCoverImgId );
} );
} );
} );

View File

@ -0,0 +1,210 @@
const { test: baseTest } = require( './block-editor-fixtures' );
const { expect } = require( '../../../../fixtures' );
const test = baseTest.extend( {
product: async ( { api }, use ) => {
let product;
await api
.post( 'products', {
name: `Product ${ Date.now() }`,
type: 'simple',
regular_price: '12.99',
stock_status: 'instock',
} )
.then( ( response ) => {
product = response.data;
} );
await use( product );
// Cleanup
await api.delete( `products/${ product.id }`, { force: true } );
},
page: async ( { page, product }, use ) => {
await test.step( 'go to product editor, inventory tab', async () => {
await page.goto(
`wp-admin/post.php?post=${ product.id }&action=edit`
);
await page.getByRole( 'button', { name: 'Inventory' } ).click();
} );
await use( page );
},
} );
test( 'can update sku', async ( { page, product } ) => {
const sku = `SKU_${ Date.now() }`;
await test.step( 'update the sku value', async () => {
await page.locator( '[name="woocommerce-product-sku"]' ).fill( sku );
} );
await test.step( 'update the product', async () => {
await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify product was updated
await expect( page.getByLabel( 'Dismiss this notice' ) ).toContainText(
'Product updated'
);
} );
await test.step( 'verify the change in product editor', async () => {
await expect(
page.locator( '[name="woocommerce-product-sku"]' )
).toHaveValue( sku );
} );
await test.step( 'verify the changes in the store frontend', async () => {
// Verify image in store frontend
await page.goto( product.permalink );
await expect( page.getByText( `SKU: ${ sku }` ) ).toBeVisible();
} );
} );
test( 'can update stock status', async ( { page, product } ) => {
await test.step( 'update the sku value', async () => {
await page.getByLabel( 'Out of stock' ).check();
} );
await test.step( 'update the product', async () => {
await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify product was updated
await expect( page.getByLabel( 'Dismiss this notice' ) ).toContainText(
'Product updated'
);
} );
await test.step( 'verify the change in product editor', async () => {
await expect( page.getByLabel( 'Out of stock' ) ).toBeChecked();
} );
await test.step( 'verify the changes in the store frontend', async () => {
// Verify image in store frontend
await page.goto( product.permalink );
await expect( page.getByText( 'Out of stock' ) ).toBeVisible();
} );
} );
test( 'can track stock quantity', async ( { page, product } ) => {
await test.step( 'enable track stock quantity', async () => {
await page.getByLabel( 'Track stock quantity for this' ).check();
// await closeTourModal( { page, timeout: 2000 } );
await page.getByRole( 'button', { name: 'Advanced' } ).click();
await page.getByLabel( "Don't allow purchases" ).check();
} );
const quantity = '1';
await test.step( 'update available quantity', async () => {
await page.locator( '[name="stock_quantity"]' ).fill( quantity );
} );
await test.step( 'update the product', async () => {
await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify product was updated
await expect( page.getByLabel( 'Dismiss this notice' ) ).toContainText(
'Product updated'
);
} );
await test.step( 'verify the change in product editor', async () => {
await expect( page.locator( '[name="stock_quantity"]' ) ).toHaveValue(
quantity
);
} );
await test.step( 'verify the changes in the store frontend', async () => {
// Verify image in store frontend
await page.goto( product.permalink );
await expect(
page.getByText( `${ quantity } in stock` )
).toBeVisible();
} );
await test.step( 'return to product editor', async () => {
await page.goto( `wp-admin/post.php?post=${ product.id }&action=edit` );
await page.getByRole( 'button', { name: 'Inventory' } ).click();
} );
await test.step( 'update available quantity', async () => {
await page.locator( '[name="stock_quantity"]' ).fill( '0' );
} );
await test.step( 'update the product', async () => {
await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify product was updated
await expect( page.getByLabel( 'Dismiss this notice' ) ).toContainText(
'Product updated'
);
} );
await test.step( 'verify the change in product editor', async () => {
await expect( page.locator( '[name="stock_quantity"]' ) ).toHaveValue(
'0'
);
} );
await test.step( 'verify the changes in the store frontend', async () => {
// Verify image in store frontend
await page.goto( product.permalink );
await expect( page.getByText( 'Out of stock' ) ).toBeVisible();
} );
} );
test( 'can limit purchases', async ( { page, product } ) => {
await test.step( 'ensure limit purchases is disabled', async () => {
// await closeTourModal( { page, timeout: 2000 } );
await page.getByRole( 'button', { name: 'Advanced' } ).click();
await expect(
page.getByLabel( 'Limit purchases to 1 item per order' )
).not.toBeChecked();
} );
await test.step( 'add 2 items to cart', async () => {
// Verify image in store frontend
await page.goto( product.permalink );
await page.getByLabel( 'Product quantity' ).fill( '2' );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect(
page.getByText(
`2 ×${ product.name }” have been added to your cart.`
)
).toBeVisible();
} );
await test.step( 'return to product editor', async () => {
await page.goto( `wp-admin/post.php?post=${ product.id }&action=edit` );
await page.getByRole( 'button', { name: 'Inventory' } ).click();
} );
await test.step( 'enable limit purchases', async () => {
await page.getByRole( 'button', { name: 'Advanced' } ).click();
await page.getByLabel( 'Limit purchases to 1 item per order' ).check();
} );
await test.step( 'update the product', async () => {
await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify product was updated
await expect( page.getByLabel( 'Dismiss this notice' ) ).toContainText(
'Product updated'
);
} );
await test.step( 'verify you cannot order more than 1 item', async () => {
// Verify image in store frontend
await page.goto( product.permalink );
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await page.getByRole( 'button', { name: 'Add to cart' } ).click();
await expect(
page.getByText(
`You cannot add another "${ product.name }" to your cart.`
)
).toBeVisible();
} );
} );