1
import { test, expect } from "@gradio/tootils";
3
test("text input by a user should be shown in the chatbot as a paragraph", async ({
6
const textbox = await page.getByTestId("textbox");
7
await textbox.fill("Lorem ipsum");
8
await page.keyboard.press("Enter");
9
const user_message = await page
12
.getByRole("paragraph")
14
const bot_message = await page
17
.getByRole("paragraph")
19
await expect(user_message).toEqual("Lorem ipsum");
20
await expect(bot_message).toBeTruthy();
23
test("images uploaded by a user should be shown in the chat", async ({
26
const fileChooserPromise = page.waitForEvent("filechooser");
27
await page.getByRole("button", { name: "📁" }).click();
28
const fileChooser = await fileChooserPromise;
29
await fileChooser.setFiles("./test/files/cheetah1.jpg");
30
await page.keyboard.press("Enter");
32
const user_message = await page.getByTestId("user").first().getByRole("img");
33
const bot_message = await page
36
.getByRole("paragraph")
38
const image_src = await user_message.getAttribute("src");
39
expect(image_src).toBeTruthy();
41
expect(bot_message).toBeTruthy();
44
test("audio uploaded by a user should be shown in the chatbot", async ({
47
const fileChooserPromise = page.waitForEvent("filechooser");
48
await page.getByRole("button", { name: "📁" }).click();
49
const fileChooser = await fileChooserPromise;
50
await fileChooser.setFiles("../../test/test_files/audio_sample.wav");
51
await page.keyboard.press("Enter");
53
const user_message = await page.getByTestId("user").first().locator("audio");
54
const bot_message = await page
57
.getByRole("paragraph")
59
const audio_data = await user_message.getAttribute("src");
60
await expect(audio_data).toBeTruthy();
61
await expect(bot_message).toBeTruthy();
64
test("videos uploaded by a user should be shown in the chatbot", async ({
67
const fileChooserPromise = page.waitForEvent("filechooser");
68
await page.getByRole("button", { name: "📁" }).click();
69
const fileChooser = await fileChooserPromise;
70
await fileChooser.setFiles("../../test/test_files/video_sample.mp4");
71
await page.keyboard.press("Enter");
73
const user_message = await page.getByTestId("user").first().locator("video");
74
const bot_message = await page
77
.getByRole("paragraph")
79
const video_data = await user_message.getAttribute("src");
80
await expect(video_data).toBeTruthy();
81
await expect(bot_message).toBeTruthy();
84
test("markdown input by a user should be correctly formatted: bold, italics, links", async ({
87
const textbox = await page.getByTestId("textbox");
89
"This is **bold text**. This is *italic text*. This is a [link](https://gradio.app)."
91
await page.keyboard.press("Enter");
92
const user_message = await page
95
.getByRole("paragraph")
97
const bot_message = await page
100
.getByRole("paragraph")
102
await expect(user_message).toEqual(
103
'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>.'
105
await expect(bot_message).toBeTruthy();
108
test("inline code markdown input by the user should be correctly formatted", async ({
111
const textbox = await page.getByTestId("textbox");
112
await textbox.fill("This is `code`.");
113
await page.keyboard.press("Enter");
114
const user_message = await page
117
.getByRole("paragraph")
119
const bot_message = await page
122
.getByRole("paragraph")
124
await expect(user_message).toEqual("This is <code>code</code>.");
125
await expect(bot_message).toBeTruthy();
128
test("markdown code blocks input by a user should be rendered correctly with the correct language tag", async ({
131
const textbox = await page.getByTestId("textbox");
132
await textbox.fill("```python\nprint('Hello')\nprint('World!')\n```");
133
await page.keyboard.press("Enter");
134
const user_message = await page
139
const bot_message = await page
142
.getByRole("paragraph")
144
await expect(user_message).toContain("language-python");
145
await expect(bot_message).toBeTruthy();
148
test("LaTeX input by a user should be rendered correctly", async ({ page }) => {
149
const textbox = await page.getByTestId("textbox");
150
await textbox.fill("This is LaTeX $$x^2$$");
151
await page.keyboard.press("Enter");
152
const user_message = await page
155
.getByRole("paragraph")
157
const bot_message = await page
160
.getByRole("paragraph")
162
await expect(user_message).toContain("katex-display");
163
await expect(bot_message).toBeTruthy();
166
test("when a new message is sent the chatbot should scroll to the latest message", async ({
169
const textbox = await page.getByTestId("textbox");
170
const line_break = "<br>";
171
await textbox.fill(line_break.repeat(30));
172
await page.keyboard.press("Enter");
173
const bot_message = await page
176
.getByRole("paragraph");
177
await expect(bot_message).toBeVisible();
178
const bot_message_text = bot_message.textContent();
179
await expect(bot_message_text).toBeTruthy();
182
test("chatbot like and dislike functionality", async ({ page }) => {
183
await page.getByTestId("textbox").click();
184
await page.getByTestId("textbox").fill("hello");
185
await page.keyboard.press("Enter");
186
await page.getByLabel("like", { exact: true }).click();
187
await page.getByLabel("dislike").click();
189
expect(await page.getByLabel("clicked dislike").count()).toEqual(1);
190
expect(await page.getByLabel("clicked like").count()).toEqual(0);