feat(i18n): add localeStore with localStorage persistence

This commit is contained in:
Bastien Chanot committed 2026-05-20 06:55:43 +02:00
1 parent 0a05c479a0
commit a57047505d
3 files changed
+53

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { useLocaleStore, LOCALE_STORAGE_KEY } from '@/state/localeStore'
beforeEach(() => {
localStorage.removeItem(LOCALE_STORAGE_KEY)
useLocaleStore.setState({ locale: 'fr' })
})
describe('localeStore', () => {
it('defaults to fr when localStorage is empty', () => {
expect(useLocaleStore.getState().locale).toBe('fr')
})
it('setLocale updates state', () => {
useLocaleStore.getState().setLocale('en')
expect(useLocaleStore.getState().locale).toBe('en')
})
it('setLocale writes to localStorage', () => {
useLocaleStore.getState().setLocale('en')
expect(localStorage.getItem(LOCALE_STORAGE_KEY)).toBe('en')
})
})