-
Notifications
You must be signed in to change notification settings - Fork 313
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
test: 音声書き出しe2eテスト #2473
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "wip-\u97F3\u58F0\u66F8\u304D\u51FA\u3057e2e\u30C6\u30B9\u30C8"
test: 音声書き出しe2eテスト #2473
Changes from 33 commits
529c58e
6c559a6
c16383f
39f682f
67411ce
c660368
53600c9
fa8f624
b4d35a6
1a89577
8cbebf8
6ce4a26
0d53426
d0631c2
727ce50
03be644
84295c5
19e05a6
9ab5b02
a78b3f6
c48533f
3e0ef71
97f2d44
5587acb
664516c
f0809d7
b4e016a
afc51d0
c97e3e5
80b6d54
6d2d43c
007f179
e48405b
ba6f855
370e2e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,7 +178,7 @@ export async function textToActtentPhrasesMock(text: string, styleId: number) { | |
const pauseMora = { | ||
text: "、", | ||
vowel: "pau", | ||
vowelLength: 1 - 1 / (accentPhrases.length + 1), | ||
vowelLength: 1 - 1 / (accentPhrases.length + 2), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 今の |
||
pitch: 0, | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Page } from "@playwright/test"; | ||
import { Brand } from "@/type/utility"; | ||
import { success } from "@/type/result"; | ||
|
||
type TestFileId = Brand<string, "TestFileId">; | ||
|
||
/** ファイル書き出し選択ダイアログをモックにする */ | ||
// TODO: モックを戻せるようにする | ||
export async function mockShowSaveFileDialog(page: Page): Promise<{ | ||
getFileIds: () => Promise<TestFileId[]>; | ||
}> { | ||
type _Window = Window & { | ||
_mockShowSaveFileDialog: { | ||
returnValues: TestFileId[]; | ||
}; | ||
}; | ||
|
||
// モックを差し込む | ||
await page.evaluate(() => { | ||
const _window = window as unknown as _Window; | ||
_window._mockShowSaveFileDialog = { | ||
returnValues: [], | ||
}; | ||
|
||
_window.backend.showSaveFileDialog = async () => { | ||
const id = `${Date.now()}` as TestFileId; | ||
_window._mockShowSaveFileDialog.returnValues.push(id); | ||
return id; | ||
}; | ||
}); | ||
|
||
return { | ||
getFileIds: async () => { | ||
return page.evaluate(() => { | ||
const _window = window as unknown as _Window; | ||
return _window._mockShowSaveFileDialog.returnValues; | ||
}); | ||
}, | ||
}; | ||
} | ||
|
||
/** ファイル書き出しをモックにする */ | ||
// TODO: モックを戻せるようにする | ||
export async function mockWriteFile(page: Page): Promise<{ | ||
getWrittenFileBuffers: () => Promise<Record<string | TestFileId, Buffer>>; | ||
}> { | ||
type _Window = Window & { | ||
_mockWriteFile: Record<string | TestFileId, Uint8Array>; | ||
}; | ||
|
||
// モックを差し込む | ||
await page.evaluate( | ||
({ sucecssResult }) => { | ||
const _window = window as unknown as _Window; | ||
_window._mockWriteFile = {}; | ||
|
||
_window.backend.writeFile = async ({ filePath, buffer }) => { | ||
_window._mockWriteFile[filePath] = new Uint8Array(buffer); | ||
return sucecssResult; | ||
}; | ||
}, | ||
{ sucecssResult: success(undefined) }, | ||
); | ||
|
||
return { | ||
getWrittenFileBuffers: async () => { | ||
const arrays = await page.evaluate(() => { | ||
const _window = window as unknown as _Window; | ||
return Object.fromEntries( | ||
Object.entries(_window._mockWriteFile).map(([key, value]) => [ | ||
key, | ||
Array.from(value), | ||
]), | ||
); | ||
}); | ||
return Object.fromEntries( | ||
Object.entries(arrays).map(([key, value]) => [key, Buffer.from(value)]), | ||
); | ||
}, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { test, expect, Page } from "@playwright/test"; | ||
import { gotoHome, navigateToMain } from "../navigators"; | ||
import { getQuasarMenu } from "../locators"; | ||
import { mockShowSaveFileDialog, mockWriteFile } from "./utility"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. window.backends関数のモックを作るにあたっていくつか妥協したポイントもあったのでコメント。
|
||
|
||
test.beforeEach(gotoHome); | ||
|
||
/** 選択音声を書き出し、その音声ファイルのバイナリをスナップショットテストする */ | ||
async function exportSelectedAudioAndSnapshot(page: Page, name: string) { | ||
const { getFileIds } = await mockShowSaveFileDialog(page); | ||
const { getWrittenFileBuffers } = await mockWriteFile(page); | ||
|
||
await page.getByRole("button", { name: "ファイル" }).click(); | ||
await getQuasarMenu(page, "選択音声を書き出し").click(); | ||
await expect(page.getByText("音声を書き出しました")).toBeVisible(); | ||
|
||
const fileId = (await getFileIds())[0]; | ||
const buffer = (await getWrittenFileBuffers())[fileId]; | ||
expect(buffer).toMatchSnapshot(`${name}.wav`); | ||
} | ||
|
||
test.describe("音声書き出し", () => { | ||
test.skip(process.platform !== "win32", "Windows以外のためスキップします"); | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await navigateToMain(page); | ||
|
||
const audioCell = page.getByRole("textbox", { name: "1行目" }); | ||
const accentPhrase = page.locator(".accent-phrase"); | ||
|
||
await audioCell.click(); | ||
await audioCell.fill("こんにちは、テストです"); | ||
await audioCell.press("Enter"); | ||
await expect(accentPhrase).not.toHaveCount(0); | ||
}); | ||
|
||
test("各パラメータを変更して音声書き出し", async ({ page }) => { | ||
await exportSelectedAudioAndSnapshot(page, "デフォルト"); | ||
|
||
const parameters = [ | ||
["話速", "1.5"], | ||
["音高", "0.5"], | ||
["抑揚", "1.5"], | ||
["音量", "1.5"], | ||
["間の長さ", "1.5"], | ||
["開始無音", "0.3"], | ||
["終了無音", "0.3"], | ||
] as const; | ||
|
||
for (const [name, newValue] of parameters) { | ||
await test.step(`${name}変更`, async () => { | ||
const input = page.getByLabel(name); | ||
const originalValue = await input.inputValue(); | ||
|
||
await input.fill(newValue); | ||
await input.press("Enter"); | ||
|
||
await exportSelectedAudioAndSnapshot(page, `${name}変更`); | ||
|
||
await input.fill(originalValue); | ||
await input.press("Enter"); | ||
}); | ||
} | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ポーズの長さを変えるのもテストしたかったのでモックを修正しました。