Skip to content

Commit

Permalink
Refactor showCustomNotifierMock
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax committed Apr 26, 2024
1 parent db069e2 commit 7bdb591
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { ConfigResponse } from "@/serverApi/v3/api";
import NotifierModule from "@/store/notifier";
import { injectStrict } from "@/utils/inject";
import setupStores from "@@/tests/test-utils/setupStores";
import { createMock } from "@golevelup/ts-jest";
import { useBoardNotifier, useSharedLastCreatedElement } from "@util-board";
import { ref } from "vue";
import { setupSharedElementTypeSelectionMock } from "../test-utils/sharedElementTypeSelectionMock";
import { useAddElementDialog } from "./AddElementDialog.composable";

Expand All @@ -29,12 +32,12 @@ jest.mock("vue-i18n", () => {
};
});

jest.mock("@util-board", () => {
jest.mock("@util-board");
const mockedUseBoardNotifier = jest.mocked(useBoardNotifier);
jest.mocked(useSharedLastCreatedElement).mockImplementation(() => {
return {
...jest.requireActual("@util-board"),
useBoardNotifier: jest.fn().mockReturnValue({
showCustomNotifier: jest.fn(),
}),
lastCreatedElementId: ref(undefined),
resetLastCreatedElementId: jest.fn(),
};
});

Expand Down Expand Up @@ -96,20 +99,29 @@ describe("ElementTypeSelection Composable", () => {
const addElementMock = jest.fn();
const elementType = ContentElementType.CollaborativeTextEditor;

const showCustomNotifierMock = jest.fn();
const mockedBoardNotifierCalls = createMock<
ReturnType<typeof useBoardNotifier>
>({
showCustomNotifier: showCustomNotifierMock,
});
mockedUseBoardNotifier.mockReturnValue(mockedBoardNotifierCalls);

return {
addElementMock,
elementType,
showCustomNotifierMock,
};
};
it("should show Notification", async () => {
const { addElementMock, elementType } = setup();
const { addElementMock, elementType, showCustomNotifierMock } =
setup();

const { onElementClick, showCustomNotifier } =
useAddElementDialog(addElementMock);
const { onElementClick } = useAddElementDialog(addElementMock);

await onElementClick(elementType);

expect(showCustomNotifier).toHaveBeenCalledWith(i18nKey, "info");
expect(showCustomNotifierMock).toHaveBeenCalledWith(i18nKey, "info");
});
});

Expand Down

0 comments on commit 7bdb591

Please sign in to comment.