-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some tests to avatarEditorPreviewModelView (Part 1)
- Loading branch information
1 parent
83e6810
commit 7adaa79
Showing
2 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...rEditor/AvatarEditorPreview/AvatarEditorPreviewModel/AvatarEditorPreviewModelView.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { mockDeep } from "jest-mock-extended"; | ||
import CoreDIContainer from "../../../../../Core/DependencyInjection/CoreDIContainer"; | ||
import SCENE_TYPES from "../../../../../Core/DependencyInjection/Scenes/SCENE_TYPES"; | ||
import AvatarEditorPreviewModelView from "../../../../../Core/Presentation/AvatarEditor/AvatarEditorPreview/AvatarEditorPreviewModel/AvatarEditorPreviewModelView"; | ||
import AvatarEditorPreviewModelViewModel from "../../../../../Core/Presentation/AvatarEditor/AvatarEditorPreview/AvatarEditorPreviewModel/AvatarEditorPreviewModelViewModel"; | ||
import IScenePresenter from "../../../../../Core/Presentation/Babylon/SceneManagement/IScenePresenter"; | ||
import { AbstractMesh, NullEngine, Scene } from "@babylonjs/core"; | ||
|
||
const scenePresenterMock = mockDeep<IScenePresenter>(); | ||
const scenePresenterFactoryMock = () => scenePresenterMock; | ||
function buildSystemUnderTest(): [ | ||
AvatarEditorPreviewModelViewModel, | ||
AvatarEditorPreviewModelView, | ||
] { | ||
const viewModel = new AvatarEditorPreviewModelViewModel(); | ||
const systemUnderTest = new AvatarEditorPreviewModelView(viewModel); | ||
return [viewModel, systemUnderTest]; | ||
} | ||
|
||
describe("AvatarEditorPreviewModelView", () => { | ||
let systemUnderTest: AvatarEditorPreviewModelView; | ||
|
||
beforeAll(() => { | ||
CoreDIContainer.snapshot(); | ||
CoreDIContainer.rebind(SCENE_TYPES.ScenePresenterFactory).toConstantValue( | ||
scenePresenterFactoryMock, | ||
); | ||
}); | ||
beforeEach(() => { | ||
buildSystemUnderTest(); | ||
}); | ||
|
||
afterAll(() => { | ||
CoreDIContainer.restore(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("constructor injects scenePresenter", async () => { | ||
scenePresenterMock.loadModel.mockResolvedValue([ | ||
new AbstractMesh("TestMesh", new Scene(new NullEngine())), | ||
]); | ||
|
||
const [, systemUnderTest] = buildSystemUnderTest(); | ||
expect(systemUnderTest["scenePresenter"]).toBeDefined(); | ||
}); | ||
|
||
test("constructor subscribes to viewModel.isOpen", () => { | ||
scenePresenterMock.loadModel.mockResolvedValue([ | ||
new AbstractMesh("TestMesh", new Scene(new NullEngine())), | ||
]); | ||
|
||
const [viewModel, systemUnderTest] = buildSystemUnderTest(); | ||
|
||
expect(viewModel.avatarConfigDiff["subscribers"]).toStrictEqual([ | ||
systemUnderTest["onAvatarConfigChanged"], | ||
]); | ||
}); | ||
}); |