From f0540a55277afbc9ae113499041299bd292d8a8c Mon Sep 17 00:00:00 2001 From: Attiya Ishaque Date: Mon, 12 Feb 2024 16:26:33 +0500 Subject: [PATCH] feat: remove username from profile page. --- src/profile/ProfilePage.jsx | 12 +- src/profile/ProfilePage.test.jsx | 42 + .../__snapshots__/ProfilePage.test.jsx.snap | 1748 +++++++++++++++++ src/profile/data/selectors.js | 3 + 4 files changed, 1804 insertions(+), 1 deletion(-) diff --git a/src/profile/ProfilePage.jsx b/src/profile/ProfilePage.jsx index 3b9d02c74..3e95385f5 100644 --- a/src/profile/ProfilePage.jsx +++ b/src/profile/ProfilePage.jsx @@ -124,9 +124,13 @@ class ProfilePage extends React.Component { renderHeadingLockup() { const { dateJoined } = this.props; + const hideUserName = !!this.props.hideUsername; + const { firstName, lastName } = this.props; return ( -

{this.props.params.username}

+

+ {!hideUserName ? this.props.params.username : `${firstName} ${lastName}`} +

{this.isYOBDisabled() && }
@@ -331,11 +335,14 @@ ProfilePage.propTypes = { // Account data requiresParentalConsent: PropTypes.bool, dateJoined: PropTypes.string, + hideUsername: PropTypes.bool, // Bio form data bio: PropTypes.string, yearOfBirth: PropTypes.number, visibilityBio: PropTypes.string.isRequired, + firstName: PropTypes.string, + lastName: PropTypes.string, // Certificates form data courseCertificates: PropTypes.arrayOf(PropTypes.shape({ @@ -423,6 +430,9 @@ ProfilePage.defaultProps = { courseCertificates: null, requiresParentalConsent: null, dateJoined: null, + hideUsername: false, + firstName: '', + lastName: '', }; export default connect( diff --git a/src/profile/ProfilePage.test.jsx b/src/profile/ProfilePage.test.jsx index 997a92e86..2521d15d2 100644 --- a/src/profile/ProfilePage.test.jsx +++ b/src/profile/ProfilePage.test.jsx @@ -113,6 +113,48 @@ describe('', () => { expect(tree).toMatchSnapshot(); }); + it('renders the component without the username field when hide_username is true', () => { + const storeData = JSON.parse(JSON.stringify(storeMocks.viewOwnProfile)); + storeData.profilePage.account.hideUsername = true; + + const contextValue = { + authenticatedUser: { userId: 123, username: 'staff', administrator: true }, + config: getConfig(), + }; + + const component = ( + + ); + + const { container: tree } = render(component); + expect(tree).toMatchSnapshot(); + }); + + it('renders the component without the username field and displays the full name when hide_username is true', () => { + const storeData = JSON.parse(JSON.stringify(storeMocks.viewOwnProfile)); + storeData.profilePage.account.hideUsername = true; + storeData.profilePage.account.firstName = 'John'; + storeData.profilePage.account.lastName = 'D'; + + const contextValue = { + authenticatedUser: { userId: 123, username: 'staff', administrator: true }, + config: getConfig(), + }; + + const component = ( + + ); + + const { container: tree } = render(component); + expect(tree).toMatchSnapshot(); + }); + it('viewing other profile with all fields', () => { const contextValue = { authenticatedUser: { userId: 123, username: 'staff', administrator: true }, diff --git a/src/profile/__snapshots__/ProfilePage.test.jsx.snap b/src/profile/__snapshots__/ProfilePage.test.jsx.snap index c4d355ae3..8cc60bb2e 100644 --- a/src/profile/__snapshots__/ProfilePage.test.jsx.snap +++ b/src/profile/__snapshots__/ProfilePage.test.jsx.snap @@ -29,6 +29,1754 @@ exports[` Renders correctly in various states app loading 1`] = ` `; +exports[` Renders correctly in various states renders the component without the username field and displays the full name when hide_username is true 1`] = ` +
+
+
+
+
+
+
+
+
+
+ +
+ profile avatar +
+
+ +
+
+
+
+
+
+ +

+ John D +

+

+ Member since + 2017 +

+
+
+
+ +
+
+
+
+
+ +

+ John D +

+

+ Member since + 2017 +

+
+
+
+ +
+
+
+

+ Full Name + +

+

+ + + + Just me + +

+
+

+ Lemon Seltzer +

+ + This is the name that appears in your account and on your certificates. + +
+
+
+
+
+

+ Location + +

+

+ + + + Everyone on localhost + +

+
+

+ Montenegro +

+
+
+
+
+
+

+ Primary Language Spoken + +

+

+ + + + Everyone on localhost + +

+
+

+ Yoruba +

+
+
+
+
+
+

+ Education + +

+

+ + + + Just me + +

+
+

+ Elementary/primary school +

+
+
+
+
+
+

+ Social Links + +

+

+ + + + Everyone on localhost + +

+
+ +
+
+
+
+
+
+
+

+ About Me + +

+

+ + + + Everyone on localhost + +

+
+

+ This is my bio +

+
+
+
+
+
+

+ My Certificates + +

+

+ + + + Everyone on localhost + +

+
+
+
+
+
+
+
+

+ Verified Certificate +

+

+ edX Demonstration Course +

+
+

+ From +

+

+ edX +

+
+

+ Completed on + 3/4/2019 +

+ +
+
+
+
+
+
+
+
+
+
+
+`; + +exports[` Renders correctly in various states renders the component without the username field when hide_username is true 1`] = ` +
+
+
+
+
+
+
+
+
+
+ +
+ profile avatar +
+
+ +
+
+
+
+
+
+ +

+ +

+

+ Member since + 2017 +

+
+
+
+ +
+
+
+
+
+ +

+ +

+

+ Member since + 2017 +

+
+
+
+ +
+
+
+

+ Full Name + +

+

+ + + + Just me + +

+
+

+ Lemon Seltzer +

+ + This is the name that appears in your account and on your certificates. + +
+
+
+
+
+

+ Location + +

+

+ + + + Everyone on localhost + +

+
+

+ Montenegro +

+
+
+
+
+
+

+ Primary Language Spoken + +

+

+ + + + Everyone on localhost + +

+
+

+ Yoruba +

+
+
+
+
+
+

+ Education + +

+

+ + + + Just me + +

+
+

+ Elementary/primary school +

+
+
+
+
+
+

+ Social Links + +

+

+ + + + Everyone on localhost + +

+
+ +
+
+
+
+
+
+
+

+ About Me + +

+

+ + + + Everyone on localhost + +

+
+

+ This is my bio +

+
+
+
+
+
+

+ My Certificates + +

+

+ + + + Everyone on localhost + +

+
+
+
+
+
+
+
+

+ Verified Certificate +

+

+ edX Demonstration Course +

+
+

+ From +

+

+ edX +

+
+

+ Completed on + 3/4/2019 +

+ +
+
+
+
+
+
+
+
+
+
+
+`; + exports[` Renders correctly in various states test country edit with error 1`] = `
({ // Account data we need username: account.username, + hideUsername: account.hideUsername, profileImage, requiresParentalConsent: account.requiresParentalConsent, dateJoined: account.dateJoined, yearOfBirth: account.yearOfBirth, + firstName: account.firstName, + lastName: account.lastName, // Bio form data bio: formValues.bio,