[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 { expect } = require( '@playwright/test' );
|
||||||
|
|
||||||
const { clickOnTab } = require( '../../../../utils/simple-products' );
|
const { clickOnTab } = require( '../../../../utils/simple-products' );
|
||||||
const { api } = require( '../../../../utils' );
|
const { helpers } = require( '../../../../utils' );
|
||||||
|
|
||||||
const NEW_EDITOR_ADD_PRODUCT_URL =
|
const NEW_EDITOR_ADD_PRODUCT_URL =
|
||||||
'wp-admin/admin.php?page=wc-admin&path=%2Fadd-product';
|
'wp-admin/admin.php?page=wc-admin&path=%2Fadd-product';
|
||||||
|
|
||||||
const isTrackingSupposedToBeEnabled = !! process.env.ENABLE_TRACKING;
|
const isTrackingSupposedToBeEnabled = !! process.env.ENABLE_TRACKING;
|
||||||
|
|
||||||
|
const uniqueId = helpers.random();
|
||||||
|
let categoryId = 0;
|
||||||
|
const categoryName = `cat_${ uniqueId }`;
|
||||||
|
const productName = `Product ${ uniqueId }`;
|
||||||
const productData = {
|
const productData = {
|
||||||
name: `Linked product Name ${ new Date().getTime().toString() }`,
|
name: `Linked ${ productName }`,
|
||||||
summary: 'This is a product summary',
|
summary: 'This is a product summary',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -20,27 +24,45 @@ let productId = 0;
|
||||||
|
|
||||||
test.describe( 'General tab', { tag: '@gutenberg' }, () => {
|
test.describe( 'General tab', { tag: '@gutenberg' }, () => {
|
||||||
test.describe( 'Linked product', () => {
|
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++ ) {
|
for ( let i = 1; i <= 5; i++ ) {
|
||||||
const product = {
|
const product = {
|
||||||
name: `Product name ${ i } ${ new Date()
|
name: `Product ${ uniqueId } ${ i }`,
|
||||||
.getTime()
|
regular_price: `${ i }0000`,
|
||||||
.toString() }`,
|
sale_price: `${ i }000`,
|
||||||
productPrice: `${ i }00`,
|
|
||||||
type: 'simple',
|
type: 'simple',
|
||||||
|
categories: [ { id: categoryId } ],
|
||||||
};
|
};
|
||||||
linkedProductsData.push( product );
|
await api.post( 'products', product ).then( ( response ) => {
|
||||||
const id = await api.create.product( product );
|
productIds.push( response.data.id );
|
||||||
productIds.push( id );
|
linkedProductsData.push( product );
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test.afterAll( async () => {
|
test.afterAll( async ( { api } ) => {
|
||||||
for ( const aProductId of productIds ) {
|
for ( const aProductId of productIds ) {
|
||||||
await api.deletePost.product( aProductId );
|
await api.delete( `products/${ aProductId }`, {
|
||||||
|
force: true,
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
await api.deletePost.product( productId );
|
await api.delete( `products/${ productId }`, {
|
||||||
|
force: true,
|
||||||
|
} );
|
||||||
|
|
||||||
|
await api.delete( `products/categories/${ categoryId }`, {
|
||||||
|
force: true,
|
||||||
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test.skip(
|
test.skip(
|
||||||
isTrackingSupposedToBeEnabled,
|
isTrackingSupposedToBeEnabled,
|
||||||
'The block product editor is not being tested'
|
'The block product editor is not being tested'
|
||||||
|
@ -61,7 +83,30 @@ test.describe( 'General tab', { tag: '@gutenberg' }, () => {
|
||||||
.last()
|
.last()
|
||||||
.fill( productData.summary );
|
.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 clickOnTab( 'Linked products', page );
|
||||||
|
await waitForProductsSearchResponse;
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByRole( 'heading', {
|
page.getByRole( 'heading', {
|
||||||
|
@ -75,7 +120,7 @@ test.describe( 'General tab', { tag: '@gutenberg' }, () => {
|
||||||
)
|
)
|
||||||
.first()
|
.first()
|
||||||
.getByRole( 'combobox' )
|
.getByRole( 'combobox' )
|
||||||
.fill( linkedProductsData[ 0 ].name );
|
.fill( productName );
|
||||||
|
|
||||||
await page.getByText( linkedProductsData[ 0 ].name ).click();
|
await page.getByText( linkedProductsData[ 0 ].name ).click();
|
||||||
|
|
||||||
|
@ -92,7 +137,7 @@ test.describe( 'General tab', { tag: '@gutenberg' }, () => {
|
||||||
await chooseProductsResponsePromise;
|
await chooseProductsResponsePromise;
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByRole( 'row', { name: 'Product name' } )
|
page.getByRole( 'row', { name: productName } )
|
||||||
).toHaveCount( 4 );
|
).toHaveCount( 4 );
|
||||||
|
|
||||||
const upsellsRows = page.locator(
|
const upsellsRows = page.locator(
|
||||||
|
|
Loading…
Reference in New Issue