[e2e tests] Fix linked products flaky test (#51099)
This commit is contained in:
parent
cfcf074886
commit
0be7e3deb0
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: dev
|
||||
|
||||
|
|
@ -2,15 +2,19 @@ const { test } = require( '../../../../fixtures/block-editor-fixtures' );
|
|||
const { expect } = require( '@playwright/test' );
|
||||
|
||||
const { clickOnTab } = require( '../../../../utils/simple-products' );
|
||||
const { api } = require( '../../../../utils' );
|
||||
const { helpers } = require( '../../../../utils' );
|
||||
|
||||
const NEW_EDITOR_ADD_PRODUCT_URL =
|
||||
'wp-admin/admin.php?page=wc-admin&path=%2Fadd-product';
|
||||
|
||||
const isTrackingSupposedToBeEnabled = !! process.env.ENABLE_TRACKING;
|
||||
|
||||
const uniqueId = helpers.random();
|
||||
let categoryId = 0;
|
||||
const categoryName = `cat_${ uniqueId }`;
|
||||
const productName = `Product ${ uniqueId }`;
|
||||
const productData = {
|
||||
name: `Linked product Name ${ new Date().getTime().toString() }`,
|
||||
name: `Linked ${ productName }`,
|
||||
summary: 'This is a product summary',
|
||||
};
|
||||
|
||||
|
@ -20,27 +24,45 @@ let productId = 0;
|
|||
|
||||
test.describe( 'General tab', { tag: '@gutenberg' }, () => {
|
||||
test.describe( 'Linked product', () => {
|
||||
test.beforeAll( async () => {
|
||||
test.beforeAll( async ( { api } ) => {
|
||||
await api
|
||||
.post( 'products/categories', {
|
||||
name: categoryName,
|
||||
} )
|
||||
.then( ( response ) => {
|
||||
categoryId = response.data.id;
|
||||
} );
|
||||
|
||||
for ( let i = 1; i <= 5; i++ ) {
|
||||
const product = {
|
||||
name: `Product name ${ i } ${ new Date()
|
||||
.getTime()
|
||||
.toString() }`,
|
||||
productPrice: `${ i }00`,
|
||||
name: `Product ${ uniqueId } ${ i }`,
|
||||
regular_price: `${ i }0000`,
|
||||
sale_price: `${ i }000`,
|
||||
type: 'simple',
|
||||
categories: [ { id: categoryId } ],
|
||||
};
|
||||
await api.post( 'products', product ).then( ( response ) => {
|
||||
productIds.push( response.data.id );
|
||||
linkedProductsData.push( product );
|
||||
const id = await api.create.product( product );
|
||||
productIds.push( id );
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
||||
test.afterAll( async () => {
|
||||
test.afterAll( async ( { api } ) => {
|
||||
for ( const aProductId of productIds ) {
|
||||
await api.deletePost.product( aProductId );
|
||||
}
|
||||
await api.deletePost.product( productId );
|
||||
await api.delete( `products/${ aProductId }`, {
|
||||
force: true,
|
||||
} );
|
||||
}
|
||||
await api.delete( `products/${ productId }`, {
|
||||
force: true,
|
||||
} );
|
||||
|
||||
await api.delete( `products/categories/${ categoryId }`, {
|
||||
force: true,
|
||||
} );
|
||||
} );
|
||||
|
||||
test.skip(
|
||||
isTrackingSupposedToBeEnabled,
|
||||
'The block product editor is not being tested'
|
||||
|
@ -61,7 +83,30 @@ test.describe( 'General tab', { tag: '@gutenberg' }, () => {
|
|||
.last()
|
||||
.fill( productData.summary );
|
||||
|
||||
// Include in category
|
||||
await clickOnTab( 'Organization', page );
|
||||
const waitForCategoriesResponse = page.waitForResponse(
|
||||
( response ) =>
|
||||
response.url().includes( '/wp-json/wp/v2/product_cat' ) &&
|
||||
response.status() === 200
|
||||
);
|
||||
await page.getByLabel( 'Categories' ).click();
|
||||
await waitForCategoriesResponse;
|
||||
await page.getByLabel( categoryName ).check();
|
||||
await page.getByLabel( `Remove Uncategorized` ).click();
|
||||
await expect(
|
||||
page.getByLabel( `Remove ${ categoryName }` )
|
||||
).toBeVisible();
|
||||
|
||||
const waitForProductsSearchResponse = page.waitForResponse(
|
||||
( response ) =>
|
||||
response
|
||||
.url()
|
||||
.includes( '/wp-json/wc/v3/products?search' ) &&
|
||||
response.status() === 200
|
||||
);
|
||||
await clickOnTab( 'Linked products', page );
|
||||
await waitForProductsSearchResponse;
|
||||
|
||||
await expect(
|
||||
page.getByRole( 'heading', {
|
||||
|
@ -75,7 +120,7 @@ test.describe( 'General tab', { tag: '@gutenberg' }, () => {
|
|||
)
|
||||
.first()
|
||||
.getByRole( 'combobox' )
|
||||
.fill( linkedProductsData[ 0 ].name );
|
||||
.fill( productName );
|
||||
|
||||
await page.getByText( linkedProductsData[ 0 ].name ).click();
|
||||
|
||||
|
@ -92,7 +137,7 @@ test.describe( 'General tab', { tag: '@gutenberg' }, () => {
|
|||
await chooseProductsResponsePromise;
|
||||
|
||||
await expect(
|
||||
page.getByRole( 'row', { name: 'Product name' } )
|
||||
page.getByRole( 'row', { name: productName } )
|
||||
).toHaveCount( 4 );
|
||||
|
||||
const upsellsRows = page.locator(
|
||||
|
|
Loading…
Reference in New Issue