-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This removes the need of fetching user settings in the i18n initialisation. Apps typically need to fetch user settings for other uses, so the locale can be passed from the app to the shim reducing the number of (mostly identical) requests for user settings.
- Loading branch information
Showing
5 changed files
with
65 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { renderHook } from '@testing-library/react-hooks' | ||
import * as alld2 from 'd2' | ||
import { useD2 } from '../useD2' | ||
|
||
jest.mock('@dhis2/app-runtime', () => { | ||
return { | ||
useConfig: () => { | ||
return { | ||
baseUrl: 'baseurl', | ||
apiVersion: '42', | ||
} | ||
}, | ||
} | ||
}) | ||
|
||
describe('useD2 with locale', () => { | ||
it('sets the language from the given locale', async () => { | ||
const initSpy = jest.spyOn(alld2, 'init').mockResolvedValue('d2obj') | ||
const userSettingsSpy = jest | ||
.spyOn(alld2, 'getUserSettings') | ||
.mockResolvedValue({ | ||
keyUiLocale: 'no', | ||
}) | ||
const spy = jest.spyOn(alld2.config.i18n.sources, 'add') | ||
const { waitForNextUpdate } = renderHook(() => | ||
useD2({ | ||
d2Config: { schemas: ['schema1'] }, | ||
i18nRoot: 'i18n_old', | ||
locale: 'it', | ||
}) | ||
) | ||
|
||
await waitForNextUpdate() | ||
|
||
expect(userSettingsSpy).toHaveBeenCalledTimes(0) | ||
|
||
expect(spy).toHaveBeenCalledWith('i18n_old/i18n_module_it.properties') | ||
|
||
jest.restoreAllMocks() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters