|
4 | 4 | getPrimaryLanguageSubtag, |
5 | 5 | getLocale, |
6 | 6 | getMessages, |
| 7 | + getSupportedLocales, |
7 | 8 | isRtl, |
8 | 9 | handleRtl, |
9 | 10 | getCookies, |
@@ -184,6 +185,40 @@ describe('lib', () => { |
184 | 185 | }); |
185 | 186 | }); |
186 | 187 |
|
| 188 | + describe('getSupportedLocales', () => { |
| 189 | + beforeEach(() => { |
| 190 | + configure({ |
| 191 | + loggingService: { logError: jest.fn() }, |
| 192 | + config: { |
| 193 | + ENVIRONMENT: 'production', |
| 194 | + LANGUAGE_PREFERENCE_COOKIE_NAME: 'yum', |
| 195 | + }, |
| 196 | + messages: { |
| 197 | + 'es-419': { message: 'es-hah' }, |
| 198 | + de: { message: 'de-hah' }, |
| 199 | + 'en-us': { message: 'en-us-hah' }, |
| 200 | + fr: { message: 'fr-hah' }, |
| 201 | + }, |
| 202 | + }); |
| 203 | + }); |
| 204 | + |
| 205 | + it('should return an array of supported locale codes', () => { |
| 206 | + const supportedLocales = getSupportedLocales(); |
| 207 | + expect(Array.isArray(supportedLocales)).toBe(true); |
| 208 | + expect(supportedLocales).toEqual(['es-419', 'de', 'en-us', 'fr']); |
| 209 | + }); |
| 210 | + |
| 211 | + it('should throw an error if i18n is not configured', () => { |
| 212 | + // Reset the configuration to null |
| 213 | + jest.resetModules(); |
| 214 | + const { getSupportedLocales: freshGetSupportedLocales } = require('./lib'); |
| 215 | + |
| 216 | + expect(() => freshGetSupportedLocales()).toThrow( |
| 217 | + 'getSupportedLocales called before configuring i18n. Call configure with messages first.' |
| 218 | + ); |
| 219 | + }); |
| 220 | + }); |
| 221 | + |
187 | 222 | describe('isRtl', () => { |
188 | 223 | it('should be true for RTL languages', () => { |
189 | 224 | expect(isRtl('ar')).toBe(true); |
|
0 commit comments