|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +test.describe('Browser E2E — Declarative meta page', () => { |
| 4 | + test.beforeEach(async ({ page }) => { |
| 5 | + await page.goto('/?page=meta'); |
| 6 | + await page.waitForSelector('#page-indicator'); |
| 7 | + }); |
| 8 | + |
| 9 | + test('sets document title', async ({ page }) => { |
| 10 | + await expect(page).toHaveTitle('E2E Test Page'); |
| 11 | + }); |
| 12 | + |
| 13 | + test('renders meta charset', async ({ page }) => { |
| 14 | + const charset = page.locator('head meta[charset]'); |
| 15 | + await expect(charset).toHaveAttribute('charset', 'utf-8'); |
| 16 | + }); |
| 17 | + |
| 18 | + test('renders meta description', async ({ page }) => { |
| 19 | + const desc = page.locator('head meta[name="description"]'); |
| 20 | + await expect(desc).toHaveAttribute('content', 'E2E test description'); |
| 21 | + }); |
| 22 | + |
| 23 | + test('renders og:title meta', async ({ page }) => { |
| 24 | + const og = page.locator('head meta[property="og:title"]'); |
| 25 | + await expect(og).toHaveAttribute('content', 'E2E OG Title'); |
| 26 | + }); |
| 27 | + |
| 28 | + test('renders canonical link', async ({ page }) => { |
| 29 | + const link = page.locator('head link[rel="canonical"]'); |
| 30 | + await expect(link).toHaveAttribute('href', 'https://example.com/e2e'); |
| 31 | + }); |
| 32 | + |
| 33 | + test('renders stylesheet link', async ({ page }) => { |
| 34 | + const link = page.locator('head link[rel="stylesheet"]'); |
| 35 | + await expect(link).toHaveAttribute('href', '/test.css'); |
| 36 | + }); |
| 37 | + |
| 38 | + test('renders base tag', async ({ page }) => { |
| 39 | + const base = page.locator('head base'); |
| 40 | + await expect(base).toHaveAttribute('href', 'https://example.com/'); |
| 41 | + }); |
| 42 | + |
| 43 | + test('renders inline style', async ({ page }) => { |
| 44 | + const style = page.locator('head style'); |
| 45 | + const text = await style.textContent(); |
| 46 | + expect(text).toContain('background: red'); |
| 47 | + }); |
| 48 | + |
| 49 | + test('renders inline script', async ({ page }) => { |
| 50 | + const script = page.locator('head script[type="application/ld+json"]'); |
| 51 | + const text = await script.textContent(); |
| 52 | + expect(text).toContain('"@context"'); |
| 53 | + }); |
| 54 | + |
| 55 | + test('sets html attributes', async ({ page }) => { |
| 56 | + const lang = await page.locator('html').getAttribute('lang'); |
| 57 | + expect(lang).toBe('en'); |
| 58 | + const cls = await page.locator('html').getAttribute('class'); |
| 59 | + expect(cls).toContain('e2e-html'); |
| 60 | + }); |
| 61 | + |
| 62 | + test('sets body attributes', async ({ page }) => { |
| 63 | + const cls = await page.locator('body').getAttribute('class'); |
| 64 | + expect(cls).toContain('e2e-body'); |
| 65 | + const dataPage = await page.locator('body').getAttribute('data-page'); |
| 66 | + expect(dataPage).toBe('meta'); |
| 67 | + }); |
| 68 | +}); |
| 69 | + |
| 70 | +test.describe('Browser E2E — Title template page', () => { |
| 71 | + test('applies titleTemplate', async ({ page }) => { |
| 72 | + await page.goto('/?page=title-template'); |
| 73 | + await page.waitForSelector('#title-template-content'); |
| 74 | + await expect(page).toHaveTitle('Site Name - Templated'); |
| 75 | + }); |
| 76 | +}); |
| 77 | + |
| 78 | +test.describe('Browser E2E — API props page', () => { |
| 79 | + test.beforeEach(async ({ page }) => { |
| 80 | + await page.goto('/?page=api'); |
| 81 | + await page.waitForSelector('#page-indicator'); |
| 82 | + }); |
| 83 | + |
| 84 | + test('sets title via prop', async ({ page }) => { |
| 85 | + await expect(page).toHaveTitle('API Title'); |
| 86 | + }); |
| 87 | + |
| 88 | + test('sets meta via prop array', async ({ page }) => { |
| 89 | + const robots = page.locator('head meta[name="robots"]'); |
| 90 | + await expect(robots).toHaveAttribute('content', 'noindex'); |
| 91 | + |
| 92 | + const ogUrl = page.locator('head meta[property="og:url"]'); |
| 93 | + await expect(ogUrl).toHaveAttribute('content', 'https://example.com/api'); |
| 94 | + }); |
| 95 | + |
| 96 | + test('sets link via prop array', async ({ page }) => { |
| 97 | + const link = page.locator('head link[rel="canonical"]'); |
| 98 | + await expect(link).toHaveAttribute('href', 'https://example.com/api'); |
| 99 | + }); |
| 100 | + |
| 101 | + test('sets html lang via htmlAttributes', async ({ page }) => { |
| 102 | + const lang = await page.locator('html').getAttribute('lang'); |
| 103 | + expect(lang).toBe('fr'); |
| 104 | + }); |
| 105 | + |
| 106 | + test('sets body class via bodyAttributes', async ({ page }) => { |
| 107 | + const cls = await page.locator('body').getAttribute('class'); |
| 108 | + expect(cls).toContain('api-body'); |
| 109 | + }); |
| 110 | +}); |
| 111 | + |
| 112 | +test.describe('Browser E2E — Nested Helmet components', () => { |
| 113 | + test.beforeEach(async ({ page }) => { |
| 114 | + await page.goto('/?page=nested'); |
| 115 | + await page.waitForSelector('#page-indicator'); |
| 116 | + }); |
| 117 | + |
| 118 | + test('innermost title wins', async ({ page }) => { |
| 119 | + await expect(page).toHaveTitle('Inner Title'); |
| 120 | + }); |
| 121 | + |
| 122 | + test('innermost description wins', async ({ page }) => { |
| 123 | + const desc = page.locator('head meta[name="description"]'); |
| 124 | + await expect(desc).toHaveAttribute('content', 'Inner description'); |
| 125 | + }); |
| 126 | + |
| 127 | + test('keywords from inner component are present', async ({ page }) => { |
| 128 | + const kw = page.locator('head meta[name="keywords"]'); |
| 129 | + await expect(kw).toHaveAttribute('content', 'inner,nested'); |
| 130 | + }); |
| 131 | +}); |
0 commit comments