Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions dotcom-rendering/src/model/enhance-product-summary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ describe('enhanceProductSummary', () => {
pageId: allowedPageId,
serverSideABTests: { 'thefilter-at-a-glance-redesign': 'carousel' },
renderingTarget: 'Web',
filterAtAGlanceEnabled: true,
})(input);

const carousel = findCarousel(output);
Expand Down Expand Up @@ -265,6 +266,7 @@ describe('enhanceProductSummary', () => {
pageId: allowedPageId,
serverSideABTests: { 'thefilter-at-a-glance-redesign': 'stacked' },
renderingTarget: 'Web',
filterAtAGlanceEnabled: true,
})(input);

const stacked = findStacked(output);
Expand Down Expand Up @@ -306,6 +308,49 @@ describe('enhanceProductSummary', () => {
pageId: allowedPageId,
serverSideABTests: { 'thefilter-at-a-glance-redesign': 'stacked' },
renderingTarget: 'Apps',
filterAtAGlanceEnabled: true,
})(input);

const stacked = findStacked(output);

expect(stacked).toBeUndefined();
});

it('does not return stacked cards when the filterAtAGlance switch is OFF', () => {
const allowedPageId =
'thefilter/test-article-example-for-product-summary';

const input = [
atAGlanceHeading(),
linkElement(
'https://www.homebase.co.uk/en-uk/tower-airx-t17166-5l-grey-single-basket-air-fryer-digital-air-fryer/p/0757395',
'Buy now',
),
linkElement(
'https://www.lakeland.co.uk/27537/lakeland-slimline-air-fryer-black-8l',
'Buy now',
),
linkElement(
'https://ninjakitchen.co.uk/product/ninja-double-stack-xl-9-5l-air-fryer-sl400uk-zidSL400UK',
'Buy now',
),
dividerElement(),
productElement([
'https://www.homebase.co.uk/en-uk/tower-airx-t17166-5l-grey-single-basket-air-fryer-digital-air-fryer/p/0757395',
]),
productElement([
'https://www.lakeland.co.uk/27537/lakeland-slimline-air-fryer-black-8l',
]),
productElement([
'https://ninjakitchen.co.uk/product/ninja-double-stack-xl-9-5l-air-fryer-sl400uk-zidSL400UK',
]),
];

const output = enhanceProductSummary({
pageId: allowedPageId,
serverSideABTests: { 'thefilter-at-a-glance-redesign': 'stacked' },
renderingTarget: 'Web',
filterAtAGlanceEnabled: false,
})(input);

const stacked = findStacked(output);
Expand Down
5 changes: 4 additions & 1 deletion dotcom-rendering/src/model/enhance-product-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,20 @@ export const enhanceProductSummary =
pageId,
serverSideABTests,
renderingTarget,
filterAtAGlanceEnabled,
}: {
pageId: string;
serverSideABTests?: Record<string, string>;
renderingTarget: RenderingTarget;
filterAtAGlanceEnabled: boolean;
}) =>
(elements: FEElement[]): FEElement[] => {
const abTestVariant =
serverSideABTests?.['thefilter-at-a-glance-redesign'];

// do nothing if article is not on allow list / not in the test / variant is 'control' / renderingTarget is Apps
// do nothing if article is not on allow list / not in the test / variant is 'control' / renderingTarget is Apps / filterAtAGlance switch is OFF
if (
filterAtAGlanceEnabled &&
abTestVariant &&
isCarouselOrStacked(abTestVariant) &&
isEligibleForSummary(pageId) &&
Expand Down
3 changes: 3 additions & 0 deletions dotcom-rendering/src/model/enhanceBlocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isUndefined } from '@guardian/libs';
import { type ArticleFormat } from '../lib/articleFormat';
import type { Block } from '../types/blocks';
import type { Switches } from '../types/config';
import type {
FEElement,
ImageBlockElement,
Expand Down Expand Up @@ -37,6 +38,7 @@ type Options = {
shouldHideAds: boolean;
pageId: string;
serverSideABTests?: Record<string, string>;
switches?: Switches;
};

const enhanceNewsletterSignup =
Expand Down Expand Up @@ -101,6 +103,7 @@ export const enhanceElements =
pageId: options.pageId,
serverSideABTests: options.serverSideABTests,
renderingTarget: options.renderingTarget,
filterAtAGlanceEnabled: !!options.switches?.filterAtAGlance,
}),
].reduce(
(enhancedBlocks, enhancer) => enhancer(enhancedBlocks),
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/server/handler.article.apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const handleAppsBlocks: RequestHandler = ({ body }, res) => {
hasAffiliateLinksDisclaimer: false,
shouldHideAds,
pageId,
switches,
});
const html = renderAppsBlocks({
blocks: enhancedBlocks,
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/server/handler.article.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const handleBlocks: RequestHandler = ({ body }, res) => {
shouldHideAds,
pageId,
serverSideABTests,
switches,
});
const html = renderBlocks({
blocks: enhancedBlocks,
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/types/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const enhanceArticleType = (
shouldHideAds: data.shouldHideAds,
pageId: data.pageId,
serverSideABTests: data.config.serverSideABTests,
switches: data.config.switches,
});

const crosswordBlock = buildCrosswordBlock(data);
Expand Down
Loading