|
1 | 1 | import { test, expect } from '@playwright/test' |
2 | 2 | import AxeBuilder from '@axe-core/playwright' |
3 | 3 |
|
| 4 | +for (const width of [1280, 390, 320]) { |
| 5 | + test(`homepage support links remain usable at ${width}px`, async ({ |
| 6 | + page, |
| 7 | + browserName, |
| 8 | + }) => { |
| 9 | + await page.setViewportSize({ width, height: 900 }) |
| 10 | + await page.goto('/') |
| 11 | + const support = page.getByRole('region', { |
| 12 | + name: 'Useful in your project?', |
| 13 | + }) |
| 14 | + await expect(support).toBeVisible() |
| 15 | + expect( |
| 16 | + await support.evaluate((node) => node.previousElementSibling?.id), |
| 17 | + ).toBe('in-products') |
| 18 | + const star = support.getByRole('link', { |
| 19 | + name: 'Star on GitHub', |
| 20 | + exact: true, |
| 21 | + }) |
| 22 | + const explore = support.getByRole('link', { |
| 23 | + name: 'Explore NIPE Open Source', |
| 24 | + exact: true, |
| 25 | + }) |
| 26 | + await expect(star).toHaveAttribute( |
| 27 | + 'href', |
| 28 | + 'https://github.com/NIPE-Solutions/react-data-inspector', |
| 29 | + ) |
| 30 | + await expect(explore).toHaveAttribute( |
| 31 | + 'href', |
| 32 | + 'https://opensource.nipesolutions.com', |
| 33 | + ) |
| 34 | + for (const link of [star, explore]) { |
| 35 | + const bounds = await link.boundingBox() |
| 36 | + expect(bounds!.height).toBeGreaterThanOrEqual(44) |
| 37 | + expect(bounds!.width).toBeGreaterThanOrEqual(44) |
| 38 | + expect(bounds!.x).toBeGreaterThanOrEqual(0) |
| 39 | + expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(width) |
| 40 | + expect(await link.evaluate((node) => node.tagName)).toBe('A') |
| 41 | + } |
| 42 | + await star.focus() |
| 43 | + // macOS Safari navigates native links with Option+Tab. |
| 44 | + const tab = |
| 45 | + browserName === 'webkit' && process.platform === 'darwin' |
| 46 | + ? 'Alt+Tab' |
| 47 | + : 'Tab' |
| 48 | + await page.keyboard.press(tab) |
| 49 | + await expect(explore).toBeFocused() |
| 50 | + await page.keyboard.press(`Shift+${tab}`) |
| 51 | + await expect(star).toBeFocused() |
| 52 | + expect( |
| 53 | + await star.evaluate((node) => getComputedStyle(node).outlineStyle), |
| 54 | + ).not.toBe('none') |
| 55 | + if (process.env.CTA_SCREENSHOT_DIR) { |
| 56 | + await support.screenshot({ |
| 57 | + path: `${process.env.CTA_SCREENSHOT_DIR}/${test.info().project.name}-${width}.png`, |
| 58 | + }) |
| 59 | + } |
| 60 | + }) |
| 61 | +} |
| 62 | + |
4 | 63 | test('homepage proofs use actual values and safe inspection', async ({ |
5 | 64 | page, |
6 | 65 | }) => { |
@@ -95,6 +154,9 @@ test('static pages hydrate without errors and documentation links work', async ( |
95 | 154 | ]) { |
96 | 155 | await page.goto(route) |
97 | 156 | await expect(page.getByRole('heading', { level: 1 })).toBeVisible() |
| 157 | + await expect( |
| 158 | + page.getByRole('region', { name: 'Useful in your project?' }), |
| 159 | + ).toHaveCount(route === '/' ? 1 : 0) |
98 | 160 | if (route === '/') |
99 | 161 | await page.getByRole('button', { name: 'Classic', exact: true }).click() |
100 | 162 | } |
|
0 commit comments