test(01-01): add failing tests for IndexedDB wrapper

- Tests for openDB with 5 stores, progress CRUD, settings CRUD
- Tests for null return on empty DB
- RED phase: implementation not yet created

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-29 11:01:40 +02:00
co-authored by Claude Opus 4.6
parent 4dc9523044
commit 35c1ef1b80
+60
View File
@@ -0,0 +1,60 @@
import "fake-indexeddb/auto";
import { describe, expect, it, beforeEach } from "vitest";
import { openDB, getProgress, saveProgress, getSettings, saveSettings } from "./db";
import type { Progress, Settings } from "../types";
describe("IndexedDB wrapper", () => {
let db: IDBDatabase;
beforeEach(async () => {
// Each test gets a fresh database by using a unique name
// fake-indexeddb/auto resets between tests in vitest
db = await openDB();
});
it("openDB resolves to an IDBDatabase with 5 object store names", () => {
const storeNames = Array.from(db.objectStoreNames);
expect(storeNames).toHaveLength(5);
expect(storeNames).toContain("progress");
expect(storeNames).toContain("companionAssets");
expect(storeNames).toContain("styleReference");
expect(storeNames).toContain("forestElements");
expect(storeNames).toContain("settings");
});
it("saveProgress then getProgress returns same data", async () => {
const progress: Progress = {
id: 1,
currentLevel: 1,
completedLevels: [],
totalSessions: 0,
sessionDates: [],
selectedCharacter: "fee",
selectedLayout: "de",
};
await saveProgress(db, progress);
const result = await getProgress(db);
expect(result).toEqual(progress);
});
it("saveSettings then getSettings returns same data", async () => {
const settings: Settings = {
id: 1,
audioEnabled: true,
apiKey: "test-key",
};
await saveSettings(db, settings);
const result = await getSettings(db);
expect(result).toEqual(settings);
});
it("getProgress on empty DB returns null", async () => {
const result = await getProgress(db);
expect(result).toBeNull();
});
it("getSettings on empty DB returns null", async () => {
const result = await getSettings(db);
expect(result).toBeNull();
});
});