Skip to content

Commit 10add79

Browse files
authored
Merge pull request #15306 from guardian/gh-filterAtAGlance-switch
Read the filterAtAGlance switch on the server
2 parents ff3b836 + 8498b5e commit 10add79

File tree

6 files changed

+55
-1
lines changed

6 files changed

+55
-1
lines changed

dotcom-rendering/src/model/enhance-product-summary.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ describe('enhanceProductSummary', () => {
224224
pageId: allowedPageId,
225225
serverSideABTests: { 'thefilter-at-a-glance-redesign': 'carousel' },
226226
renderingTarget: 'Web',
227+
filterAtAGlanceEnabled: true,
227228
})(input);
228229

229230
const carousel = findCarousel(output);
@@ -265,6 +266,7 @@ describe('enhanceProductSummary', () => {
265266
pageId: allowedPageId,
266267
serverSideABTests: { 'thefilter-at-a-glance-redesign': 'stacked' },
267268
renderingTarget: 'Web',
269+
filterAtAGlanceEnabled: true,
268270
})(input);
269271

270272
const stacked = findStacked(output);
@@ -306,6 +308,49 @@ describe('enhanceProductSummary', () => {
306308
pageId: allowedPageId,
307309
serverSideABTests: { 'thefilter-at-a-glance-redesign': 'stacked' },
308310
renderingTarget: 'Apps',
311+
filterAtAGlanceEnabled: true,
312+
})(input);
313+
314+
const stacked = findStacked(output);
315+
316+
expect(stacked).toBeUndefined();
317+
});
318+
319+
it('does not return stacked cards when the filterAtAGlance switch is OFF', () => {
320+
const allowedPageId =
321+
'thefilter/test-article-example-for-product-summary';
322+
323+
const input = [
324+
atAGlanceHeading(),
325+
linkElement(
326+
'https://www.homebase.co.uk/en-uk/tower-airx-t17166-5l-grey-single-basket-air-fryer-digital-air-fryer/p/0757395',
327+
'Buy now',
328+
),
329+
linkElement(
330+
'https://www.lakeland.co.uk/27537/lakeland-slimline-air-fryer-black-8l',
331+
'Buy now',
332+
),
333+
linkElement(
334+
'https://ninjakitchen.co.uk/product/ninja-double-stack-xl-9-5l-air-fryer-sl400uk-zidSL400UK',
335+
'Buy now',
336+
),
337+
dividerElement(),
338+
productElement([
339+
'https://www.homebase.co.uk/en-uk/tower-airx-t17166-5l-grey-single-basket-air-fryer-digital-air-fryer/p/0757395',
340+
]),
341+
productElement([
342+
'https://www.lakeland.co.uk/27537/lakeland-slimline-air-fryer-black-8l',
343+
]),
344+
productElement([
345+
'https://ninjakitchen.co.uk/product/ninja-double-stack-xl-9-5l-air-fryer-sl400uk-zidSL400UK',
346+
]),
347+
];
348+
349+
const output = enhanceProductSummary({
350+
pageId: allowedPageId,
351+
serverSideABTests: { 'thefilter-at-a-glance-redesign': 'stacked' },
352+
renderingTarget: 'Web',
353+
filterAtAGlanceEnabled: false,
309354
})(input);
310355

311356
const stacked = findStacked(output);

dotcom-rendering/src/model/enhance-product-summary.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,20 @@ export const enhanceProductSummary =
180180
pageId,
181181
serverSideABTests,
182182
renderingTarget,
183+
filterAtAGlanceEnabled,
183184
}: {
184185
pageId: string;
185186
serverSideABTests?: Record<string, string>;
186187
renderingTarget: RenderingTarget;
188+
filterAtAGlanceEnabled: boolean;
187189
}) =>
188190
(elements: FEElement[]): FEElement[] => {
189191
const abTestVariant =
190192
serverSideABTests?.['thefilter-at-a-glance-redesign'];
191193

192-
// do nothing if article is not on allow list / not in the test / variant is 'control' / renderingTarget is Apps
194+
// do nothing if article is not on allow list / not in the test / variant is 'control' / renderingTarget is Apps / filterAtAGlance switch is OFF
193195
if (
196+
filterAtAGlanceEnabled &&
194197
abTestVariant &&
195198
isCarouselOrStacked(abTestVariant) &&
196199
isEligibleForSummary(pageId) &&

dotcom-rendering/src/model/enhanceBlocks.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { isUndefined } from '@guardian/libs';
22
import { type ArticleFormat } from '../lib/articleFormat';
33
import type { Block } from '../types/blocks';
4+
import type { Switches } from '../types/config';
45
import type {
56
FEElement,
67
ImageBlockElement,
@@ -37,6 +38,7 @@ type Options = {
3738
shouldHideAds: boolean;
3839
pageId: string;
3940
serverSideABTests?: Record<string, string>;
41+
switches?: Switches;
4042
};
4143

4244
const enhanceNewsletterSignup =
@@ -101,6 +103,7 @@ export const enhanceElements =
101103
pageId: options.pageId,
102104
serverSideABTests: options.serverSideABTests,
103105
renderingTarget: options.renderingTarget,
106+
filterAtAGlanceEnabled: !!options.switches?.filterAtAGlance,
104107
}),
105108
].reduce(
106109
(enhancedBlocks, enhancer) => enhancer(enhancedBlocks),

dotcom-rendering/src/server/handler.article.apps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const handleAppsBlocks: RequestHandler = ({ body }, res) => {
5555
hasAffiliateLinksDisclaimer: false,
5656
shouldHideAds,
5757
pageId,
58+
switches,
5859
});
5960
const html = renderAppsBlocks({
6061
blocks: enhancedBlocks,

dotcom-rendering/src/server/handler.article.web.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const handleBlocks: RequestHandler = ({ body }, res) => {
6060
shouldHideAds,
6161
pageId,
6262
serverSideABTests,
63+
switches,
6364
});
6465
const html = renderBlocks({
6566
blocks: enhancedBlocks,

dotcom-rendering/src/types/article.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export const enhanceArticleType = (
105105
shouldHideAds: data.shouldHideAds,
106106
pageId: data.pageId,
107107
serverSideABTests: data.config.serverSideABTests,
108+
switches: data.config.switches,
108109
});
109110

110111
const crosswordBlock = buildCrosswordBlock(data);

0 commit comments

Comments
 (0)