-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show user email & name in user menu dropdown (#558)
VAN-1851
- Loading branch information
1 parent
2bba7f5
commit 2e76a03
Showing
18 changed files
with
184 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,8 @@ subscribe(APP_READY, () => { | |
authenticatedUser: { | ||
userId: '123abc', | ||
username: 'testuser', | ||
name: 'test user', | ||
name: 'Test User', | ||
email: '[email protected]', | ||
roles: [], | ||
administrator: false, | ||
}, | ||
|
@@ -38,8 +39,9 @@ subscribe(APP_READY, () => { | |
<AppContext.Provider value={{ | ||
authenticatedUser: { | ||
userId: '123abc', | ||
name: 'test name', | ||
username: 'testuser', | ||
name: 'Test User', | ||
email: '[email protected]', | ||
roles: [], | ||
administrator: false, | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,27 @@ describe('<Header />', () => { | |
expect(wrapper.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('displays user menu in dropdown', () => { | ||
const authenticatedUser = { | ||
userId: 'abc123', | ||
username: 'edX', | ||
name: 'edX', | ||
email: '[email protected]', | ||
roles: [], | ||
administrator: false, | ||
}; | ||
const contextValue = { | ||
authenticatedUser, | ||
config: APP_CONTEXT_CONFIG, | ||
}; | ||
const component = <HeaderContext width={{ width: 1280 }} contextValue={contextValue} />; | ||
const wrapper = render(component); | ||
fireEvent.click(wrapper.container.querySelector('#menu-dropdown')); | ||
|
||
expect(screen.getByText(authenticatedUser.name)).toBeInTheDocument(); | ||
expect(screen.getByText(authenticatedUser.email)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders correctly for authenticated users on desktop with or without learner portal links', async () => { | ||
const contextValue = { | ||
authenticatedUser: { | ||
|
@@ -143,6 +164,7 @@ describe('<Header />', () => { | |
authenticatedUser: { | ||
userId: 'abc123', | ||
username: 'edX', | ||
name: 'edX Test', | ||
roles: [], | ||
administrator: false, | ||
}, | ||
|
@@ -185,6 +207,7 @@ describe('<Header />', () => { | |
authenticatedUser: { | ||
userId: 'abc123', | ||
username: 'edX', | ||
name: 'edX Test', | ||
roles: [], | ||
administrator: false, | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { Avatar } from '@openedx/paragon'; | ||
import { injectIntl } from '@edx/frontend-platform/i18n'; | ||
|
||
import './style.scss'; | ||
|
||
const UserMenuItem = ({ name, email }) => ( | ||
<> | ||
<Avatar | ||
size="sm" | ||
className="mr-2" | ||
alt={name} | ||
data-testid="avatar-icon" | ||
/> | ||
<div className="text-left"> | ||
{name && <span className="h5 d-block">{name}</span>} | ||
{email && <span className="small d-block">{email}</span>} | ||
</div> | ||
</> | ||
); | ||
|
||
UserMenuItem.propTypes = { | ||
name: PropTypes.string, | ||
email: PropTypes.string, | ||
}; | ||
|
||
UserMenuItem.defaultProps = { | ||
name: '', | ||
email: '', | ||
}; | ||
|
||
export default injectIntl(UserMenuItem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.dropdown-menu a:first-child { | ||
pointer-events: none; | ||
} | ||
|
||
@media screen and (max-width: 768px) { | ||
.menu-content li:first-child { | ||
display: flex; | ||
align-items: center; | ||
padding: 0 16px; | ||
border-bottom: 1px solid #70828E; | ||
|
||
a { | ||
display: flex; | ||
align-items: center; | ||
border-bottom: 1px solid #70828E !important; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@mubbsharanwar is this supposed to appear in every dropdown in the header navigation? I am seeing it in the Content, Settings, and Tools dropdowns as well as the User dropdown (the expected location)