32 lines
1.6 KiB
TypeScript
32 lines
1.6 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { createInitialAppState } from "@editor/initial-state";
|
|
import { createAppStore } from "@editor/store";
|
|
import { createCommandRegistry } from "./registry";
|
|
import { documentAddArtboardCommand, documentRenameArtboardCommand } from "./document";
|
|
import { projectOpenCommand } from "./project";
|
|
import { commandIds } from "./ids";
|
|
|
|
describe("open project command", () => {
|
|
test("replaces the document and resets transient sessions and history", () => {
|
|
const app = createTestApp("Original");
|
|
const replacement = createTestApp("Opened").store.getState().document;
|
|
const originalArtboardId = app.store.getState().document.artboards[0]!.id;
|
|
app.store.dispatch(commandIds.documentRenameArtboard, { id: originalArtboardId, name: "Changed" });
|
|
expect(app.store.getState().history.past).toHaveLength(2);
|
|
|
|
app.store.dispatch(commandIds.projectOpen, { document: replacement });
|
|
|
|
const state = app.store.getState();
|
|
expect(state.document).toBe(replacement);
|
|
expect(state.editor.selection).toEqual({ artboardId: replacement.artboards[0]!.id, layerIds: [] });
|
|
expect(state.editor.generation.candidates).toEqual([]);
|
|
expect(state.history).toEqual({ past: [], future: [] });
|
|
});
|
|
});
|
|
|
|
function createTestApp(name: string) {
|
|
const store = createAppStore(createInitialAppState(name), createCommandRegistry([projectOpenCommand, documentAddArtboardCommand, documentRenameArtboardCommand]));
|
|
store.dispatch(commandIds.documentAddArtboard, { id: `${name}-artboard`, name: "Board", bounds: { x: 0, y: 0, w: 100, h: 100 } });
|
|
return { store };
|
|
}
|