2023-06-29 23:42:26 +08:00
|
|
|
import { test, expect } from "@playwright/experimental-ct-svelte";
|
2023-08-04 06:01:18 +08:00
|
|
|
import Label from "./static";
|
2023-06-29 23:42:26 +08:00
|
|
|
import { spy } from "tinyspy";
|
|
|
|
|
2023-08-16 02:21:41 +08:00
|
|
|
import type { LoadingStatus } from "@gradio/statustracker";
|
2023-06-29 23:42:26 +08:00
|
|
|
|
|
|
|
const loading_status: LoadingStatus = {
|
|
|
|
eta: 0,
|
|
|
|
queue_position: 1,
|
|
|
|
queue_size: 1,
|
|
|
|
status: "complete",
|
|
|
|
scroll_to_output: false,
|
|
|
|
visible: true,
|
|
|
|
fn_index: 0,
|
|
|
|
show_progress: "full"
|
|
|
|
};
|
|
|
|
|
|
|
|
test("gr.Label default value and label rendered with confidences", async ({
|
|
|
|
mount,
|
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
const component = await mount(Label, {
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
label: "Good",
|
|
|
|
confidences: [
|
|
|
|
{ label: "Good", confidence: 0.9 },
|
|
|
|
{ label: "Bad", confidence: 0.1 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
label: "My Label",
|
|
|
|
show_label: true,
|
2023-08-24 04:48:10 +08:00
|
|
|
loading_status: loading_status,
|
|
|
|
gradio: {
|
|
|
|
dispatch() {}
|
|
|
|
}
|
2023-06-29 23:42:26 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
await expect(component).toContainText("My Label");
|
|
|
|
await expect(component.getByTestId("block-label")).toBeVisible();
|
|
|
|
await expect(page.getByTestId("label-output-value")).toContainText("Good");
|
|
|
|
await expect(page.getByTestId("Good-confidence-set")).toContainText("90");
|
|
|
|
await expect(page.getByTestId("Bad-confidence-set")).toContainText("10");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("gr.Label hides label when show_label=false", async ({ mount, page }) => {
|
|
|
|
const component = await mount(Label, {
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
label: "Good",
|
|
|
|
confidences: [
|
|
|
|
{ label: "Good", confidence: 0.9 },
|
|
|
|
{ label: "Bad", confidence: 0.1 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
label: "My Label",
|
|
|
|
show_label: false,
|
2023-08-24 04:48:10 +08:00
|
|
|
loading_status: loading_status,
|
|
|
|
gradio: {
|
|
|
|
dispatch() {}
|
|
|
|
}
|
2023-06-29 23:42:26 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
await expect(component.getByTestId("block-label")).toBeHidden();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("gr.Label confidence bars not rendered without confidences", async ({
|
|
|
|
mount
|
|
|
|
}) => {
|
|
|
|
const component = await mount(Label, {
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
label: "Good"
|
|
|
|
},
|
|
|
|
label: "My Label",
|
|
|
|
show_label: true,
|
2023-08-24 04:48:10 +08:00
|
|
|
loading_status: loading_status,
|
|
|
|
gradio: {
|
|
|
|
dispatch() {}
|
|
|
|
}
|
2023-06-29 23:42:26 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
await expect(component).toContainText("My Label");
|
|
|
|
expect(await component.getByTestId("Good-confidence-set").count()).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("gr.Label confidence bars trigger select event when clicked", async ({
|
|
|
|
mount,
|
|
|
|
page
|
|
|
|
}) => {
|
2023-08-24 04:48:10 +08:00
|
|
|
const events = {
|
|
|
|
select: [0, null]
|
|
|
|
};
|
|
|
|
|
|
|
|
function event(name: "select", value: any) {
|
|
|
|
events[name] = [events[name][0]! + 1, value];
|
|
|
|
}
|
|
|
|
|
2023-06-29 23:42:26 +08:00
|
|
|
const component = await mount(Label, {
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
label: "Good",
|
|
|
|
confidences: [
|
|
|
|
{ label: "Good", confidence: 0.9 },
|
|
|
|
{ label: "Bad", confidence: 0.1 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
label: "My Label",
|
|
|
|
show_label: true,
|
2023-08-24 04:48:10 +08:00
|
|
|
loading_status: loading_status,
|
|
|
|
gradio: {
|
|
|
|
dispatch: event
|
|
|
|
}
|
2023-06-29 23:42:26 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
await expect(component).toContainText("My Label");
|
|
|
|
await component.getByTestId("Bad-confidence-set").click();
|
2023-08-24 04:48:10 +08:00
|
|
|
expect(events.select[0]).toEqual(1);
|
|
|
|
expect(events.select[1]).toEqual({ index: 1, value: "Bad" });
|
2023-06-29 23:42:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("gr.Label triggers change event", async ({ mount, page }) => {
|
2023-08-24 04:48:10 +08:00
|
|
|
const events = {
|
|
|
|
change: 0
|
|
|
|
};
|
|
|
|
|
|
|
|
function event(name: "change") {
|
|
|
|
events[name] += 1;
|
|
|
|
}
|
|
|
|
|
2023-06-29 23:42:26 +08:00
|
|
|
const component = await mount(Label, {
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
label: "Good",
|
|
|
|
confidences: [
|
|
|
|
{ label: "Good", confidence: 0.9 },
|
|
|
|
{ label: "Bad", confidence: 0.1 }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
label: "My Label",
|
|
|
|
show_label: true,
|
2023-08-24 04:48:10 +08:00
|
|
|
loading_status: loading_status,
|
|
|
|
gradio: {
|
|
|
|
dispatch: event
|
|
|
|
}
|
2023-06-29 23:42:26 +08:00
|
|
|
}
|
|
|
|
});
|
2023-08-24 04:48:10 +08:00
|
|
|
|
2023-06-29 23:42:26 +08:00
|
|
|
await component.update({
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
label: "Good",
|
|
|
|
confidences: [
|
|
|
|
{ label: "Good", confidence: 0.1 },
|
|
|
|
{ label: "Bad", confidence: 0.9 }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-08-24 04:48:10 +08:00
|
|
|
expect(events.change).toEqual(2);
|
2023-06-29 23:42:26 +08:00
|
|
|
});
|