@@ -9,13 +9,15 @@ import PropTypes from 'prop-types';
9
9
import { Provider } from 'react-redux' ;
10
10
import configureMockStore from 'redux-mock-store' ;
11
11
import thunk from 'redux-thunk' ;
12
+ import { BrowserRouter , useNavigate } from 'react-router-dom' ;
12
13
13
14
import messages from '../i18n' ;
14
15
import ProfilePage from './ProfilePage' ;
15
16
16
17
const mockStore = configureMockStore ( [ thunk ] ) ;
17
18
const storeMocks = {
18
19
loadingApp : require ( './__mocks__/loadingApp.mockStore' ) ,
20
+ invalidUser : require ( './__mocks__/invalidUser.mockStore' ) ,
19
21
viewOwnProfile : require ( './__mocks__/viewOwnProfile.mockStore' ) ,
20
22
viewOtherProfile : require ( './__mocks__/viewOtherProfile.mockStore' ) ,
21
23
savingEditedBio : require ( './__mocks__/savingEditedBio.mockStore' ) ,
@@ -65,6 +67,23 @@ beforeEach(() => {
65
67
analytics . sendTrackingLogEvent . mockReset ( ) ;
66
68
} ) ;
67
69
70
+ const ProfileWrapper = ( { params, requiresParentalConsent } ) => {
71
+ const navigate = useNavigate ( ) ;
72
+ return (
73
+ < ProfilePage
74
+ { ...requiredProfilePageProps }
75
+ params = { params }
76
+ requiresParentalConsent = { requiresParentalConsent }
77
+ navigate = { navigate }
78
+ />
79
+ ) ;
80
+ } ;
81
+
82
+ ProfileWrapper . propTypes = {
83
+ params : PropTypes . shape ( { } ) . isRequired ,
84
+ requiresParentalConsent : PropTypes . bool . isRequired ,
85
+ } ;
86
+
68
87
const ProfilePageWrapper = ( {
69
88
contextValue, store, params, requiresParentalConsent,
70
89
} ) => (
@@ -73,7 +92,12 @@ const ProfilePageWrapper = ({
73
92
>
74
93
< IntlProvider locale = "en" >
75
94
< Provider store = { store } >
76
- < ProfilePage { ...requiredProfilePageProps } params = { params } requiresParentalConsent = { requiresParentalConsent } />
95
+ < BrowserRouter >
96
+ < ProfileWrapper
97
+ params = { params }
98
+ requiresParentalConsent = { requiresParentalConsent }
99
+ />
100
+ </ BrowserRouter >
77
101
</ Provider >
78
102
</ IntlProvider >
79
103
</ AppContext . Provider >
@@ -103,6 +127,16 @@ describe('<ProfilePage />', () => {
103
127
expect ( tree ) . toMatchSnapshot ( ) ;
104
128
} ) ;
105
129
130
+ it ( 'successfully redirected to not found page.' , ( ) => {
131
+ const contextValue = {
132
+ authenticatedUser : { userId : 123 , username : 'staff' , administrator : true } ,
133
+ config : getConfig ( ) ,
134
+ } ;
135
+ const component = < ProfilePageWrapper contextValue = { contextValue } store = { mockStore ( storeMocks . invalidUser ) } /> ;
136
+ const { container : tree } = render ( component ) ;
137
+ expect ( tree ) . toMatchSnapshot ( ) ;
138
+ } ) ;
139
+
106
140
it ( 'viewing own profile' , ( ) => {
107
141
const contextValue = {
108
142
authenticatedUser : { userId : 123 , username : 'staff' , administrator : true } ,
0 commit comments