File size: 6,138 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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
import { test, expect } from "@gradio/tootils";
test("text input by a user should be shown in the chatbot as a paragraph", async ({
page
}) => {
const textbox = await page.getByTestId("textbox");
await textbox.fill("Lorem ipsum");
await page.keyboard.press("Enter");
const user_message = await page
.getByTestId("user")
.first()
.getByRole("paragraph")
.textContent();
const bot_message = await page
.getByTestId("bot")
.first()
.getByRole("paragraph")
.textContent();
await expect(user_message).toEqual("Lorem ipsum");
await expect(bot_message).toBeTruthy();
});
test("images uploaded by a user should be shown in the chat", async ({
page
}) => {
const fileChooserPromise = page.waitForEvent("filechooser");
await page.getByRole("button", { name: "π" }).click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles("./test/files/cheetah1.jpg");
await page.keyboard.press("Enter");
const user_message = await page.getByTestId("user").first().getByRole("img");
const bot_message = await page
.getByTestId("bot")
.first()
.getByRole("paragraph")
.textContent();
const image_data = await user_message.getAttribute("src");
await expect(image_data).toContain("cheetah1.jpg");
await expect(bot_message).toBeTruthy();
});
test("audio uploaded by a user should be shown in the chatbot", async ({
page
}) => {
const fileChooserPromise = page.waitForEvent("filechooser");
await page.getByRole("button", { name: "π" }).click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles("../../test/test_files/audio_sample.wav");
await page.keyboard.press("Enter");
const user_message = await page.getByTestId("user").first().locator("audio");
const bot_message = await page
.getByTestId("bot")
.first()
.getByRole("paragraph")
.textContent();
const audio_data = await user_message.getAttribute("src");
await expect(audio_data).toContain("audio_sample.wav");
await expect(bot_message).toBeTruthy();
});
test("videos uploaded by a user should be shown in the chatbot", async ({
page
}) => {
const fileChooserPromise = page.waitForEvent("filechooser");
await page.getByRole("button", { name: "π" }).click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles("../../test/test_files/video_sample.mp4");
await page.keyboard.press("Enter");
const user_message = await page.getByTestId("user").first().locator("video");
const bot_message = await page
.getByTestId("bot")
.first()
.getByRole("paragraph")
.textContent();
const video_data = await user_message.getAttribute("src");
await expect(video_data).toContain("video_sample.mp4");
await expect(bot_message).toBeTruthy();
});
test("markdown input by a user should be correctly formatted: bold, italics, links", async ({
page
}) => {
const textbox = await page.getByTestId("textbox");
await textbox.fill(
"This is **bold text**. This is *italic text*. This is a [link](https://gradio.app)."
);
await page.keyboard.press("Enter");
const user_message = await page
.getByTestId("user")
.first()
.getByRole("paragraph")
.innerHTML();
const bot_message = await page
.getByTestId("bot")
.first()
.getByRole("paragraph")
.textContent();
await expect(user_message).toEqual(
'This is <strong>bold text</strong>. This is <em>italic text</em>. This is a <a href="https://gradio.app" target="_blank" rel="noopener noreferrer">link</a>.'
);
await expect(bot_message).toBeTruthy();
});
test("inline code markdown input by the user should be correctly formatted", async ({
page
}) => {
const textbox = await page.getByTestId("textbox");
await textbox.fill("This is `code`.");
await page.keyboard.press("Enter");
const user_message = await page
.getByTestId("user")
.first()
.getByRole("paragraph")
.innerHTML();
const bot_message = await page
.getByTestId("bot")
.first()
.getByRole("paragraph")
.textContent();
await expect(user_message).toEqual("This is <code>code</code>.");
await expect(bot_message).toBeTruthy();
});
test("markdown code blocks input by a user should be rendered correctly with the correct language tag", async ({
page
}) => {
const textbox = await page.getByTestId("textbox");
await textbox.fill("```python\nprint('Hello')\nprint('World!')\n```");
await page.keyboard.press("Enter");
const user_message = await page
.getByTestId("user")
.first()
.locator("pre")
.innerHTML();
const bot_message = await page
.getByTestId("bot")
.first()
.getByRole("paragraph")
.textContent();
await expect(user_message).toContain("language-python");
await expect(bot_message).toBeTruthy();
});
test("LaTeX input by a user should be rendered correctly", async ({ page }) => {
const textbox = await page.getByTestId("textbox");
await textbox.fill("This is LaTeX $$x^2$$");
await page.keyboard.press("Enter");
const user_message = await page
.getByTestId("user")
.first()
.getByRole("paragraph")
.innerHTML();
const bot_message = await page
.getByTestId("bot")
.first()
.getByRole("paragraph")
.textContent();
await expect(user_message).toContain("katex-display");
await expect(bot_message).toBeTruthy();
});
test("when a new message is sent the chatbot should scroll to the latest message", async ({
page
}) => {
const textbox = await page.getByTestId("textbox");
const line_break = "<br>";
await textbox.fill(line_break.repeat(30));
await page.keyboard.press("Enter");
const bot_message = await page
.getByTestId("bot")
.first()
.getByRole("paragraph");
await expect(bot_message).toBeVisible();
const bot_message_text = bot_message.textContent();
await expect(bot_message_text).toBeTruthy();
});
test("chatbot like and dislike functionality", async ({ page }) => {
await page.getByTestId("textbox").click();
await page.getByTestId("textbox").fill("hello");
await page.keyboard.press("Enter");
await page.getByLabel("like", { exact: true }).click();
await page.getByLabel("dislike").click();
expect(await page.getByLabel("clicked dislike").count()).toEqual(1);
expect(await page.getByLabel("clicked like").count()).toEqual(0);
});
|