Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

labファイルの書き出しに関するe2eテストを追加 #1768

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions tests/e2e/browser/labファイル書き出し.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { test, expect, Download, Page } from "@playwright/test";

import { gotoHome, navigateToMain, toggleSetting } from "../navigators";

test.beforeEach(gotoHome);

async function commonAction(
page: Page,
toggleCheck: boolean,
testText: string
) {
if (toggleCheck) {
await toggleSetting(page, "labファイルを書き出し");
}
await page.locator(".audio-cell input").first().fill(testText);
await page.getByRole("button", { name: "ファイル" }).click();
await page.getByText("音声を繋げて書き出し").click();
}

/**
* 一定時間の間でダウンロードを行う。
* 一定時間を超えた場合は、ダウンロードを終了
*/
async function downloadAction(page: Page, timeout: number) {
const downloads: string[] = [];
for (let _ = 0; _ < 2; _++) {
const downloadPromise = page.waitForEvent("download");
const timeoutPromise = new Promise((resolve, reject) =>
setTimeout(() => {
try {
resolve(null);
} catch (error) {
reject(error);
}
}, timeout)
);

const result = await Promise.race([downloadPromise, timeoutPromise]);
if (result instanceof Error) {
throw result;
} else {
if (result == null) {
continue;
}
const File: string = ((await result) as Download).suggestedFilename();
downloads.push(File);
}
}
return downloads;
}

test("「labファイルを書き出し」のトグルがオンの場合のみ、labファイルが書き出される", async ({
page,
}) => {
// labファイルを生成しない
await navigateToMain(page);
await commonAction(page, false, "おはようございます");
const downloadWav = await downloadAction(page, 5100); // labファイル生成時より長く待つ(ダウンロード漏れがないことを保証したい)
await expect(downloadWav.length).toBe(1);
await expect(downloadWav[0]).toBe("おはようございます.wav");

// labファイルを生成する
await commonAction(page, true, ""); // おはようございます」がすでに入力されているためから文字列にする
weweweok marked this conversation as resolved.
Show resolved Hide resolved
const downloads = await downloadAction(page, 5000);
await expect(downloads.length).toBe(2);
await expect(downloads[0]).toBe("おはようございます.wav");
await expect(downloads[1]).toBe("おはようございます.lab");
});
Loading