|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +test('code tabs support keyboard selection, deep links, and browser history', async ({ |
| 4 | + page, |
| 5 | +}) => { |
| 6 | + await page.goto('/en'); |
| 7 | + const tabs = page |
| 8 | + .getByRole('tablist', { name: 'Code samples' }) |
| 9 | + .getByRole('tab'); |
| 10 | + const first = tabs.first(); |
| 11 | + const second = tabs.nth(1); |
| 12 | + const firstId = await first.getAttribute('aria-controls'); |
| 13 | + const secondId = await second.getAttribute('aria-controls'); |
| 14 | + |
| 15 | + await first.focus(); |
| 16 | + await page.keyboard.press('ArrowRight'); |
| 17 | + await expect(second).toBeFocused(); |
| 18 | + await expect(second).toHaveAttribute('aria-selected', 'true'); |
| 19 | + await expect(page.locator(`[id="${secondId}"]`)).toBeVisible(); |
| 20 | + await expect(page.locator(`[id="${firstId}"]`)).toBeHidden(); |
| 21 | + |
| 22 | + await page.reload(); |
| 23 | + await expect(second).toHaveAttribute('aria-selected', 'true'); |
| 24 | + await expect(page.locator(`[id="${secondId}"]`)).toBeVisible(); |
| 25 | + await first.click(); |
| 26 | + await expect(page.locator(`[id="${firstId}"]`)).toBeVisible(); |
| 27 | + await page.goBack(); |
| 28 | + await expect(second).toHaveAttribute('aria-selected', 'true'); |
| 29 | + await expect(page.locator(`[id="${secondId}"]`)).toBeVisible(); |
| 30 | + await page.goForward(); |
| 31 | + await expect(first).toHaveAttribute('aria-selected', 'true'); |
| 32 | + await expect(page.locator(`[id="${firstId}"]`)).toBeVisible(); |
| 33 | +}); |
| 34 | + |
| 35 | +test.describe('without JavaScript', () => { |
| 36 | + test.use({ javaScriptEnabled: false }); |
| 37 | + |
| 38 | + test('native links select visible panels and survive a reload', async ({ |
| 39 | + page, |
| 40 | + }) => { |
| 41 | + await page.goto('/en'); |
| 42 | + const links = page |
| 43 | + .getByRole('navigation', { name: 'Code samples' }) |
| 44 | + .getByRole('link'); |
| 45 | + const firstId = await links.first().getAttribute('aria-controls'); |
| 46 | + const second = links.nth(1); |
| 47 | + const secondId = await second.getAttribute('aria-controls'); |
| 48 | + await expect(page.locator(`[id="${firstId}"]`)).toBeVisible(); |
| 49 | + await expect(page.locator(`[id="${secondId}"]`)).toBeHidden(); |
| 50 | + await second.click(); |
| 51 | + await expect(page.locator(`[id="${secondId}"]`)).toBeVisible(); |
| 52 | + await expect(page.locator(`[id="${firstId}"]`)).toBeHidden(); |
| 53 | + await page.reload(); |
| 54 | + await expect(page.locator(`[id="${secondId}"]`)).toBeVisible(); |
| 55 | + await expect(page.locator(`[id="${firstId}"]`)).toBeHidden(); |
| 56 | + }); |
| 57 | +}); |
0 commit comments