Skip to content

Commit

Permalink
added tests for other parts of BreakTimeNotificationOverview parts
Browse files Browse the repository at this point in the history
  • Loading branch information
DerKatsche committed Oct 18, 2024
1 parent f51183f commit 13d0bd3
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import mock from "jest-mock-extended/lib/Mock";
import CoreDIContainer from "../../../../../Core/DependencyInjection/CoreDIContainer";
import PRESENTATION_TYPES from "../../../../../Core/DependencyInjection/Presentation/PRESENTATION_TYPES";
import IBreakTimeNotificationOverviewPresenter from "../../../../../Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/IBreakTimeNotificationOverviewPresenter";
import BreakTimeNotificationOverviewBuilder from "../../../../../Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverviewBuilder";

describe("BreakTimeNotificationOverviewBuilder", () => {
let systemUnderTest: BreakTimeNotificationOverviewBuilder;

beforeEach(() => {
systemUnderTest = new BreakTimeNotificationOverviewBuilder();
});

test("buildPresenter registers presenter with the CoreDIContainer", () => {
systemUnderTest.buildViewModel();
systemUnderTest.buildPresenter();

expect(
CoreDIContainer.isBound(
PRESENTATION_TYPES.IBreakTimeNotificationOverviewPresenter,
),
).toBe(true);
expect(
CoreDIContainer.get(
PRESENTATION_TYPES.IBreakTimeNotificationOverviewPresenter,
),
).toBe(systemUnderTest.getPresenter()!);
});

test("buildPresenter unbinds the presenter if it is already bound", () => {
CoreDIContainer.bind(
PRESENTATION_TYPES.IBreakTimeNotificationOverviewPresenter,
).toConstantValue(mock<IBreakTimeNotificationOverviewPresenter>);

const unbindSpy = jest.spyOn(CoreDIContainer, "unbind");

systemUnderTest.buildViewModel();
systemUnderTest.buildPresenter();

expect(unbindSpy).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import mock from "jest-mock-extended/lib/Mock";
import BreakTimeNotificationOverviewController from "../../../../../Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverviewController";
import BreakTimeNotificationOverviewViewModel from "../../../../../Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverviewViewModel";
import IBreakTimeNotification from "../../../../../Core/Domain/BreakTimeNotifications/IBreakTimeNotification";

describe("BreakTimeNotificationOverviewController", () => {
let systemUnderTest: BreakTimeNotificationOverviewController;

test("selectNotification sets selected notification in view model", () => {
const viewModel = new BreakTimeNotificationOverviewViewModel();
systemUnderTest = new BreakTimeNotificationOverviewController(viewModel);

const notification = mock<IBreakTimeNotification>();

systemUnderTest.selectNotification(notification);

expect(viewModel.selectedNotification.Value).toBe(notification);
});

test("returnToOverview sets selected notification to null in view model", () => {
const viewModel = new BreakTimeNotificationOverviewViewModel();
viewModel.selectedNotification.Value = mock<IBreakTimeNotification>();
systemUnderTest = new BreakTimeNotificationOverviewController(viewModel);

systemUnderTest.returnToOverview();

expect(viewModel.selectedNotification.Value).toBeNull();
});

test("closeModal sets show modal to false and selected notification to null in view model", () => {
const viewModel = new BreakTimeNotificationOverviewViewModel();
viewModel.showModal.Value = true;
viewModel.selectedNotification.Value = mock<IBreakTimeNotification>();
systemUnderTest = new BreakTimeNotificationOverviewController(viewModel);

systemUnderTest.closeModal();

expect(viewModel.showModal.Value).toBe(false);
expect(viewModel.selectedNotification.Value).toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import BreakTimeNotificationOverviewViewModel from "../../../../../Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverviewViewModel";
import BreakTimeNotificationOverviewPresenter from "../../../../../Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverviewPresenter";

describe("BreakTimeNotificationOverviewPresenter", () => {
test("openModal sets show modal to true in view model", () => {
const viewModel = new BreakTimeNotificationOverviewViewModel();
const systemUnderTest = new BreakTimeNotificationOverviewPresenter(
viewModel,
);

systemUnderTest.openModal();

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

0 comments on commit 13d0bd3

Please sign in to comment.