@@ -9,13 +9,15 @@ import PropTypes from 'prop-types';
99import { Provider } from 'react-redux' ;
1010import configureMockStore from 'redux-mock-store' ;
1111import thunk from 'redux-thunk' ;
12+ import { BrowserRouter , useNavigate } from 'react-router-dom' ;
1213
1314import messages from '../i18n' ;
1415import ProfilePage from './ProfilePage' ;
1516
1617const mockStore = configureMockStore ( [ thunk ] ) ;
1718const storeMocks = {
1819 loadingApp : require ( './__mocks__/loadingApp.mockStore' ) ,
20+ invalidUser : require ( './__mocks__/invalidUser.mockStore' ) ,
1921 viewOwnProfile : require ( './__mocks__/viewOwnProfile.mockStore' ) ,
2022 viewOtherProfile : require ( './__mocks__/viewOtherProfile.mockStore' ) ,
2123 savingEditedBio : require ( './__mocks__/savingEditedBio.mockStore' ) ,
@@ -65,6 +67,23 @@ beforeEach(() => {
6567 analytics . sendTrackingLogEvent . mockReset ( ) ;
6668} ) ;
6769
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+
6887const ProfilePageWrapper = ( {
6988 contextValue, store, params, requiresParentalConsent,
7089} ) => (
@@ -73,7 +92,12 @@ const ProfilePageWrapper = ({
7392 >
7493 < IntlProvider locale = "en" >
7594 < Provider store = { store } >
76- < ProfilePage { ...requiredProfilePageProps } params = { params } requiresParentalConsent = { requiresParentalConsent } />
95+ < BrowserRouter >
96+ < ProfileWrapper
97+ params = { params }
98+ requiresParentalConsent = { requiresParentalConsent }
99+ />
100+ </ BrowserRouter >
77101 </ Provider >
78102 </ IntlProvider >
79103 </ AppContext . Provider >
@@ -103,6 +127,16 @@ describe('<ProfilePage />', () => {
103127 expect ( tree ) . toMatchSnapshot ( ) ;
104128 } ) ;
105129
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+
106140 it ( 'viewing own profile' , ( ) => {
107141 const contextValue = {
108142 authenticatedUser : { userId : 123 , username : 'staff' , administrator : true } ,
0 commit comments