diff --git a/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/atomic-commerce-recommendation-list.new.stories.tsx b/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/atomic-commerce-recommendation-list.new.stories.tsx index dd87f78b044..39ace84c054 100644 --- a/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/atomic-commerce-recommendation-list.new.stories.tsx +++ b/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/atomic-commerce-recommendation-list.new.stories.tsx @@ -85,6 +85,24 @@ export const WithFullTemplate: Story = { }, }; +export const RecsOpeningInNewTab: Story = { + tags: ['test'], + args: { + 'slots-default': ` + + + `, + }, +}; + export const AsCarousel: Story = { args: { 'attributes-products-per-page': 3, diff --git a/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/atomic-commerce-recommendation-list.tsx b/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/atomic-commerce-recommendation-list.tsx index b8b1cd72474..b9bcec17986 100644 --- a/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/atomic-commerce-recommendation-list.tsx +++ b/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/atomic-commerce-recommendation-list.tsx @@ -313,6 +313,9 @@ export class AtomicCommerceRecommendationList } private getAtomicProductProps(product: Product) { + const linkContent = + this.productTemplateProvider.getLinkTemplateContent(product); + return { interactiveProduct: this.recommendations.interactiveProduct({ options: {product}, @@ -327,7 +330,8 @@ export class AtomicCommerceRecommendationList this.imageSize ), content: this.productTemplateProvider.getTemplateContent(product), - linkContent: this.productTemplateProvider.getLinkTemplateContent(product), + linkContent, + stopPropagation: !!linkContent, store: this.bindings.store, density: this.density, display: this.display, diff --git a/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts b/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts index 5bf5d80ea70..2ea3ea29cb7 100644 --- a/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts +++ b/packages/atomic/src/components/commerce/atomic-commerce-recommendation-list/e2e/atomic-commerce-recommendation-list.e2e.ts @@ -103,6 +103,24 @@ test.describe('when there are no enough recommendations for multiple pages', () }); }); +test.describe('when recommendations open in a new tab', async () => { + test.beforeEach(async ({recommendationList}) => { + await recommendationList.load({story: 'recs-opening-in-new-tab'}); + await recommendationList.hydrated.waitFor(); + }); + + test('should open a single tab when clicking a recommendation', async ({ + recommendationList, + context, + }) => { + const pagePromise = context.waitForEvent('page'); + await recommendationList.recommendation.first().click(); + await pagePromise; + + expect(context.pages().length).toBe(2); + }); +}); + test('with no recommendations returned by the API, should render placeholders', async ({ recommendationList, }) => { diff --git a/packages/atomic/src/components/ipx/atomic-ipx-recs-list/atomic-recs-list/atomic-ipx-recs-list.tsx b/packages/atomic/src/components/ipx/atomic-ipx-recs-list/atomic-recs-list/atomic-ipx-recs-list.tsx index dff76927c4a..1d6841ad0a1 100644 --- a/packages/atomic/src/components/ipx/atomic-ipx-recs-list/atomic-recs-list/atomic-ipx-recs-list.tsx +++ b/packages/atomic/src/components/ipx/atomic-ipx-recs-list/atomic-recs-list/atomic-ipx-recs-list.tsx @@ -347,6 +347,9 @@ export class AtomicIPXRecsList implements InitializableComponent { interactiveResult.select = () => { this.onSelect(recommendation, originalSelect); }; + const linkContent = + this.itemTemplateProvider.getLinkTemplateContent(recommendation); + return { interactiveResult, result: recommendation, @@ -359,8 +362,8 @@ export class AtomicIPXRecsList implements InitializableComponent { this.imageSize ), content: this.itemTemplateProvider.getTemplateContent(recommendation), - linkContent: - this.itemTemplateProvider.getLinkTemplateContent(recommendation), + linkContent, + stopPropagation: !!linkContent, store: this.bindings.store, density: this.density, display: this.display, diff --git a/packages/atomic/src/components/recommendations/atomic-recs-list/atomic-recs-list.new.stories.tsx b/packages/atomic/src/components/recommendations/atomic-recs-list/atomic-recs-list.new.stories.tsx index b51a2a05823..f8fb62872de 100644 --- a/packages/atomic/src/components/recommendations/atomic-recs-list/atomic-recs-list.new.stories.tsx +++ b/packages/atomic/src/components/recommendations/atomic-recs-list/atomic-recs-list.new.stories.tsx @@ -74,6 +74,24 @@ export const RecsWithFullTemplate: Story = { }, }; +export const RecsOpeningInNewTab: Story = { + tags: ['test'], + args: { + 'slots-default': ` + + + `, + }, +}; + export const RecsAsCarousel: Story = { args: { 'attributes-number-of-recommendations-per-page': 4, diff --git a/packages/atomic/src/components/recommendations/atomic-recs-list/atomic-recs-list.tsx b/packages/atomic/src/components/recommendations/atomic-recs-list/atomic-recs-list.tsx index a61b824c19a..7691fbcf98b 100644 --- a/packages/atomic/src/components/recommendations/atomic-recs-list/atomic-recs-list.tsx +++ b/packages/atomic/src/components/recommendations/atomic-recs-list/atomic-recs-list.tsx @@ -319,6 +319,9 @@ export class AtomicRecsList implements InitializableComponent { } private getPropsForAtomicRecsResult(recommendation: RecsResult) { + const linkContent = + this.itemTemplateProvider.getLinkTemplateContent(recommendation); + return { interactiveResult: buildRecsInteractiveResult(this.bindings.engine, { options: {result: recommendation}, @@ -333,8 +336,8 @@ export class AtomicRecsList implements InitializableComponent { this.imageSize ), content: this.itemTemplateProvider.getTemplateContent(recommendation), - linkContent: - this.itemTemplateProvider.getLinkTemplateContent(recommendation), + linkContent, + stopPropagation: !!linkContent, store: this.bindings.store, density: this.density, display: this.display, diff --git a/packages/atomic/src/components/recommendations/atomic-recs-list/e2e/atomic-recs-list.e2e.ts b/packages/atomic/src/components/recommendations/atomic-recs-list/e2e/atomic-recs-list.e2e.ts index e6ad2538fed..bc67dcec607 100644 --- a/packages/atomic/src/components/recommendations/atomic-recs-list/e2e/atomic-recs-list.e2e.ts +++ b/packages/atomic/src/components/recommendations/atomic-recs-list/e2e/atomic-recs-list.e2e.ts @@ -101,6 +101,24 @@ test.describe('when there are no enough recommendations for multiple pages', () }); }); +test.describe('when recommendations open in a new tab', async () => { + test.beforeEach(async ({recsList}) => { + await recsList.load({story: 'recs-opening-in-new-tab'}); + await recsList.hydrated.waitFor(); + }); + + test('should open a single tab when clicking a recommendation', async ({ + recsList, + context, + }) => { + const pagePromise = context.waitForEvent('page'); + await recsList.recommendation.first().click(); + await pagePromise; + + expect(context.pages().length).toBe(2); + }); +}); + test('with no recommendations returned by the API, should render placeholders', async ({ recsList, page,