Skip to content

Commit a8e29b2

Browse files
author
jatin.gundabathula
committed
feat: WF-2856 Test with latest cookie banner
1 parent 9f90057 commit a8e29b2

8 files changed

Lines changed: 5248 additions & 5165 deletions

File tree

.yarnrc.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
approvedGitRepositories:
2+
- "**"
3+
4+
compressionLevel: mixed
5+
6+
enableGlobalCache: false
7+
8+
enableScripts: true
9+
110
nodeLinker: node-modules
11+
12+
npmMinimalAgeGate: 0

nextjs-app-v15/src/app/components/cookie-banner/cookie-banner.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,28 @@
33
import NavigationLayout from "@/app/layout/navigation";
44
import { PieCookieBanner } from '@justeattakeaway/pie-webc/react/cookie-banner.js';
55

6-
export default function CookieBanner() {
6+
type CookieBannerProps = {
7+
variant?: string;
8+
};
9+
10+
export default function CookieBanner({ variant }: CookieBannerProps) {
11+
const personalizedLabel = variant === 'personalized-label' ? 'Custom personalized label' : undefined;
12+
const personalizedDescription = variant === 'personalized-description'
13+
? 'Read our <a href="https://example.com/privacy">privacy policy</a> for more info.'
14+
: undefined;
15+
716
return (
817
<NavigationLayout title="Cookie Banner">
9-
<PieCookieBanner
10-
defaultPreferences={{functional: true, personalized: true, analytical: true}}
11-
language="da"
12-
country="dk"
13-
hasPrimaryActionsOnly
14-
cookieTechnologiesLink="https://justeattakeaway.com"
15-
cookieStatementLink="https://justeattakeaway.com" />
18+
<PieCookieBanner
19+
defaultPreferences={{ functional: true, personalized: true, analytical: true }}
20+
language="da"
21+
country="dk"
22+
hasPrimaryActionsOnly
23+
cookieTechnologiesLink="https://justeattakeaway.com"
24+
cookieStatementLink="https://justeattakeaway.com"
25+
personalizedLabel={personalizedLabel}
26+
personalizedDescription={personalizedDescription}
27+
/>
1628
</NavigationLayout>
1729
);
1830
}

nextjs-app-v15/src/app/components/cookie-banner/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ export const metadata: Metadata = {
66
}
77

88
export default function CookieBannerComponent() {
9-
return <CookieBanner/>;
9+
return <CookieBanner />;
1010
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import CookieBanner from '../cookie-banner';
2+
import { type Metadata } from 'next';
3+
4+
export const metadata: Metadata = {
5+
title: 'Cookie Banner',
6+
};
7+
8+
export default function PersonalizedDescriptionCookieBannerPage() {
9+
return <CookieBanner variant="personalized-description" />;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import CookieBanner from '../cookie-banner';
2+
import { type Metadata } from 'next';
3+
4+
export const metadata: Metadata = {
5+
title: 'Cookie Banner',
6+
};
7+
8+
export default function PersonalizedLabelCookieBannerPage() {
9+
return <CookieBanner variant="personalized-label" />;
10+
}

nextjs-app-v15/src/app/layout/navigation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useRouter, usePathname } from "next/navigation";
66
import { type ReactNode } from "react";
77

88
interface NavigationLayoutProps {
9-
children: ReactNode;
9+
children?: ReactNode;
1010
title: string;
1111
}
1212

test/system/cookie-banner.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { test, expect, type Page } from '@playwright/test';
2+
3+
const { APP_NAME } = process.env;
4+
const isNextJsAppV15 = APP_NAME === 'nextjs-app-v15';
5+
6+
test.describe('Cookie Banner personalized content', () => {
7+
test.skip(!isNextJsAppV15, 'Runs only against nextjs-app-v15');
8+
9+
async function openManagePreferences(page: Page) {
10+
await page.getByTestId('actions-manage-prefs').click();
11+
await expect(page.getByRole('dialog')).toBeVisible();
12+
}
13+
14+
test('uses built-in copy when no override props are provided', async ({ page }) => {
15+
await page.goto('components/cookie-banner');
16+
await openManagePreferences(page);
17+
18+
await expect(page.getByTestId('personalized-label')).toHaveText('Personlige (målretning og annoncering)');
19+
await expect(page.getByTestId('personalized-description')).toContainText('Disse markedsføringscookier bruges til at skræddersy leveringen af oplysninger');
20+
});
21+
22+
test('supports overriding the personalized label', async ({ page }) => {
23+
await page.goto('components/cookie-banner/personalized-label');
24+
await openManagePreferences(page);
25+
26+
await expect(page.getByTestId('personalized-label')).toHaveText('Custom personalized label');
27+
await expect(page.getByTestId('personalized-description')).toContainText('Disse markedsføringscookier bruges til at skræddersy leveringen af oplysninger');
28+
});
29+
30+
test('supports overriding the personalized description with HTML content', async ({ page }) => {
31+
await page.goto('components/cookie-banner/personalized-description');
32+
await openManagePreferences(page);
33+
34+
const personalizedDescription = page.getByTestId('personalized-description');
35+
36+
await expect(page.getByTestId('personalized-label')).toHaveText('Personlige (målretning og annoncering)');
37+
await expect(personalizedDescription).toContainText('Read our privacy policy for more info.');
38+
await expect(personalizedDescription.getByRole('link', { name: 'privacy policy' })).toHaveAttribute('href', 'https://example.com/privacy');
39+
});
40+
});

0 commit comments

Comments
 (0)