gradio/js/image/Image.test.ts
pngwn 1419538ea7
Refactor component directories (#5074)
* asd

* changes

* fix everything

* cleanup

* add changeset

* fix casing

* lockfile

* fix casing

* fix ci, enable linting

* fix test

* add changeset

* add changeset

* delete changeset

* fix dirs

* fix casing

* fix notebooks

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

* fix casing

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
2023-08-03 23:01:18 +01:00

58 lines
1.3 KiB
TypeScript

import {
test,
describe,
assert,
afterEach,
vi,
beforeAll,
beforeEach
} from "vitest";
import { spy } from "tinyspy";
import { cleanup, render } from "@gradio/tootils";
import { setupi18n } from "../app/src/i18n";
import Image from "./index.svelte";
import type { LoadingStatus } from "@gradio/statustracker/types";
const loading_status = {
eta: 0,
queue_position: 1,
queue_size: 1,
status: "complete" as LoadingStatus["status"],
scroll_to_output: false,
visible: true,
fn_index: 0,
show_progress: "full" as LoadingStatus["show_progress"]
};
describe("Image", () => {
beforeAll(() => {
window.HTMLMediaElement.prototype.play = vi.fn();
window.HTMLMediaElement.prototype.pause = vi.fn();
});
beforeEach(setupi18n);
afterEach(() => cleanup());
test("image change event trigger fires when value is changed and only fires once", async () => {
const { component } = await render(Image, {
show_label: true,
loading_status,
mode: "dynamic",
value:
"https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png",
root: "foo",
root_url: null,
streaming: false,
pending: false,
source: "upload"
});
const mock = spy();
component.$on("change", mock);
component.value =
"https://github.com/gradio-app/gradio/blob/main/test/test_files/cheetah1.jpg";
assert.equal(mock.callCount, 1);
});
});