From b4af371f740414ca8c7a9d4a9c6bd88c44f5803a Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Sat, 13 Jul 2024 22:14:23 +0900 Subject: [PATCH 1/9] stash --- .../store/__snapshots__/command.spec.ts.snap | 41 +++++++++++++++++++ tests/unit/store/command.spec.ts | 20 +++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/unit/store/__snapshots__/command.spec.ts.snap create mode 100644 tests/unit/store/command.spec.ts diff --git a/tests/unit/store/__snapshots__/command.spec.ts.snap b/tests/unit/store/__snapshots__/command.spec.ts.snap new file mode 100644 index 0000000000..612a4d0f5a --- /dev/null +++ b/tests/unit/store/__snapshots__/command.spec.ts.snap @@ -0,0 +1,41 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`コマンド実行で履歴が作られる 1`] = ` +{ + "audioKeys": [ + "00000000-0000-0000-0000-000000000000", + ], + "redoCommands": { + "song": [], + "talk": [], + }, + "undoCommands": { + "song": [], + "talk": [ + { + "redoPatches": [ + { + "op": "replace", + "path": [ + "audioKeys", + ], + "value": [ + "00000000-0000-0000-0000-000000000000", + ], + }, + ], + "undoPatches": [ + { + "op": "replace", + "path": [ + "audioKeys", + ], + "value": [], + }, + ], + "unixMillisec": 1720797286952, + }, + ], + }, +} +`; diff --git a/tests/unit/store/command.spec.ts b/tests/unit/store/command.spec.ts new file mode 100644 index 0000000000..0b69b81eae --- /dev/null +++ b/tests/unit/store/command.spec.ts @@ -0,0 +1,20 @@ +import { toRaw } from "vue"; +import { store } from "@/store"; +import { AudioKey } from "@/type/preload"; + +const initialState = structuredClone(toRaw(store.state)); +beforeEach(() => { + store.replaceState(initialState); +}); + +test("コマンド実行で履歴が作られる", async () => { + await store.dispatch("COMMAND_SET_AUDIO_KEYS", { + audioKeys: [AudioKey("00000000-0000-0000-0000-000000000000")], + }); + + // npm run test-watch:unit -- "tests\unit\store\command.spec.ts" + // millisecをrandomUuidにし、かつrandomUuidをmockにする + + const { audioKeys, redoCommands, undoCommands } = store.state; + expect({ audioKeys, redoCommands, undoCommands }).toMatchSnapshot(); +}); From 34f0ac7d995b64195a3ce2cc5ae945f38795753a Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Sat, 20 Jul 2024 23:15:12 +0900 Subject: [PATCH 2/9] stash --- src/store/command.ts | 33 ++++++++++----------------------- src/store/project.ts | 40 ++++++++++++++++++++++++++++------------ src/store/singing.ts | 4 ++-- src/store/type.ts | 17 +++++++++++------ src/type/preload.ts | 4 ++++ 5 files changed, 55 insertions(+), 43 deletions(-) diff --git a/src/store/command.ts b/src/store/command.ts index 83de848ed3..2d8e062f38 100644 --- a/src/store/command.ts +++ b/src/store/command.ts @@ -9,7 +9,7 @@ import { MutationsBase, MutationTree, } from "@/store/vuex"; -import { EditorType } from "@/type/preload"; +import { CommandId, EditorType } from "@/type/preload"; enablePatches(); enableMapSet(); @@ -67,7 +67,7 @@ const recordPatches = (draft: S) => recipe(draft, payload), ); return { - unixMillisec: new Date().getTime(), + id: CommandId(crypto.randomUUID()), redoPatches: doPatches, undoPatches: undoPatches, }; @@ -133,30 +133,17 @@ export const commandStore = createPartialStore({ }, }, - LAST_COMMAND_UNIX_MILLISEC: { + LAST_COMMAND_IDS: { getter(state) { - const getLastCommandUnixMillisec = ( - commands: Command[], - ): number | null => { - const lastCommand = commands[commands.length - 1]; - // 型的にはundefinedにはならないが、lengthが0の場合はundefinedになる - return lastCommand ? lastCommand.unixMillisec : null; + const getLastCommandId = (commands: Command[]): CommandId | null => { + if (commands.length > 0) return null; + else return commands[commands.length - 1].id; }; - const lastTalkCommandTime = getLastCommandUnixMillisec( - state.undoCommands["talk"], - ); - const lastSongCommandTime = getLastCommandUnixMillisec( - state.undoCommands["song"], - ); - - if (lastTalkCommandTime != null && lastSongCommandTime != null) { - return Math.max(lastTalkCommandTime, lastSongCommandTime); - } else if (lastTalkCommandTime != null) { - return lastTalkCommandTime; - } else { - return lastSongCommandTime; - } + return { + talk: getLastCommandId(state.undoCommands["talk"]), + song: getLastCommandId(state.undoCommands["song"]), + }; }, }, diff --git a/src/store/project.ts b/src/store/project.ts index 951b69dbd8..4adf90b4ff 100755 --- a/src/store/project.ts +++ b/src/store/project.ts @@ -19,9 +19,10 @@ import { createDefaultTimeSignature, DEFAULT_TPQN, } from "@/sing/domain"; +import { EditorType } from "@/type/preload"; export const projectStoreState: ProjectStoreState = { - savedLastCommandUnixMillisec: null, + savedLastCommandIds: { talk: null, song: null }, }; const applyTalkProjectToStore = async ( @@ -132,7 +133,7 @@ export const projectStore = createPartialStore({ await context.dispatch("CLEAR_PITCH_EDIT_DATA"); context.commit("SET_PROJECT_FILEPATH", { filePath: undefined }); - context.commit("SET_SAVED_LAST_COMMAND_UNIX_MILLISEC", null); + context.commit("RESET_SAVED_LAST_COMMAND_IDS"); context.commit("CLEAR_COMMANDS"); }, ), @@ -211,7 +212,7 @@ export const projectStore = createPartialStore({ await applySongProjectToStore(dispatch, parsedProjectData.song); commit("SET_PROJECT_FILEPATH", { filePath }); - commit("SET_SAVED_LAST_COMMAND_UNIX_MILLISEC", null); + context.commit("RESET_SAVED_LAST_COMMAND_IDS"); commit("CLEAR_COMMANDS"); return true; } catch (err) { @@ -314,8 +315,8 @@ export const projectStore = createPartialStore({ .then(getValueOrThrow); context.commit("SET_PROJECT_FILEPATH", { filePath }); context.commit( - "SET_SAVED_LAST_COMMAND_UNIX_MILLISEC", - context.getters.LAST_COMMAND_UNIX_MILLISEC, + "SET_SAVED_LAST_COMMAND_IDS", + context.getters.LAST_COMMAND_IDS, ); return true; } catch (err) { @@ -372,16 +373,31 @@ export const projectStore = createPartialStore({ IS_EDITED: { getter(state, getters) { - return ( - getters.LAST_COMMAND_UNIX_MILLISEC !== - state.savedLastCommandUnixMillisec - ); + if ( + Object.keys(state.savedLastCommandIds) != + Object.keys(getters.LAST_COMMAND_IDS) + ) + throw new Error( + "Object.keys(state.savedLastCommandIds) != Object.keys(getters.LAST_COMMAND_IDS)", + ); + return Object.keys(state.savedLastCommandIds).some((_editor) => { + const editor = _editor as EditorType; + return ( + state.savedLastCommandIds[editor] !== getters.LAST_COMMAND_IDS[editor] + ); + }); + }, + }, + + SET_SAVED_LAST_COMMAND_IDS: { + mutation(state, commandIds) { + state.savedLastCommandIds = commandIds; }, }, - SET_SAVED_LAST_COMMAND_UNIX_MILLISEC: { - mutation(state, unixMillisec) { - state.savedLastCommandUnixMillisec = unixMillisec; + RESET_SAVED_LAST_COMMAND_IDS: { + mutation(state) { + state.savedLastCommandIds = { talk: null, song: null }; }, }, }); diff --git a/src/store/singing.ts b/src/store/singing.ts index d08ae47906..90255efe9b 100644 --- a/src/store/singing.ts +++ b/src/store/singing.ts @@ -1708,7 +1708,7 @@ export const singingStore = createPartialStore({ await dispatch("SET_TIME_SIGNATURES", { timeSignatures }); await dispatch("SET_NOTES", { notes }); - commit("SET_SAVED_LAST_COMMAND_UNIX_MILLISEC", null); + context.commit("RESET_SAVED_LAST_COMMAND_IDS"); commit("CLEAR_COMMANDS"); dispatch("RENDER"); }, @@ -1751,7 +1751,7 @@ export const singingStore = createPartialStore({ startFrame: 0, }); - commit("SET_SAVED_LAST_COMMAND_UNIX_MILLISEC", null); + context.commit("RESET_SAVED_LAST_COMMAND_IDS"); commit("CLEAR_COMMANDS"); dispatch("RENDER"); }, diff --git a/src/store/type.ts b/src/store/type.ts index b94864d7aa..3f1516897d 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -52,6 +52,7 @@ import { RootMiscSettingType, EditorType, NoteId, + CommandId, } from "@/type/preload"; import { IEngineConnectorFactory } from "@/infrastructures/EngineConnector"; import { @@ -94,7 +95,7 @@ export type FetchAudioResult = { }; export type Command = { - unixMillisec: number; + id: CommandId; undoPatches: Patch[]; redoPatches: Patch[]; }; @@ -1233,8 +1234,8 @@ export type CommandStoreTypes = { action(payload: { editor: EditorType }): void; }; - LAST_COMMAND_UNIX_MILLISEC: { - getter: number | null; + LAST_COMMAND_IDS: { + getter: Record; }; CLEAR_COMMANDS: { @@ -1469,7 +1470,7 @@ export type IndexStoreTypes = { export type ProjectStoreState = { projectFilePath?: string; - savedLastCommandUnixMillisec: number | null; + savedLastCommandIds: Record; }; export type ProjectStoreTypes = { @@ -1511,8 +1512,12 @@ export type ProjectStoreTypes = { getter: boolean; }; - SET_SAVED_LAST_COMMAND_UNIX_MILLISEC: { - mutation: number | null; + SET_SAVED_LAST_COMMAND_IDS: { + mutation: Record; + }; + + RESET_SAVED_LAST_COMMAND_IDS: { + mutation: void; }; }; diff --git a/src/type/preload.ts b/src/type/preload.ts index 01a3bdecb7..7272f90943 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -69,6 +69,10 @@ export const noteIdSchema = z.string().brand<"NoteId">(); export type NoteId = z.infer; export const NoteId = (id: string): NoteId => noteIdSchema.parse(id); +export const commandIdSchema = z.string().brand<"CommandId">(); +export type CommandId = z.infer; +export const CommandId = (id: string): CommandId => commandIdSchema.parse(id); + // 共通のアクション名 export const actionPostfixSelectNthCharacter = "番目のキャラクターを選択"; From ee67249b845bc6aa3816058591b1858a8f760bd7 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Sat, 20 Jul 2024 23:37:10 +0900 Subject: [PATCH 3/9] =?UTF-8?q?Fix:=20=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=81=AEunixMillisec=E3=82=92UUID4=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/command.ts | 2 +- src/store/project.ts | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/store/command.ts b/src/store/command.ts index 2d8e062f38..9af3013e82 100644 --- a/src/store/command.ts +++ b/src/store/command.ts @@ -136,7 +136,7 @@ export const commandStore = createPartialStore({ LAST_COMMAND_IDS: { getter(state) { const getLastCommandId = (commands: Command[]): CommandId | null => { - if (commands.length > 0) return null; + if (commands.length == 0) return null; else return commands[commands.length - 1].id; }; diff --git a/src/store/project.ts b/src/store/project.ts index 4adf90b4ff..4de85b6be7 100755 --- a/src/store/project.ts +++ b/src/store/project.ts @@ -20,6 +20,7 @@ import { DEFAULT_TPQN, } from "@/sing/domain"; import { EditorType } from "@/type/preload"; +import { IsEqual } from "@/type/utility"; export const projectStoreState: ProjectStoreState = { savedLastCommandIds: { talk: null, song: null }, @@ -373,13 +374,11 @@ export const projectStore = createPartialStore({ IS_EDITED: { getter(state, getters) { - if ( - Object.keys(state.savedLastCommandIds) != - Object.keys(getters.LAST_COMMAND_IDS) - ) - throw new Error( - "Object.keys(state.savedLastCommandIds) != Object.keys(getters.LAST_COMMAND_IDS)", - ); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const _: IsEqual< + typeof state.savedLastCommandIds, + typeof getters.LAST_COMMAND_IDS + > = true; return Object.keys(state.savedLastCommandIds).some((_editor) => { const editor = _editor as EditorType; return ( From b341b77ae6480976827f85153a619ade0511f0d9 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Sat, 20 Jul 2024 23:43:50 +0900 Subject: [PATCH 4/9] =?UTF-8?q?=E3=83=9F=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/project.ts | 2 +- src/store/singing.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/store/project.ts b/src/store/project.ts index 4de85b6be7..c5b847df25 100755 --- a/src/store/project.ts +++ b/src/store/project.ts @@ -213,7 +213,7 @@ export const projectStore = createPartialStore({ await applySongProjectToStore(dispatch, parsedProjectData.song); commit("SET_PROJECT_FILEPATH", { filePath }); - context.commit("RESET_SAVED_LAST_COMMAND_IDS"); + commit("RESET_SAVED_LAST_COMMAND_IDS"); commit("CLEAR_COMMANDS"); return true; } catch (err) { diff --git a/src/store/singing.ts b/src/store/singing.ts index 90255efe9b..29a688bdda 100644 --- a/src/store/singing.ts +++ b/src/store/singing.ts @@ -1751,7 +1751,7 @@ export const singingStore = createPartialStore({ startFrame: 0, }); - context.commit("RESET_SAVED_LAST_COMMAND_IDS"); + commit("RESET_SAVED_LAST_COMMAND_IDS"); commit("CLEAR_COMMANDS"); dispatch("RENDER"); }, From b3ccb2e5dfebccdf97506d3f10453339414823e0 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Sun, 21 Jul 2024 00:08:10 +0900 Subject: [PATCH 5/9] =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/browser/fileImpl.ts | 3 ++- src/components/Sing/ScoreSequencer.vue | 3 ++- src/helpers/random.ts | 27 +++++++++++++++++++ src/sing/utaformatixProject/toVoicevox.ts | 3 ++- src/store/audio.ts | 3 ++- src/store/command.ts | 3 ++- src/store/preset.ts | 3 ++- src/store/singing.ts | 5 ++-- tests/unit/lib/selectPriorPhrase.spec.ts | 3 ++- .../lib/utaformatixProject/export.spec.ts | 3 ++- .../store/__snapshots__/command.spec.ts.snap | 6 ++--- tests/unit/store/command.spec.ts | 5 +++- tests/unit/store/utility.spec.ts | 5 ++-- 13 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 src/helpers/random.ts diff --git a/src/backend/browser/fileImpl.ts b/src/backend/browser/fileImpl.ts index d60f85f30f..0dab45ac29 100644 --- a/src/backend/browser/fileImpl.ts +++ b/src/backend/browser/fileImpl.ts @@ -4,6 +4,7 @@ import { openDB } from "./browserConfig"; import { SandboxKey } from "@/type/preload"; import { failure, success } from "@/type/result"; import { createLogger } from "@/domain/frontend/log"; +import { uuid4 } from "@/helpers/random"; const log = createLogger("fileImpl"); @@ -200,7 +201,7 @@ export const showOpenFilePickerImpl = async (options: { }); const paths = []; for (const handle of handles) { - const fakePath = `-${handle.name}`; + const fakePath = `-${handle.name}`; fileHandleMap.set(fakePath, handle); paths.push(fakePath); } diff --git a/src/components/Sing/ScoreSequencer.vue b/src/components/Sing/ScoreSequencer.vue index 5a8a3c6514..a3717121ab 100644 --- a/src/components/Sing/ScoreSequencer.vue +++ b/src/components/Sing/ScoreSequencer.vue @@ -193,6 +193,7 @@ import { import { applyGaussianFilter, linearInterpolation } from "@/sing/utility"; import { useLyricInput } from "@/composables/useLyricInput"; import { ExhaustiveError } from "@/type/utility"; +import { uuid4 } from "@/helpers/random"; type PreviewMode = | "ADD_NOTE" @@ -720,7 +721,7 @@ const startPreview = (event: MouseEvent, mode: PreviewMode, note?: Note) => { return; } note = { - id: NoteId(crypto.randomUUID()), + id: NoteId(uuid4()), position: guideLineTicks, duration: snapTicks.value, noteNumber: cursorNoteNumber, diff --git a/src/helpers/random.ts b/src/helpers/random.ts new file mode 100644 index 0000000000..d8d8fca5c9 --- /dev/null +++ b/src/helpers/random.ts @@ -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-0000-0000-${mockCount.toString().padStart(12, "0")}`; + } +} diff --git a/src/sing/utaformatixProject/toVoicevox.ts b/src/sing/utaformatixProject/toVoicevox.ts index f3e2448d67..04a80a6244 100644 --- a/src/sing/utaformatixProject/toVoicevox.ts +++ b/src/sing/utaformatixProject/toVoicevox.ts @@ -4,6 +4,7 @@ import { DEFAULT_TPQN, createDefaultTrack } from "@/sing/domain"; import { getDoremiFromNoteNumber } from "@/sing/viewHelper"; import { NoteId } from "@/type/preload"; import { Note, Tempo, TimeSignature, Track } from "@/store/type"; +import { uuid4 } from "@/helpers/random"; /** UtaformatixのプロジェクトをVoicevoxの楽譜データに変換する */ export const ufProjectToVoicevox = (project: UfProject): VoicevoxScore => { @@ -72,7 +73,7 @@ export const ufProjectToVoicevox = (project: UfProject): VoicevoxScore => { const notes = trackNotes.map((value): Note => { return { - id: NoteId(crypto.randomUUID()), + id: NoteId(uuid4()), position: convertPosition(value.tickOn, projectTpqn, tpqn), duration: convertDuration( value.tickOn, diff --git a/src/store/audio.ts b/src/store/audio.ts index 343ae6e8f8..df75e2cf66 100644 --- a/src/store/audio.ts +++ b/src/store/audio.ts @@ -58,9 +58,10 @@ import { AudioQuery, AccentPhrase, Speaker, SpeakerInfo } from "@/openapi"; import { base64ImageToUri, base64ToUri } from "@/helpers/base64Helper"; import { getValueOrThrow, ResultError } from "@/type/result"; import { generateWriteErrorMessage } from "@/helpers/fileHelper"; +import { uuid4 } from "@/helpers/random"; function generateAudioKey() { - return AudioKey(crypto.randomUUID()); + return AudioKey(uuid4()); } function parseTextFile( diff --git a/src/store/command.ts b/src/store/command.ts index 9af3013e82..2842ee4185 100644 --- a/src/store/command.ts +++ b/src/store/command.ts @@ -10,6 +10,7 @@ import { MutationTree, } from "@/store/vuex"; import { CommandId, EditorType } from "@/type/preload"; +import { uuid4 } from "@/helpers/random"; enablePatches(); enableMapSet(); @@ -67,7 +68,7 @@ const recordPatches = (draft: S) => recipe(draft, payload), ); return { - id: CommandId(crypto.randomUUID()), + id: CommandId(uuid4()), redoPatches: doPatches, undoPatches: undoPatches, }; diff --git a/src/store/preset.ts b/src/store/preset.ts index 7ceaa9ccf9..428cc5b1f8 100644 --- a/src/store/preset.ts +++ b/src/store/preset.ts @@ -1,3 +1,4 @@ +import { uuid4 } from "@/helpers/random"; import { createPartialStore } from "./vuex"; import { PresetStoreState, PresetStoreTypes, State } from "@/store/type"; import { Preset, PresetKey, Voice, VoiceId } from "@/type/preload"; @@ -181,7 +182,7 @@ export const presetStore = createPartialStore({ ADD_PRESET: { async action(context, { presetData }: { presetData: Preset }) { - const newKey = PresetKey(crypto.randomUUID()); + const newKey = PresetKey(uuid4()); const newPresetItems = { ...context.state.presetItems, [newKey]: presetData, diff --git a/src/store/singing.ts b/src/store/singing.ts index 29a688bdda..7d44d6d6d2 100644 --- a/src/store/singing.ts +++ b/src/store/singing.ts @@ -85,6 +85,7 @@ import { createLogger } from "@/domain/frontend/log"; import { noteSchema } from "@/domain/project/schema"; import { getOrThrow } from "@/helpers/mapHelper"; import { ufProjectToVoicevox } from "@/sing/utaformatixProject/toVoicevox"; +import { uuid4 } from "@/helpers/random"; const logger = createLogger("store/singing"); @@ -1724,7 +1725,7 @@ export const singingStore = createPartialStore({ const track = tracks[trackIndex]; const notes = track.notes.map((note) => ({ ...note, - id: NoteId(crypto.randomUUID()), + id: NoteId(uuid4()), })); if (tpqn !== state.tpqn) { @@ -2144,7 +2145,7 @@ export const singingStore = createPartialStore({ const quantizedPastePos = Math.round(pasteOriginPos / snapTicks) * snapTicks; return { - id: NoteId(crypto.randomUUID()), + id: NoteId(uuid4()), position: quantizedPastePos, duration: Number(note.duration), noteNumber: Number(note.noteNumber), diff --git a/tests/unit/lib/selectPriorPhrase.spec.ts b/tests/unit/lib/selectPriorPhrase.spec.ts index 4f8b2e2580..cebfdcaca6 100644 --- a/tests/unit/lib/selectPriorPhrase.spec.ts +++ b/tests/unit/lib/selectPriorPhrase.spec.ts @@ -7,6 +7,7 @@ import { } from "@/store/type"; import { DEFAULT_TPQN, selectPriorPhrase } from "@/sing/domain"; import { NoteId } from "@/type/preload"; +import { uuid4 } from "@/helpers/random"; const createPhrase = ( firstRestDuration: number, @@ -18,7 +19,7 @@ const createPhrase = ( firstRestDuration: firstRestDuration * DEFAULT_TPQN, notes: [ { - id: NoteId(crypto.randomUUID()), + id: NoteId(uuid4()), position: start * DEFAULT_TPQN, duration: (end - start) * DEFAULT_TPQN, noteNumber: 60, diff --git a/tests/unit/lib/utaformatixProject/export.spec.ts b/tests/unit/lib/utaformatixProject/export.spec.ts index 1fad3469b5..5193905dc7 100644 --- a/tests/unit/lib/utaformatixProject/export.spec.ts +++ b/tests/unit/lib/utaformatixProject/export.spec.ts @@ -6,8 +6,9 @@ import { createDefaultTrack, } from "@/sing/domain"; import { NoteId } from "@/type/preload"; +import { uuid4 } from "@/helpers/random"; -const createNoteId = () => NoteId(crypto.randomUUID()); +const createNoteId = () => NoteId(uuid4()); it("トラックを変換できる", async () => { const track = createDefaultTrack(); diff --git a/tests/unit/store/__snapshots__/command.spec.ts.snap b/tests/unit/store/__snapshots__/command.spec.ts.snap index 612a4d0f5a..3e3359dae0 100644 --- a/tests/unit/store/__snapshots__/command.spec.ts.snap +++ b/tests/unit/store/__snapshots__/command.spec.ts.snap @@ -3,7 +3,7 @@ exports[`コマンド実行で履歴が作られる 1`] = ` { "audioKeys": [ - "00000000-0000-0000-0000-000000000000", + "00000000-0000-0000-0000-000000000001", ], "redoCommands": { "song": [], @@ -13,6 +13,7 @@ exports[`コマンド実行で履歴が作られる 1`] = ` "song": [], "talk": [ { + "id": "00000000-0000-0000-0000-000000000002", "redoPatches": [ { "op": "replace", @@ -20,7 +21,7 @@ exports[`コマンド実行で履歴が作られる 1`] = ` "audioKeys", ], "value": [ - "00000000-0000-0000-0000-000000000000", + "00000000-0000-0000-0000-000000000001", ], }, ], @@ -33,7 +34,6 @@ exports[`コマンド実行で履歴が作られる 1`] = ` "value": [], }, ], - "unixMillisec": 1720797286952, }, ], }, diff --git a/tests/unit/store/command.spec.ts b/tests/unit/store/command.spec.ts index 0b69b81eae..3a06f661da 100644 --- a/tests/unit/store/command.spec.ts +++ b/tests/unit/store/command.spec.ts @@ -1,15 +1,18 @@ 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("00000000-0000-0000-0000-000000000000")], + audioKeys: [AudioKey(uuid4())], }); // npm run test-watch:unit -- "tests\unit\store\command.spec.ts" diff --git a/tests/unit/store/utility.spec.ts b/tests/unit/store/utility.spec.ts index c4a8907dc9..cb6430de9e 100644 --- a/tests/unit/store/utility.spec.ts +++ b/tests/unit/store/utility.spec.ts @@ -22,6 +22,7 @@ import { isOnCommandOrCtrlKeyDown, filterCharacterInfosByStyleType, } from "@/store/utility"; +import { uuid4 } from "@/helpers/random"; function createDummyMora(text: string): Mora { return { @@ -305,13 +306,13 @@ describe("filterCharacterInfosByStyleType", () => { const createCharacterInfo = ( styleTypes: (undefined | "talk" | "frame_decode" | "sing")[], ): CharacterInfo => { - const engineId = EngineId(crypto.randomUUID()); + const engineId = EngineId(uuid4()); return { portraitPath: "path/to/portrait", metas: { policy: "policy", speakerName: "speakerName", - speakerUuid: SpeakerId(crypto.randomUUID()), + speakerUuid: SpeakerId(uuid4()), styles: styleTypes.map((styleType) => ({ styleType, styleName: "styleName", From c56ab8cf1dc21e45c3fde4736a6e65881b57dc66 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Sun, 21 Jul 2024 00:12:54 +0900 Subject: [PATCH 6/9] =?UTF-8?q?=E3=83=A1=E3=83=A2=E3=81=8C=E6=AE=8B?= =?UTF-8?q?=E3=81=A3=E3=81=A6=E3=81=84=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unit/store/command.spec.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/unit/store/command.spec.ts b/tests/unit/store/command.spec.ts index 3a06f661da..4ee14a1068 100644 --- a/tests/unit/store/command.spec.ts +++ b/tests/unit/store/command.spec.ts @@ -14,10 +14,6 @@ test("コマンド実行で履歴が作られる", async () => { await store.dispatch("COMMAND_SET_AUDIO_KEYS", { audioKeys: [AudioKey(uuid4())], }); - - // npm run test-watch:unit -- "tests\unit\store\command.spec.ts" - // millisecをrandomUuidにし、かつrandomUuidをmockにする - const { audioKeys, redoCommands, undoCommands } = store.state; expect({ audioKeys, redoCommands, undoCommands }).toMatchSnapshot(); }); From 2bb70449ce6bcd44019e484b8dedebf8fa3b24ca Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Sun, 21 Jul 2024 01:14:01 +0900 Subject: [PATCH 7/9] fix --- src/store/preset.ts | 2 +- src/store/singing.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/store/preset.ts b/src/store/preset.ts index 428cc5b1f8..a4981632f9 100644 --- a/src/store/preset.ts +++ b/src/store/preset.ts @@ -1,5 +1,5 @@ -import { uuid4 } from "@/helpers/random"; import { createPartialStore } from "./vuex"; +import { uuid4 } from "@/helpers/random"; import { PresetStoreState, PresetStoreTypes, State } from "@/store/type"; import { Preset, PresetKey, Voice, VoiceId } from "@/type/preload"; diff --git a/src/store/singing.ts b/src/store/singing.ts index 7d44d6d6d2..fbc4a2896e 100644 --- a/src/store/singing.ts +++ b/src/store/singing.ts @@ -1709,7 +1709,7 @@ export const singingStore = createPartialStore({ await dispatch("SET_TIME_SIGNATURES", { timeSignatures }); await dispatch("SET_NOTES", { notes }); - context.commit("RESET_SAVED_LAST_COMMAND_IDS"); + commit("RESET_SAVED_LAST_COMMAND_IDS"); commit("CLEAR_COMMANDS"); dispatch("RENDER"); }, From 9f3327a10dd7e530883281b429ea5f61fe4ea7d3 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Wed, 24 Jul 2024 00:31:58 +0900 Subject: [PATCH 8/9] Update src/helpers/random.ts Co-authored-by: Nanashi. --- src/helpers/random.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/random.ts b/src/helpers/random.ts index d8d8fca5c9..62e41e1ca1 100644 --- a/src/helpers/random.ts +++ b/src/helpers/random.ts @@ -22,6 +22,6 @@ export function uuid4(): string { return crypto.randomUUID(); } else { mockCount++; - return `00000000-0000-0000-0000-${mockCount.toString().padStart(12, "0")}`; + return `00000000-0000-4000-0000-${mockCount.toString().padStart(12, "0")}`; } } From 2dd3cc0a2812daff69510072542ac2769ea2f453 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Wed, 24 Jul 2024 00:41:39 +0900 Subject: [PATCH 9/9] update --- tests/unit/store/__snapshots__/command.spec.ts.snap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/store/__snapshots__/command.spec.ts.snap b/tests/unit/store/__snapshots__/command.spec.ts.snap index 3e3359dae0..6d2a116d0c 100644 --- a/tests/unit/store/__snapshots__/command.spec.ts.snap +++ b/tests/unit/store/__snapshots__/command.spec.ts.snap @@ -3,7 +3,7 @@ exports[`コマンド実行で履歴が作られる 1`] = ` { "audioKeys": [ - "00000000-0000-0000-0000-000000000001", + "00000000-0000-4000-0000-000000000001", ], "redoCommands": { "song": [], @@ -13,7 +13,7 @@ exports[`コマンド実行で履歴が作られる 1`] = ` "song": [], "talk": [ { - "id": "00000000-0000-0000-0000-000000000002", + "id": "00000000-0000-4000-0000-000000000002", "redoPatches": [ { "op": "replace", @@ -21,7 +21,7 @@ exports[`コマンド実行で履歴が作られる 1`] = ` "audioKeys", ], "value": [ - "00000000-0000-0000-0000-000000000001", + "00000000-0000-4000-0000-000000000001", ], }, ],