Protect util handling, update test
This commit is contained in:
@@ -188,9 +188,10 @@ export function fixLegacyLanguageCode(code: string | null): string | null {
|
|||||||
*
|
*
|
||||||
* If no match, returns `en`.
|
* If no match, returns `en`.
|
||||||
*/
|
*/
|
||||||
export function findSupportedAppLanguage(languageTags: string[]) {
|
export function findSupportedAppLanguage(languageTags: (string | undefined)[]) {
|
||||||
const supported = new Set(Object.values(AppLanguage))
|
const supported = new Set(Object.values(AppLanguage))
|
||||||
for (const tag of languageTags) {
|
for (const tag of languageTags) {
|
||||||
|
if (!tag) continue
|
||||||
if (supported.has(tag as AppLanguage)) {
|
if (supported.has(tag as AppLanguage)) {
|
||||||
return tag
|
return tag
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ export const defaults: Schema = {
|
|||||||
.slice(0, 6),
|
.slice(0, 6),
|
||||||
// try full language tag first, then fallback to language code
|
// try full language tag first, then fallback to language code
|
||||||
appLanguage: findSupportedAppLanguage([
|
appLanguage: findSupportedAppLanguage([
|
||||||
deviceLocales[0].languageTag,
|
deviceLocales.at(0)?.languageTag,
|
||||||
deviceLanguageCodes[0],
|
deviceLanguageCodes[0],
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ jest.mock('jwt-decode', () => ({
|
|||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
jest.mock('expo-localization', () => ({
|
||||||
|
getLocales: () => [],
|
||||||
|
}))
|
||||||
|
|
||||||
describe('session', () => {
|
describe('session', () => {
|
||||||
it('can log in and out', () => {
|
it('can log in and out', () => {
|
||||||
let state = getInitialState([])
|
let state = getInitialState([])
|
||||||
|
|||||||
Reference in New Issue
Block a user