Protect util handling, update test

This commit is contained in:
Eric Bailey
2024-09-17 10:06:48 -05:00
parent bc46ae65df
commit ec847816c1
3 changed files with 7 additions and 2 deletions
+2 -1
View File
@@ -188,9 +188,10 @@ export function fixLegacyLanguageCode(code: string | null): string | null {
*
* If no match, returns `en`.
*/
export function findSupportedAppLanguage(languageTags: string[]) {
export function findSupportedAppLanguage(languageTags: (string | undefined)[]) {
const supported = new Set(Object.values(AppLanguage))
for (const tag of languageTags) {
if (!tag) continue
if (supported.has(tag as AppLanguage)) {
return tag
}
+1 -1
View File
@@ -146,7 +146,7 @@ export const defaults: Schema = {
.slice(0, 6),
// try full language tag first, then fallback to language code
appLanguage: findSupportedAppLanguage([
deviceLocales[0].languageTag,
deviceLocales.at(0)?.languageTag,
deviceLanguageCodes[0],
]),
},
@@ -10,6 +10,10 @@ jest.mock('jwt-decode', () => ({
},
}))
jest.mock('expo-localization', () => ({
getLocales: () => [],
}))
describe('session', () => {
it('can log in and out', () => {
let state = getInitialState([])