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(",");
|
2024-02-24 00:29:11 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
files.some((f) => f.endsWith("dir4")) &&
|
|
|
|
files.some((f) => f.endsWith("dir_4_foo.txt")) &&
|
|
|
|
files.some((f) => f.endsWith("dir3_foo.txt"))
|
|
|
|
);
|
2023-12-13 08:39:11 +08:00
|
|
|
};
|
2024-02-24 00:29:11 +08:00
|
|
|
|
|
|
|
await expect.poll(directory_paths_displayed).toBe(true);
|
2023-12-13 08:39:11 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
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-24 00:29:11 +08:00
|
|
|
await Promise.all([page.getByRole("button", { name: "Run" }).click()]);
|
2024-02-17 02:03:10 +08:00
|
|
|
|
2024-02-24 00:29:11 +08:00
|
|
|
async function directory_paths_displayed() {
|
2023-12-13 08:39:11 +08:00
|
|
|
const value = await page.getByLabel("Selected Directory").inputValue();
|
|
|
|
const files_and_dirs = value.split(",");
|
2024-02-24 00:29:11 +08:00
|
|
|
|
|
|
|
return files_and_dirs.length === 7;
|
|
|
|
}
|
|
|
|
await expect.poll(directory_paths_displayed).toBe(true);
|
2023-12-13 08:39:11 +08:00
|
|
|
});
|
|
|
|
|
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-24 00:29:11 +08:00
|
|
|
async function text_files_displayed() {
|
2023-12-13 08:39:11 +08:00
|
|
|
const value = await page.getByLabel("Selected Directory").inputValue();
|
|
|
|
const dirs = value.split(",");
|
2024-02-24 00:29:11 +08:00
|
|
|
return dirs.length === 3 && dirs.every((d) => d.endsWith(".txt"));
|
|
|
|
}
|
|
|
|
|
|
|
|
await expect.poll(text_files_displayed).toBe(true);
|
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-24 00:29:11 +08:00
|
|
|
return (
|
|
|
|
files.length === 4 &&
|
|
|
|
files.some((f) => f.endsWith(".log")) &&
|
|
|
|
!files.some((f) => f.endsWith(".txt"))
|
|
|
|
);
|
2023-12-13 08:39:11 +08:00
|
|
|
};
|
2024-02-24 00:29:11 +08:00
|
|
|
|
|
|
|
await expect.poll(only_files_displayed).toBe(true);
|
2023-12-13 08:39:11 +08:00
|
|
|
});
|