|
1 | 1 | import { expect, test } from '@playwright/test';
|
2 | 2 | import { Standard as standardArticle } from '../../fixtures/generated/fe-articles/Standard';
|
3 | 3 | import { disableCMP } from '../lib/cmp';
|
4 |
| -import { addCookie } from '../lib/cookies'; |
5 | 4 | import { waitForIsland } from '../lib/islands';
|
6 |
| -import { loadPageNoOkta } from '../lib/load-page'; |
7 |
| -import { stubResponse } from '../lib/network'; |
8 |
| - |
9 |
| -const profileResponse = { |
10 |
| - status: 'ok', |
11 |
| - userProfile: { |
12 |
| - userId: '102309223', |
13 |
| - displayName: 'Guardian User', |
14 |
| - webUrl: 'https://profile.theguardian.com/user/id/102309223', |
15 |
| - apiUrl: 'https://discussion.guardianapis.com/discussion-api/profile/102309223', |
16 |
| - avatar: 'https://avatar.guim.co.uk/user/102309223', |
17 |
| - secureAvatarUrl: 'https://avatar.guim.co.uk/user/102309223', |
18 |
| - badge: [], |
19 |
| - privateFields: { |
20 |
| - canPostComment: true, |
21 |
| - isPremoderated: false, |
22 |
| - hasCommented: false, |
23 |
| - }, |
24 |
| - }, |
25 |
| -}; |
26 |
| - |
27 |
| -const idapiIdentifiersResponse = { |
28 |
| - id: '000000000', |
29 |
| - brazeUuid: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', |
30 |
| - puzzleUuid: 'aaaaaaaaaaaa', |
31 |
| - googleTagId: 'aaaaaaaaaaaa', |
32 |
| -}; |
| 5 | +import { loadPageWithOverrides } from '../lib/load-page'; |
33 | 6 |
|
34 | 7 | test.describe('Signed in readers', () => {
|
35 |
| - test('should display the correct page state for signed in users', async ({ |
36 |
| - context, |
37 |
| - page, |
38 |
| - }) => { |
39 |
| - // Fake login |
40 |
| - await addCookie(context, { name: 'GU_U', value: 'true' }); |
41 |
| - |
42 |
| - // Mock call to '/user/me/identifiers' |
43 |
| - const idapiReponseProfile = stubResponse( |
44 |
| - page, |
45 |
| - '**/user/me/identifiers', |
46 |
| - { |
47 |
| - json: idapiIdentifiersResponse, |
48 |
| - }, |
49 |
| - ); |
50 |
| - |
51 |
| - // Mock call to 'profile/me' |
52 |
| - const profileResponsePromise = stubResponse( |
53 |
| - page, |
54 |
| - '**/profile/me?strict_sanctions_check=false', |
55 |
| - { |
56 |
| - json: profileResponse, |
57 |
| - }, |
58 |
| - ); |
59 |
| - |
60 |
| - await disableCMP(context); |
61 |
| - await loadPageNoOkta(page, standardArticle); |
62 |
| - |
63 |
| - await idapiReponseProfile; |
64 |
| - await profileResponsePromise; |
65 |
| - |
66 |
| - // This text is shown in the header for signed in users |
67 |
| - await expect(page.getByText('My account')).toBeVisible(); |
68 |
| - }); |
69 |
| - |
70 |
| - test('should have the correct urls for the header links', async ({ |
71 |
| - context, |
72 |
| - page, |
73 |
| - }) => { |
74 |
| - // Fake login |
75 |
| - await addCookie(context, { name: 'GU_U', value: 'true' }); |
76 |
| - |
77 |
| - await addCookie(context, { |
78 |
| - name: 'gu_hide_support_messaging', |
79 |
| - value: 'true', |
80 |
| - }); |
81 |
| - |
82 |
| - // Mock call to 'profile/me' |
83 |
| - const profileResponsePromise = stubResponse( |
84 |
| - page, |
85 |
| - '**/profile/me?strict_sanctions_check=false', |
86 |
| - { |
87 |
| - json: profileResponse, |
88 |
| - }, |
89 |
| - ); |
90 |
| - |
91 |
| - await disableCMP(context); |
92 |
| - await loadPageNoOkta(page, standardArticle); |
93 |
| - |
94 |
| - await profileResponsePromise; |
95 |
| - |
96 |
| - expect( |
97 |
| - await page |
98 |
| - .locator('a[data-link-name="header : topbar : printsubs"]') |
99 |
| - .getAttribute('href'), |
100 |
| - ).toContain('support.theguardian.com/subscribe'); |
101 |
| - |
102 |
| - expect( |
103 |
| - await page |
104 |
| - .locator('a[data-link-name="header : topbar : job-cta"]') |
105 |
| - .getAttribute('href'), |
106 |
| - ).toContain('https://jobs.theguardian.com'); |
107 |
| - |
108 |
| - expect( |
109 |
| - await page |
110 |
| - .locator( |
111 |
| - 'button[data-link-name="header : topbar : my account"]', |
112 |
| - ) |
113 |
| - .textContent(), |
114 |
| - ).toContain('My account'); |
115 |
| - }); |
116 |
| - |
117 | 8 | test('should not display signed in texts when users are not signed in', async ({
|
118 | 9 | context,
|
119 | 10 | page,
|
120 | 11 | }) => {
|
121 | 12 | await disableCMP(context);
|
122 |
| - await loadPageNoOkta(page, standardArticle); |
| 13 | + await loadPageWithOverrides(page, standardArticle); |
123 | 14 |
|
124 | 15 | await waitForIsland(page, 'DiscussionWeb');
|
125 | 16 |
|
|
0 commit comments