diff --git a/tests/e2e/config/default.json b/tests/e2e/config/default.json index eb0e7a5486..f421e1145b 100644 --- a/tests/e2e/config/default.json +++ b/tests/e2e/config/default.json @@ -14,7 +14,12 @@ "simple": { "name": "Simple product", "type": "simple", - "regular_price": "9.99" + "regular_price": "9.99", + "tags": [ + { + "name": "related" + } + ] }, "variable": { "name": "Variable product", diff --git a/tests/e2e/specs/gtag-events/gtag-events.test.js b/tests/e2e/specs/gtag-events/gtag-events.test.js index e7b9e6c88f..3bda09127b 100644 --- a/tests/e2e/specs/gtag-events/gtag-events.test.js +++ b/tests/e2e/specs/gtag-events/gtag-events.test.js @@ -17,7 +17,10 @@ import { relatedProductAddToCart, singleProductAddToCart, } from '../../utils/customer'; -import { createBlockShopPage } from '../../utils/block-page'; +import { + createBlockShopPage, + createRelatedProductsPage, +} from '../../utils/block-page'; import { getEventData, trackGtagEvent } from '../../utils/track-event'; const config = require( '../../config/default' ); @@ -74,12 +77,12 @@ test.describe( 'GTag events', () => { test( 'Add to cart event is sent from a block shop page', async ( { page, } ) => { - await createBlockShopPage(); + const pageSlug = await createBlockShopPage(); const event = trackGtagEvent( page, 'add_to_cart' ); // Go to block shop page - await page.goto( 'all-products-block' ); + await page.goto( pageSlug ); await blockProductAddToCart( page ); await event.then( ( request ) => { @@ -111,9 +114,45 @@ test.describe( 'GTag events', () => { page, } ) => { await createSimpleProduct(); // Create an additional product for related to show up. + await page.goto( `?p=${ simpleProductID }` ); + + // Check if it has the related products section. + const hasRelatedProducts = await page + .getByRole( 'heading', { + name: 'Related products', + } ) + .isVisible(); + + test.skip( + ! hasRelatedProducts, + 'This WC setup does not have "Related products" section on the single product page.' + ); + const event = trackGtagEvent( page, 'add_to_cart' ); - await page.goto( `?p=${ simpleProductID }` ); + const relatedProductID = await relatedProductAddToCart( page ); + + await event.then( ( request ) => { + const data = getEventData( request ); + expect( data.id ).toEqual( 'gla_' + relatedProductID ); + expect( data.ecomm_pagetype ).toEqual( 'cart' ); + expect( data.event_category ).toEqual( 'ecommerce' ); + expect( data.google_business_vertical ).toEqual( 'retail' ); + } ); + } ); + + test( 'Add to cart event is sent from related products block', async ( { + page, + } ) => { + await createSimpleProduct(); // Create an additional product for related to show up. + + const pageSlug = await createRelatedProductsPage( simpleProductID ); + + const event = trackGtagEvent( page, 'add_to_cart' ); + + // Go to block page + await page.goto( pageSlug ); + const relatedProductID = await relatedProductAddToCart( page ); await event.then( ( request ) => { diff --git a/tests/e2e/utils/__fixtures__/all-products.fixture.json b/tests/e2e/utils/__fixtures__/all-products.fixture.json index 006e50ee0c..4695ec40e2 100644 --- a/tests/e2e/utils/__fixtures__/all-products.fixture.json +++ b/tests/e2e/utils/__fixtures__/all-products.fixture.json @@ -1 +1,5 @@ -{"title":"All Products Block","pageContent":"\n
\n"} +{ + "title": "All Products Block", + "slug": "all-products-block", + "pageContent": "\n\n" +} diff --git a/tests/e2e/utils/__fixtures__/related-products.fixture.mjs b/tests/e2e/utils/__fixtures__/related-products.fixture.mjs new file mode 100644 index 0000000000..93e4a900c1 --- /dev/null +++ b/tests/e2e/utils/__fixtures__/related-products.fixture.mjs @@ -0,0 +1,21 @@ +export default { + title: 'Related Products Block', + slug: 'related-products-block', + pageContent: ( + productId + ) => ` +