2023-11-03 04:25:09 +08:00
|
|
|
import { test, expect, drag_and_drop_file } from "@gradio/tootils";
|
|
|
|
|
2023-11-15 02:55:28 +08:00
|
|
|
test("Audio click-to-upload uploads audio successfuly. File downloading works and file has correct name.", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
2023-11-03 04:25:09 +08:00
|
|
|
await page
|
|
|
|
.getByRole("button", { name: "Drop Audio Here - or - Click to Upload" })
|
|
|
|
.click();
|
|
|
|
const uploader = await page.locator("input[type=file]");
|
|
|
|
await Promise.all([
|
|
|
|
uploader.setInputFiles(["../../test/test_files/audio_sample.wav"]),
|
2023-11-08 08:02:31 +08:00
|
|
|
page.waitForResponse("**/upload?*")
|
2023-11-03 04:25:09 +08:00
|
|
|
]);
|
|
|
|
|
2023-11-17 04:55:25 +08:00
|
|
|
await expect(page.getByLabel("# Input Change Events")).toHaveValue("1");
|
|
|
|
await expect(page.getByLabel("# Input Upload Events")).toHaveValue("1");
|
2023-11-03 04:25:09 +08:00
|
|
|
|
|
|
|
await page.getByLabel("Clear").click();
|
2023-11-17 04:55:25 +08:00
|
|
|
await expect(page.getByLabel("# Input Change Events")).toHaveValue("2");
|
2023-11-03 04:25:09 +08:00
|
|
|
await page
|
|
|
|
.getByRole("button", { name: "Drop Audio Here - or - Click to Upload" })
|
|
|
|
.click();
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
uploader.setInputFiles(["../../test/test_files/audio_sample.wav"]),
|
2023-11-08 08:02:31 +08:00
|
|
|
page.waitForResponse("**/upload?*")
|
2023-11-03 04:25:09 +08:00
|
|
|
]);
|
|
|
|
|
2023-11-17 04:55:25 +08:00
|
|
|
await expect(page.getByLabel("# Input Change Events")).toHaveValue("3");
|
|
|
|
await expect(page.getByLabel("# Input Upload Events")).toHaveValue("2");
|
2023-11-15 02:55:28 +08:00
|
|
|
|
|
|
|
const downloadPromise = page.waitForEvent("download");
|
|
|
|
await page.getByLabel("Download").click();
|
|
|
|
const download = await downloadPromise;
|
|
|
|
await expect(download.suggestedFilename()).toBe("audio_sample.wav");
|
2023-11-03 04:25:09 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("Audio drag-and-drop uploads a file to the server correctly.", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
await Promise.all([
|
|
|
|
drag_and_drop_file(
|
|
|
|
page,
|
|
|
|
"input[type=file]",
|
|
|
|
"../../test/test_files/audio_sample.wav",
|
|
|
|
"audio_sample.wav",
|
|
|
|
"audio/wav"
|
|
|
|
),
|
2023-11-08 08:02:31 +08:00
|
|
|
page.waitForResponse("**/upload?*")
|
2023-11-03 04:25:09 +08:00
|
|
|
]);
|
2023-11-17 04:55:25 +08:00
|
|
|
await expect(page.getByLabel("# Input Change Events")).toHaveValue("1");
|
|
|
|
await expect(page.getByLabel("# Input Upload Events")).toHaveValue("1");
|
2023-11-03 04:25:09 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("Audio drag-and-drop displays a warning when the file is of the wrong mime type.", async ({
|
|
|
|
page
|
|
|
|
}) => {
|
|
|
|
await drag_and_drop_file(
|
|
|
|
page,
|
|
|
|
"input[type=file]",
|
|
|
|
"../../test/test_files/audio_sample.wav",
|
|
|
|
"audio_sample.wav"
|
|
|
|
);
|
|
|
|
const toast = page.getByTestId("toast-body");
|
|
|
|
expect(toast).toContainText("warning");
|
|
|
|
});
|
2023-11-17 04:55:25 +08:00
|
|
|
|
|
|
|
test("Play, Pause, and stop events work correctly.", async ({ page }) => {
|
|
|
|
const uploader = await page.locator("input[type=file]");
|
|
|
|
await Promise.all([
|
2023-12-08 03:22:16 +08:00
|
|
|
uploader.setInputFiles(["../../demo/audio_debugger/cantina.wav"]),
|
2023-11-17 04:55:25 +08:00
|
|
|
page.waitForResponse("**/upload?*")
|
|
|
|
]);
|
|
|
|
|
|
|
|
await page
|
|
|
|
.getByTestId("waveform-Output Audio")
|
|
|
|
.getByLabel("Play", { exact: true })
|
|
|
|
.click();
|
|
|
|
await page.getByTestId("waveform-Output Audio").getByLabel("Pause").click();
|
|
|
|
await page
|
|
|
|
.getByTestId("waveform-Output Audio")
|
|
|
|
.getByLabel("Play", { exact: true })
|
|
|
|
.click();
|
|
|
|
|
2023-12-08 03:22:16 +08:00
|
|
|
const event_triggered = async (label: string) => {
|
|
|
|
const value = await page.getByLabel(label).inputValue();
|
|
|
|
expect(Number(value)).toBeGreaterThan(0);
|
|
|
|
};
|
|
|
|
|
|
|
|
// toPass will retry the function until it passes or times out
|
|
|
|
// need this because the stop event is only triggered when the video is done playing
|
|
|
|
// hard to time otherwise
|
|
|
|
await expect(async () => event_triggered("# Output Play Events")).toPass();
|
|
|
|
await expect(async () => event_triggered("# Output Pause Events")).toPass();
|
|
|
|
await expect(async () => event_triggered("# Output Stop Events")).toPass();
|
2023-11-17 04:55:25 +08:00
|
|
|
});
|