|
| 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 | +}); |
0 commit comments