Skip to content

Commit 3c21707

Browse files
committed
refactor: simplify imports and use getSupportedLocaleList
1 parent 8390c1e commit 3c21707

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

src/language-selector/LanguageSelector.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import PropTypes from 'prop-types';
2-
import React, { useContext, useState } from 'react';
2+
import React, { useState } from 'react';
33

4-
import { changeUserSessionLanguage, getPrimaryLanguageSubtag, injectIntl } from '@edx/frontend-platform/i18n';
4+
import {
5+
changeUserSessionLanguage,
6+
getSupportedLocaleList,
7+
getPrimaryLanguageSubtag,
8+
injectIntl,
9+
} from '@edx/frontend-platform/i18n';
510
import { getLocale } from '@edx/frontend-platform/i18n/lib';
6-
import { AppContext } from '@edx/frontend-platform/react';
711
import { Dropdown } from '@openedx/paragon';
812
import { Language } from '@openedx/paragon/icons';
913

@@ -37,9 +41,7 @@ const getDisplayName = (locale) => {
3741
* @requires config.LANGUAGE_PREFERENCE_COOKIE_NAME - Cookie name for storing language preference
3842
*/
3943
const LanguageSelector = ({ className }) => {
40-
const { config } = useContext(AppContext);
41-
42-
const languageOptions = config.SITE_SUPPORTED_LANGUAGES;
44+
const languageOptions = getSupportedLocaleList();
4345
const [currentLocale, setCurrentLocale] = useState(getLocale());
4446

4547
/**

src/language-selector/LanguageSelector.test.jsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { mergeConfig } from '@edx/frontend-platform';
33
import { getLocale } from '@edx/frontend-platform/i18n/lib';
4-
import { changeUserSessionLanguage } from '@edx/frontend-platform/i18n';
4+
import { changeUserSessionLanguage, getSupportedLocaleList } from '@edx/frontend-platform/i18n';
55
import {
66
act, fireEvent, initializeMockApp, render, screen,
77
} from '../setupTest';
@@ -10,6 +10,7 @@ import LanguageSelector from './LanguageSelector';
1010
jest.mock('@edx/frontend-platform/i18n', () => ({
1111
...jest.requireActual('@edx/frontend-platform/i18n'),
1212
changeUserSessionLanguage: jest.fn().mockResolvedValue({}),
13+
getSupportedLocaleList: jest.fn(),
1314
}));
1415

1516
jest.mock('@edx/frontend-platform/i18n/lib', () => ({
@@ -29,33 +30,21 @@ jest.mock('@openedx/paragon', () => ({
2930
const LANGUAGE_PREFERENCE_COOKIE_NAME = 'language-preference';
3031

3132
describe('LanguageSelector', () => {
32-
let mockReload;
33-
3433
beforeEach(() => {
3534
jest.clearAllMocks();
3635

3736
mergeConfig({
3837
ENABLE_HEADER_LANG_SELECTOR: true,
3938
LANGUAGE_PREFERENCE_COOKIE_NAME,
40-
SITE_SUPPORTED_LANGUAGES: ['es', 'en'],
4139
});
42-
40+
getSupportedLocaleList.mockReturnValue(['es', 'en']);
4341
initializeMockApp();
4442

45-
mockReload = jest.fn();
46-
Object.defineProperty(window, 'location', {
47-
configurable: true,
48-
writable: true,
49-
value: { reload: mockReload },
50-
});
51-
5243
global.innerWidth = 1200;
5344
});
5445

5546
it('should not render when no supported languages are available', () => {
56-
mergeConfig({
57-
SITE_SUPPORTED_LANGUAGES: [],
58-
});
47+
getSupportedLocaleList.mockReturnValue([]);
5948

6049
const { container } = render(<LanguageSelector />);
6150
// expect(container).toMatchSnapshot('no-supported-languages');

src/learning-header/LearningHeader.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext } from 'react';
1+
import { useContext } from 'react';
22
import PropTypes from 'prop-types';
33
import { getConfig } from '@edx/frontend-platform';
44
import { useIntl } from '@edx/frontend-platform/i18n';

0 commit comments

Comments
 (0)