mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
fix(native): keep a chosen language on the app sign-in screen
The sign-in screen in the app now speaks the device language only when no language was chosen before, so the screen and the signed-in session match what the next launch shows.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-LOGIN-NATIVE-001 to FE-LOGIN-NATIVE-011: useLogin inside the iOS/Android app
|
||||
// FE-LOGIN-NATIVE-001 to FE-LOGIN-NATIVE-012: useLogin inside the iOS/Android app
|
||||
import { startAuthentication } from '@simplewebauthn/browser';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import React from 'react';
|
||||
@@ -166,8 +166,7 @@ describe('useLogin in the native app', () => {
|
||||
expect(result.current.showTakeoff).toBe(false);
|
||||
});
|
||||
|
||||
it('FE-LOGIN-NATIVE-009: speaks the device language, over a language once picked on this page', async () => {
|
||||
localStorage.setItem('app_language', 'fr');
|
||||
it('FE-LOGIN-NATIVE-009: speaks the device language when no language was chosen', async () => {
|
||||
deviceLanguages(['de-DE', 'en-US']);
|
||||
renderLogin();
|
||||
await waitFor(() => expect(useSettingsStore.getState().settings.language).toBe('de'));
|
||||
@@ -190,4 +189,13 @@ describe('useLogin in the native app', () => {
|
||||
await waitFor(() => expect(mockNavigate).toHaveBeenCalledWith('/'), { timeout: 2500 });
|
||||
expect(document.documentElement.hasAttribute('data-app-handover')).toBe(true);
|
||||
});
|
||||
|
||||
it('FE-LOGIN-NATIVE-012: keeps a language once picked on this page over the device language', async () => {
|
||||
localStorage.setItem('app_language', 'fr');
|
||||
useSettingsStore.setState((state) => ({ settings: { ...state.settings, language: 'fr' } }));
|
||||
deviceLanguages(['de-DE', 'en-US']);
|
||||
const { result } = renderLogin();
|
||||
await waitFor(() => expect(result.current.appConfig).not.toBeNull());
|
||||
expect(useSettingsStore.getState().settings.language).toBe('fr');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -300,16 +300,16 @@ export function useLogin() {
|
||||
// 2. Browser/OS language (navigator.languages)
|
||||
// 3. Server default (DEFAULT_LANGUAGE env var)
|
||||
// 4. 'en' → hardcoded fallback already in store
|
||||
// Inside the iOS and Android app the sign-in screen has no language menu: it
|
||||
// speaks the device's language, as the address screen before it does, and
|
||||
// English where TREK has no translation for it. The account's own language
|
||||
// takes over once signed in.
|
||||
// Inside the iOS and Android app the sign-in screen has no language menu: unless
|
||||
// a language was chosen before, it speaks the device's language, as the address
|
||||
// screen before it does, and English where TREK has no translation for it. The
|
||||
// account's own language takes over once signed in.
|
||||
useEffect(() => {
|
||||
if (hasStoredLanguage()) return
|
||||
if (nativeApp) {
|
||||
setLanguageTransient(detectBrowserLanguage() ?? 'en')
|
||||
return
|
||||
}
|
||||
if (hasStoredLanguage()) return
|
||||
|
||||
const detected = detectBrowserLanguage()
|
||||
if (detected) {
|
||||
|
||||
Reference in New Issue
Block a user