|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +import { loginAsAdmin } from "./helpers"; |
| 4 | + |
| 5 | +test.beforeEach(async ({ page }) => { |
| 6 | + await loginAsAdmin(page); |
| 7 | + await page.goto("/article/editor"); |
| 8 | +}); |
| 9 | + |
| 10 | +test("toggles the article summary with Enter and Space", async ({ page }) => { |
| 11 | + const summary = page.getByRole("button", { name: /^(Summary|文章摘要)$/ }); |
| 12 | + const content = page.getByPlaceholder(/Enter article summary|请输入文章摘要/); |
| 13 | + |
| 14 | + await expect(summary).toHaveAttribute("aria-expanded", "true"); |
| 15 | + await summary.press("Enter"); |
| 16 | + await expect(summary).toHaveAttribute("aria-expanded", "false"); |
| 17 | + await expect(summary).toBeFocused(); |
| 18 | + await expect(content).toBeHidden(); |
| 19 | + |
| 20 | + await summary.press("Space"); |
| 21 | + await expect(summary).toHaveAttribute("aria-expanded", "true"); |
| 22 | + await expect(content).toBeVisible(); |
| 23 | +}); |
| 24 | + |
| 25 | +test("moves between editor toolbar buttons and activates them with the keyboard", async ({ |
| 26 | + page, |
| 27 | +}) => { |
| 28 | + const split = page.getByRole("button", { name: /^(Split|分屏)$/ }); |
| 29 | + const toolbar = page.locator("header").filter({ has: split }); |
| 30 | + const edit = toolbar.getByRole("button", { name: /^(Edit|编辑)$/ }); |
| 31 | + const preview = toolbar.getByRole("button", { name: /^(Preview|预览)$/ }); |
| 32 | + const outline = toolbar.getByRole("button", { name: /^(Outline|大纲)$/ }); |
| 33 | + |
| 34 | + await expect(split).toHaveAttribute("aria-pressed", "true"); |
| 35 | + await edit.press("Enter"); |
| 36 | + await expect(edit).toHaveAttribute("aria-pressed", "true"); |
| 37 | + await page.keyboard.press("Tab"); |
| 38 | + await expect(split).toBeFocused(); |
| 39 | + await page.keyboard.press("Tab"); |
| 40 | + await expect(preview).toBeFocused(); |
| 41 | + await page.keyboard.press("Space"); |
| 42 | + await expect(preview).toHaveAttribute("aria-pressed", "true"); |
| 43 | + |
| 44 | + await outline.press("Enter"); |
| 45 | + await expect(outline).toHaveAttribute("aria-pressed", "false"); |
| 46 | + await outline.press("Space"); |
| 47 | + await expect(outline).toHaveAttribute("aria-pressed", "true"); |
| 48 | + await page.keyboard.press("Tab"); |
| 49 | + await expect(toolbar.getByRole("button", { name: /^(Fullscreen|全屏)$/ })).toBeFocused(); |
| 50 | +}); |
0 commit comments