-
Notifications
You must be signed in to change notification settings - Fork 164
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 all 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
+6
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
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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`); | ||||||||||||||||||||||||||||
|
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
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| expect(screen.getByText(messages.profile.defaultMessage)).toHaveAttribute('href', `${process.env.ACCOUNT_PROFILE_URL}/u/${username}`); | ||||||||||||||||||||||||||||
|
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
|
||||||||||||||||||||||||||||
| expect(screen.getByText(messages.account.defaultMessage)).toHaveAttribute('href', process.env.ACCOUNT_SETTINGS_URL); | ||||||||||||||||||||||||||||
|
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
|
||||||||||||||||||||||||||||
| expect(screen.getByText(messages.orderHistory.defaultMessage)).toHaveAttribute('href', process.env.ORDER_HISTORY_URL); | ||||||||||||||||||||||||||||
|
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
|
||||||||||||||||||||||||||||
| expect(screen.getByText(messages.signOut.defaultMessage)).toHaveAttribute('href', process.env.LOGOUT_URL); | ||||||||||||||||||||||||||||
|
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
|
||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| it('loops focus from last to first and vice versa with Tab and Shift+Tab', async () => { | ||||||||||||||||||||||||||||
| renderComponent(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const toggleButton = screen.getByRole('button', { name: 'User Options' }); | ||||||||||||||||||||||||||||
|
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. Can we use translations instead of hardcoded text?
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
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 userOptionsDropdownLabel |
||||||||||||||||||||||||||||
| 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.
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const menuItems = await screen.findAllByRole('menuitem'); | ||||||||||||||||||||||||||||
| const firstItem = menuItems[0]; | ||||||||||||||||||||||||||||
| const lastItem = menuItems[menuItems.length - 1]; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| lastItem.focus(); | ||||||||||||||||||||||||||||
| expect(lastItem).toHaveFocus(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| fireEvent.keyDown(lastItem, { key: 'Tab' }); | ||||||||||||||||||||||||||||
| expect(firstItem).toHaveFocus(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| firstItem.focus(); | ||||||||||||||||||||||||||||
| expect(firstItem).toHaveFocus(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| fireEvent.keyDown(firstItem, { key: 'Tab', shiftKey: true }); | ||||||||||||||||||||||||||||
| expect(lastItem).toHaveFocus(); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| it('focuses next link when Tab is pressed on middle item', async () => { | ||||||||||||||||||||||||||||
| renderComponent(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const toggleButton = screen.getByRole('button', { name: 'User Options' }); | ||||||||||||||||||||||||||||
|
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 userOptionsDropdownLabel |
||||||||||||||||||||||||||||
| 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.
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const menuItems = await screen.findAllByRole('menuitem'); | ||||||||||||||||||||||||||||
| const secondItem = menuItems[1]; | ||||||||||||||||||||||||||||
| const thirdItem = menuItems[2]; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| secondItem.focus(); | ||||||||||||||||||||||||||||
| expect(secondItem).toHaveFocus(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Object.defineProperty(secondItem, 'nextElementSibling', { | ||||||||||||||||||||||||||||
| value: thirdItem, | ||||||||||||||||||||||||||||
| configurable: true, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| Object.defineProperty(thirdItem, 'tagName', { | ||||||||||||||||||||||||||||
| value: 'A', | ||||||||||||||||||||||||||||
| configurable: true, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| fireEvent.keyDown(secondItem, { key: 'Tab' }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| expect(thirdItem).toHaveFocus(); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| 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
+16
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
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| 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