Skip to content

Commit

Permalink
Added tests for Sidebarbuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Lizardguard committed Feb 11, 2025
1 parent c843c21 commit 671fe96
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,50 @@
import mock from "jest-mock-extended/lib/Mock";
import CoreDIContainer from "../../../../../Core/DependencyInjection/CoreDIContainer";
import PRESENTATION_TYPES from "../../../../../Core/DependencyInjection/Presentation/PRESENTATION_TYPES";
import SideBarBuilder from "../../../../../Core/Presentation/React/LearningSpaceDisplay/SideBar/SideBarBuilder";
import ILearningWorldPort from "../../../../../Core/Application/Ports/Interfaces/ILearningWorldPort";
import PORT_TYPES from "../../../../../Core/DependencyInjection/Ports/PORT_TYPES";
import {
HistoryWrapper,
LocationScope,
} from "../../../../../Core/Presentation/React/ReactRelated/ReactEntryPoint/HistoryWrapper";

const worldPortMock = mock<ILearningWorldPort>();

describe("SideBarBuilder", () => {
let systemUnderTest: SideBarBuilder;
beforeAll(() => {
CoreDIContainer.snapshot();
CoreDIContainer.rebind<ILearningWorldPort>(
PORT_TYPES.ILearningWorldPort,
).toConstantValue(worldPortMock);
});

beforeEach(() => {
systemUnderTest = new SideBarBuilder();
jest
.spyOn(HistoryWrapper, "currentLocationScope")
.mockReturnValue(LocationScope.spaceDisplay);
});

afterAll(() => {
CoreDIContainer.restore();
jest.restoreAllMocks();
});

test("constructor didn't throw error", () => {
expect(systemUnderTest).toBeDefined();
});
test("buildPresenter builds the presenter and registers it with the WorldPort", () => {
systemUnderTest.buildViewModel();
systemUnderTest.buildController();
systemUnderTest.buildPresenter();

expect(systemUnderTest["presenter"]).toBeDefined();
expect(worldPortMock.registerAdapter).toHaveBeenCalledTimes(1);
expect(worldPortMock.registerAdapter).toHaveBeenCalledWith(
systemUnderTest["presenter"],
LocationScope.spaceDisplay,
);
});
});

0 comments on commit 671fe96

Please sign in to comment.