feat(history): add undo redo stack
This commit is contained in:
29
commands/history.test.ts
Normal file
29
commands/history.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { createInitialAppState } from "@editor/initial-state";
|
||||
import { createAppStore } from "@editor/store";
|
||||
import { documentAddArtboardCommand } from "./document";
|
||||
import { historyCommands } from "./history";
|
||||
import { commandIds } from "./ids";
|
||||
import { createCommandRegistry } from "./registry";
|
||||
|
||||
const registry = createCommandRegistry([documentAddArtboardCommand, ...historyCommands]);
|
||||
|
||||
describe("history commands", () => {
|
||||
test("records document changes and undoes/redoes them", () => {
|
||||
const store = createAppStore(createInitialAppState("Test"), registry);
|
||||
|
||||
store.dispatch(commandIds.documentAddArtboard, { id: "a1", name: "Artboard", bounds: { x: 0, y: 0, w: 100, h: 100 } });
|
||||
|
||||
expect(store.getState().document.artboards.map((artboard) => artboard.id)).toEqual(["a1"]);
|
||||
expect(store.getState().history.past).toHaveLength(1);
|
||||
|
||||
store.dispatch(commandIds.historyUndo, undefined);
|
||||
|
||||
expect(store.getState().document.artboards).toEqual([]);
|
||||
expect(store.getState().history.future).toHaveLength(1);
|
||||
|
||||
store.dispatch(commandIds.historyRedo, undefined);
|
||||
|
||||
expect(store.getState().document.artboards.map((artboard) => artboard.id)).toEqual(["a1"]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user