Skip to content

Commit e244e09

Browse files
authored
Use destination field in choice cards (#14621)
* Use destination field in choice cards * fix storybook * fix storybook * remove dead code, unit tests * test names
1 parent 503dd3c commit e244e09

File tree

11 files changed

+190
-250
lines changed

11 files changed

+190
-250
lines changed

dotcom-rendering/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@guardian/shimport": "1.0.2",
4545
"@guardian/source": "11.3.0",
4646
"@guardian/source-development-kitchen": "18.1.1",
47-
"@guardian/support-dotcom-components": "7.8.1",
47+
"@guardian/support-dotcom-components": "7.9.0",
4848
"@guardian/tsconfig": "0.2.0",
4949
"@playwright/test": "1.52.0",
5050
"@sentry/browser": "10.10.0",

dotcom-rendering/src/components/marketing/banners/common/BannerWrapper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ const withBannerData =
338338
tracking,
339339
submitComponentEvent,
340340
design,
341+
promoCodes,
341342
};
342343

343344
return (

dotcom-rendering/src/components/marketing/banners/common/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ export interface BannerRenderProps {
8080
tracking: Tracking;
8181
submitComponentEvent?: (componentEvent: ComponentEvent) => void;
8282
design?: ConfigurableDesign;
83+
promoCodes?: string[];
8384
}

dotcom-rendering/src/components/marketing/banners/designableBanner/DesignableBanner.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
} from '../../../../lib/useMatchMedia';
3434
import { getChoiceCards } from '../../lib/choiceCards';
3535
import type { ReactComponent } from '../../lib/ReactComponent';
36-
import { getChoiceCardUrl } from '../../lib/tracking';
36+
import { enrichSupportUrl, getChoiceCardUrl } from '../../lib/tracking';
3737
import { ThreeTierChoiceCards } from '../../shared/ThreeTierChoiceCards';
3838
import { bannerWrapper, validatedBannerWrapper } from '../common/BannerWrapper';
3939
import type { BannerRenderProps } from '../common/types';
@@ -132,6 +132,8 @@ const DesignableBanner: ReactComponent<BannerRenderProps> = ({
132132
submitComponentEvent,
133133
tracking,
134134
design,
135+
countryCode,
136+
promoCodes,
135137
}: BannerRenderProps): JSX.Element => {
136138
const isTabletOrAbove = useMatchMedia(removeMediaRulePrefix(from.tablet));
137139

@@ -480,10 +482,15 @@ const DesignableBanner: ReactComponent<BannerRenderProps> = ({
480482
)}
481483
<div css={styles.ctaContainer(isCollapsed)}>
482484
<LinkButton
483-
href={getChoiceCardUrl(
484-
selectedChoiceCard,
485-
mainOrMobileContent.primaryCta.ctaUrl,
486-
)}
485+
href={enrichSupportUrl({
486+
baseUrl:
487+
getChoiceCardUrl(
488+
selectedChoiceCard,
489+
),
490+
tracking,
491+
promoCodes: promoCodes ?? [],
492+
countryCode,
493+
})}
487494
onClick={onCtaClick}
488495
priority="primary"
489496
cssOverrides={styles.linkButtonStyles}

dotcom-rendering/src/components/marketing/banners/designableBanner/stories/DesignableBanner.stories.tsx

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import type { Meta, StoryObj } from '@storybook/react';
77
import lzstring from 'lz-string';
88
import {
99
choiceCardsSettings,
10-
choiceCardsWithDestinationUrl,
11-
choiceCardsWithDestinationUrlTwoCards,
10+
choiceCardsWithMixedDestinations,
1211
} from '../../../lib/storybook';
1312
import {
1413
contentNoHeading,
@@ -286,7 +285,7 @@ export const NoChoiceCardOrImage: Story = {
286285
},
287286
};
288287

289-
export const WithDestinationUrlAllCards: Story = {
288+
export const WithMixedDestinations: Story = {
290289
name: 'With destinationUrl on all choice cards',
291290
args: {
292291
...meta.args,
@@ -302,39 +301,12 @@ export const WithDestinationUrlAllCards: Story = {
302301
abTestVariant: 'THREE_TIER_CHOICE_CARDS',
303302
},
304303
choiceCardAmounts: regularChoiceCardAmounts,
305-
choiceCardsSettings: choiceCardsWithDestinationUrl,
304+
choiceCardsSettings: choiceCardsWithMixedDestinations,
306305
},
307306
parameters: {
308307
docs: {
309308
description: {
310-
story: 'All choice cards have a destinationUrl configured. The banner should use these custom URLs instead of constructing URLs with product parameters.',
311-
},
312-
},
313-
},
314-
};
315-
316-
export const WithDestinationUrlTwoCards: Story = {
317-
name: 'With destinationUrl in two choice cards',
318-
args: {
319-
...meta.args,
320-
design: {
321-
...design,
322-
visual: {
323-
kind: 'ChoiceCards',
324-
buttonColour: stringToHexColour('E5E5E5'),
325-
},
326-
},
327-
tracking: {
328-
...tracking,
329-
abTestVariant: 'THREE_TIER_CHOICE_CARDS',
330-
},
331-
choiceCardAmounts: regularChoiceCardAmounts,
332-
choiceCardsSettings: choiceCardsWithDestinationUrlTwoCards,
333-
},
334-
parameters: {
335-
docs: {
336-
description: {
337-
story: 'All choice cards have a destinationUrl configured. The banner should use these custom URLs instead of constructing URLs with product parameters.',
309+
story: 'Two out of three choice cards have destination set to checkout.',
338310
},
339311
},
340312
},

dotcom-rendering/src/components/marketing/epics/ContributionsEpic.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import lzstring from 'lz-string';
1010
import React from 'react';
1111
import {
1212
choiceCardsSettings,
13-
choiceCardsWithDestinationUrl,
13+
choiceCardsWithMixedDestinations,
1414
} from '../lib/storybook';
1515
import { ContributionsEpicUnvalidated as ContributionsEpic } from './ContributionsEpic';
1616
import { props } from './utils/storybook';
@@ -385,16 +385,16 @@ export const WithParagraphLinks: Story = {
385385
},
386386
};
387387

388-
export const WithThreeTierChoiceCardsAndCustomDestinationUrl: Story = {
389-
name: 'ContributionsEpic with three tier choice cards and custom destination URL',
388+
export const WithThreeTierChoiceCardsAndMixedDestinations: Story = {
389+
name: 'ContributionsEpic with three tier choice cards and mixed destinations',
390390
args: {
391391
...meta.args,
392392
variant: {
393393
...props.variant,
394394
name: 'THREE_TIER_CHOICE_CARDS',
395395
secondaryCta: undefined,
396396
showChoiceCards: true,
397-
choiceCardsSettings: choiceCardsWithDestinationUrl,
397+
choiceCardsSettings: choiceCardsWithMixedDestinations,
398398
},
399399
},
400400
};

dotcom-rendering/src/components/marketing/epics/ctas/ContributionsEpicButtons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export const ContributionsEpicButtons = ({
184184

185185
return {
186186
text: cta.text,
187-
baseUrl: getChoiceCardUrl(threeTierSelectedChoiceCard, cta.baseUrl),
187+
baseUrl: getChoiceCardUrl(threeTierSelectedChoiceCard),
188188
};
189189
};
190190

dotcom-rendering/src/components/marketing/lib/storybook.ts

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const choiceCardsSettings: ChoiceCardsSettings = {
9797
],
9898
};
9999

100-
export const choiceCardsWithDestinationUrl: ChoiceCardsSettings = {
100+
export const choiceCardsWithMixedDestinations: ChoiceCardsSettings = {
101101
choiceCards: [
102102
{
103103
product: {
@@ -106,8 +106,7 @@ export const choiceCardsWithDestinationUrl: ChoiceCardsSettings = {
106106
},
107107
label: 'Support £5/month',
108108
isDefault: false,
109-
destinationUrl:
110-
'https://support.theguardian.com/contribute/monthly?custom-destination=contribution',
109+
destination: 'LandingPage',
111110
benefits: [
112111
{
113112
copy: 'Give to the Guardian every month with Support',
@@ -121,8 +120,7 @@ export const choiceCardsWithDestinationUrl: ChoiceCardsSettings = {
121120
},
122121
label: 'Support £12/month',
123122
isDefault: true,
124-
destinationUrl:
125-
'https://support.theguardian.com/subscribe/monthly?custom-destination=supporter-plus',
123+
destination: 'Checkout',
126124
benefitsLabel:
127125
'Unlock <strong>All-access digital</strong> benefits:',
128126
benefits: [
@@ -142,63 +140,7 @@ export const choiceCardsWithDestinationUrl: ChoiceCardsSettings = {
142140
},
143141
label: 'One-time support',
144142
isDefault: false,
145-
destinationUrl:
146-
'https://support.theguardian.com/contribute/one-time?custom-destination=one-off',
147-
benefits: [
148-
{
149-
copy: 'Support the Guardian with a one-time contribution',
150-
},
151-
],
152-
},
153-
],
154-
};
155-
156-
export const choiceCardsWithDestinationUrlTwoCards: ChoiceCardsSettings = {
157-
choiceCards: [
158-
{
159-
product: {
160-
supportTier: 'Contribution',
161-
ratePlan: 'Monthly',
162-
},
163-
label: 'Support £5/month',
164-
isDefault: false,
165-
destinationUrl: null,
166-
benefits: [
167-
{
168-
copy: 'Give to the Guardian every month with Support',
169-
},
170-
],
171-
},
172-
{
173-
product: {
174-
supportTier: 'SupporterPlus',
175-
ratePlan: 'Monthly',
176-
},
177-
label: 'Support £12/month',
178-
isDefault: true,
179-
destinationUrl:
180-
'https://support.theguardian.com/subscribe/monthly?custom-destination=supporter-plus',
181-
benefitsLabel:
182-
'Unlock <strong>All-access digital</strong> benefits:',
183-
benefits: [
184-
{
185-
copy: '<strong>Unlimited</strong> access to the Guardian app',
186-
},
187-
{ copy: 'Unlimited access to our new Feast App' },
188-
{ copy: 'Ad-free reading on all your devices' },
189-
{
190-
copy: 'Exclusive newsletters for subscribers',
191-
},
192-
],
193-
},
194-
{
195-
product: {
196-
supportTier: 'OneOff',
197-
},
198-
label: 'One-time support',
199-
isDefault: false,
200-
destinationUrl:
201-
'https://support.theguardian.com/contribute/one-time?custom-destination=one-off',
143+
destination: 'Checkout',
202144
benefits: [
203145
{
204146
copy: 'Support the Guardian with a one-time contribution',

dotcom-rendering/src/components/marketing/lib/tracking.test.ts

Lines changed: 97 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
import type { Tracking } from '@guardian/support-dotcom-components/dist/shared/types';
2-
import { addChoiceCardsParams, enrichSupportUrl } from './tracking';
3-
4-
describe('addChoiceCardsParams', () => {
5-
it('adds choice cards params to url without existing querystring', () => {
6-
const result = addChoiceCardsParams(
7-
'https://support.theguardian.com/contribute',
8-
'ONE_OFF',
9-
5,
10-
);
11-
expect(result).toEqual(
12-
'https://support.theguardian.com/contribute?selected-contribution-type=ONE_OFF&selected-amount=5',
13-
);
14-
});
15-
16-
it('adds choice cards params to url with existing querystring', () => {
17-
const result = addChoiceCardsParams(
18-
'https://support.theguardian.com/contribute?test=test',
19-
'ONE_OFF',
20-
5,
21-
);
22-
expect(result).toEqual(
23-
'https://support.theguardian.com/contribute?test=test&selected-contribution-type=ONE_OFF&selected-amount=5',
24-
);
25-
});
26-
});
2+
import { enrichSupportUrl, getChoiceCardUrl } from './tracking';
273

284
describe('enrichSupportUrl', () => {
295
const tracking: Tracking = {
@@ -81,3 +57,99 @@ describe('enrichSupportUrl', () => {
8157
);
8258
});
8359
});
60+
61+
describe('getChoiceCardUrl', () => {
62+
// One-time
63+
it('builds landing page url for one-time choice', () => {
64+
const url = getChoiceCardUrl({
65+
benefits: [],
66+
isDefault: false,
67+
label: 'label',
68+
product: {
69+
supportTier: 'OneOff',
70+
},
71+
destination: 'LandingPage',
72+
});
73+
expect(url).toEqual(
74+
'https://support.theguardian.com/contribute?oneTime',
75+
);
76+
});
77+
it('builds checkout page url for one-time choice', () => {
78+
const url = getChoiceCardUrl({
79+
benefits: [],
80+
isDefault: false,
81+
label: 'label',
82+
product: {
83+
supportTier: 'OneOff',
84+
},
85+
destination: 'Checkout',
86+
});
87+
expect(url).toEqual(
88+
'https://support.theguardian.com/one-time-checkout',
89+
);
90+
});
91+
92+
// Recurring contribution
93+
it('builds landing page url for recurring contribution choice', () => {
94+
const url = getChoiceCardUrl({
95+
benefits: [],
96+
isDefault: false,
97+
label: 'label',
98+
product: {
99+
supportTier: 'Contribution',
100+
ratePlan: 'Monthly',
101+
},
102+
destination: 'LandingPage',
103+
});
104+
expect(url).toEqual(
105+
'https://support.theguardian.com/contribute?product=Contribution&ratePlan=Monthly',
106+
);
107+
});
108+
it('builds checkout page url for recurring contribution choice', () => {
109+
const url = getChoiceCardUrl({
110+
benefits: [],
111+
isDefault: false,
112+
label: 'label',
113+
product: {
114+
supportTier: 'Contribution',
115+
ratePlan: 'Monthly',
116+
},
117+
destination: 'Checkout',
118+
});
119+
expect(url).toEqual(
120+
'https://support.theguardian.com/checkout?product=Contribution&ratePlan=Monthly',
121+
);
122+
});
123+
124+
// SupporterPlus
125+
it('builds landing page url for Supporter Plus choice', () => {
126+
const url = getChoiceCardUrl({
127+
benefits: [],
128+
isDefault: false,
129+
label: 'label',
130+
product: {
131+
supportTier: 'SupporterPlus',
132+
ratePlan: 'Annual',
133+
},
134+
destination: 'LandingPage',
135+
});
136+
expect(url).toEqual(
137+
'https://support.theguardian.com/contribute?product=SupporterPlus&ratePlan=Annual',
138+
);
139+
});
140+
it('builds checkout page url for Supporter Plus choice', () => {
141+
const url = getChoiceCardUrl({
142+
benefits: [],
143+
isDefault: false,
144+
label: 'label',
145+
product: {
146+
supportTier: 'SupporterPlus',
147+
ratePlan: 'Annual',
148+
},
149+
destination: 'Checkout',
150+
});
151+
expect(url).toEqual(
152+
'https://support.theguardian.com/checkout?product=SupporterPlus&ratePlan=Annual',
153+
);
154+
});
155+
});

0 commit comments

Comments
 (0)