Skip to content

Commit 8c777b8

Browse files
authored
Merge pull request #14169 from guardian/jm/new-sign-in-gate
chore(storybook): add missing stories for sign in gate auxia
2 parents c54a192 + 0e5b707 commit 8c777b8

File tree

3 files changed

+199
-1
lines changed

3 files changed

+199
-1
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
export const mockAuxiaResponseDismissible = {
2+
status: true,
3+
data: {
4+
userTreatment: {
5+
treatmentId: 'auxia-treatment-001',
6+
treatmentTrackingId: 'tracking-001',
7+
surface: 'signin-gate',
8+
treatmentContent: JSON.stringify({
9+
title: 'Register for free and continue reading',
10+
subtitle: "It's still free to read – this is not a paywall",
11+
body: "We're committed to keeping our quality reporting open. By registering and providing us with insight into your preferences, you're helping us to engage with you more deeply.",
12+
first_cta_name: 'Register for free',
13+
first_cta_link: 'https://profile.theguardian.com/register',
14+
second_cta_name: "I'll do it later",
15+
}),
16+
},
17+
},
18+
};
19+
20+
export const mockAuxiaResponseNonDismissible = {
21+
status: true,
22+
data: {
23+
userTreatment: {
24+
treatmentId: 'auxia-treatment-002',
25+
treatmentTrackingId: 'tracking-002',
26+
surface: 'signin-gate',
27+
treatmentContent: JSON.stringify({
28+
title: 'Complete registration to continue reading',
29+
subtitle: 'Registration is required to access this content',
30+
body: 'To continue reading this article and access our quality journalism, please complete your registration.',
31+
first_cta_name: 'Complete registration',
32+
first_cta_link: 'https://profile.theguardian.com/register',
33+
second_cta_name: '', // Empty makes it non-dismissible
34+
}),
35+
},
36+
},
37+
};
38+
39+
export const mockAuxiaResponseLegacy = {
40+
status: true,
41+
data: {
42+
userTreatment: {
43+
treatmentId: 'default-treatment-id', // This triggers legacy gate
44+
treatmentTrackingId: 'legacy-tracking',
45+
surface: 'signin-gate',
46+
treatmentContent: JSON.stringify({
47+
title: 'Register to continue reading',
48+
subtitle: '',
49+
body: '',
50+
first_cta_name: 'Register',
51+
first_cta_link: 'https://profile.theguardian.com/register',
52+
second_cta_name: 'Not now',
53+
}),
54+
},
55+
},
56+
};
57+
58+
export const mockAuxiaResponseNoTreatment = {
59+
status: false,
60+
data: undefined,
61+
};
62+
63+
export const getAuxiaMock = (payload: string): unknown => {
64+
const body = JSON.parse(payload) as Record<string, unknown>;
65+
66+
const mocks = {
67+
dismissable: mockAuxiaResponseDismissible,
68+
'non-dismissable': mockAuxiaResponseNonDismissible,
69+
legacy: mockAuxiaResponseLegacy,
70+
'no-treatment': mockAuxiaResponseNoTreatment,
71+
};
72+
73+
const key = body.sectionId as keyof typeof mocks;
74+
const mock: unknown = mocks[key];
75+
76+
return mock ?? mockAuxiaResponseNoTreatment;
77+
};

