diff --git a/src/Components/Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverview.tsx b/src/Components/Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverview.tsx index 78c4e4f08..b3a63c1fa 100644 --- a/src/Components/Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverview.tsx +++ b/src/Components/Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverview.tsx @@ -20,7 +20,7 @@ function BreakTimeNotificationThumbnail({ return (
- + {translate(notification.titleKey)(BUILDER_TYPES.IBreakTimeNotificationOverviewBuilder); - const [showModal] = useObservable(viewModel.showModal); - const [selectedNotification] = useObservable(viewModel.selectedNotification); + const [showModal] = useObservable(viewModel?.showModal); + const [selectedNotification] = useObservable(viewModel?.selectedNotification); const { t: translate } = useTranslation("breakTime"); diff --git a/src/Components/CoreTest/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverview.test.tsx b/src/Components/CoreTest/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverview.test.tsx new file mode 100644 index 000000000..385d9d899 --- /dev/null +++ b/src/Components/CoreTest/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverview.test.tsx @@ -0,0 +1,99 @@ +import { act, fireEvent, render } from "@testing-library/react"; +import React from "react"; +import BreakTimeNotificationOverview from "../../../../../Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverview"; +import { Provider } from "inversify-react"; +import CoreDIContainer from "../../../../../Core/DependencyInjection/CoreDIContainer"; +import useBuilderMock from "../../ReactRelated/CustomHooks/useBuilder/useBuilderMock"; +import BreakTimeNotificationOverviewViewModel from "../../../../../Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/BreakTimeNotificationOverviewViewModel"; +import "@testing-library/jest-dom"; +import IBreakTimeNotificationOverviewController from "../../../../../Core/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/IBreakTimeNotificationOverviewController"; +import mock from "jest-mock-extended/lib/Mock"; +import { get } from "http"; + +describe("BreakTimeNotificationOverview", () => { + test("should render", () => { + const viewModel = new BreakTimeNotificationOverviewViewModel(); + viewModel.showModal.Value = true; + useBuilderMock([ + viewModel, + mock(), + ]); + + const renderResult = render( + + + , + ); + + expect(renderResult.container).not.toBeEmptyDOMElement(); + expect(renderResult.container).toMatchSnapshot(); + }); + + test("should not render without view model", () => { + useBuilderMock([undefined, undefined]); + + const renderResult = render( + + + , + ); + + expect(renderResult.container.firstChild).toBeNull(); + }); + + test("should not render without view model show modal value", () => { + const viewModel = new BreakTimeNotificationOverviewViewModel(); + viewModel.showModal.Value = false; + useBuilderMock([ + viewModel, + mock(), + ]); + + const renderResult = render( + + + , + ); + + expect(renderResult.container.firstChild).toBeNull(); + }); + + test("should not render without controller", () => { + const viewModel = new BreakTimeNotificationOverviewViewModel(); + viewModel.showModal.Value = true; + useBuilderMock([viewModel, undefined]); + + const renderResult = render( + + + , + ); + + expect(renderResult.container.firstChild).toBeNull(); + }); + + test("calls controller with clicked notification", () => { + const viewModel = new BreakTimeNotificationOverviewViewModel(); + viewModel.showModal.Value = true; + const controllerMock = mock(); + useBuilderMock([viewModel, controllerMock]); + + const renderResult = render( + + + , + ); + + const notificationElement = renderResult.getByTestId( + viewModel.shortBreakTimeNotifications[0].titleKey, + ); + act(() => { + fireEvent.click(notificationElement); + }); + + expect(controllerMock.selectNotification).toHaveBeenCalledTimes(1); + expect(controllerMock.selectNotification).toHaveBeenCalledWith( + viewModel.shortBreakTimeNotifications[0], + ); + }); +}); diff --git a/src/Components/CoreTest/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/__snapshots__/BreakTimeNotificationOverview.test.tsx.snap b/src/Components/CoreTest/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/__snapshots__/BreakTimeNotificationOverview.test.tsx.snap new file mode 100644 index 000000000..4b4c67040 --- /dev/null +++ b/src/Components/CoreTest/Presentation/React/GeneralComponents/BreakTimeNotificationOverview/__snapshots__/BreakTimeNotificationOverview.test.tsx.snap @@ -0,0 +1,305 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BreakTimeNotificationOverview should render 1`] = ` +
+
+
+
+
+
+ overviewTitle +
+ +
+
+
+
+

+ shortBreaks +

+
+
+
+ +
+
+ B3 +
+
+
+
+ +
+
+ B7 +
+
+
+
+ +
+
+ B8 +
+
+
+
+ +
+
+ E2 +
+
+
+
+ +
+
+ E4 +
+
+
+
+ +
+
+ E10 +
+
+
+
+ +
+
+ L1 +
+
+
+
+ +
+
+ L3 +
+
+
+
+ +
+
+ L5 +
+
+
+
+ +
+
+ U3 +
+
+
+
+
+

+ mediumBreaks +

+
+
+
+ +
+
+ S1 +
+
+
+
+ +
+
+ S3 +
+
+
+
+
+

+ longBreaks +

+
+
+
+ +
+
+ H1 +
+
+
+
+
+
+
+
+
+
+`;