Skip to content

Commit

Permalink
added tests for StoryNPCPresenter
Browse files Browse the repository at this point in the history
  • Loading branch information
DerKatsche committed Jan 12, 2024
1 parent b311e72 commit 6f0a286
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Vector3 } from "@babylonjs/core";
import IStoryNPCPresenter from "./IStoryNPCPresenter";
import StoryNPCViewModel from "./StoryNPCViewModel";
import StoryElementTextTO from "src/Components/Core/Application/DataTransferObjects/StoryElementTextTO";

export default class StoryNPCPresenter implements IStoryNPCPresenter {
constructor(private viewModel: StoryNPCViewModel) {}
Expand All @@ -15,4 +16,13 @@ export default class StoryNPCPresenter implements IStoryNPCPresenter {
this.viewModel.isInteractable.Value = true;
else this.viewModel.isInteractable.Value = false;
}

onStoryElementLoaded(storyElementTextTO: StoryElementTextTO): void {
this.viewModel.isIntro =
storyElementTextTO.introTexts !== undefined &&
storyElementTextTO.introTexts.length > 0;
this.viewModel.isOutro =
storyElementTextTO.outroTexts !== undefined &&
storyElementTextTO.outroTexts.length > 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { NullEngine, Scene, TransformNode, Vector3 } from "@babylonjs/core";
import StoryNPCPresenter from "../../../../Core/Presentation/Babylon/StoryNPC/StoryNPCPresenter";
import StoryNPCViewModel from "../../../../Core/Presentation/Babylon/StoryNPC/StoryNPCViewModel";

describe("StoryNPCPresenter", () => {
let systemUnderTest: StoryNPCPresenter;
let viewModel: StoryNPCViewModel;

beforeEach(() => {
viewModel = new StoryNPCViewModel();
systemUnderTest = new StoryNPCPresenter(viewModel);
});

test("onAvatarPositionChanged sets isInteractable to true when the avatar is in the interaction radius", () => {
viewModel.parentNode = new TransformNode(
"mockParentNode",
new Scene(new NullEngine())
);
viewModel.parentNode.position = new Vector3(0, 0, 0);
viewModel.isInteractable.Value = false;
systemUnderTest.onAvatarPositionChanged(new Vector3(0, 0, 0), 1);

expect(viewModel.isInteractable.Value).toBe(true);
});

test("onAvatarPositionChanged sets isInteractable to false when the avatar is outside the interaction radius", () => {
viewModel.parentNode = new TransformNode(
"mockParentNode",
new Scene(new NullEngine())
);
viewModel.parentNode.position = new Vector3(0, 0, 0);
viewModel.isInteractable.Value = true;
systemUnderTest.onAvatarPositionChanged(new Vector3(0, 0, 2), 1);

expect(viewModel.isInteractable.Value).toBe(false);
});

test("onStoryElementLoaded sets isIntro to false when the introTexts are undefined", () => {
viewModel.isIntro = true;
systemUnderTest.onStoryElementLoaded({ introTexts: undefined } as any);

expect(viewModel.isIntro).toBe(false);
});

test("onStoryElementLoaded sets isIntro to false when the introTexts are empty", () => {
viewModel.isIntro = true;
systemUnderTest.onStoryElementLoaded({ introTexts: [] } as any);

expect(viewModel.isIntro).toBe(false);
});

test("onStoryElementLoaded sets isIntro to true when the introTexts are not empty", () => {
viewModel.isIntro = false;
systemUnderTest.onStoryElementLoaded({ introTexts: ["test"] } as any);

expect(viewModel.isIntro).toBe(true);
});

test("onStoryElementLoaded sets isOutro to false when the outroTexts are undefined", () => {
viewModel.isOutro = true;
systemUnderTest.onStoryElementLoaded({ outroTexts: undefined } as any);

expect(viewModel.isOutro).toBe(false);
});

test("onStoryElementLoaded sets isOutro to false when the outroTexts are empty", () => {
viewModel.isOutro = true;
systemUnderTest.onStoryElementLoaded({ outroTexts: [] } as any);

expect(viewModel.isOutro).toBe(false);
});

test("onStoryElementLoaded sets isOutro to true when the outroTexts are not empty", () => {
viewModel.isOutro = false;
systemUnderTest.onStoryElementLoaded({ outroTexts: ["test"] } as any);

expect(viewModel.isOutro).toBe(true);
});
});

0 comments on commit 6f0a286

Please sign in to comment.