2023-10-31 12:46:02 +08:00
|
|
|
import { afterEach, beforeAll, describe, expect, test } from "vitest";
|
2023-07-06 17:55:45 +08:00
|
|
|
import { render, cleanup } from "@gradio/tootils";
|
|
|
|
import { setupi18n } from "../src/i18n";
|
2023-10-31 12:46:02 +08:00
|
|
|
import { Gradio } from "../src/gradio_helper";
|
|
|
|
|
|
|
|
import StaticAnnotatedImage from "@gradio/annotatedimage";
|
|
|
|
import StaticAudio from "@gradio/audio";
|
|
|
|
import StaticChatbot from "@gradio/chatbot";
|
|
|
|
import StaticCheckbox from "@gradio/checkbox";
|
|
|
|
import StaticCheckboxGroup from "@gradio/checkboxgroup";
|
|
|
|
import StaticColorPicker from "@gradio/colorpicker";
|
|
|
|
import StaticDataframe from "@gradio/dataframe";
|
|
|
|
import StaticDropdown from "@gradio/dropdown";
|
|
|
|
import StaticFile from "@gradio/file";
|
|
|
|
import StaticGallery from "@gradio/gallery";
|
|
|
|
import StaticHTML from "@gradio/html";
|
|
|
|
import StaticHighlightedText from "@gradio/highlightedtext";
|
|
|
|
import StaticJson from "@gradio/json";
|
|
|
|
import StaticLabel from "@gradio/label";
|
|
|
|
import StaticMarkdown from "@gradio/markdown";
|
|
|
|
import StaticModel3D from "@gradio/model3d";
|
|
|
|
import StaticNumber from "@gradio/number";
|
|
|
|
import StaticRadio from "@gradio/radio";
|
|
|
|
import StaticSlider from "@gradio/slider";
|
|
|
|
import StaticTextbox from "@gradio/textbox";
|
|
|
|
import StaticUploadButton from "@gradio/uploadbutton";
|
|
|
|
import StaticVideo from "@gradio/video";
|
|
|
|
|
|
|
|
import InteractiveAudio from "@gradio/audio";
|
|
|
|
import InteractiveCheckbox from "@gradio/checkbox";
|
|
|
|
import InteractiveCheckboxGroup from "@gradio/checkboxgroup";
|
|
|
|
import InteractiveColorPicker from "@gradio/colorpicker";
|
|
|
|
import InteractiveDataframe from "@gradio/dataframe";
|
|
|
|
import InteractiveDropdown from "@gradio/dropdown";
|
|
|
|
import InteractiveFile from "@gradio/file";
|
|
|
|
import InteractiveModel3D from "@gradio/model3d";
|
|
|
|
import InteractiveNumber from "@gradio/number";
|
|
|
|
import InteractiveRadio from "@gradio/radio";
|
|
|
|
import InteractiveSlider from "@gradio/slider";
|
|
|
|
import InteractiveTextbox from "@gradio/textbox";
|
|
|
|
import InteractiveUploadButton from "@gradio/uploadbutton";
|
|
|
|
import InteractiveVideo from "@gradio/video";
|
2023-08-16 02:21:41 +08:00
|
|
|
import { LoadingStatus } from "@gradio/statustracker";
|
2023-07-06 17:55:45 +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"
|
|
|
|
};
|
|
|
|
|
|
|
|
const components = [
|
|
|
|
[
|
2023-08-18 23:33:07 +08:00
|
|
|
"StaticAnnotatedImage",
|
|
|
|
StaticAnnotatedImage,
|
2023-10-31 12:46:02 +08:00
|
|
|
{ height: 100, width: 100, value: null, interactive: false }
|
2023-08-18 23:33:07 +08:00
|
|
|
],
|
2023-10-31 12:46:02 +08:00
|
|
|
["InteractiveAudio", InteractiveAudio, { interactive: true }],
|
|
|
|
["StaticAudio", StaticAudio, { interactive: false }],
|
2023-08-18 23:33:07 +08:00
|
|
|
|
2023-10-31 12:46:02 +08:00
|
|
|
["StaticChatbot", StaticChatbot, { interactive: false }],
|
|
|
|
["InteractiveCheckbox", InteractiveCheckbox, { interactive: true }],
|
|
|
|
["StaticCheckbox", StaticCheckbox, { interactive: false }],
|
2023-08-18 23:33:07 +08:00
|
|
|
[
|
|
|
|
"InteractiveCheckboxGroup",
|
|
|
|
InteractiveCheckboxGroup,
|
2023-10-31 12:46:02 +08:00
|
|
|
{ choices: ["a", "b", "c"], interactive: true }
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"StaticCheckboxGroup",
|
|
|
|
StaticCheckboxGroup,
|
|
|
|
{ choices: ["a", "b", "c"], interactive: false }
|
2023-08-18 23:33:07 +08:00
|
|
|
],
|
2023-10-31 12:46:02 +08:00
|
|
|
["InteractiveColorPicker", InteractiveColorPicker, { interactive: true }],
|
|
|
|
["StaticColorPicker", StaticColorPicker, { interactive: false }],
|
2023-08-18 23:33:07 +08:00
|
|
|
[
|
|
|
|
"InteractiveDataFrame",
|
|
|
|
InteractiveDataframe,
|
2023-10-31 12:46:02 +08:00
|
|
|
{
|
|
|
|
value: [[1, 2, 3]],
|
|
|
|
col_count: [3, "fixed"],
|
|
|
|
row_count: [3, "fixed"],
|
|
|
|
interactive: true
|
|
|
|
}
|
2023-08-18 23:33:07 +08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
"StaticDataFrame",
|
|
|
|
StaticDataframe,
|
2023-10-31 12:46:02 +08:00
|
|
|
{
|
|
|
|
value: [[1, 2, 3]],
|
|
|
|
col_count: [3, "fixed"],
|
|
|
|
row_count: [3, "fixed"],
|
|
|
|
interactive: false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"InteractiveDropdown",
|
|
|
|
InteractiveDropdown,
|
|
|
|
{ choices: ["a", "b", "c"], interactive: true }
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"StaticDropdown",
|
|
|
|
StaticDropdown,
|
|
|
|
{ choices: ["a", "b", "c"], interactive: false }
|
|
|
|
],
|
|
|
|
["InteractiveFile", InteractiveFile, { interactive: true }],
|
|
|
|
["StaticFile", StaticFile, { interactive: false }],
|
|
|
|
|
|
|
|
["StaticGallery", StaticGallery, { interactive: false }],
|
|
|
|
|
|
|
|
["StaticHTML", StaticHTML, { interactive: false }],
|
|
|
|
|
|
|
|
["StaticHighlightedText", StaticHighlightedText, { interactive: false }],
|
|
|
|
|
|
|
|
["StaticJson", StaticJson, { interactive: false }],
|
|
|
|
|
|
|
|
["StaticLabel", StaticLabel, { interactive: false }],
|
|
|
|
|
|
|
|
["StaticMarkdown", StaticMarkdown, { interactive: false }],
|
|
|
|
["InteractiveModel3D", InteractiveModel3D, { interactive: true }],
|
|
|
|
["StaticModel3D", StaticModel3D, { interactive: false }],
|
|
|
|
["InteractiveNumber", InteractiveNumber, { interactive: true }],
|
|
|
|
["StaticNumber", StaticNumber, { interactive: false }],
|
|
|
|
["InteractiveRadio", InteractiveRadio, { interactive: true }],
|
|
|
|
["StaticRadio", StaticRadio, { interactive: false }],
|
|
|
|
["InteractiveSlider", InteractiveSlider, { interactive: true }],
|
|
|
|
["StaticSlider", StaticSlider, { interactive: false }],
|
|
|
|
[
|
|
|
|
"InteractiveTextbox",
|
|
|
|
InteractiveTextbox,
|
|
|
|
{ container: false, interactive: true }
|
2023-07-06 17:55:45 +08:00
|
|
|
],
|
2023-10-31 12:46:02 +08:00
|
|
|
["StaticTextbox", StaticTextbox, { container: false, interactive: false }],
|
|
|
|
// ["InteractiveTimeSeries", InteractiveTimeSeries, {}],
|
|
|
|
// ["StaticTimeSeries", StaticTimeSeries, {}],
|
|
|
|
["InteractiveUploadButton", InteractiveUploadButton, { interactive: true }],
|
|
|
|
["StaticUploadButton", StaticUploadButton, { interactive: false }],
|
|
|
|
["InteractiveVideo", InteractiveVideo, { interactive: true }],
|
|
|
|
["StaticVideo", StaticVideo, { interactive: false }]
|
2023-07-06 17:55:45 +08:00
|
|
|
] as const;
|
|
|
|
|
|
|
|
describe("all components should apply provided class names", () => {
|
2023-10-31 12:46:02 +08:00
|
|
|
beforeAll(async () => {
|
|
|
|
await setupi18n();
|
2023-07-06 17:55:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
components.forEach(([name, component, props]) => {
|
|
|
|
test(name, async () => {
|
|
|
|
const { container } = await render(component, {
|
|
|
|
...props,
|
|
|
|
loading_status,
|
2023-10-31 12:46:02 +08:00
|
|
|
elem_classes: ["test-class"],
|
|
|
|
gradio: new Gradio(
|
|
|
|
0,
|
|
|
|
document.createElement("div"),
|
|
|
|
"light",
|
|
|
|
"3.1.1",
|
|
|
|
"",
|
|
|
|
false
|
|
|
|
)
|
2023-07-06 17:55:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const elem = container.querySelector(`.test-class`);
|
|
|
|
expect(elem).not.toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
["Button", "Code", "Image", "Plot"].forEach((name) => {
|
|
|
|
test.todo(name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("all components should apply provided id", () => {
|
2023-10-31 12:46:02 +08:00
|
|
|
beforeAll(async () => {
|
|
|
|
await setupi18n();
|
2023-07-06 17:55:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
components.forEach(([name, component, props]) => {
|
|
|
|
test(name, async () => {
|
|
|
|
const { container } = await render(component, {
|
|
|
|
...props,
|
|
|
|
loading_status,
|
|
|
|
elem_id: "test-id"
|
|
|
|
});
|
|
|
|
|
|
|
|
const elem = container.querySelector(`#test-id`);
|
|
|
|
expect(elem).not.toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
["Button", "Code", "Image", "Plot"].forEach((name) => {
|
|
|
|
test.todo(name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("all components should be invisible when visible=false", () => {
|
2023-10-31 12:46:02 +08:00
|
|
|
beforeAll(async () => {
|
|
|
|
await setupi18n();
|
2023-07-06 17:55:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
components.forEach(([name, component, props]) => {
|
|
|
|
test(name, async () => {
|
|
|
|
const { container } = await render(component, {
|
|
|
|
...props,
|
|
|
|
loading_status,
|
|
|
|
elem_id: "test-id",
|
|
|
|
visible: false
|
|
|
|
});
|
|
|
|
|
|
|
|
const elem = container.querySelector(`#test-id`);
|
|
|
|
|
2023-07-18 01:05:46 +08:00
|
|
|
expect(elem).toHaveClass("hidden");
|
2023-07-06 17:55:45 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
["Button", "Code", "Image", "Plot"].forEach((name) => {
|
|
|
|
test.todo(name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("all components should have the appropriate label when set via the `label` prop", () => {
|
2023-10-31 12:46:02 +08:00
|
|
|
beforeAll(async () => {
|
|
|
|
await setupi18n();
|
2023-07-06 17:55:45 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
components
|
2023-08-18 23:33:07 +08:00
|
|
|
.filter(([name]) => name !== "StaticMarkdown" && name !== "StaticHTML")
|
2023-07-06 17:55:45 +08:00
|
|
|
.forEach(([name, component, props]) => {
|
|
|
|
test(name, async () => {
|
|
|
|
const { getAllByText } = await render(component, {
|
|
|
|
...props,
|
|
|
|
loading_status,
|
|
|
|
label: name + "LABEL_TEST"
|
|
|
|
});
|
|
|
|
|
|
|
|
const elems = getAllByText(name + "LABEL_TEST");
|
|
|
|
|
|
|
|
expect(elems.length).toBeGreaterThan(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
["Button", "Code", "Image", "Plot"].forEach((name) => {
|
|
|
|
test.todo(name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("all components should hide their label when `show_label=false`", () => {
|
2023-08-24 04:48:10 +08:00
|
|
|
components.forEach(([name, component, props]) => {
|
|
|
|
test.todo(name);
|
|
|
|
});
|
2023-07-06 17:55:45 +08:00
|
|
|
|
|
|
|
["Button", "Code", "Image", "Plot"].forEach((name) => {
|
|
|
|
test.todo(name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("all components should show their label when `show_label=true`", () => {
|
2023-08-24 04:48:10 +08:00
|
|
|
components.forEach(([name, component, props]) => {
|
|
|
|
test.todo(name);
|
|
|
|
});
|
2023-07-06 17:55:45 +08:00
|
|
|
|
|
|
|
["Button", "Code", "Image", "Plot"].forEach((name) => {
|
|
|
|
test.todo(name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("all components should hide their container when `container=false`", () => {
|
2023-08-24 04:48:10 +08:00
|
|
|
components.forEach(([name, component, props]) => {
|
|
|
|
test.todo(name);
|
|
|
|
});
|
2023-07-06 17:55:45 +08:00
|
|
|
|
|
|
|
["Button", "Code", "Image", "Plot"].forEach((name) => {
|
|
|
|
test.todo(name);
|
|
|
|
});
|
|
|
|
});
|