From a23e975eaa1925e7da73a69269fa9923dc9efbfd Mon Sep 17 00:00:00 2001 From: Veljko V Date: Mon, 18 Sep 2023 23:18:29 +0200 Subject: [PATCH] Add new E2E test for Shopper Product-related flows (#40132) * Add new E2E test to cover Shopper Product page * Make product-related tests granular --- .../e2e-add-new-test-shopper-product | 4 + .../tests/shopper/product-grouped.spec.js | 120 +++++++ .../tests/shopper/product-simple.spec.js | 223 ++++++++++++ ...dates.spec.js => product-variable.spec.js} | 145 +++++++- .../tests/shopper/single-product.spec.js | 326 ------------------ 5 files changed, 485 insertions(+), 333 deletions(-) create mode 100644 plugins/woocommerce/changelog/e2e-add-new-test-shopper-product create mode 100644 plugins/woocommerce/tests/e2e-pw/tests/shopper/product-grouped.spec.js create mode 100644 plugins/woocommerce/tests/e2e-pw/tests/shopper/product-simple.spec.js rename plugins/woocommerce/tests/e2e-pw/tests/shopper/{variable-product-updates.spec.js => product-variable.spec.js} (65%) delete mode 100644 plugins/woocommerce/tests/e2e-pw/tests/shopper/single-product.spec.js diff --git a/plugins/woocommerce/changelog/e2e-add-new-test-shopper-product b/plugins/woocommerce/changelog/e2e-add-new-test-shopper-product new file mode 100644 index 00000000000..d3d8827ff09 --- /dev/null +++ b/plugins/woocommerce/changelog/e2e-add-new-test-shopper-product @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Add new E2E test covering shopper product page and make Product-related tests granular (separated test files) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/product-grouped.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/product-grouped.spec.js new file mode 100644 index 00000000000..72e02d8e4fe --- /dev/null +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/product-grouped.spec.js @@ -0,0 +1,120 @@ +const { test, expect } = require( '@playwright/test' ); +const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; + +const productPrice = '18.16'; +const simpleProductName = 'Simple single product'; +const groupedProductName = 'Grouped single product'; + +let simpleProductId, simpleProduct2Id, groupedProductId; + +test.describe( 'Grouped Product Page', () => { + const slug = groupedProductName.replace( / /gi, '-' ).toLowerCase(); + const simpleProduct1 = simpleProductName + ' 1'; + const simpleProduct2 = simpleProductName + ' 2'; + + test.beforeAll( async ( { baseURL } ) => { + const api = new wcApi( { + url: baseURL, + consumerKey: process.env.CONSUMER_KEY, + consumerSecret: process.env.CONSUMER_SECRET, + version: 'wc/v3', + } ); + // add products + await api + .post( 'products', { + name: simpleProduct1, + type: 'simple', + regular_price: productPrice, + } ) + .then( ( response ) => { + simpleProductId = response.data.id; + } ); + await api + .post( 'products', { + name: simpleProduct2, + type: 'simple', + regular_price: productPrice, + } ) + .then( ( response ) => { + simpleProduct2Id = response.data.id; + } ); + await api + .post( 'products', { + name: groupedProductName, + type: 'grouped', + grouped_products: [ simpleProductId, simpleProduct2Id ], + } ) + .then( ( response ) => { + groupedProductId = response.data.id; + } ); + } ); + + test.beforeEach( async ( { context } ) => { + // Shopping cart is very sensitive to cookies, so be explicit + await context.clearCookies(); + } ); + + test.afterAll( async ( { baseURL } ) => { + const api = new wcApi( { + url: baseURL, + consumerKey: process.env.CONSUMER_KEY, + consumerSecret: process.env.CONSUMER_SECRET, + version: 'wc/v3', + } ); + await api.delete( `products/${ simpleProductId }`, { + force: true, + } ); + await api.delete( `products/${ simpleProduct2Id }`, { + force: true, + } ); + await api.delete( `products/${ groupedProductId }`, { + force: true, + } ); + } ); + + test( 'should be able to add grouped products to the cart', async ( { + page, + } ) => { + await page.goto( `product/${ slug }` ); + + await page.getByRole( 'button', { name: 'Add to cart' } ).click(); + await expect( page.locator( '.woocommerce-error' ) ).toContainText( + 'Please choose the quantity of items you wish to add to your cart…' + ); + + await page.locator( 'div.quantity input.qty >> nth=0' ).fill( '5' ); + await page.locator( 'div.quantity input.qty >> nth=1' ).fill( '5' ); + await page.getByRole( 'button', { name: 'Add to cart' } ).click(); + await expect( page.locator( '.woocommerce-message' ) ).toContainText( + `“${ simpleProduct1 }” and “${ simpleProduct2 }” have been added to your cart.` + ); + + await page.goto( 'cart/' ); + await expect( + page.locator( 'td.product-name >> nth=0' ) + ).toContainText( simpleProduct1 ); + await expect( + page.locator( 'td.product-name >> nth=1' ) + ).toContainText( simpleProduct2 ); + await expect( page.locator( 'tr.order-total > td' ) ).toContainText( + ( +productPrice * 10 ).toString() + ); + } ); + + test( 'should be able to remove grouped products from the cart', async ( { + page, + } ) => { + await page.goto( `product/${ slug }` ); + await page.locator( 'div.quantity input.qty >> nth=0' ).fill( '1' ); + await page.locator( 'div.quantity input.qty >> nth=1' ).fill( '1' ); + await page.getByRole( 'button', { name: 'Add to cart' } ).click(); + + await page.goto( 'cart/' ); + await page.locator( 'a.remove >> nth=1' ).click(); + await page.locator( 'a.remove >> nth=0' ).click(); + + await expect( page.locator( '.cart-empty' ) ).toContainText( + 'Your cart is currently empty.' + ); + } ); +} ); diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/product-simple.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/product-simple.spec.js new file mode 100644 index 00000000000..1f4a32e1cd6 --- /dev/null +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/product-simple.spec.js @@ -0,0 +1,223 @@ +const { test, expect } = require( '@playwright/test' ); +const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; + +const productPrice = '18.16'; +const simpleProductName = 'Simple single product'; + +let simpleProductId, + simpleProduct1Id, + simpleProduct2Id, + productCategory1Id, + productCategory2Id; + +test.describe( 'Single Product Page', () => { + const simpleProduct1 = simpleProductName + ' Related'; + const simpleProduct2 = simpleProductName + ' Upsell'; + const productCategoryName1 = 'Hoodies'; + const productCategoryName2 = 'Jumpers'; + const productDescription = 'Lorem ipsum dolor sit amet.'; + + test.beforeAll( async ( { baseURL } ) => { + const api = new wcApi( { + url: baseURL, + consumerKey: process.env.CONSUMER_KEY, + consumerSecret: process.env.CONSUMER_SECRET, + version: 'wc/v3', + } ); + + // add product categories + await api + .post( 'products/categories', { + name: productCategoryName1, + } ) + .then( ( response ) => { + productCategory1Id = response.data.id; + } ); + await api + .post( 'products/categories', { + name: productCategoryName2, + } ) + .then( ( response ) => { + productCategory2Id = response.data.id; + } ); + + // add products + await api + .post( 'products', { + name: simpleProduct1, + type: 'simple', + categories: [ + { + id: productCategory1Id, + name: productCategoryName1, + }, + ], + regular_price: productPrice, + } ) + .then( ( response ) => { + simpleProduct1Id = response.data.id; + } ); + await api + .post( 'products', { + name: simpleProduct2, + type: 'simple', + categories: [ + { + id: productCategory2Id, + name: productCategoryName2, + }, + ], + regular_price: productPrice, + } ) + .then( ( response ) => { + simpleProduct2Id = response.data.id; + } ); + await api + .post( 'products', { + name: simpleProductName, + description: productDescription, + type: 'simple', + categories: [ + { + id: productCategory1Id, + name: productCategoryName1, + }, + ], + regular_price: productPrice, + related_ids: simpleProduct1Id, + upsell_ids: simpleProduct2Id, + } ) + .then( ( response ) => { + simpleProductId = response.data.id; + } ); + } ); + + test.beforeEach( async ( { context } ) => { + // Shopping cart is very sensitive to cookies, so be explicit + await context.clearCookies(); + } ); + + test.afterAll( async ( { baseURL } ) => { + const api = new wcApi( { + url: baseURL, + consumerKey: process.env.CONSUMER_KEY, + consumerSecret: process.env.CONSUMER_SECRET, + version: 'wc/v3', + } ); + await api.delete( `products/${ simpleProductId }`, { + force: true, + } ); + await api.delete( `products/${ simpleProduct1Id }`, { + force: true, + } ); + await api.delete( `products/${ simpleProduct2Id }`, { + force: true, + } ); + await api.post( 'products/categories/batch', { + delete: [ productCategory1Id, productCategory2Id ], + } ); + } ); + + test( 'should be able to see upsell and related products', async ( { + page, + } ) => { + const slug = simpleProductName.replace( / /gi, '-' ).toLowerCase(); + await page.goto( `product/${ slug }` ); + + await expect( page.locator( '.upsells > h2' ) ).toContainText( + 'You may also like…' + ); + await expect( page.locator( '.related > h2' ) ).toContainText( + 'Related products' + ); + await expect( + page.locator( + '.upsells > .products > li > a > .woocommerce-loop-product__title' + ) + ).toContainText( simpleProduct2 ); + await expect( + page.locator( + '.related > .products > li > a > .woocommerce-loop-product__title' + ) + ).toContainText( simpleProduct1 ); + } ); + + test( 'should be able to post a review and see it after', async ( { + page, + } ) => { + await page.goto( 'my-account' ); + await page.locator( '#username' ).fill( 'admin' ); + await page.locator( '#password' ).fill( 'password' ); + await page.locator( 'text=Log in' ).click(); + + const slug = simpleProductName.replace( / /gi, '-' ).toLowerCase(); + await page.goto( `product/${ slug }` ); + + await expect( page.locator( '.reviews_tab' ) ).toContainText( + 'Reviews (0)' + ); + await page.locator( '.reviews_tab' ).click(); + await page.locator( '.star-4' ).click(); + await page.locator( '#comment' ).fill( 'This product is great!' ); + await page.locator( 'text=Submit' ).click(); + await expect( + page.locator( '.woocommerce-Reviews-title' ) + ).toContainText( `1 review for ${ simpleProductName }` ); + await expect( page.locator( '.reviews_tab' ) ).toContainText( + 'Reviews (1)' + ); + } ); + + test( 'should be able to see product description and image', async ( { + page, + } ) => { + const slug = simpleProductName.replace( / /gi, '-' ).toLowerCase(); + await page.goto( `product/${ slug }` ); + + await expect( page.locator( '#tab-description > p' ) ).toContainText( + productDescription + ); + await expect( + page.locator( + '.woocommerce-product-gallery__image--placeholder > .wp-post-image' + ) + ).toBeVisible(); + } ); + + test( 'should be able to add simple products to the cart', async ( { + page, + } ) => { + const slug = simpleProductName.replace( / /gi, '-' ).toLowerCase(); + await page.goto( `product/${ slug }` ); + + await page.locator( 'input.qty' ).fill( '5' ); + await page.getByRole( 'button', { name: 'Add to cart' } ).click(); + + await expect( page.locator( '.woocommerce-message' ) ).toContainText( + 'have been added to your cart.' + ); + + await page.goto( 'cart/' ); + await expect( page.locator( 'td.product-name' ) ).toContainText( + simpleProductName + ); + await expect( page.locator( 'input.qty' ) ).toHaveValue( '5' ); + await expect( page.locator( 'td.product-subtotal' ) ).toContainText( + ( 5 * +productPrice ).toString() + ); + } ); + + test( 'should be able to remove simple products from the cart', async ( { + page, + } ) => { + await page.goto( `/shop/?add-to-cart=${ simpleProductId }` ); + await page.waitForLoadState( 'networkidle' ); + + await page.goto( 'cart/' ); + await page.locator( 'a.remove' ).click(); + + await expect( page.locator( '.cart-empty' ) ).toContainText( + 'Your cart is currently empty.' + ); + } ); +} ); diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/variable-product-updates.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/product-variable.spec.js similarity index 65% rename from plugins/woocommerce/tests/e2e-pw/tests/shopper/variable-product-updates.spec.js rename to plugins/woocommerce/tests/e2e-pw/tests/shopper/product-variable.spec.js index b987fae5afc..815823157b2 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/variable-product-updates.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/product-variable.spec.js @@ -1,9 +1,49 @@ const { test, expect } = require( '@playwright/test' ); const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; -const variableProductName = 'Variable Product Updates'; -const productPrice = '11.16'; -const variations = [ +const productPrice = '18.16'; +const variableProductName = 'Variable single product'; +const cartDialogMessage = + 'Please select some product options before adding this product to your cart.'; +const variations1 = [ + { + regular_price: productPrice, + attributes: [ + { + name: 'Size', + option: 'Small', + }, + ], + }, + { + regular_price: ( +productPrice * 2 ).toString(), + attributes: [ + { + name: 'Size', + option: 'Medium', + }, + ], + }, + { + regular_price: ( +productPrice * 3 ).toString(), + attributes: [ + { + name: 'Size', + option: 'Large', + }, + ], + }, + { + regular_price: ( +productPrice * 4 ).toString(), + attributes: [ + { + name: 'Size', + option: 'XLarge', + }, + ], + }, +]; +const variations2 = [ { attributes: [ { @@ -90,8 +130,99 @@ const variations = [ }, ]; -const cartDialogMessage = - 'Please select some product options before adding this product to your cart.'; +let variableProductId; + +test.describe( 'Variable Product Page', () => { + const slug = variableProductName.replace( / /gi, '-' ).toLowerCase(); + + test.beforeAll( async ( { baseURL } ) => { + const api = new wcApi( { + url: baseURL, + consumerKey: process.env.CONSUMER_KEY, + consumerSecret: process.env.CONSUMER_SECRET, + version: 'wc/v3', + } ); + // add product + await api + .post( 'products', { + name: variableProductName, + type: 'variable', + attributes: [ + { + name: 'Size', + options: [ 'Small', 'Medium', 'Large', 'XLarge' ], + visible: true, + variation: true, + }, + ], + } ) + .then( async ( response ) => { + variableProductId = response.data.id; + for ( const key in variations1 ) { + await api.post( + `products/${ variableProductId }/variations`, + variations1[ key ] + ); + } + } ); + } ); + + test.beforeEach( async ( { context } ) => { + // Shopping cart is very sensitive to cookies, so be explicit + await context.clearCookies(); + } ); + + test.afterAll( async ( { baseURL } ) => { + const api = new wcApi( { + url: baseURL, + consumerKey: process.env.CONSUMER_KEY, + consumerSecret: process.env.CONSUMER_SECRET, + version: 'wc/v3', + } ); + await api.delete( `products/${ variableProductId }`, { + force: true, + } ); + } ); + + test( 'should be able to add variation products to the cart', async ( { + page, + } ) => { + await page.goto( `product/${ slug }` ); + + for ( const attr of variations1 ) { + await page + .locator( '#size' ) + .selectOption( attr.attributes[ 0 ].option ); + await page.getByRole( 'button', { name: 'Add to cart' } ).click(); + await expect( + page.locator( '.woocommerce-message' ) + ).toContainText( 'has been added to your cart.' ); + } + + await page.goto( 'cart/' ); + await expect( + page.locator( 'td.product-name >> nth=0' ) + ).toContainText( variableProductName ); + await expect( page.locator( 'tr.order-total > td' ) ).toContainText( + ( +productPrice * 10 ).toString() + ); + } ); + + test( 'should be able to remove variation products from the cart', async ( { + page, + } ) => { + await page.goto( `product/${ slug }` ); + await page.locator( '#size' ).selectOption( 'Large' ); + await page.getByRole( 'button', { name: 'Add to cart' } ).click(); + + await page.goto( 'cart/' ); + await page.locator( 'a.remove' ).click(); + + await expect( page.locator( '.cart-empty' ) ).toContainText( + 'Your cart is currently empty.' + ); + } ); +} ); test.describe( 'Shopper > Update variable product', () => { let variableProductId; @@ -125,10 +256,10 @@ test.describe( 'Shopper > Update variable product', () => { } ) .then( async ( response ) => { variableProductId = response.data.id; - for ( const key in variations ) { + for ( const key in variations2 ) { await api.post( `products/${ variableProductId }/variations`, - variations[ key ] + variations2[ key ] ); } } ); diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/single-product.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/single-product.spec.js deleted file mode 100644 index 8f9b5447881..00000000000 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/single-product.spec.js +++ /dev/null @@ -1,326 +0,0 @@ -const { test, expect } = require( '@playwright/test' ); -const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; - -const productPrice = '18.16'; -const simpleProductName = 'Simple single product'; -const variableProductName = 'Variable single product'; -const variations = [ - { - regular_price: productPrice, - attributes: [ - { - name: 'Size', - option: 'Small', - }, - ], - }, - { - regular_price: ( +productPrice * 2 ).toString(), - attributes: [ - { - name: 'Size', - option: 'Medium', - }, - ], - }, - { - regular_price: ( +productPrice * 3 ).toString(), - attributes: [ - { - name: 'Size', - option: 'Large', - }, - ], - }, - { - regular_price: ( +productPrice * 4 ).toString(), - attributes: [ - { - name: 'Size', - option: 'XLarge', - }, - ], - }, -]; -const groupedProductName = 'Grouped single product'; - -let simpleProductId, simpleProduct2Id, variableProductId, groupedProductId; - -test.describe( 'Single Product Page', () => { - test.beforeAll( async ( { baseURL } ) => { - const api = new wcApi( { - url: baseURL, - consumerKey: process.env.CONSUMER_KEY, - consumerSecret: process.env.CONSUMER_SECRET, - version: 'wc/v3', - } ); - // add product - await api - .post( 'products', { - name: simpleProductName, - type: 'simple', - regular_price: productPrice, - } ) - .then( ( response ) => { - simpleProductId = response.data.id; - } ); - } ); - - test.beforeEach( async ( { context } ) => { - // Shopping cart is very sensitive to cookies, so be explicit - await context.clearCookies(); - } ); - - test.afterAll( async ( { baseURL } ) => { - const api = new wcApi( { - url: baseURL, - consumerKey: process.env.CONSUMER_KEY, - consumerSecret: process.env.CONSUMER_SECRET, - version: 'wc/v3', - } ); - await api.delete( `products/${ simpleProductId }`, { - force: true, - } ); - } ); - - test( 'should be able to add simple products to the cart', async ( { - page, - } ) => { - const slug = simpleProductName.replace( / /gi, '-' ).toLowerCase(); - await page.goto( `product/${ slug }` ); - - await page.locator( 'input.qty' ).fill( '5' ); - await page.getByRole( 'button', { name: 'Add to cart' } ).click(); - - await expect( page.locator( '.woocommerce-message' ) ).toContainText( - 'have been added to your cart.' - ); - - await page.goto( 'cart/' ); - await expect( page.locator( 'td.product-name' ) ).toContainText( - simpleProductName - ); - await expect( page.locator( 'input.qty' ) ).toHaveValue( '5' ); - await expect( page.locator( 'td.product-subtotal' ) ).toContainText( - ( 5 * +productPrice ).toString() - ); - } ); - - test( 'should be able to remove simple products from the cart', async ( { - page, - } ) => { - await page.goto( `/shop/?add-to-cart=${ simpleProductId }` ); - await page.waitForLoadState( 'networkidle' ); - - await page.goto( 'cart/' ); - await page.locator( 'a.remove' ).click(); - - await expect( page.locator( '.cart-empty' ) ).toContainText( - 'Your cart is currently empty.' - ); - } ); -} ); - -test.describe( 'Variable Product Page', () => { - const slug = variableProductName.replace( / /gi, '-' ).toLowerCase(); - - test.beforeAll( async ( { baseURL } ) => { - const api = new wcApi( { - url: baseURL, - consumerKey: process.env.CONSUMER_KEY, - consumerSecret: process.env.CONSUMER_SECRET, - version: 'wc/v3', - } ); - // add product - await api - .post( 'products', { - name: variableProductName, - type: 'variable', - attributes: [ - { - name: 'Size', - options: [ 'Small', 'Medium', 'Large', 'XLarge' ], - visible: true, - variation: true, - }, - ], - } ) - .then( async ( response ) => { - variableProductId = response.data.id; - for ( const key in variations ) { - await api.post( - `products/${ variableProductId }/variations`, - variations[ key ] - ); - } - } ); - } ); - - test.beforeEach( async ( { context } ) => { - // Shopping cart is very sensitive to cookies, so be explicit - await context.clearCookies(); - } ); - - test.afterAll( async ( { baseURL } ) => { - const api = new wcApi( { - url: baseURL, - consumerKey: process.env.CONSUMER_KEY, - consumerSecret: process.env.CONSUMER_SECRET, - version: 'wc/v3', - } ); - await api.delete( `products/${ variableProductId }`, { - force: true, - } ); - } ); - - test( 'should be able to add variation products to the cart', async ( { - page, - } ) => { - await page.goto( `product/${ slug }` ); - - for ( const attr of variations ) { - await page - .locator( '#size' ) - .selectOption( attr.attributes[ 0 ].option ); - await page.getByRole( 'button', { name: 'Add to cart' } ).click(); - await expect( - page.locator( '.woocommerce-message' ) - ).toContainText( 'has been added to your cart.' ); - } - - await page.goto( 'cart/' ); - await expect( - page.locator( 'td.product-name >> nth=0' ) - ).toContainText( variableProductName ); - await expect( page.locator( 'tr.order-total > td' ) ).toContainText( - ( +productPrice * 10 ).toString() - ); - } ); - - test( 'should be able to remove variation products from the cart', async ( { - page, - } ) => { - await page.goto( `product/${ slug }` ); - await page.locator( '#size' ).selectOption( 'Large' ); - await page.getByRole( 'button', { name: 'Add to cart' } ).click(); - - await page.goto( 'cart/' ); - await page.locator( 'a.remove' ).click(); - - await expect( page.locator( '.cart-empty' ) ).toContainText( - 'Your cart is currently empty.' - ); - } ); -} ); - -test.describe( 'Grouped Product Page', () => { - const slug = groupedProductName.replace( / /gi, '-' ).toLowerCase(); - const simpleProduct1 = simpleProductName + ' 1'; - const simpleProduct2 = simpleProductName + ' 2'; - - test.beforeAll( async ( { baseURL } ) => { - const api = new wcApi( { - url: baseURL, - consumerKey: process.env.CONSUMER_KEY, - consumerSecret: process.env.CONSUMER_SECRET, - version: 'wc/v3', - } ); - // add products - await api - .post( 'products', { - name: simpleProduct1, - type: 'simple', - regular_price: productPrice, - } ) - .then( ( response ) => { - simpleProductId = response.data.id; - } ); - await api - .post( 'products', { - name: simpleProduct2, - type: 'simple', - regular_price: productPrice, - } ) - .then( ( response ) => { - simpleProduct2Id = response.data.id; - } ); - await api - .post( 'products', { - name: groupedProductName, - type: 'grouped', - grouped_products: [ simpleProductId, simpleProduct2Id ], - } ) - .then( ( response ) => { - groupedProductId = response.data.id; - } ); - } ); - - test.beforeEach( async ( { context } ) => { - // Shopping cart is very sensitive to cookies, so be explicit - await context.clearCookies(); - } ); - - test.afterAll( async ( { baseURL } ) => { - const api = new wcApi( { - url: baseURL, - consumerKey: process.env.CONSUMER_KEY, - consumerSecret: process.env.CONSUMER_SECRET, - version: 'wc/v3', - } ); - await api.delete( `products/${ simpleProductId }`, { - force: true, - } ); - await api.delete( `products/${ simpleProduct2Id }`, { - force: true, - } ); - await api.delete( `products/${ groupedProductId }`, { - force: true, - } ); - } ); - - test( 'should be able to add grouped products to the cart', async ( { - page, - } ) => { - await page.goto( `product/${ slug }` ); - - await page.getByRole( 'button', { name: 'Add to cart' } ).click(); - await expect( page.locator( '.woocommerce-error' ) ).toContainText( - 'Please choose the quantity of items you wish to add to your cart…' - ); - - await page.locator( 'div.quantity input.qty >> nth=0' ).fill( '5' ); - await page.locator( 'div.quantity input.qty >> nth=1' ).fill( '5' ); - await page.getByRole( 'button', { name: 'Add to cart' } ).click(); - await expect( page.locator( '.woocommerce-message' ) ).toContainText( - `“${ simpleProduct1 }” and “${ simpleProduct2 }” have been added to your cart.` - ); - - await page.goto( 'cart/' ); - await expect( - page.locator( 'td.product-name >> nth=0' ) - ).toContainText( simpleProduct1 ); - await expect( - page.locator( 'td.product-name >> nth=1' ) - ).toContainText( simpleProduct2 ); - await expect( page.locator( 'tr.order-total > td' ) ).toContainText( - ( +productPrice * 10 ).toString() - ); - } ); - - test( 'should be able to remove grouped products from the cart', async ( { - page, - } ) => { - await page.goto( `product/${ slug }` ); - await page.locator( 'div.quantity input.qty >> nth=0' ).fill( '1' ); - await page.locator( 'div.quantity input.qty >> nth=1' ).fill( '1' ); - await page.getByRole( 'button', { name: 'Add to cart' } ).click(); - - await page.goto( 'cart/' ); - await page.locator( 'a.remove >> nth=1' ).click(); - await page.locator( 'a.remove >> nth=0' ).click(); - - await expect( page.locator( '.cart-empty' ) ).toContainText( - 'Your cart is currently empty.' - ); - } ); -} );