Localize macOS application menu and correct AITURK package checks
This commit is contained in:
@@ -30,6 +30,42 @@ describe('I18nProvider', () => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('keeps the native menu aligned with loaded, optimistic and rolled-back language', async () => {
|
||||
const original = window.hermesDesktop
|
||||
const setUiLanguage = vi.fn()
|
||||
window.hermesDesktop = { ...original, setUiLanguage }
|
||||
let rejectSave: (error: Error) => void = () => undefined
|
||||
|
||||
const configClient: I18nConfigClient = {
|
||||
getConfig: vi.fn().mockResolvedValue({ display: { language: 'en' } }),
|
||||
saveConfig: vi.fn().mockImplementation(
|
||||
() =>
|
||||
new Promise((_resolve, reject) => {
|
||||
rejectSave = reject
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
try {
|
||||
render(
|
||||
<I18nProvider configClient={configClient}>
|
||||
<LanguageProbe target="tr" />
|
||||
</I18nProvider>
|
||||
)
|
||||
await waitFor(() => expect(setUiLanguage).toHaveBeenLastCalledWith('en'))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'switch' }))
|
||||
await waitFor(() => expect(configClient.saveConfig).toHaveBeenCalledTimes(1))
|
||||
expect(setUiLanguage).toHaveBeenLastCalledWith('tr')
|
||||
rejectSave(new Error('Cannot save language'))
|
||||
await waitFor(() => expect(screen.getByTestId('save-error').textContent).toBe('Cannot save language'))
|
||||
expect(setUiLanguage).toHaveBeenLastCalledWith('en')
|
||||
expect(screen.getByTestId('locale').textContent).toBe('en')
|
||||
} finally {
|
||||
cleanup()
|
||||
window.hermesDesktop = original
|
||||
}
|
||||
})
|
||||
|
||||
it('defaults to Turkish without a config client', () => {
|
||||
render(
|
||||
<I18nProvider configClient={null}>
|
||||
|
||||
@@ -105,6 +105,10 @@ export function I18nProvider({ children, configClient = defaultConfigClient, ini
|
||||
localeRef.current = locale
|
||||
setRuntimeI18nLocale(locale)
|
||||
applyDocumentLocale(locale)
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.hermesDesktop?.setUiLanguage?.(locale)
|
||||
}
|
||||
}, [locale])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user