dotcom-rendering/src/components/SignInGate/SignInGate.stories.tsx

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { type EditionId } from '../../lib/edition';
2+
import type { TagType } from '../../types/tag';
13
import { Section } from '../Section';
24
import { SignInGateSelector } from '../SignInGateSelector.importable';
35
import { SignInGateCustomizableText } from './gateDesigns/SignInGateCustomizableText';
@@ -154,3 +156,110 @@ signInGateMainCheckoutCompletePersonalisedCopy.argTypes = {
154156
control: { type: 'radio' },
155157
},
156158
};
159+
160+
export const signInGateSelectorStoryDismissable = () => {
161+
const tags: TagType[] = [
162+
{ id: 'politics/politics', type: 'Keyword', title: 'Politics' },
163+
{ id: 'world/europe-news', type: 'Keyword', title: 'Europe News' },
164+
];
165+
166+
return (
167+
<Section fullWidth={true}>
168+
<SignInGateSelector
169+
contentType="Article"
170+
sectionId="dismissable"
171+
tags={tags}
172+
isPaidContent={false}
173+
isPreview={false}
174+
pageId="dismissable"
175+
host="https://www.theguardian.com"
176+
idUrl="https://profile.theguardian.com"
177+
contributionsServiceUrl="https://contributions.guardianapis.com"
178+
editionId={'UK' as EditionId}
179+
/>
180+
</Section>
181+
);
182+
};
183+
184+
signInGateSelectorStoryDismissable.storyName =
185+
'sign_in_gate_selector_dismissable';
186+
187+
export const signInGateSelectorStoryNonDismissable = () => {
188+
const tags: TagType[] = [
189+
{ id: 'politics/politics', type: 'Keyword', title: 'Politics' },
190+
{ id: 'world/europe-news', type: 'Keyword', title: 'Europe News' },
191+
];
192+
193+
return (
194+
<Section fullWidth={true}>
195+
<SignInGateSelector
196+
contentType="Article"
197+
sectionId="non-dismissable"
198+
tags={tags}
199+
isPaidContent={false}
200+
isPreview={false}
201+
pageId="non-dismissable"
202+
host="https://www.theguardian.com"
203+
idUrl="https://profile.theguardian.com"
204+
contributionsServiceUrl="https://contributions.guardianapis.com"
205+
editionId={'UK' as EditionId}
206+
/>
207+
</Section>
208+
);
209+
};
210+
211+
signInGateSelectorStoryNonDismissable.storyName =
212+
'sign_in_gate_selector_non_dismissable';
213+
214+
export const signInGateSelectorStoryLegacy = () => {
215+
const tags: TagType[] = [
216+
{ id: 'politics/politics', type: 'Keyword', title: 'Politics' },
217+
{ id: 'world/europe-news', type: 'Keyword', title: 'Europe News' },
218+
];
219+
220+
return (
221+
<Section fullWidth={true}>
222+
<SignInGateSelector
223+
contentType="Article"
224+
sectionId="legacy"
225+
tags={tags}
226+
isPaidContent={false}
227+
isPreview={false}
228+
pageId="legacy"
229+
host="https://www.theguardian.com"
230+
idUrl="https://profile.theguardian.com"
231+
contributionsServiceUrl="https://contributions.guardianapis.com"
232+
editionId={'UK' as EditionId}
233+
/>
234+
</Section>
235+
);
236+
};
237+
238+
signInGateSelectorStoryLegacy.storyName = 'sign_in_gate_selector_legacy';
239+
240+
export const signInGateSelectorStoryNoTreatment = () => {
241+
const tags: TagType[] = [
242+
{ id: 'politics/politics', type: 'Keyword', title: 'Politics' },
243+
{ id: 'world/europe-news', type: 'Keyword', title: 'Europe News' },
244+
];
245+
246+
return (
247+
<Section fullWidth={true}>
248+
<SignInGateSelector
249+
contentType="Article"
250+
sectionId="no-treatment"
251+
tags={tags}
252+
isPaidContent={false}
253+
isPreview={false}
254+
pageId="no-treatment"
255+
host="https://www.theguardian.com"
256+
idUrl="https://profile.theguardian.com"
257+
contributionsServiceUrl="https://contributions.guardianapis.com"
258+
editionId={'UK' as EditionId}
259+
/>
260+
</Section>
261+
);
262+
};
263+
264+
signInGateSelectorStoryNoTreatment.storyName =
265+
'sign_in_gate_selector_no_treatment';

dotcom-rendering/src/lib/mockRESTCalls.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { mostReadGeo } from '../../fixtures/manual/most-read-geo';
1313
import { noTopPicks } from '../../fixtures/manual/noTopPicks';
1414
import { related } from '../../fixtures/manual/related';
1515
import { shortDiscussion } from '../../fixtures/manual/short-discussion';
16+
import { getAuxiaMock } from '../../fixtures/manual/sign-in-gate';
1617
import { topPicks } from '../../fixtures/manual/topPicks';
1718

1819
const createMockResponse = (status: number, body?: any): Promise<Response> => {
@@ -257,8 +258,19 @@ export const mockFetch: typeof global.fetch = (
257258
return exampleDomainRegex.test(decodedBody)
258259
? createMockResponse(500)
259260
: createMockResponse(200);
261+
case /.*contributions\.(code\.dev-)?guardianapis\.com\/auxia\/get-treatments/.test(
262+
url,
263+
) && requestInit?.method === 'POST':
264+
return createMockResponse(
265+
200,
266+
getAuxiaMock(requestInit.body?.toString() ?? ''),
267+
);
268+
case /.*contributions\.(code\.dev-)?guardianapis\.com\/auxia\/log-treatment-interaction/.test(
269+
url,
270+
) && requestInit?.method === 'POST':
271+
return createMockResponse(200);
260272
default:
261-
console.log('could not find url');
273+
console.log(`could not find url ${requestInit?.method} ${url}`);
262274
return Promise.resolve(
263275
new Response(JSON.stringify({ error: 'Not Found' }), {
264276
status: 404,

0 commit comments

Comments
 (0)