From 9612bfaa3e5c76130bff0af7e3cb63afc9af40c0 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 | 5 +- src/profile/ProfilePage.test.jsx | 19 + .../__snapshots__/ProfilePage.test.jsx.snap | 769 ++++++++++++++++++ 3 files changed, 791 insertions(+), 2 deletions(-) diff --git a/src/profile/ProfilePage.jsx b/src/profile/ProfilePage.jsx index 3b9d02c74..67790a4a8 100644 --- a/src/profile/ProfilePage.jsx +++ b/src/profile/ProfilePage.jsx @@ -123,10 +123,10 @@ class ProfilePage extends React.Component { // Inserted into the DOM in two places (for responsive layout) renderHeadingLockup() { const { dateJoined } = this.props; - + const hideUserName = !!this.props.params?.hide_username; return ( -

{this.props.params.username}

+ {!hideUserName &&

{this.props.params.username}

} {this.isYOBDisabled() && }
@@ -400,6 +400,7 @@ ProfilePage.propTypes = { // Router params: PropTypes.shape({ username: PropTypes.string.isRequired, + hide_username: PropTypes.bool, }).isRequired, // i18n diff --git a/src/profile/ProfilePage.test.jsx b/src/profile/ProfilePage.test.jsx index 997a92e86..d32914234 100644 --- a/src/profile/ProfilePage.test.jsx +++ b/src/profile/ProfilePage.test.jsx @@ -113,6 +113,25 @@ describe('', () => { expect(tree).toMatchSnapshot(); }); + it('renders the component without the username field when hide_username is true', () => { + const contextValue = { + authenticatedUser: { userId: 123, username: 'staff', administrator: true }, + config: getConfig(), + }; + + // Render the component with hide_username set to true + 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..b53c3213b 100644 --- a/src/profile/__snapshots__/ProfilePage.test.jsx.snap +++ b/src/profile/__snapshots__/ProfilePage.test.jsx.snap @@ -29,6 +29,775 @@ exports[` Renders correctly in various states app loading 1`] = ` `; +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`] = `