Skip to content

Commit c1e28cb

Browse files
committed
test: create banner test
1 parent 0506169 commit c1e28cb

2 files changed

Lines changed: 130 additions & 0 deletions

File tree

e2e/announcement-banner.spec.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
const REMOTE_CONFIG_URL = 'https://nodejs.org/site.json';
4+
5+
test.describe('Announcement Banner', () => {
6+
test('renders a text-only banner', async ({ page }) => {
7+
await page.route(REMOTE_CONFIG_URL, route =>
8+
route.fulfill({
9+
contentType: 'application/json',
10+
body: JSON.stringify({
11+
websiteBanners: {
12+
index: { text: 'Important announcement for all users' },
13+
},
14+
}),
15+
})
16+
);
17+
18+
await page.goto('/assert.html');
19+
20+
const banner = page.getByRole('region', { name: 'Announcements' });
21+
await expect(banner).toBeVisible();
22+
await expect(banner).toContainText('Important announcement for all users');
23+
});
24+
25+
test('renders a banner with a link', async ({ page }) => {
26+
await page.route(REMOTE_CONFIG_URL, route =>
27+
route.fulfill({
28+
contentType: 'application/json',
29+
body: JSON.stringify({
30+
websiteBanners: {
31+
index: {
32+
text: 'Read the release notes',
33+
link: 'https://nodejs.org/releases',
34+
},
35+
},
36+
}),
37+
})
38+
);
39+
40+
await page.goto('/assert.html');
41+
42+
const banner = page.getByRole('region', { name: 'Announcements' });
43+
await expect(banner).toBeVisible();
44+
45+
const link = banner.getByRole('link', { name: 'Read the release notes' });
46+
await expect(link).toBeVisible();
47+
await expect(link).toHaveAttribute('href', 'https://nodejs.org/releases');
48+
await expect(link).toHaveAttribute('target', '_blank');
49+
});
50+
51+
test('does not render when there are no active banners', async ({ page }) => {
52+
await page.route(REMOTE_CONFIG_URL, route =>
53+
route.fulfill({
54+
contentType: 'application/json',
55+
body: JSON.stringify({ websiteBanners: {} }),
56+
})
57+
);
58+
59+
await page.goto('/assert.html');
60+
await page.waitForLoadState('networkidle');
61+
62+
await expect(
63+
page.getByRole('region', { name: 'Announcements' })
64+
).not.toBeAttached();
65+
});
66+
});

package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)