feat: add project management features including open/save functionality and recovery support
This commit is contained in:
31
commands/project.test.ts
Normal file
31
commands/project.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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 };
|
||||
}
|
||||
Reference in New Issue
Block a user