auto-git:
[change] tests/domain/interaction-links.validation.test.ts
This commit is contained in:
@@ -4,12 +4,20 @@ import { createBoxBrush } from "../../src/document/brushes";
|
|||||||
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
import { createEmptySceneDocument } from "../../src/document/scene-document";
|
||||||
import { validateSceneDocument } from "../../src/document/scene-document-validation";
|
import { validateSceneDocument } from "../../src/document/scene-document-validation";
|
||||||
import { createModelInstance } from "../../src/assets/model-instances";
|
import { createModelInstance } from "../../src/assets/model-instances";
|
||||||
import { createProjectAssetStorageKey, type ModelAssetRecord } from "../../src/assets/project-assets";
|
import { createProjectAssetStorageKey, type AudioAssetRecord, type ModelAssetRecord } from "../../src/assets/project-assets";
|
||||||
import { createInteractableEntity, createPlayerStartEntity, createTeleportTargetEntity, createTriggerVolumeEntity } from "../../src/entities/entity-instances";
|
import {
|
||||||
|
createInteractableEntity,
|
||||||
|
createPlayerStartEntity,
|
||||||
|
createSoundEmitterEntity,
|
||||||
|
createTeleportTargetEntity,
|
||||||
|
createTriggerVolumeEntity
|
||||||
|
} from "../../src/entities/entity-instances";
|
||||||
import {
|
import {
|
||||||
createPlayAnimationInteractionLink,
|
createPlayAnimationInteractionLink,
|
||||||
|
createPlaySoundInteractionLink,
|
||||||
createTeleportPlayerInteractionLink,
|
createTeleportPlayerInteractionLink,
|
||||||
createToggleVisibilityInteractionLink
|
createToggleVisibilityInteractionLink,
|
||||||
|
createStopSoundInteractionLink
|
||||||
} from "../../src/interactions/interaction-links";
|
} from "../../src/interactions/interaction-links";
|
||||||
|
|
||||||
describe("interaction link validation", () => {
|
describe("interaction link validation", () => {
|
||||||
@@ -24,6 +32,25 @@ describe("interaction link validation", () => {
|
|||||||
const teleportTarget = createTeleportTargetEntity({
|
const teleportTarget = createTeleportTargetEntity({
|
||||||
id: "entity-teleport-main"
|
id: "entity-teleport-main"
|
||||||
});
|
});
|
||||||
|
const audioAsset = {
|
||||||
|
id: "asset-audio-main",
|
||||||
|
kind: "audio" as const,
|
||||||
|
sourceName: "lobby-loop.ogg",
|
||||||
|
mimeType: "audio/ogg",
|
||||||
|
storageKey: createProjectAssetStorageKey("asset-audio-main"),
|
||||||
|
byteLength: 4096,
|
||||||
|
metadata: {
|
||||||
|
kind: "audio" as const,
|
||||||
|
durationSeconds: 4,
|
||||||
|
channelCount: 2,
|
||||||
|
sampleRateHz: 48000,
|
||||||
|
warnings: []
|
||||||
|
}
|
||||||
|
} satisfies AudioAssetRecord;
|
||||||
|
const soundEmitter = createSoundEmitterEntity({
|
||||||
|
id: "entity-sound-main",
|
||||||
|
audioAssetId: audioAsset.id
|
||||||
|
});
|
||||||
const brush = createBoxBrush({
|
const brush = createBoxBrush({
|
||||||
id: "brush-door"
|
id: "brush-door"
|
||||||
});
|
});
|
||||||
@@ -35,7 +62,11 @@ describe("interaction link validation", () => {
|
|||||||
entities: {
|
entities: {
|
||||||
[triggerVolume.id]: triggerVolume,
|
[triggerVolume.id]: triggerVolume,
|
||||||
[interactable.id]: interactable,
|
[interactable.id]: interactable,
|
||||||
[teleportTarget.id]: teleportTarget
|
[teleportTarget.id]: teleportTarget,
|
||||||
|
[soundEmitter.id]: soundEmitter
|
||||||
|
},
|
||||||
|
assets: {
|
||||||
|
[audioAsset.id]: audioAsset
|
||||||
},
|
},
|
||||||
interactionLinks: {
|
interactionLinks: {
|
||||||
"link-teleport": createTeleportPlayerInteractionLink({
|
"link-teleport": createTeleportPlayerInteractionLink({
|
||||||
@@ -56,6 +87,18 @@ describe("interaction link validation", () => {
|
|||||||
sourceEntityId: interactable.id,
|
sourceEntityId: interactable.id,
|
||||||
trigger: "click",
|
trigger: "click",
|
||||||
targetEntityId: teleportTarget.id
|
targetEntityId: teleportTarget.id
|
||||||
|
}),
|
||||||
|
"link-play-sound": createPlaySoundInteractionLink({
|
||||||
|
id: "link-play-sound",
|
||||||
|
sourceEntityId: interactable.id,
|
||||||
|
trigger: "click",
|
||||||
|
targetSoundEmitterId: soundEmitter.id
|
||||||
|
}),
|
||||||
|
"link-stop-sound": createStopSoundInteractionLink({
|
||||||
|
id: "link-stop-sound",
|
||||||
|
sourceEntityId: triggerVolume.id,
|
||||||
|
trigger: "exit",
|
||||||
|
targetSoundEmitterId: soundEmitter.id
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -65,6 +108,40 @@ describe("interaction link validation", () => {
|
|||||||
expect(validation.errors).toEqual([]);
|
expect(validation.errors).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("detects sound playback links that target a sound emitter without an audio asset", () => {
|
||||||
|
const triggerVolume = createTriggerVolumeEntity({
|
||||||
|
id: "entity-trigger-main"
|
||||||
|
});
|
||||||
|
const soundEmitter = createSoundEmitterEntity({
|
||||||
|
id: "entity-sound-main"
|
||||||
|
});
|
||||||
|
|
||||||
|
const validation = validateSceneDocument({
|
||||||
|
...createEmptySceneDocument(),
|
||||||
|
entities: {
|
||||||
|
[triggerVolume.id]: triggerVolume,
|
||||||
|
[soundEmitter.id]: soundEmitter
|
||||||
|
},
|
||||||
|
interactionLinks: {
|
||||||
|
"link-play-sound": createPlaySoundInteractionLink({
|
||||||
|
id: "link-play-sound",
|
||||||
|
sourceEntityId: triggerVolume.id,
|
||||||
|
trigger: "enter",
|
||||||
|
targetSoundEmitterId: soundEmitter.id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(validation.errors).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
code: "missing-sound-emitter-audio-asset",
|
||||||
|
path: "interactionLinks.link-play-sound.action.targetSoundEmitterId"
|
||||||
|
})
|
||||||
|
])
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("detects invalid interaction link source and target references", () => {
|
it("detects invalid interaction link source and target references", () => {
|
||||||
const playerStart = createPlayerStartEntity({
|
const playerStart = createPlayerStartEntity({
|
||||||
id: "entity-player-start-main"
|
id: "entity-player-start-main"
|
||||||
|
|||||||
Reference in New Issue
Block a user