gradio

Форк
0
/
chatbot_multimodal.spec.ts 
191 строка · 5.9 Кб
1
import { test, expect } from "@gradio/tootils";
2

3
test("text input by a user should be shown in the chatbot as a paragraph", async ({
4
	page
5
}) => {
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
10
		.getByTestId("user")
11
		.first()
12
		.getByRole("paragraph")
13
		.textContent();
14
	const bot_message = await page
15
		.getByTestId("bot")
16
		.first()
17
		.getByRole("paragraph")
18
		.textContent();
19
	await expect(user_message).toEqual("Lorem ipsum");
20
	await expect(bot_message).toBeTruthy();
21
});
22

23
test("images uploaded by a user should be shown in the chat", async ({
24
	page
25
}) => {
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");
31

32
	const user_message = await page.getByTestId("user").first().getByRole("img");
33
	const bot_message = await page
34
		.getByTestId("bot")
35
		.first()
36
		.getByRole("paragraph")
37
		.textContent();
38
	const image_src = await user_message.getAttribute("src");
39
	expect(image_src).toBeTruthy();
40

41
	expect(bot_message).toBeTruthy();
42
});
43

44
test("audio uploaded by a user should be shown in the chatbot", async ({
45
	page
46
}) => {
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");
52

53
	const user_message = await page.getByTestId("user").first().locator("audio");
54
	const bot_message = await page
55
		.getByTestId("bot")
56
		.first()
57
		.getByRole("paragraph")
58
		.textContent();
59
	const audio_data = await user_message.getAttribute("src");
60
	await expect(audio_data).toBeTruthy();
61
	await expect(bot_message).toBeTruthy();
62
});
63

64
test("videos uploaded by a user should be shown in the chatbot", async ({
65
	page
66
}) => {
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");
72

73
	const user_message = await page.getByTestId("user").first().locator("video");
74
	const bot_message = await page
75
		.getByTestId("bot")
76
		.first()
77
		.getByRole("paragraph")
78
		.textContent();
79
	const video_data = await user_message.getAttribute("src");
80
	await expect(video_data).toBeTruthy();
81
	await expect(bot_message).toBeTruthy();
82
});
83

84
test("markdown input by a user should be correctly formatted: bold, italics, links", async ({
85
	page
86
}) => {
87
	const textbox = await page.getByTestId("textbox");
88
	await textbox.fill(
89
		"This is **bold text**. This is *italic text*. This is a [link](https://gradio.app)."
90
	);
91
	await page.keyboard.press("Enter");
92
	const user_message = await page
93
		.getByTestId("user")
94
		.first()
95
		.getByRole("paragraph")
96
		.innerHTML();
97
	const bot_message = await page
98
		.getByTestId("bot")
99
		.first()
100
		.getByRole("paragraph")
101
		.textContent();
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>.'
104
	);
105
	await expect(bot_message).toBeTruthy();
106
});
107

108
test("inline code markdown input by the user should be correctly formatted", async ({
109
	page
110
}) => {
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
115
		.getByTestId("user")
116
		.first()
117
		.getByRole("paragraph")
118
		.innerHTML();
119
	const bot_message = await page
120
		.getByTestId("bot")
121
		.first()
122
		.getByRole("paragraph")
123
		.textContent();
124
	await expect(user_message).toEqual("This is <code>code</code>.");
125
	await expect(bot_message).toBeTruthy();
126
});
127

128
test("markdown code blocks input by a user should be rendered correctly with the correct language tag", async ({
129
	page
130
}) => {
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
135
		.getByTestId("user")
136
		.first()
137
		.locator("pre")
138
		.innerHTML();
139
	const bot_message = await page
140
		.getByTestId("bot")
141
		.first()
142
		.getByRole("paragraph")
143
		.textContent();
144
	await expect(user_message).toContain("language-python");
145
	await expect(bot_message).toBeTruthy();
146
});
147

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
153
		.getByTestId("user")
154
		.first()
155
		.getByRole("paragraph")
156
		.innerHTML();
157
	const bot_message = await page
158
		.getByTestId("bot")
159
		.first()
160
		.getByRole("paragraph")
161
		.textContent();
162
	await expect(user_message).toContain("katex-display");
163
	await expect(bot_message).toBeTruthy();
164
});
165

166
test("when a new message is sent the chatbot should scroll to the latest message", async ({
167
	page
168
}) => {
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
174
		.getByTestId("bot")
175
		.first()
176
		.getByRole("paragraph");
177
	await expect(bot_message).toBeVisible();
178
	const bot_message_text = bot_message.textContent();
179
	await expect(bot_message_text).toBeTruthy();
180
});
181

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();
188

189
	expect(await page.getByLabel("clicked dislike").count()).toEqual(1);
190
	expect(await page.getByLabel("clicked like").count()).toEqual(0);
191
});
192

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.