From 13293fe0d4f1acb12e0413f968549eb25af2913e Mon Sep 17 00:00:00 2001 From: Segun Adebayo Date: Mon, 16 Oct 2023 16:16:18 +0100 Subject: [PATCH] revert: slider e2e --- e2e/slider.e2e.ts | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 e2e/slider.e2e.ts diff --git a/e2e/slider.e2e.ts b/e2e/slider.e2e.ts new file mode 100644 index 0000000000..fd5ec06a79 --- /dev/null +++ b/e2e/slider.e2e.ts @@ -0,0 +1,84 @@ +import { expect, test } from "@playwright/test" +import { testid, a11y, rect } from "./__utils" + +const output = testid("output") +const thumb = testid("thumb") +const track = testid("track") + +test.describe("slider", () => { + test.beforeEach(async ({ page }) => { + await page.goto("/slider") + }) + + test("should have no accessibility violation", async ({ page }) => { + await a11y(page) + }) + + test("[keyboard] should work with arrow left/right keys", async ({ page }) => { + await page.focus(thumb) + + await page.keyboard.press("ArrowRight") + await expect(page.locator(output)).toHaveText("1") + + await page.keyboard.press("ArrowRight") + await expect(page.locator(output)).toHaveText("2") + }) + + test("[keyboard] should work with home/end keys", async ({ page }) => { + await page.focus(thumb) + + await page.keyboard.press("ArrowRight") + await page.keyboard.press("ArrowRight") + + await page.keyboard.press("Home") + await expect(page.locator(output)).toHaveText("0") + + await page.keyboard.press("End") + await expect(page.locator(output)).toHaveText("100") + }) + + test("[keyboard] should work with shift key", async ({ page }) => { + await page.focus(thumb) + + await page.keyboard.press("Shift+ArrowRight") + await expect(page.locator(output)).toHaveText("10") + + await page.keyboard.press("Shift+ArrowLeft") + await expect(page.locator(output)).toHaveText("0") + }) + + test("[keyboard] should work with page up/down keys", async ({ page }) => { + await page.focus(thumb) + + await page.keyboard.press("PageUp") + await expect(page.locator(output)).toHaveText("10") + + await page.keyboard.press("PageDown") + await expect(page.locator(output)).toHaveText("0") + }) + + test("[pointer] should set value on click track", async ({ page }) => { + const el = page.locator(track) + const bbox = await rect(el) + await el.dispatchEvent("pointerdown", { + button: 0, + clientY: bbox.y + bbox.height / 2, + clientX: bbox.x + bbox.width * 0.8, + }) + await expect(page.locator(output)).toHaveText("80") + }) + + test("[pointer] should set the value on drag", async ({ page }) => { + const el = page.locator(track) + const bbox = await rect(el) + await el.dispatchEvent("pointerdown", { + button: 0, + clientY: bbox.y + bbox.height / 2, + clientX: bbox.x + bbox.width * 0.8, + }) + await expect(page.locator(output)).toHaveText("80") + await page.mouse.move(bbox.x + bbox.width * 0.9, bbox.y + bbox.height / 2) + await page.mouse.up() + await expect(page.locator(output)).toHaveText("90") + }) +})