Greenfield implementation of CardClaws Phase 1 across three surfaces. Backend (Rust/Axum workspace, 67 tests): - cardclaws-types/config/db/auth/api/wallet crates - Auth: register, login + lockout, magic link, refresh rotation, Apple verify - Cards: CRUD, tier-limited publish, duplicate, public handle lookup - Assets: R2 presigned uploads; vCard export - Apple Wallet .pkpass pipeline (PKCS#7 signer behind apple-signing feature) - Analytics ingest + summary with daily-salted IP hashing - Migrations 0001 (incl. cardclaws_sessions) + 0002 analytics Web profile (Astro SSR): cardclaws.com/[handle] hero + flip, contact actions, client-built vCard, visit attribution. Verified end-to-end. Mobile (Expo SDK 51): auth, card list/create, builder v1 (bg/text/logo, palette, undo/redo), Skia/Reanimated viewer (flip + ambient). 22 logic tests. CI: policy/backend/profile/mobile jobs; LOC + no-placeholder lint. Review fixes baked in: `back` (not `cardclaws`) key; strip image is a bundled manifest file (not a URL); sessions table added; NFC reframed; test doubles allowed for external services. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
108 lines
3.2 KiB
TypeScript
108 lines
3.2 KiB
TypeScript
import { MAX_HISTORY, newLayerId, useCardStore } from "../../src/stores/cardStore";
|
|
import { CardDefinition, DEFAULT_SETTINGS, emptySide, TextLayer } from "../../src/types/card";
|
|
|
|
function baseCard(): CardDefinition {
|
|
return {
|
|
id: "card-1",
|
|
ownerId: "user-1",
|
|
handle: "omar",
|
|
version: 1,
|
|
face: emptySide(),
|
|
back: emptySide(),
|
|
palette: { colors: [] },
|
|
settings: DEFAULT_SETTINGS,
|
|
};
|
|
}
|
|
|
|
function textLayer(text: string): TextLayer {
|
|
return {
|
|
id: newLayerId(),
|
|
type: "text",
|
|
x: 0.1,
|
|
y: 0.1,
|
|
width: 0.8,
|
|
height: 0.1,
|
|
opacity: 1,
|
|
zIndex: 1,
|
|
text,
|
|
fontFamily: "System",
|
|
fontWeight: 700,
|
|
fontSize: 28,
|
|
lineHeight: 32,
|
|
letterSpacing: 0,
|
|
color: "#ffffff",
|
|
align: "left",
|
|
};
|
|
}
|
|
|
|
beforeEach(() => {
|
|
useCardStore.getState().load(baseCard());
|
|
});
|
|
|
|
describe("cardStore undo/redo", () => {
|
|
it("starts with no history", () => {
|
|
const s = useCardStore.getState();
|
|
expect(s.canUndo()).toBe(false);
|
|
expect(s.canRedo()).toBe(false);
|
|
expect(s.card?.face.layers).toHaveLength(0);
|
|
});
|
|
|
|
it("adds a layer and can undo/redo it", () => {
|
|
const s = useCardStore.getState();
|
|
s.addLayer("face", textLayer("Omar"));
|
|
expect(useCardStore.getState().card?.face.layers).toHaveLength(1);
|
|
expect(useCardStore.getState().canUndo()).toBe(true);
|
|
|
|
useCardStore.getState().undo();
|
|
expect(useCardStore.getState().card?.face.layers).toHaveLength(0);
|
|
expect(useCardStore.getState().canRedo()).toBe(true);
|
|
|
|
useCardStore.getState().redo();
|
|
expect(useCardStore.getState().card?.face.layers).toHaveLength(1);
|
|
});
|
|
|
|
it("a new edit clears the redo stack", () => {
|
|
const s = useCardStore.getState();
|
|
s.addLayer("face", textLayer("A"));
|
|
useCardStore.getState().undo();
|
|
expect(useCardStore.getState().canRedo()).toBe(true);
|
|
|
|
useCardStore.getState().addLayer("face", textLayer("B"));
|
|
expect(useCardStore.getState().canRedo()).toBe(false);
|
|
expect(useCardStore.getState().card?.face.layers[0]).toMatchObject({ text: "B" });
|
|
});
|
|
|
|
it("updateLayer is reversible", () => {
|
|
const layer = textLayer("Before");
|
|
useCardStore.getState().addLayer("face", layer);
|
|
useCardStore.getState().updateLayer("face", layer.id, { text: "After" } as Partial<TextLayer>);
|
|
|
|
const after = useCardStore.getState().card?.face.layers[0] as TextLayer;
|
|
expect(after.text).toBe("After");
|
|
|
|
useCardStore.getState().undo();
|
|
const before = useCardStore.getState().card?.face.layers[0] as TextLayer;
|
|
expect(before.text).toBe("Before");
|
|
});
|
|
|
|
it("caps history at MAX_HISTORY and can still undo that many times", () => {
|
|
for (let i = 0; i < MAX_HISTORY + 10; i++) {
|
|
useCardStore.getState().addLayer("face", textLayer(`L${i}`));
|
|
}
|
|
expect(useCardStore.getState().past.length).toBe(MAX_HISTORY);
|
|
|
|
let undos = 0;
|
|
while (useCardStore.getState().canUndo()) {
|
|
useCardStore.getState().undo();
|
|
undos++;
|
|
}
|
|
expect(undos).toBe(MAX_HISTORY);
|
|
});
|
|
|
|
it("undo/redo are no-ops at the ends", () => {
|
|
expect(() => useCardStore.getState().undo()).not.toThrow();
|
|
expect(() => useCardStore.getState().redo()).not.toThrow();
|
|
expect(useCardStore.getState().card?.face.layers).toHaveLength(0);
|
|
});
|
|
});
|