|
| 1 | +import { test, expect } from "@playwright/test" |
| 2 | +import { a11y, part, controls, testid } from "./_utils" |
| 3 | +import path from "node:path" |
| 4 | + |
| 5 | +const root = part("root") |
| 6 | +const trigger = part("trigger") |
| 7 | +const dropzone = part("dropzone") |
| 8 | + |
| 9 | +test.describe("file-upload", () => { |
| 10 | + test.beforeEach(async ({ page }) => { |
| 11 | + await page.goto("/file-upload") |
| 12 | + }) |
| 13 | + |
| 14 | + // TBD: fix a11y complaints |
| 15 | + test.skip("should have no accessibility violations", async ({ page }) => { |
| 16 | + await a11y(page) |
| 17 | + }) |
| 18 | + |
| 19 | + test("should be focused when page is tabbed", async ({ page }) => { |
| 20 | + const dropzone = part("dropzone") |
| 21 | + |
| 22 | + await page.click("main") |
| 23 | + await page.keyboard.press("Tab") |
| 24 | + |
| 25 | + await expect(page.locator(dropzone)).toBeFocused() |
| 26 | + }) |
| 27 | + |
| 28 | + test("should open file picker on trigger click", async ({ page }) => { |
| 29 | + const fileChooserPromise = page.waitForEvent("filechooser") |
| 30 | + |
| 31 | + await page.locator(trigger).click() |
| 32 | + |
| 33 | + const prom = await fileChooserPromise |
| 34 | + |
| 35 | + expect(prom).toBeDefined() |
| 36 | + }) |
| 37 | + |
| 38 | + test("should display chosen file", async ({ page }) => { |
| 39 | + const fileChooserPromise = page.waitForEvent("filechooser") |
| 40 | + await page.locator(trigger).click() |
| 41 | + const fileChooser = await fileChooserPromise |
| 42 | + await fileChooser.setFiles(path.join(__dirname, "fixtures/text.txt")) |
| 43 | + |
| 44 | + const item = page.locator(part("item")) |
| 45 | + const deleteTrigger = page.locator(part("item-delete-trigger")) |
| 46 | + |
| 47 | + expect(item).toBeVisible() |
| 48 | + expect(await item.innerText()).toContain("text.txt") |
| 49 | + expect(deleteTrigger).toBeVisible() |
| 50 | + }) |
| 51 | + |
| 52 | + test("should have disabled attributes when disabled", async ({ page }) => { |
| 53 | + await controls(page).bool("disabled") |
| 54 | + await expect(page.locator(root)).toHaveAttribute("data-disabled", "") |
| 55 | + await expect(page.locator(dropzone)).toHaveAttribute("data-disabled", "") |
| 56 | + await expect(page.locator(trigger)).toHaveAttribute("data-disabled", "") |
| 57 | + await expect(page.locator(trigger)).toBeDisabled() |
| 58 | + await expect(page.locator(testid("input"))).toBeDisabled() |
| 59 | + }) |
| 60 | +}) |
0 commit comments