File size: 4,500 Bytes
a03b3ba |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
import { test, expect } from "@gradio/tootils";
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();
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();
});
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")
.filter({ hasText: "dir4 dir5 dir7 . dir_4_foo.txt" })
.getByRole("checkbox")
.nth(3)
.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();
await page.getByRole("button", { name: "Run" }).click();
const directory_paths_displayed = async () => {
const value = await page.getByLabel("Selected Directory").inputValue();
const files_and_dirs = value.split(",");
expect(files_and_dirs.length).toBe(6);
};
await expect(directory_paths_displayed).toPass();
});
test("File Explorer correctly displays only directories and properly adds it to the value", async ({
page
}) => {
const check = page.getByRole("checkbox", {
name: "Show only directories",
exact: true
});
await check.click();
await page
.locator("span")
.filter({ hasText: "dir4" })
.getByRole("checkbox")
.check();
await page.getByRole("button", { name: "Run" }).click();
const directory_paths_displayed = async () => {
const value = await page.getByLabel("Selected Directory").inputValue();
const dirs = value.split(",");
expect(dirs.some((f) => f.endsWith("dir4"))).toBeTruthy();
expect(dirs.some((f) => f.endsWith("dir5"))).toBeTruthy();
expect(dirs.some((f) => f.endsWith("dir7"))).toBeTruthy();
};
await expect(directory_paths_displayed).toPass();
});
test("File Explorer correctly excludes directories when ignore_glob is '**/'.", async ({
page
}) => {
const check = page.getByRole("checkbox", {
name: "Ignore directories in glob",
exact: true
});
await check.click();
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(",");
expect(files.length).toBe(3);
expect(files.some((f) => f.endsWith("dir_4_foo.txt"))).toBeTruthy();
expect(files.some((f) => f.endsWith("dir5_foo.txt"))).toBeTruthy();
expect(files.some((f) => f.endsWith("dir7_foo.txt"))).toBeTruthy();
};
await expect(only_files_displayed).toPass();
});
|