Skip to content

Commit

Permalink
Added a few more tests to AvatarEditorPreviewModelView, cleaned up so…
Browse files Browse the repository at this point in the history
…me code from the tested module
  • Loading branch information
Lizardguard committed Feb 14, 2025
1 parent 38cff72 commit 2bf6087
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,22 @@ export default class AvatarEditorPreviewModelView {
private async updateHairModels(mode: "initial" | "diff"): Promise<void> {
if (mode === "initial" || this.viewModel.avatarConfigDiff.Value.hair) {
await Promise.resolve(
this.updateModelHair(this.viewModel.currentAvatarConfig.Value.hair),
this.updateModel(
this.viewModel.currentAvatarConfig.Value.hair,
AvatarModelAssetPaths.hairPath,
this.viewModel.hairMeshes,
this.viewModel.hairAnchorNode,
),
);
}
if (mode === "initial" || this.viewModel.avatarConfigDiff.Value.beard) {
await Promise.resolve(
this.updateModelBeard(this.viewModel.currentAvatarConfig.Value.beard),
this.updateModel(
this.viewModel.currentAvatarConfig.Value.beard,
AvatarModelAssetPaths.beardPath,
this.viewModel.beardMeshes,
this.viewModel.beardAnchorNode,
),
);
}
if (mode === "initial" || this.viewModel.avatarConfigDiff.Value.hairColor) {
Expand Down Expand Up @@ -198,19 +208,6 @@ export default class AvatarEditorPreviewModelView {
}
}

private async updateModelHair(
hair?: AvatarHairModels | undefined,
): Promise<void> {
await Promise.resolve(
this.updateModel(
hair,
AvatarModelAssetPaths.hairPath,
this.viewModel.hairMeshes,
this.viewModel.hairAnchorNode,
),
);
}

private updateHairColor(hairColor?: AvatarColor) {
let hairMesh = this.viewModel.hairMeshes.get(
this.viewModel.currentAvatarConfig.Value.hair,
Expand All @@ -230,15 +227,6 @@ export default class AvatarEditorPreviewModelView {
hairTexture.vOffset = hairColorVOffset - vDisplacement;
}

private async updateModelBeard(beard?: AvatarBeardModels | undefined) {
await this.updateModel(
beard,
AvatarModelAssetPaths.beardPath,
this.viewModel.beardMeshes,
this.viewModel.beardAnchorNode,
);
}

private updateBeardColor(beardColor?: AvatarColor) {
let beardMesh = this.viewModel.beardMeshes.get(
this.viewModel.currentAvatarConfig.Value.beard,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,81 @@ describe("AvatarEditorPreviewModelView", () => {
expect(systemUnderTest["updateBodyModels"]).toHaveBeenCalled();
});

test("updateHairModels calls updateModel if a new hairstyle is provided", async () => {
const [viewModel, systemUnderTest] = buildSystemUnderTest();
setupScenePresenterMockLoadingResults();
viewModel.currentAvatarConfig.Value.hair = "hair-backhead";
viewModel.avatarConfigDiff.Value.hair = "hair-backhead";

systemUnderTest["updateModel"] = jest.fn();

await systemUnderTest["updateHairModels"]("diff");

expect(systemUnderTest["updateModel"]).toHaveBeenCalledWith(
"hair-backhead",
"hair/hairstyle",
viewModel.hairMeshes,
viewModel.hairAnchorNode,
);
});
test("updateHairModels calls updateModel if a new beardtyle is provided", async () => {
const [viewModel, systemUnderTest] = buildSystemUnderTest();
setupScenePresenterMockLoadingResults();
viewModel.currentAvatarConfig.Value.beard =
"beard-full-friendly-muttonchops";
viewModel.avatarConfigDiff.Value.beard = "beard-full-friendly-muttonchops";

systemUnderTest["updateModel"] = jest.fn();

await systemUnderTest["updateHairModels"]("diff");

expect(systemUnderTest["updateModel"]).toHaveBeenCalledWith(
"beard-full-friendly-muttonchops",
"hair/beards",
viewModel.beardMeshes,
viewModel.beardAnchorNode,
);
});

test("updateHairModels calls updateHairColor and updateBeardColor if a new haircolor is provided", async () => {
const [viewModel, systemUnderTest] = buildSystemUnderTest();
setupScenePresenterMockLoadingResults();
viewModel.currentAvatarConfig.Value.hairColor = {
id: 0,
nameKey: "Black 1",
hexColor: "#000000",
uOffset: 0,
vOffset: 0,
};
viewModel.avatarConfigDiff.Value.hairColor = {
id: 0,
nameKey: "Black 1",
hexColor: "#000000",
uOffset: 0,
vOffset: 0,
};

systemUnderTest["updateHairColor"] = jest.fn();
systemUnderTest["updateBeardColor"] = jest.fn();

await systemUnderTest["updateHairModels"]("diff");

expect(systemUnderTest["updateHairColor"]).toHaveBeenCalledWith({
id: 0,
nameKey: "Black 1",
hexColor: "#000000",
uOffset: 0,
vOffset: 0,
});
expect(systemUnderTest["updateBeardColor"]).toHaveBeenCalledWith({
id: 0,
nameKey: "Black 1",
hexColor: "#000000",
uOffset: 0,
vOffset: 0,
});
});

test("updateHairModels updates hair models if a new hairstyle is provided", async () => {
const [viewModel, systemUnderTest] = buildSystemUnderTest();
setupScenePresenterMockLoadingResults();
Expand Down

0 comments on commit 2bf6087

Please sign in to comment.