2023-12-09 02:27:25 +08:00
|
|
|
import { test, expect } from "@gradio/tootils";
|
2023-11-28 18:27:45 +08:00
|
|
|
|
|
|
|
test("File Explorer is interactive and re-runs the server_fn when root is updated", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
await page
|
|
|
|
.locator("span")
|
|
|
|
.filter({ hasText: "bar.txt" })
|
|
|
|
.getByRole("checkbox")
|
|
|
|
.check();
|
|
|
|
await page
|
|
|
|
.locator("span")
|
|
|
|
.filter({ hasText: "foo.txt" })
|
|
|
|
.getByRole("checkbox")
|
|
|
|
.check();
|
|
|
|
|
|
|
|
await page.getByLabel("Select File Explorer Root").click();
|
|
|
|
await page.getByLabel(new RegExp("/dir2$"), { exact: true }).first().click();
|
|
|
|
await page
|
|
|
|
.locator("span")
|
|
|
|
.filter({ hasText: "baz.png" })
|
|
|
|
.getByRole("checkbox")
|
|
|
|
.check();
|
|
|
|
await page
|
|
|
|
.locator("span")
|
|
|
|
.filter({ hasText: "foo.png" })
|
|
|
|
.getByRole("checkbox")
|
|
|
|
.check();
|
2023-12-09 02:27:25 +08:00
|
|
|
|
|
|
|
await page.locator("#input-box").getByTestId("textbox").fill("test");
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
page.locator("span").filter({ hasText: "baz.png" }).getByRole("checkbox")
|
|
|
|
).toBeChecked();
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
page.locator("span").filter({ hasText: "foo.png" }).getByRole("checkbox")
|
|
|
|
).toBeChecked();
|
2024-02-17 02:03:10 +08:00
|
|
|
|
|
|
|
await page
|
|
|
|
.locator("span")
|
|
|
|
.filter({ hasText: "foo.png" })
|
|
|
|
.getByRole("checkbox")
|
|
|
|
.uncheck();
|
|
|
|
|
|
|
|
await expect(page.locator("#total-changes input")).toHaveValue("3");
|
2023-11-28 18:27:45 +08:00
|
|
|
});
|
2023-12-13 08:39:11 +08:00
|
|
|
|
|
|
|
test("File Explorer correctly displays both directories and files. Directories included in value.", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
await page.getByLabel("Select File Explorer Root").click();
|
|
|
|
await page.getByLabel(new RegExp("/dir3$"), { exact: true }).first().click();
|
|
|
|
|
|
|
|
await page
|
|
|
|
.locator("span")
|
|
|
|
.filter({ hasText: "dir4" })
|
|
|
|
.getByLabel("expand directory")
|
|
|
|
.click();
|
|
|
|
|
|
|
|
await page
|
|
|
|
.locator("li")
|
2024-02-14 06:51:47 +08:00
|
|
|
.filter({ hasText: "dir4 . dir5 dir7 dir_4_bar.log dir_4_foo.txt" })
|
2023-12-13 08:39:11 +08:00
|
|
|
.getByRole("checkbox")
|
2024-02-14 06:51:47 +08:00
|
|
|
.first()
|
2023-12-13 08:39:11 +08:00
|
|
|
.check();
|
|
|
|
|
|
|
|
await page
|
|
|
|
.locator("span")
|
|
|
|
.filter({ hasText: "dir_4_foo.txt" })
|
|
|
|
.getByRole("checkbox")
|
|
|
|
.check();
|
|
|
|
|
|
|
|
await page
|
|
|
|
.locator("span")
|
|
|
|
.filter({ hasText: "dir3_foo.txt" })
|
|
|
|
.getByRole("checkbox")
|
|
|
|
.check();
|
|
|
|
|
|
|
|
await page.getByRole("button", { name: "Run" }).click();
|
|
|
|
const directory_paths_displayed = async () => {
|
|
|
|
const value = await page.getByLabel("Selected Directory").inputValue();
|
|
|
|
const files = value.split(",");
|
|
|
|
expect(files.some((f) => f.endsWith("dir4"))).toBeTruthy();
|
|
|
|
expect(files.some((f) => f.endsWith("dir_4_foo.txt"))).toBeTruthy();
|
|
|
|
expect(files.some((f) => f.endsWith("dir3_foo.txt"))).toBeTruthy();
|
|
|
|
};
|
|
|
|
await expect(directory_paths_displayed).toPass();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("File Explorer selects all children when top level directory is selected.", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
await page.getByLabel("Select File Explorer Root").click();
|
|
|
|
await page.getByLabel(new RegExp("/dir3$"), { exact: true }).first().click();
|
|
|
|
|
|
|
|
await page
|
|
|
|
.locator("span")
|
|
|
|
.filter({ hasText: "dir4" })
|
|
|
|
.getByRole("checkbox")
|
|
|
|
.check();
|
|
|
|
|
2024-02-17 02:03:10 +08:00
|
|
|
const res = page.waitForEvent("response", {
|
|
|
|
predicate: async (response) => {
|
|
|
|
return (await response.text()).indexOf("process_completed") !== -1;
|
|
|
|
}
|
|
|
|
});
|
2023-12-13 08:39:11 +08:00
|
|
|
await page.getByRole("button", { name: "Run" }).click();
|
|
|
|
|
2024-02-17 02:03:10 +08:00
|
|
|
await res;
|
|
|
|
|
2023-12-13 08:39:11 +08:00
|
|
|
const directory_paths_displayed = async () => {
|
|
|
|
const value = await page.getByLabel("Selected Directory").inputValue();
|
|
|
|
const files_and_dirs = value.split(",");
|
2024-02-14 06:51:47 +08:00
|
|
|
expect(files_and_dirs.length).toBe(7);
|
2023-12-13 08:39:11 +08:00
|
|
|
};
|
|
|
|
await expect(directory_paths_displayed).toPass();
|
|
|
|
});
|
|
|
|
|
2024-02-14 06:51:47 +08:00
|
|
|
test("File Explorer correctly displays only text files", async ({ page }) => {
|
2023-12-13 08:39:11 +08:00
|
|
|
const check = page.getByRole("checkbox", {
|
2024-02-14 06:51:47 +08:00
|
|
|
name: "Show only text files",
|
2023-12-13 08:39:11 +08:00
|
|
|
exact: true
|
|
|
|
});
|
|
|
|
await check.click();
|
|
|
|
|
2024-02-14 06:51:47 +08:00
|
|
|
await page.getByLabel("Select File Explorer Root").click();
|
|
|
|
await page.getByLabel(new RegExp("/dir3$"), { exact: true }).first().click();
|
|
|
|
|
2023-12-13 08:39:11 +08:00
|
|
|
await page
|
|
|
|
.locator("span")
|
|
|
|
.filter({ hasText: "dir4" })
|
|
|
|
.getByRole("checkbox")
|
|
|
|
.check();
|
|
|
|
await page.getByRole("button", { name: "Run" }).click();
|
|
|
|
|
2024-02-14 06:51:47 +08:00
|
|
|
const text_files_displayed = async () => {
|
2023-12-13 08:39:11 +08:00
|
|
|
const value = await page.getByLabel("Selected Directory").inputValue();
|
|
|
|
const dirs = value.split(",");
|
2024-02-14 06:51:47 +08:00
|
|
|
expect(dirs.length).toBe(3);
|
|
|
|
expect(dirs.every((d) => d.endsWith(".txt"))).toBeTruthy();
|
2023-12-13 08:39:11 +08:00
|
|
|
};
|
2024-02-14 06:51:47 +08:00
|
|
|
await expect(text_files_displayed).toPass();
|
2023-12-13 08:39:11 +08:00
|
|
|
});
|
|
|
|
|
2024-02-14 06:51:47 +08:00
|
|
|
test("File Explorer correctly excludes text files when ignore_glob is '*.txt'.", async ({
|
2023-12-13 08:39:11 +08:00
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
const check = page.getByRole("checkbox", {
|
2024-02-14 06:51:47 +08:00
|
|
|
name: "Ignore text files in glob",
|
2023-12-13 08:39:11 +08:00
|
|
|
exact: true
|
|
|
|
});
|
|
|
|
await check.click();
|
|
|
|
|
2024-02-14 06:51:47 +08:00
|
|
|
await page.getByLabel("Select File Explorer Root").click();
|
|
|
|
await page.getByLabel(new RegExp("/dir3$"), { exact: true }).first().click();
|
|
|
|
|
2023-12-13 08:39:11 +08:00
|
|
|
await page
|
|
|
|
.locator("span")
|
|
|
|
.filter({ hasText: "dir4" })
|
|
|
|
.getByRole("checkbox")
|
|
|
|
.check();
|
|
|
|
await page.getByRole("button", { name: "Run" }).click();
|
|
|
|
|
|
|
|
const only_files_displayed = async () => {
|
|
|
|
const value = await page.getByLabel("Selected Directory").inputValue();
|
|
|
|
const files = value.split(",");
|
2024-02-14 06:51:47 +08:00
|
|
|
expect(files.length).toBe(4);
|
|
|
|
expect(files.some((f) => f.endsWith(".log"))).toBeTruthy();
|
|
|
|
expect(files.some((f) => f.endsWith(".txt"))).toBeFalsy();
|
2023-12-13 08:39:11 +08:00
|
|
|
};
|
|
|
|
await expect(only_files_displayed).toPass();
|
|
|
|
});
|