1+ /* eslint-disable react/prop-types */
12import React from 'react' ;
23import { IntlProvider } from '@edx/frontend-platform/i18n' ;
34import TestRenderer from 'react-test-renderer' ;
@@ -6,119 +7,95 @@ import { Context as ResponsiveContext } from 'react-responsive';
67
78import Header from './index' ;
89
10+ const HeaderComponent = ( { width, contextValue } ) => (
11+ < ResponsiveContext . Provider value = { width } >
12+ < IntlProvider locale = "en" messages = { { } } >
13+ < AppContext . Provider
14+ value = { contextValue }
15+ >
16+ < Header />
17+ </ AppContext . Provider >
18+ </ IntlProvider >
19+ </ ResponsiveContext . Provider >
20+ ) ;
21+
922describe ( '<Header />' , ( ) => {
1023 it ( 'renders correctly for anonymous desktop' , ( ) => {
11- const component = (
12- < ResponsiveContext . Provider value = { { width : 1280 } } >
13- < IntlProvider locale = "en" messages = { { } } >
14- < AppContext . Provider
15- value = { {
16- authenticatedUser : null ,
17- config : {
18- LMS_BASE_URL : process . env . LMS_BASE_URL ,
19- SITE_NAME : process . env . SITE_NAME ,
20- LOGIN_URL : process . env . LOGIN_URL ,
21- LOGOUT_URL : process . env . LOGOUT_URL ,
22- LOGO_URL : process . env . LOGO_URL ,
23- } ,
24- } }
25- >
26- < Header />
27- </ AppContext . Provider >
28- </ IntlProvider >
29- </ ResponsiveContext . Provider >
30- ) ;
24+ const contextValue = {
25+ authenticatedUser : null ,
26+ config : {
27+ LMS_BASE_URL : process . env . LMS_BASE_URL ,
28+ SITE_NAME : process . env . SITE_NAME ,
29+ LOGIN_URL : process . env . LOGIN_URL ,
30+ LOGOUT_URL : process . env . LOGOUT_URL ,
31+ LOGO_URL : process . env . LOGO_URL ,
32+ } ,
33+ } ;
34+ const component = < HeaderComponent width = { { width : 1280 } } contextValue = { contextValue } /> ;
3135
3236 const wrapper = TestRenderer . create ( component ) ;
3337
3438 expect ( wrapper . toJSON ( ) ) . toMatchSnapshot ( ) ;
3539 } ) ;
3640
3741 it ( 'renders correctly for authenticated desktop' , ( ) => {
38- const component = (
39- < ResponsiveContext . Provider value = { { width : 1280 } } >
40- < IntlProvider locale = "en" messages = { { } } >
41- < AppContext . Provider
42- value = { {
43- authenticatedUser : {
44- userId : 'abc123' ,
45- username : 'edX' ,
46- roles : [ ] ,
47- administrator : false ,
48- } ,
49- config : {
50- LMS_BASE_URL : process . env . LMS_BASE_URL ,
51- SITE_NAME : process . env . SITE_NAME ,
52- LOGIN_URL : process . env . LOGIN_URL ,
53- LOGOUT_URL : process . env . LOGOUT_URL ,
54- LOGO_URL : process . env . LOGO_URL ,
55- } ,
56- } }
57- >
58- < Header />
59- </ AppContext . Provider >
60- </ IntlProvider >
61- </ ResponsiveContext . Provider >
62- ) ;
42+ const contextValue = {
43+ authenticatedUser : {
44+ userId : 'abc123' ,
45+ username : 'edX' ,
46+ roles : [ ] ,
47+ administrator : false ,
48+ } ,
49+ config : {
50+ LMS_BASE_URL : process . env . LMS_BASE_URL ,
51+ SITE_NAME : process . env . SITE_NAME ,
52+ LOGIN_URL : process . env . LOGIN_URL ,
53+ LOGOUT_URL : process . env . LOGOUT_URL ,
54+ LOGO_URL : process . env . LOGO_URL ,
55+ } ,
56+ } ;
57+ const component = < HeaderComponent width = { { width : 1280 } } contextValue = { contextValue } /> ;
6358
6459 const wrapper = TestRenderer . create ( component ) ;
6560
6661 expect ( wrapper . toJSON ( ) ) . toMatchSnapshot ( ) ;
6762 } ) ;
6863
6964 it ( 'renders correctly for anonymous mobile' , ( ) => {
70- const component = (
71- < ResponsiveContext . Provider value = { { width : 500 } } >
72- < IntlProvider locale = "en" messages = { { } } >
73- < AppContext . Provider
74- value = { {
75- authenticatedUser : null ,
76- config : {
77- LMS_BASE_URL : process . env . LMS_BASE_URL ,
78- SITE_NAME : process . env . SITE_NAME ,
79- LOGIN_URL : process . env . LOGIN_URL ,
80- LOGOUT_URL : process . env . LOGOUT_URL ,
81- LOGO_URL : process . env . LOGO_URL ,
82- } ,
83- } }
84- >
85- < Header />
86- </ AppContext . Provider >
87- </ IntlProvider >
88- </ ResponsiveContext . Provider >
89- ) ;
65+ const contextValue = {
66+ authenticatedUser : null ,
67+ config : {
68+ LMS_BASE_URL : process . env . LMS_BASE_URL ,
69+ SITE_NAME : process . env . SITE_NAME ,
70+ LOGIN_URL : process . env . LOGIN_URL ,
71+ LOGOUT_URL : process . env . LOGOUT_URL ,
72+ LOGO_URL : process . env . LOGO_URL ,
73+ } ,
74+ } ;
75+ const component = < HeaderComponent width = { { width : 500 } } contextValue = { contextValue } /> ;
9076
9177 const wrapper = TestRenderer . create ( component ) ;
9278
9379 expect ( wrapper . toJSON ( ) ) . toMatchSnapshot ( ) ;
9480 } ) ;
9581
9682 it ( 'renders correctly for authenticated mobile' , ( ) => {
97- const component = (
98- < ResponsiveContext . Provider value = { { width : 500 } } >
99- < IntlProvider locale = "en" messages = { { } } >
100- < AppContext . Provider
101- value = { {
102- authenticatedUser : {
103- userId : 'abc123' ,
104- username : 'edX' ,
105- roles : [ ] ,
106- administrator : false ,
107- } ,
108- config : {
109- LMS_BASE_URL : process . env . LMS_BASE_URL ,
110- SITE_NAME : process . env . SITE_NAME ,
111- LOGIN_URL : process . env . LOGIN_URL ,
112- LOGOUT_URL : process . env . LOGOUT_URL ,
113- LOGO_URL : process . env . LOGO_URL ,
114- } ,
115- } }
116- >
117- < Header />
118- </ AppContext . Provider >
119- </ IntlProvider >
120- </ ResponsiveContext . Provider >
121- ) ;
83+ const contextValue = {
84+ authenticatedUser : {
85+ userId : 'abc123' ,
86+ username : 'edX' ,
87+ roles : [ ] ,
88+ administrator : false ,
89+ } ,
90+ config : {
91+ LMS_BASE_URL : process . env . LMS_BASE_URL ,
92+ SITE_NAME : process . env . SITE_NAME ,
93+ LOGIN_URL : process . env . LOGIN_URL ,
94+ LOGOUT_URL : process . env . LOGOUT_URL ,
95+ LOGO_URL : process . env . LOGO_URL ,
96+ } ,
97+ } ;
98+ const component = < HeaderComponent width = { { width : 500 } } contextValue = { contextValue } /> ;
12299
123100 const wrapper = TestRenderer . create ( component ) ;
124101
0 commit comments