feat(i18n): add fr/en dicts + useT hook

This commit is contained in:
Bastien Chanot committed 2026-05-20 07:00:31 +02:00
1 parent a57047505d
commit 359104ce88
6 files changed
+358

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { renderHook, act } from '@testing-library/react'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
beforeEach(() => {
useLocaleStore.setState({ locale: 'fr' })
})
describe('useT', () => {
it('returns the FR value for a known key', () => {
const { result } = renderHook(() => useT())
expect(result.current('common.cancel')).toBe('Annuler')
})
it('returns the EN value after switching locale', () => {
const { result } = renderHook(() => useT())
act(() => useLocaleStore.getState().setLocale('en'))
expect(result.current('common.cancel')).toBe('Cancel')
})
it('returns the key literal and warns when key is missing', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
const { result } = renderHook(() => useT())
expect(result.current('nonexistent.key')).toBe('nonexistent.key')
expect(warn).toHaveBeenCalled()
warn.mockRestore()
})
})