gradio

Форк
0
/
file_component_events.spec.ts 
73 строки · 2.3 Кб
1
import { test, expect, drag_and_drop_file } from "@gradio/tootils";
2

3
test("File component properly dispatches load event for the single file case.", async ({
4
	page
5
}) => {
6
	await page
7
		.getByRole("button", { name: "Drop File Here - or - Click to Upload" })
8
		.first()
9
		.click();
10
	const uploader = await page.locator("input[type=file]").first();
11
	await uploader.setInputFiles(["./test/files/cheetah1.jpg"]);
12

13
	await expect(page.getByLabel("# Load Upload Single File")).toHaveValue("1");
14

15
	const downloadPromise = page.waitForEvent("download");
16
	await page.getByRole("link").nth(0).click();
17
	const download = await downloadPromise;
18
	await expect(download.suggestedFilename()).toBe("cheetah1.jpg");
19
});
20

21
test("File component drag-and-drop uploads a file to the server correctly.", async ({
22
	page
23
}) => {
24
	const uploader = await page.locator("input[type=file]").nth(1);
25
	await uploader.setInputFiles(["./test/files/alphabet.txt"]);
26

27
	await expect(
28
		page.getByLabel("# Load Upload Multiple Files").first()
29
	).toHaveValue("1");
30
});
31

32
test("File component properly handles drag and drop of image and video files.", async ({
33
	page
34
}) => {
35
	const uploader = await page.locator("input[type=file]").nth(2);
36
	await uploader.setInputFiles(["./test/files/cheetah1.jpg"]);
37

38
	// Check that the image file was uploaded
39
	await expect(
40
		page.getByLabel("# Load Upload Multiple Files Image/Video")
41
	).toHaveValue("1");
42

43
	await page.getByLabel("Clear").click();
44

45
	await uploader.setInputFiles(["./test/files/world.mp4"]);
46

47
	// Check that the video file was uploaded
48
	await expect(
49
		page.getByLabel("# Load Upload Multiple Files Image/Video")
50
	).toHaveValue("2");
51
});
52

53
test("File component properly handles drag and drop of pdf file.", async ({
54
	page
55
}) => {
56
	const uploader = await page.locator("input[type=file]").nth(3);
57
	await uploader.setInputFiles(["./test/files/contract.pdf"]);
58

59
	// Check that the pdf file was uploaded
60
	await expect(page.getByLabel("# Load Upload PDF File")).toHaveValue("1");
61
});
62

63
test("File component properly handles invalid file_types.", async ({
64
	page
65
}) => {
66
	const uploader = await page.locator("input[type=file]").last();
67
	await uploader.setInputFiles(["./test/files/cheetah1.jpg"]);
68

69
	// Check that the pdf file was uploaded
70
	await expect(
71
		page.getByLabel("# Load Upload File with Invalid file_types")
72
	).toHaveValue("1");
73
});
74

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

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

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

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