Skip to content

Commit

Permalink
audio.spec.tsのテストが通らない
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba committed Nov 3, 2024
1 parent 67fa7cd commit d0febc3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 108 deletions.
22 changes: 15 additions & 7 deletions src/mock/engineMock/characterResourceMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ const baseCharactersMock = [
},
] satisfies Speaker[];

/** 全てのキャラクターを返すモック */
export function getCharactersMock(): Speaker[] {
return baseCharactersMock;
}

/** 喋れるキャラクターを返すモック */
export function getSpeakersMock(): Speaker[] {
return (
Expand Down Expand Up @@ -85,31 +90,34 @@ export function getSingersMock(): Speaker[] {
/** キャラクターの追加情報を返すモック。 */
export function getCharacterInfoMock(speakerUuid: string): SpeakerInfo {
// NOTE: 画像のURLを得るために必要
const speakerIndex = baseCharactersMock.findIndex(
const characterIndex = baseCharactersMock.findIndex(
(speaker) => speaker.speakerUuid === speakerUuid,
);
if (speakerIndex === -1) {
throw new Error(`Speaker not found: ${speakerUuid}`);
if (characterIndex === -1) {
throw new Error(`Character not found: ${speakerUuid}`);
}

const styleIds = baseCharactersMock[speakerIndex].styles.map(
const styleIds = baseCharactersMock[characterIndex].styles.map(
(style) => style.id,
);

return {
policy: `Dummy policy for ${speakerUuid}`,
portrait: `${assetsUrl}/portrait_${speakerIndex + 1}.png`,
portrait: `${assetsUrl}/portrait_${characterIndex + 1}.png`,
styleInfos: styleIds.map((id) => {
return {
id,
icon: `${assetsUrl}/icon_${speakerIndex + 1}.png`,
icon: `${assetsUrl}/icon_${characterIndex + 1}.png`,
voiceSamples: [],
};
}),
};
}

/** 喋れるキャラクターの追加情報を返すモック */
/**
* 喋れるキャラクターの追加情報を返すモック。
* 本当は喋れるスタイルのみでフィルタリングすべき。
*/
export function getSpeakerInfoMock(speakerUuid: string): SpeakerInfo {
return getCharacterInfoMock(speakerUuid);
}
94 changes: 0 additions & 94 deletions tests/unit/store/__snapshots__/audio.spec.ts.snap

This file was deleted.

15 changes: 8 additions & 7 deletions tests/unit/store/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
} from "@/type/preload";
import { mockUrlParams } from "@/infrastructures/EngineConnector";
import {
getSpeakerInfoMock,
getSpeakersMock,
getCharacterInfoMock,
getCharactersMock,
} from "@/mock/engineMock/characterResourceMock";

/** ソフトウェアが正しく起動した場合のようにVuex.stateを初期化する */
Expand Down Expand Up @@ -52,17 +52,18 @@ export function initializeStateAsSoftwareStarted(
store.commit("SET_ENGINE_STATE", { engineId, engineState: "READY" });

// キャラクター情報
const speakers = getSpeakersMock();
const characterInfos: CharacterInfo[] = speakers.map((speaker) => {
const speakerInfo = getSpeakerInfoMock(speaker.speakerUuid);
const characters = getCharactersMock();
const characterInfos: CharacterInfo[] = characters.map((speaker) => {
const speakerInfo = getCharacterInfoMock(speaker.speakerUuid);
return {
portraitPath: speakerInfo.portrait,
metas: {
speakerUuid: SpeakerId(speaker.speakerUuid),
speakerName: speaker.name,
styles: speakerInfo.styleInfos.map((styleInfo) => {
const style = speaker.styles.find((s) => s.id === styleInfo.id);
if (style == undefined) throw new Error("style not found");
if (style == undefined)
throw new Error(`style not found: id ${styleInfo.id}`);
return {
styleName: style.name,
styleId: StyleId(style.id),
Expand All @@ -87,7 +88,7 @@ export function initializeStateAsSoftwareStarted(
});

// デフォルトスタイルID
const defaultStyleIds: DefaultStyleId[] = speakers.map((speaker) => ({
const defaultStyleIds: DefaultStyleId[] = characters.map((speaker) => ({
engineId: engineId,
speakerUuid: SpeakerId(speaker.speakerUuid),
defaultStyleId: StyleId(speaker.styles[0].id),
Expand Down

0 comments on commit d0febc3

Please sign in to comment.