gradio/js/app/test/image_editor_events.spec.ts
pngwn dbb7373dde
ensure ImageEditor events work as expected (#7845)
* changes

* changes

* more fix

* more fix

* add changeset

* fix initial crop

* fix format

* fix format

* fix formats

* faster?

* race condition

* fixes + test

* fix type?

* notebooks

* fix type

* change demo

* add changeset

* fix type

* fix type

* fix type again

* fix type again again

* lint

* lint again

* fix test

* tests

* fix

* tests

* address comments

* fix notebooks

* fix tests

* fix stories

* fix webcam ui

* cleanup

* add changeset

* fix input event

* add format param + fix input event

* fix test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2024-04-15 20:16:07 +00:00

70 lines
2.6 KiB
TypeScript

import { test, expect, drag_and_drop_file } from "@gradio/tootils";
test("upload events work as expected", async ({ page }) => {
await page.getByLabel("Upload button").first().click();
const uploader = page.locator("input[type=file]").first();
await uploader.setInputFiles(["./test/files/cheetah1.jpg"]);
await expect(page.locator("#upload h2")).toContainText("1");
});
test("change events work as expected", async ({ page }) => {
await page.getByLabel("Upload button").first().click();
const uploader = page.locator("input[type=file]").first();
await uploader.setInputFiles(["./test/files/cheetah1.jpg"]);
const change_text = page.locator("#change h2");
await expect(change_text).toContainText("1");
await page.getByLabel("Draw button").first().click();
const canvas = page.locator("#image_editor canvas").first();
await canvas.click({ position: { x: 100, y: 100 } });
await expect(change_text).toContainText("2");
await page.getByLabel("Erase button").first().click();
await canvas.click({ position: { x: 100, y: 100 } });
await expect(change_text).toContainText("3");
await page.getByLabel("Clear canvas").first().click();
await expect(change_text).toContainText("4");
});
test("input events work as expected", async ({ page }) => {
await page.getByLabel("Upload button").first().click();
const uploader = page.locator("input[type=file]").first();
await uploader.setInputFiles(["./test/files/cheetah1.jpg"]);
const input_text = page.locator("#input h2");
await expect(input_text).toContainText("1");
await page.getByLabel("Draw button").first().click();
const canvas = page.locator("#image_editor canvas").first();
await canvas.click({ position: { x: 100, y: 100 } });
await expect(input_text).toContainText("2");
await page.getByLabel("Erase button").first().click();
await canvas.click({ position: { x: 100, y: 100 } });
await expect(input_text).toContainText("3");
await page.getByLabel("Clear canvas").first().click();
await expect(input_text).toContainText("4");
});
test("apply events work as expected", async ({ page }) => {
const apply_text = page.locator("#apply h2");
const apply_button = page.getByLabel("Save changes").first();
await page.getByLabel("Draw button").first().click();
const canvas = page.locator("#image_editor canvas").first();
await canvas.click({ position: { x: 100, y: 100 } });
await apply_button.click();
await expect(apply_text).toContainText("1");
await page.getByLabel("Erase button").first().click();
await canvas.click({ position: { x: 100, y: 100 } });
await page.getByLabel("Clear canvas").first().click();
await apply_button.click();
await expect(apply_text).toContainText("2");
});