[e2e tests] Fix flaky test create-variable-product-block-editor > can create a variation option and publish the product (#51246)

This commit is contained in:
Adrian Moldovan 2024-09-10 13:51:45 +01:00 committed by GitHub
parent 9fd4b54902
commit 31a2474c3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 15 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev

View File

@ -147,10 +147,25 @@ test.describe( 'Variations tab', { tag: '@gutenberg' }, () => {
); );
for ( const term of sizeAttribute.terms ) { for ( const term of sizeAttribute.terms ) {
const apiResponsePromise = page.waitForResponse(
( response ) => {
const urlToMatch = `/wp-json/wc/v3/products/attributes/${ newAttrData.id }/terms?name=${ term.name }&slug=${ term.slug }`;
return (
response
.url()
.includes( encodeURI( urlToMatch ) ) &&
response.status() === 201
);
}
);
// Fill the input field with the option // Fill the input field with the option
await FormTokenFieldInputLocator.fill( term.name ); await FormTokenFieldInputLocator.fill( term.name );
await FormTokenFieldInputLocator.press( 'Enter' ); await FormTokenFieldInputLocator.press( 'Enter' );
await apiResponsePromise;
/* /*
* Check the new option is added to the list, * Check the new option is added to the list,
* by checking the last aria-hidden * by checking the last aria-hidden
@ -163,21 +178,6 @@ test.describe( 'Variations tab', { tag: '@gutenberg' }, () => {
await expect( newAriaHiddenTokenLocator ).toHaveText( await expect( newAriaHiddenTokenLocator ).toHaveText(
term.name term.name
); );
/*
* Wait for the async POST request
* that creates the new attribute term to finish.
*/
await page.waitForResponse( ( response ) => {
const urlToMatch = `/wp-json/wc/v3/products/attributes/${ newAttrData.id }/terms?name=${ term.name }&slug=${ term.slug }&_locale=user`;
return (
response
.url()
.includes( encodeURI( urlToMatch ) ) &&
response.status() === 201
);
} );
} }
await page await page