Skip to content

Commit 9105ea5

Browse files
feat: fixed loading issue for wrong username
1 parent 3270e27 commit 9105ea5

File tree

7 files changed

+739
-10
lines changed

7 files changed

+739
-10
lines changed

src/profile/ProfilePage.jsx

+10
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,19 @@ class ProfilePage extends React.Component {
183183
visibilityBio,
184184
requiresParentalConsent,
185185
isLoadingProfile,
186+
username,
187+
saveState,
188+
navigate,
186189
} = this.props;
187190

188191
if (isLoadingProfile) {
189192
return <PageLoading srMessage={this.props.intl.formatMessage(messages['profile.loading'])} />;
190193
}
191194

195+
if (!username && saveState === 'error' && navigate) {
196+
navigate('/notfound');
197+
}
198+
192199
const commonFormProps = {
193200
openHandler: this.handleOpen,
194201
closeHandler: this.handleClose,
@@ -330,6 +337,7 @@ ProfilePage.propTypes = {
330337
// Account data
331338
requiresParentalConsent: PropTypes.bool,
332339
dateJoined: PropTypes.string,
340+
username: PropTypes.string,
333341

334342
// Bio form data
335343
bio: PropTypes.string,
@@ -395,6 +403,7 @@ ProfilePage.propTypes = {
395403
openForm: PropTypes.func.isRequired,
396404
closeForm: PropTypes.func.isRequired,
397405
updateDraft: PropTypes.func.isRequired,
406+
navigate: PropTypes.func.isRequired,
398407

399408
// Router
400409
params: PropTypes.shape({
@@ -407,6 +416,7 @@ ProfilePage.propTypes = {
407416

408417
ProfilePage.defaultProps = {
409418
saveState: null,
419+
username: '',
410420
savePhotoState: null,
411421
photoUploadError: {},
412422
profileImage: {},

src/profile/ProfilePage.test.jsx

+35-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import PropTypes from 'prop-types';
99
import { Provider } from 'react-redux';
1010
import configureMockStore from 'redux-mock-store';
1111
import thunk from 'redux-thunk';
12+
import { BrowserRouter, useNavigate } from 'react-router-dom';
1213

1314
import messages from '../i18n';
1415
import ProfilePage from './ProfilePage';
1516

1617
const mockStore = configureMockStore([thunk]);
1718
const 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+
6887
const 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 },
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module.exports = {
2+
userAccount: {
3+
loading: false,
4+
error: null,
5+
username: 'staff',
6+
email: null,
7+
bio: null,
8+
name: null,
9+
country: null,
10+
socialLinks: null,
11+
profileImage: {
12+
imageUrlMedium: null,
13+
imageUrlLarge: null
14+
},
15+
levelOfEducation: null,
16+
learningGoal: null
17+
},
18+
profilePage: {
19+
errors: {},
20+
saveState: 'error',
21+
savePhotoState: null,
22+
currentlyEditingField: null,
23+
account: {
24+
username: '',
25+
socialLinks: []
26+
},
27+
preferences: {},
28+
courseCertificates: [],
29+
drafts: {},
30+
isLoadingProfile: false,
31+
isAuthenticatedUserProfile: true,
32+
},
33+
router: {
34+
location: {
35+
pathname: '/u/staffTest',
36+
search: '',
37+
hash: ''
38+
},
39+
action: 'POP'
40+
}
41+
};

0 commit comments

Comments
 (0)