test(quick-261016-0fm): theme switch, language switcher and footer offset
- theme: light and dark ignore prefers-color-scheme, choices and guard - i18n: ?locale= only with a preference, availableLocales from meta - usePreferences: cache validation, cycle order and PUT bodies, revert with a danger toast, profile apply, setLocale save, cache and reload - rail theme button, user menu language group, --shell-offset and the form save bar offset; fixture strings and resetState theme reset
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest'
|
||||
import {
|
||||
availableLocales,
|
||||
currentLocale,
|
||||
interpolate,
|
||||
loadStrings,
|
||||
@@ -9,7 +10,7 @@ import {
|
||||
t,
|
||||
tc,
|
||||
} from '../../src/app/i18n'
|
||||
import { API, mockApi, requestsTo } from '../helpers'
|
||||
import { API, mockApi, queryOf, requestsTo } from '../helpers'
|
||||
import { langFixture } from '../fixtures/typed'
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -128,6 +129,29 @@ describe('loadStrings', () => {
|
||||
expect(currentLocale.value).toBe('en')
|
||||
})
|
||||
|
||||
it('sends the preferred locale as ?locale= and keeps meta.locales', async () => {
|
||||
const calls = mockApi({
|
||||
[`GET ${API}/lang`]: { body: { data: {}, meta: { locale: 'en', locales: ['en', 'pl'] } } },
|
||||
})
|
||||
await loadStrings('en')
|
||||
const [request] = requestsTo(calls, 'GET', `${API}/lang`)
|
||||
expect(queryOf(request!).get('locale')).toBe('en')
|
||||
expect(availableLocales.value).toEqual(['en', 'pl'])
|
||||
expect(currentLocale.value).toBe('en')
|
||||
})
|
||||
|
||||
it('sends no locale without a preference and follows a shorter meta.locales', async () => {
|
||||
const calls = mockApi({
|
||||
[`GET ${API}/lang`]: { body: { data: {}, meta: { locale: 'pl', locales: ['pl'] } } },
|
||||
})
|
||||
await loadStrings()
|
||||
await loadStrings('')
|
||||
for (const request of requestsTo(calls, 'GET', `${API}/lang`)) {
|
||||
expect(queryOf(request).has('locale')).toBe(false)
|
||||
}
|
||||
expect(availableLocales.value).toEqual(['pl'])
|
||||
})
|
||||
|
||||
it('keeps the current strings when the bundle cannot be loaded', async () => {
|
||||
mockApi({ [`GET ${API}/lang`]: { status: 500, body: { error: { code: 'server', message: 'x', details: {} } } } })
|
||||
await loadStrings()
|
||||
|
||||
Reference in New Issue
Block a user