feat(state): implement practitioner localStorage cache

This commit is contained in:
Bastien Chanot committed 2026-05-18 21:06:18 +02:00
1 parent 1c51c672e8
commit 86f65767de
2 files changed
+56 -22

No files matched your search

@@ -0,0 +1,33 @@
import { describe, it, expect, beforeEach } from 'vitest'
import {
readCachedPractitioner,
writeCachedPractitioner,
clearPractitionerCache,
} from '@/state/practitionerCache'
beforeEach(() => localStorage.clear())
describe('practitionerCache', () => {
it('returns undefined when empty', () => {
expect(readCachedPractitioner()).toBeUndefined()
})
it('round-trips a valid practitioner', () => {
writeCachedPractitioner({ name: 'Dr. Dupont', cabinet: 'Clinic A' })
expect(readCachedPractitioner()).toEqual({
name: 'Dr. Dupont',
cabinet: 'Clinic A',
})
})
it('returns undefined on malformed JSON', () => {
localStorage.setItem('osteo:lastPractitioner', 'not-json')
expect(readCachedPractitioner()).toBeUndefined()
})
it('clear removes the entry', () => {
writeCachedPractitioner({ name: 'Dr. Dupont' })
clearPractitionerCache()
expect(readCachedPractitioner()).toBeUndefined()
})
})