Skip to content

Commit

Permalink
Refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax committed Aug 26, 2024
1 parent 50426b1 commit 925ad10
Showing 1 changed file with 49 additions and 13 deletions.
62 changes: 49 additions & 13 deletions src/hooks/useMultiplayerState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@tldraw/tldraw";
import * as Tldraw from "@tldraw/tldraw";
import { useMultiplayerState } from "./useMultiplayerState";
import { doc, room } from "../stores/setup";
import { doc, room, undoManager } from "../stores/setup";
import { deleteAsset, handleAssets } from "../utils/handleAssets";

vi.mock("@tldraw/tldraw", async () => {
Expand Down Expand Up @@ -183,26 +183,62 @@ describe("useMultiplayerState hook", () => {
});
});

it("should handle onUndo correctly", () => {
const { app } = setup();
const { result } = renderHook(() => useMultiplayerState(multiPlayerProps));
describe("onUndo", () => {
it("should call undoManager.undo", () => {
const { app } = setup();
const { result } = renderHook(() =>
useMultiplayerState(multiPlayerProps),
);
const undoSpy = vi.spyOn(undoManager, "undo");

act(() => {
result.current.onUndo(app);
act(() => {
result.current.onUndo(app);
});

expect(undoSpy).toHaveBeenCalled();
});

expect(handleAssets).toHaveBeenCalled();
it("should call handleAssets", () => {
const { app } = setup();
const { result } = renderHook(() =>
useMultiplayerState(multiPlayerProps),
);

act(() => {
result.current.onUndo(app);
});

expect(handleAssets).toHaveBeenCalled();
});
});

it("should handle onRedo correctly", () => {
const { app } = setup();
const { result } = renderHook(() => useMultiplayerState(multiPlayerProps));
describe("onRedo", () => {
it("should call undoManager.redo", () => {
const { app } = setup();
const { result } = renderHook(() =>
useMultiplayerState(multiPlayerProps),
);
const redoSpy = vi.spyOn(undoManager, "redo");

act(() => {
result.current.onRedo(app);
act(() => {
result.current.onRedo(app);
});

expect(redoSpy).toHaveBeenCalled();
});

expect(handleAssets).toHaveBeenCalled();
it("should call handleAssets", () => {
const { app } = setup();
const { result } = renderHook(() =>
useMultiplayerState(multiPlayerProps),
);

act(() => {
result.current.onRedo(app);
});

expect(handleAssets).toHaveBeenCalled();
});
});

it("should handle onChangePage correctly", () => {
Expand Down

0 comments on commit 925ad10

Please sign in to comment.