diff --git a/src/components/Footer.jsx b/src/components/Footer.jsx
index 833a88eca..309958b0a 100644
--- a/src/components/Footer.jsx
+++ b/src/components/Footer.jsx
@@ -138,7 +138,7 @@ class SiteFooter extends React.Component {
{config.ENABLE_FOOTER_LANG_SELECTOR && (
-
+
', () => {
initializeMockApp();
render();
- await fireEvent.submit(screen.getByTestId('site-footer-submit-btn'), {
- target: {
- elements: {
- 'site-footer-language-select': {
- value: 'pt-pt',
- },
- },
- },
+ await waitFor(() => {
+ document.querySelector('.language-selector');
+ });
+ expect(document.querySelectorAll('.language-selector').length).toBe(1);
+
+ document.querySelector('.language-selector>button').click();
+
+ Array.from(document.querySelectorAll('.dropdown-menu.show a')).filter((e) => e.innerHTML === 'Português')[0].click();
+
+ await waitFor(() => {
+ expect(patchPreferences).toHaveBeenCalledWith('user123', { prefLang: 'pt-pt' });
+ });
+ await waitFor(() => {
+ expect(postSetLang).toHaveBeenCalledWith('pt-pt');
});
- expect(patchPreferences).toHaveBeenCalledWith('user123', { prefLang: 'pt-pt' });
- expect(postSetLang).toHaveBeenCalledWith('pt-pt');
});
});
});
diff --git a/src/components/LanguageSelector.jsx b/src/components/LanguageSelector.jsx
index 5c000c60d..4afa67275 100644
--- a/src/components/LanguageSelector.jsx
+++ b/src/components/LanguageSelector.jsx
@@ -25,58 +25,57 @@ const onLanguageSelected = async (username, selectedLanguageCode) => {
};
const LanguageSelector = ({
- intl, options, authenticatedUser, compact, ...props
+ intl, options, authenticatedUser, compact,
}) => {
-
const languageLabel = (languageCode) => {
- const option = options.find( ({ value, label }) => value === languageCode )
- return option ? option.label : null
- }
+ const option = options.find(({ value }) => value === languageCode);
+ return option ? option.label : null;
+ };
const handleChange = (languageCode, event) => {
const previousSiteLanguage = getLocale();
+ /* eslint-disable no-console */
console.debug(previousSiteLanguage, languageCode, authenticatedUser);
if (previousSiteLanguage !== languageCode) {
onLanguageSelected(authenticatedUser?.username, languageCode);
}
- event.target.parentElement.parentElement.querySelector(".languageLabel").innerHTML = languageLabel(languageCode);
+ const languageLabelElement = event.target.parentElement.parentElement.querySelector('.languageLabel');
+ languageLabelElement.innerHTML = languageLabel(languageCode);
};
- const currentLangLabel = languageLabel(intl.locale)
- const showLabel = !Boolean(compact || false);
+ const currentLangLabel = languageLabel(intl.locale);
+ const showLabel = !(compact || false);
return (
- <>
-
-
-
- {showLabel && (
- currentLangLabel ? (
-
- {currentLangLabel}
-
- ) : (
-
-
-
- )
- )}
-
-
+
+
+
+ {showLabel && (
+ currentLangLabel ? (
+
+ {currentLangLabel}
+
+ ) : (
+
+
+
+ )
+ )}
+
+
{options.map(({ value, label }) => (
{label}
))}
-
-
- >
+
+
);
};
@@ -92,4 +91,8 @@ LanguageSelector.propTypes = {
})).isRequired,
};
+LanguageSelector.defaultProps = {
+ compact: false,
+};
+
export default injectIntl(LanguageSelector);
diff --git a/src/components/__snapshots__/Footer.test.jsx.snap b/src/components/__snapshots__/Footer.test.jsx.snap
index 650c518e3..c731e9f1b 100644
--- a/src/components/__snapshots__/Footer.test.jsx.snap
+++ b/src/components/__snapshots__/Footer.test.jsx.snap
@@ -36,46 +36,47 @@ exports[` renders correctly renders with a language selector 1`] = `
- FCT|FCCN
All rights reserved
-
-