forked from VOICEVOX/voicevox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vuexのコマンドのsnapshotテストを追加 (VOICEVOX#2175)
* stash * stash * Fix: コマンドのunixMillisecをUUID4にする * ミス * 完成 * メモが残っていた * fix * Update src/helpers/random.ts Co-authored-by: Nanashi. <[email protected]> * update --------- Co-authored-by: Nanashi. <[email protected]>
- Loading branch information
1 parent
b8a6b03
commit bb42a89
Showing
13 changed files
with
109 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* 乱数値を生成する。モックに対応している。 | ||
* モックモードでは呼ばれた回数に応じて固定の値を返す。 | ||
*/ | ||
|
||
let mockMode = false; | ||
let mockCount = 0; | ||
|
||
/** | ||
* モックモードにし、呼ばれた回数をリセットする。 | ||
*/ | ||
export function resetMockMode(): void { | ||
mockMode = true; | ||
mockCount = 0; | ||
} | ||
|
||
/** | ||
* v4 UUID を生成する。 | ||
*/ | ||
export function uuid4(): string { | ||
if (!mockMode) { | ||
return crypto.randomUUID(); | ||
} else { | ||
mockCount++; | ||
return `00000000-0000-4000-0000-${mockCount.toString().padStart(12, "0")}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`コマンド実行で履歴が作られる 1`] = ` | ||
{ | ||
"audioKeys": [ | ||
"00000000-0000-4000-0000-000000000001", | ||
], | ||
"redoCommands": { | ||
"song": [], | ||
"talk": [], | ||
}, | ||
"undoCommands": { | ||
"song": [], | ||
"talk": [ | ||
{ | ||
"id": "00000000-0000-4000-0000-000000000002", | ||
"redoPatches": [ | ||
{ | ||
"op": "replace", | ||
"path": [ | ||
"audioKeys", | ||
], | ||
"value": [ | ||
"00000000-0000-4000-0000-000000000001", | ||
], | ||
}, | ||
], | ||
"undoPatches": [ | ||
{ | ||
"op": "replace", | ||
"path": [ | ||
"audioKeys", | ||
], | ||
"value": [], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { toRaw } from "vue"; | ||
import { store } from "@/store"; | ||
import { AudioKey } from "@/type/preload"; | ||
import { resetMockMode, uuid4 } from "@/helpers/random"; | ||
|
||
const initialState = structuredClone(toRaw(store.state)); | ||
beforeEach(() => { | ||
store.replaceState(initialState); | ||
|
||
resetMockMode(); | ||
}); | ||
|
||
test("コマンド実行で履歴が作られる", async () => { | ||
await store.dispatch("COMMAND_SET_AUDIO_KEYS", { | ||
audioKeys: [AudioKey(uuid4())], | ||
}); | ||
const { audioKeys, redoCommands, undoCommands } = store.state; | ||
expect({ audioKeys, redoCommands, undoCommands }).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters