@@ -3,15 +3,19 @@ import React, { useMemo } from 'react';
33import renderer from 'react-test-renderer' ;
44import { render , screen } from '@testing-library/react' ;
55import userEvent from '@testing-library/user-event' ;
6- import { IntlProvider } from '@edx/frontend-platform/i18n' ;
6+ import { IntlProvider , changeUserSessionLanguage } from '@edx/frontend-platform/i18n' ;
77import { AppContext } from '@edx/frontend-platform/react' ;
88import { initializeMockApp } from '@edx/frontend-platform/testing' ;
99
10- import Footer from './Footer' ;
1110import FooterSlot from '../plugin-slots/FooterSlot' ;
1211import StudioFooterHelpSectionSlot from '../plugin-slots/StudioFooterHelpSectionSlot' ;
1312
14- const FooterWithContext = ( { locale = 'es' } ) => {
13+ jest . mock ( '@edx/frontend-platform/i18n' , ( ) => ( {
14+ ...jest . requireActual ( '@edx/frontend-platform/i18n' ) ,
15+ changeUserSessionLanguage : jest . fn ( ) ,
16+ } ) ) ;
17+
18+ const FooterWithContext = ( { locale = 'en' } ) => {
1519 const contextValue = useMemo ( ( ) => ( {
1620 authenticatedUser : null ,
1721 config : {
@@ -31,64 +35,24 @@ const FooterWithContext = ({ locale = 'es' }) => {
3135 ) ;
3236} ;
3337
34- const { LANGUAGE_PREFERENCE_COOKIE_NAME } = process . env ;
35- const FooterWithLanguageSelector = ( { authenticatedUser = null } ) => {
36- const contextValue = useMemo ( ( ) => ( {
37- authenticatedUser,
38- config : {
39- ENABLE_FOOTER_LANG_SELECTOR : true ,
40- LANGUAGE_PREFERENCE_COOKIE_NAME ,
41- LOGO_TRADEMARK_URL : process . env . LOGO_TRADEMARK_URL ,
42- LMS_BASE_URL : process . env . LMS_BASE_URL ,
43- SITE_SUPPORTED_LANGUAGES : [ 'es' , 'en' ] ,
44- } ,
45- } ) , [ authenticatedUser ] ) ;
46-
47- return (
48- < IntlProvider locale = "en" >
49- < AppContext . Provider
50- value = { contextValue }
51- >
52- < Footer />
53- </ AppContext . Provider >
54- </ IntlProvider >
55- ) ;
56- } ;
57-
5838describe ( '<Footer />' , ( ) => {
59- describe ( 'renders correctly' , ( ) => {
60- it ( 'renders without a language selector' , ( ) => {
61- const tree = renderer
62- . create ( < FooterWithContext locale = "en" /> )
63- . toJSON ( ) ;
64- expect ( tree ) . toMatchSnapshot ( ) ;
65- } ) ;
66- it ( 'renders without a language selector in es' , ( ) => {
67- const tree = renderer
68- . create ( < FooterWithContext locale = "es" /> )
69- . toJSON ( ) ;
70- expect ( tree ) . toMatchSnapshot ( ) ;
71- } ) ;
72- it ( 'renders with a language selector' , ( ) => {
73- initializeMockApp ( ) ;
74- const tree = renderer
75- . create ( < FooterWithLanguageSelector /> )
76- . toJSON ( ) ;
77- expect ( tree ) . toMatchSnapshot ( ) ;
78- } ) ;
39+ beforeEach ( ( ) => { initializeMockApp ( ) ; } ) ;
40+
41+ it ( 'renders correctly' , ( ) => {
42+ const tree = renderer
43+ . create ( < FooterWithContext /> )
44+ . toJSON ( ) ;
45+ expect ( tree ) . toMatchSnapshot ( ) ;
7946 } ) ;
8047
81- describe ( 'handles language switching' , ( ) => {
82- it ( 'calls onLanguageSelected prop when a language is changed' , async ( ) => {
83- const user = userEvent . setup ( ) ;
84- const mockHandleLanguageSelected = jest . fn ( ) ;
85- render ( < FooterWithLanguageSelector languageSelected = { mockHandleLanguageSelected } /> ) ;
48+ it ( 'handles language switching' , async ( ) => {
49+ const user = userEvent . setup ( ) ;
50+ render ( < FooterWithContext /> ) ;
8651
87- await user . selectOptions ( screen . getByRole ( 'combobox ' ) , 'es ' ) ;
88- await user . click ( screen . getByTestId ( 'site-footer-submit-btn' ) ) ;
52+ await user . click ( screen . getByRole ( 'button ' ) , 'English ' ) ;
53+ await user . click ( screen . getByRole ( 'button' , { name : 'Español (Latinoamérica)' } ) ) ;
8954
90- expect ( mockHandleLanguageSelected ) . toHaveBeenCalledWith ( 'es' ) ;
91- } ) ;
55+ expect ( changeUserSessionLanguage ) . toHaveBeenCalledWith ( 'es-419' ) ;
9256 } ) ;
9357} ) ;
9458
0 commit comments