feat: add valibot

This commit is contained in:
Julien Calixte
2026-06-17 10:20:40 +02:00
parent 362a448848
commit 64efc91392
6 changed files with 130 additions and 69 deletions

View File

@@ -34,6 +34,18 @@ describe('useMacroplan — load & migration', () => {
expect(m.source.value).toBe(SAMPLE_PLAN)
})
it('falls back to a fresh sample when the stored library shape is malformed', () => {
// Valid JSON, wrong shape: a plan missing its `source` — would have slipped
// through the old blind `as Library` cast.
localStorage.setItem(
LIB_KEY,
JSON.stringify({ version: 1, activeId: 'x', plans: [{ id: 'x', name: 'Bad' }] }),
)
const m = useMacroplan()
expect(m.plans.value).toHaveLength(1)
expect(m.source.value).toBe(SAMPLE_PLAN)
})
it('repairs a stale activeId instead of discarding the stored plans', () => {
localStorage.setItem(
LIB_KEY,
@@ -70,13 +82,13 @@ describe('useMacroplan — active plan binding', () => {
})
describe('useMacroplan — CRUD', () => {
it('newPlan appends a sample plan and activates it', () => {
it('newPlan appends a blank plan and activates it (the sample only seeds an empty library)', () => {
const m = useMacroplan()
const firstId = m.activeId.value
m.newPlan()
expect(m.plans.value).toHaveLength(2)
expect(m.activeId.value).not.toBe(firstId)
expect(m.source.value).toBe(SAMPLE_PLAN)
expect(m.source.value).toBe('') // blank page, not a copy of the sample
})
it('deletePlan removes the active plan and re-points to the preceding one', () => {