-
Notifications
You must be signed in to change notification settings - Fork 166
feat: improved accessibility of learning header #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,91 @@ | ||||||||||||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||||||||||||
| import AuthenticatedUserDropdown from './AuthenticatedUserDropdown'; | ||||||||||||||||||||||||||||
| import messages from './messages'; | ||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||
| render, screen, fireEvent, initializeMockApp, | ||||||||||||||||||||||||||||
| } from '../setupTest'; | ||||||||||||||||||||||||||||
|
Comment on lines
1
to
7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| describe('AuthenticatedUserDropdown', () => { | ||||||||||||||||||||||||||||
| const username = 'testuser'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| beforeEach(() => { | ||||||||||||||||||||||||||||
| initializeMockApp(); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const renderComponent = () => { | ||||||||||||||||||||||||||||
| render( | ||||||||||||||||||||||||||||
| <AuthenticatedUserDropdown username={username} />, | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| it('renders username in toggle button', () => { | ||||||||||||||||||||||||||||
| renderComponent(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| expect(screen.getByText(username)).toBeInTheDocument(); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| it('renders dropdown items after toggle click', async () => { | ||||||||||||||||||||||||||||
| renderComponent(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const toggleButton = screen.getByRole('button', { name: messages.userOptionsDropdownLabel.defaultMessage }); | ||||||||||||||||||||||||||||
| await fireEvent.click(toggleButton); | ||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| expect(await screen.findByText(messages.dashboard.defaultMessage)) | ||||||||||||||||||||||||||||
| .toHaveAttribute('href', `${process.env.LMS_BASE_URL}/dashboard`); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| .toHaveAttribute('href', `${process.env.LMS_BASE_URL}/dashboard`); | |
| .toHaveAttribute('href', `${getConfig().LMS_BASE_URL}/dashboard`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| expect(screen.getByText(messages.profile.defaultMessage)).toHaveAttribute('href', `${process.env.ACCOUNT_PROFILE_URL}/u/${username}`); | |
| expect(screen.getByText(messages.profile.defaultMessage)).toHaveAttribute('href', `${getConfig().ACCOUNT_PROFILE_URL}/u/${username}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| expect(screen.getByText(messages.account.defaultMessage)).toHaveAttribute('href', process.env.ACCOUNT_SETTINGS_URL); | |
| expect(screen.getByText(messages.account.defaultMessage)).toHaveAttribute('href', getConfig().ACCOUNT_SETTINGS_URL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| expect(screen.getByText(messages.orderHistory.defaultMessage)).toHaveAttribute('href', process.env.ORDER_HISTORY_URL); | |
| expect(screen.getByText(messages.orderHistory.defaultMessage)).toHaveAttribute('href', getConfig().ORDER_HISTORY_URL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| expect(screen.getByText(messages.signOut.defaultMessage)).toHaveAttribute('href', process.env.LOGOUT_URL); | |
| expect(screen.getByText(messages.signOut.defaultMessage)).toHaveAttribute('href', getConfig().LOGOUT_URL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use translations instead of hardcoded text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use userOptionsDropdownLabel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use userEvent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userEvent package does not use in this header-component
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use userOptionsDropdownLabel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use userEvent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userEvent package does not use in this header-component
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,11 +3,30 @@ import PropTypes from 'prop-types'; | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import { Dropdown } from '@openedx/paragon'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const LearningHeaderUserMenuItems = ({ items }) => items.map((item) => ( | ||||||||||||||||||||||||||||||||||
| <Dropdown.Item href={item.href}> | ||||||||||||||||||||||||||||||||||
| {item.message} | ||||||||||||||||||||||||||||||||||
| </Dropdown.Item> | ||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||
| const LearningHeaderUserMenuItems = ({ | ||||||||||||||||||||||||||||||||||
| items, | ||||||||||||||||||||||||||||||||||
| handleKeyDown, | ||||||||||||||||||||||||||||||||||
| firstMenuItemRef, | ||||||||||||||||||||||||||||||||||
| lastMenuItemRef, | ||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||
| const getRefForIndex = (index, length) => { | ||||||||||||||||||||||||||||||||||
| if (index === 0) { return firstMenuItemRef; } | ||||||||||||||||||||||||||||||||||
| if (index === length - 1) { return lastMenuItemRef; } | ||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
Comment on lines
12
to
20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| return items.map((item, index) => ( | ||||||||||||||||||||||||||||||||||
| <Dropdown.Item | ||||||||||||||||||||||||||||||||||
| key={item.href} | ||||||||||||||||||||||||||||||||||
| href={item.href} | ||||||||||||||||||||||||||||||||||
| role="menuitem" | ||||||||||||||||||||||||||||||||||
| onKeyDown={handleKeyDown} | ||||||||||||||||||||||||||||||||||
| ref={getRefForIndex(index, items.length)} | ||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||
| {item.message} | ||||||||||||||||||||||||||||||||||
| </Dropdown.Item> | ||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export const learningHeaderUserMenuDataShape = { | ||||||||||||||||||||||||||||||||||
| items: PropTypes.arrayOf(PropTypes.shape({ | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,11 @@ export function initializeMockApp() { | |
| CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH || null, | ||
| LOGO_URL: process.env.LOGO_URL || null, | ||
| SITE_NAME: process.env.SITE_NAME || null, | ||
| ACCOUNT_PROFILE_URL: process.env.ACCOUNT_PROFILE_URL || null, | ||
| ACCOUNT_SETTINGS_URL: process.env.ACCOUNT_SETTINGS_URL || null, | ||
| ORDER_HISTORY_URL: process.env.ORDER_HISTORY_URL || null, | ||
| ECOMMERCE_BASE_URL: process.env.ECOMMERCE_BASE_URL || null, | ||
| CREDENTIALS_BASE_URL: process.env.CREDENTIALS_BASE_URL || null, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we adding these variables?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. becouse we used this vars there |
||
|
|
||
| authenticatedUser: { | ||
| userId: 'abc123', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this React import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we remove this somewhere, errors will occur