Skip to content

Commit

Permalink
3804 suite header and header action fix accessibility scan violations (
Browse files Browse the repository at this point in the history
…#3807)

* fix(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suiteheader and headeraction): fix accessibility scan violations

#3804

* chore(suitheader and headeraction): fix accessibility scan violations

#3804

* Update PageTitleBar.test.e2e.jsx
  • Loading branch information
kalyanixraut authored Jun 27, 2023
1 parent f3cf4c2 commit dcad3b6
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 89 deletions.
10 changes: 6 additions & 4 deletions packages/react/src/components/Header/Header.test.e2e.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe(
cy.findByLabelText('Announcements').should('be.visible');
cy.findByRole('button', { name: 'help' }).should('be.visible');
cy.findByRole('button', { name: 'open and close list of options' }).should('not.exist');
cy.findByRole('menuitem', { name: 'user' }).should('be.visible');
cy.findByRole('button', { name: 'user', label: 'user' }).should('be.visible');
});

it('should hide header action actions in a small viewport', () => {
Expand Down Expand Up @@ -239,11 +239,11 @@ describe(
cy.findByRole('button', { name: 'open and close list of options' }).click();
cy.findByRole('menuitem', { name: 'user' }).click();
cy.findByText('[email protected]').should('be.visible');
cy.findByRole('menuitem', { name: 'user' })
cy.findByTestId('menuitem', { name: 'user' })
.find('svg')
.invoke('attr', 'description')
.should('eq', 'Close menu');
cy.findByRole('menuitem', { name: 'user' }).click();
cy.findByTestId('menuitem', { name: 'user' }).click();
cy.findByRole('button', { name: 'open and close list of options' }).should('be.visible');

// click the left side specifically to _not_ click the svg element right in the center
Expand Down Expand Up @@ -305,7 +305,9 @@ describe(

cy.findByRole('button', { name: 'open and close list of options' }).click();
cy.findByRole('menuitem', { name: 'Announcements' }).should('be.visible');
cy.findByRole('menuitem', { name: 'Custom icon 1' }).should('not.exist');
cy.findByRole('button', { name: 'Custom icon 1', label: 'Custom icon 1' }).should(
'not.exist'
);
});

it('should get width from documentElement when innerWidth fails', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ class HeaderActionMenu extends React.Component {
ref={focusRef}
testId="menuitem"
aria-label={ariaLabel}
role="menuitem"
id={id}
>
<MenuContent ariaLabel={ariaLabel} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ exports[`HeaderActionMenu should render 1`] = `
aria-label="Accessibility label"
class="bx--header__menu-item bx--header__menu-title iot--btn bx--btn bx--btn--primary bx--tooltip--hidden bx--btn--icon-only bx--tooltip__trigger bx--tooltip--a11y bx--btn--icon-only--bottom bx--tooltip--align-center"
data-testid="menuitem"
role="menuitem"
tabindex="0"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/U
onFocus={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
role="menuitem"
tabIndex={0}
type="button"
>
Expand Down Expand Up @@ -633,7 +632,6 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/U
onFocus={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
role="menuitem"
tabIndex={0}
type="button"
>
Expand Down Expand Up @@ -834,7 +832,6 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/U
onFocus={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
role="menuitem"
tabIndex={0}
type="button"
>
Expand Down Expand Up @@ -1057,7 +1054,6 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/U
onFocus={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
role="menuitem"
tabIndex={0}
type="button"
>
Expand Down Expand Up @@ -1643,7 +1639,6 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/U
onFocus={[Function]}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
role="menuitem"
tabIndex={0}
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ exports[`Header should render 1`] = `
class="bx--header__menu-item bx--header__menu-title iot--btn bx--btn bx--btn--primary bx--tooltip--hidden bx--btn--icon-only bx--tooltip__trigger bx--tooltip--a11y bx--btn--icon-only--bottom bx--tooltip--align-center"
data-testid="menuitem"
id="menu-item-global-action-1"
role="menuitem"
tabindex="0"
type="button"
>
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/Header/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $hoverBgColor: #2c2c2c;
}
}

&__menu-title[role='menuitem'][aria-expanded='true'] + &__menu {
&__menu-title[data-testid='menuitem'][aria-expanded='true'] + &__menu {
left: auto;
right: 0;
[dir='rtl'] & {
Expand Down Expand Up @@ -166,7 +166,7 @@ $hoverBgColor: #2c2c2c;
}

.#{$prefix}--header__menu-item {
&[role='menuitem'] {
&[data-testid='menuitem'] {
height: 100%;
justify-content: center;
padding: 0;
Expand All @@ -182,7 +182,7 @@ $hoverBgColor: #2c2c2c;
}
}

.#{$prefix}--header__menu .#{$prefix}--header__menu-item[role='menuitem'] {
.#{$prefix}--header__menu .#{$prefix}--header__menu-item[data-testid='menuitem'] {
display: flex;
align-items: center;
color: $active-ui;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,13 +709,13 @@ describe('SuiteHeader', () => {
const originalHref = window.location.href;
const onRouteChange = jest.fn().mockImplementation(() => false);
render(<SuiteHeader {...adminPageCommonProps} onRouteChange={onRouteChange} />);
userEvent.click(screen.getByRole('menuitem', { name: 'user' }));
userEvent.click(screen.getByRole('button', { name: 'user', label: 'user' }));
await userEvent.click(screen.getByTestId('suite-header-profile--profile'));
expect(onRouteChange).toHaveBeenCalledWith('PROFILE', adminPageCommonProps.routes.profile);
expect(window.location.href).toEqual(originalHref);

onRouteChange.mockImplementation(() => true);
userEvent.click(screen.getByRole('menuitem', { name: 'user' }));
userEvent.click(screen.getByRole('button', { name: 'user', label: 'user' }));
await userEvent.click(screen.getByTestId('suite-header-profile--profile'));
expect(onRouteChange).toHaveBeenCalledWith('PROFILE', adminPageCommonProps.routes.profile);
expect(window.location.href).toBe(adminPageCommonProps.routes.profile);
Expand Down Expand Up @@ -936,7 +936,9 @@ describe('SuiteHeader', () => {
/>
);

userEvent.type(screen.getByRole('menuitem', { name: 'chip' }), '{enter}', { skipClick: true });
userEvent.type(screen.getByRole('button', { name: 'chip', label: 'chip' }), '{enter}', {
skipClick: true,
});
expect(screen.getByText('this is my message to you')).toBeVisible();
jest.spyOn(HTMLAnchorElement.prototype, 'click');
fireEvent.keyDown(screen.getByTitle('this is my message to you'), { key: 'Enter' });
Expand Down Expand Up @@ -975,7 +977,9 @@ describe('SuiteHeader', () => {
/>
);

userEvent.type(screen.getByRole('menuitem', { name: 'chip' }), '{enter}', { skipClick: true });
userEvent.type(screen.getByRole('button', { name: 'chip', label: 'chip' }), '{enter}', {
skipClick: true,
});
expect(screen.getByText('this is my message to you')).toBeVisible();
jest.spyOn(HTMLButtonElement.prototype, 'click');
fireEvent.keyDown(screen.getByTitle('this is my message to you'), { key: 'Enter' });
Expand Down Expand Up @@ -1013,7 +1017,9 @@ describe('SuiteHeader', () => {
/>
);

userEvent.type(screen.getByRole('menuitem', { name: 'chip' }), '{enter}', { skipClick: true });
userEvent.type(screen.getByRole('button', { name: 'chip', label: 'chip' }), '{enter}', {
skipClick: true,
});
expect(screen.getByText('this is my message to you')).toBeVisible();
jest.spyOn(HTMLButtonElement.prototype, 'click');
fireEvent.keyDown(screen.getByTitle('this is my message to you'), { key: 'Enter' });
Expand Down Expand Up @@ -1052,7 +1058,9 @@ describe('SuiteHeader', () => {
/>
);

userEvent.type(screen.getByRole('menuitem', { name: 'chip' }), '{enter}', { skipClick: true });
userEvent.type(screen.getByRole('button', { name: 'chip', label: 'chip' }), '{enter}', {
skipClick: true,
});
expect(screen.getByText('this is my message to you')).toBeVisible();
jest.spyOn(HTMLAnchorElement.prototype, 'click');
fireEvent.keyDown(screen.getByTitle('this is my message to you'), { key: 'Enter' });
Expand Down Expand Up @@ -1094,7 +1102,9 @@ describe('SuiteHeader', () => {
/>
);

userEvent.type(screen.getByRole('menuitem', { name: 'chip' }), '{enter}', { skipClick: true });
userEvent.type(screen.getByRole('button', { name: 'chip', label: 'chip' }), '{enter}', {
skipClick: true,
});
expect(screen.getByText('this is my message to you')).toBeVisible();
jest.spyOn(HTMLAnchorElement.prototype, 'click');
fireEvent.keyDown(screen.getByTitle('this is my message to you'), { key: 'Enter' });
Expand Down Expand Up @@ -1204,7 +1214,7 @@ describe('SuiteHeader', () => {
'noopener noreferrer'
);
expect(window.open).toHaveBeenCalledTimes(1);
userEvent.click(screen.getByRole('menuitem', { name: 'user' }));
userEvent.click(screen.getByRole('button', { name: 'user', label: 'user' }));
await userEvent.click(screen.getByTestId('suite-header-profile--profile'), {
ctrlKey: true,
});
Expand All @@ -1215,7 +1225,7 @@ describe('SuiteHeader', () => {
);
expect(window.open).toHaveBeenCalledTimes(2);

userEvent.click(screen.getByRole('menuitem', { name: 'Help' }));
userEvent.click(screen.getByRole('button', { name: 'Help', label: 'Help' }));
await userEvent.click(screen.getByTitle('About'), { ctrlKey: true });
expect(window.open).toHaveBeenLastCalledWith(
workspaceBasedPageCommonProps.routes.about,
Expand Down
40 changes: 26 additions & 14 deletions packages/react/src/components/SuiteHeader/SuiteHeader.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,13 @@ describe('SuiteHeader', () => {
const originalHref = window.location.href;
const onRouteChange = jest.fn().mockImplementation(() => false);
render(<SuiteHeader {...commonProps} onRouteChange={onRouteChange} />);
userEvent.click(screen.getByRole('menuitem', { name: 'user' }));
userEvent.click(screen.getByRole('button', { name: 'user', label: 'user' }));
await userEvent.click(screen.getByTestId('suite-header-profile--profile'));
expect(onRouteChange).toHaveBeenCalledWith('PROFILE', commonProps.routes.profile);
expect(window.location.href).toEqual(originalHref);

onRouteChange.mockImplementation(() => true);
userEvent.click(screen.getByRole('menuitem', { name: 'user' }));
userEvent.click(screen.getByRole('button', { name: 'user', label: 'user' }));
await userEvent.click(screen.getByTestId('suite-header-profile--profile'));
expect(onRouteChange).toHaveBeenCalledWith('PROFILE', commonProps.routes.profile);
expect(window.location.href).toBe(commonProps.routes.profile);
Expand Down Expand Up @@ -845,7 +845,9 @@ describe('SuiteHeader', () => {
/>
);

userEvent.type(screen.getByRole('menuitem', { name: 'chip' }), '{enter}', { skipClick: true });
userEvent.type(screen.getByRole('button', { name: 'chip', label: 'chip' }), '{enter}', {
skipClick: true,
});
expect(screen.getByText('this is my message to you')).toBeVisible();
jest.spyOn(HTMLAnchorElement.prototype, 'click');
fireEvent.keyDown(screen.getByTitle('this is my message to you'), { key: 'Enter' });
Expand Down Expand Up @@ -884,7 +886,9 @@ describe('SuiteHeader', () => {
/>
);

userEvent.type(screen.getByRole('menuitem', { name: 'chip' }), '{enter}', { skipClick: true });
userEvent.type(screen.getByRole('button', { name: 'chip', label: 'chip' }), '{enter}', {
skipClick: true,
});
expect(screen.getByText('this is my message to you')).toBeVisible();
jest.spyOn(HTMLButtonElement.prototype, 'click');
fireEvent.keyDown(screen.getByTitle('this is my message to you'), { key: 'Enter' });
Expand Down Expand Up @@ -922,7 +926,9 @@ describe('SuiteHeader', () => {
/>
);

userEvent.type(screen.getByRole('menuitem', { name: 'chip' }), '{enter}', { skipClick: true });
userEvent.type(screen.getByRole('button', { name: 'chip', label: 'chip' }), '{enter}', {
skipClick: true,
});
expect(screen.getByText('this is my message to you')).toBeVisible();
jest.spyOn(HTMLButtonElement.prototype, 'click');
fireEvent.keyDown(screen.getByTitle('this is my message to you'), { key: 'Enter' });
Expand Down Expand Up @@ -961,7 +967,9 @@ describe('SuiteHeader', () => {
/>
);

userEvent.type(screen.getByRole('menuitem', { name: 'chip' }), '{enter}', { skipClick: true });
userEvent.type(screen.getByRole('button', { name: 'chip', label: 'chip' }), '{enter}', {
skipClick: true,
});
expect(screen.getByText('this is my message to you')).toBeVisible();
jest.spyOn(HTMLAnchorElement.prototype, 'click');
fireEvent.keyDown(screen.getByTitle('this is my message to you'), { key: 'Enter' });
Expand Down Expand Up @@ -1003,7 +1011,9 @@ describe('SuiteHeader', () => {
/>
);

userEvent.type(screen.getByRole('menuitem', { name: 'chip' }), '{enter}', { skipClick: true });
userEvent.type(screen.getByRole('button', { name: 'chip', label: 'chip' }), '{enter}', {
skipClick: true,
});
expect(screen.getByText('this is my message to you')).toBeVisible();
jest.spyOn(HTMLAnchorElement.prototype, 'click');
fireEvent.keyDown(screen.getByTitle('this is my message to you'), { key: 'Enter' });
Expand Down Expand Up @@ -1105,7 +1115,7 @@ describe('SuiteHeader', () => {
'noopener noreferrer'
);
expect(window.open).toHaveBeenCalledTimes(1);
userEvent.click(screen.getByRole('menuitem', { name: 'user' }));
userEvent.click(screen.getByRole('button', { name: 'user', label: 'user' }));
await userEvent.click(screen.getByTestId('suite-header-profile--profile'), {
ctrlKey: true,
});
Expand All @@ -1116,7 +1126,7 @@ describe('SuiteHeader', () => {
);
expect(window.open).toHaveBeenCalledTimes(2);

userEvent.click(screen.getByRole('menuitem', { name: 'Help' }));
userEvent.click(screen.getByRole('button', { name: 'Help', label: 'Help' }));
await userEvent.click(screen.getByTitle('About'), { ctrlKey: true });
expect(window.open).toHaveBeenLastCalledWith(
commonProps.routes.about,
Expand Down Expand Up @@ -1225,7 +1235,7 @@ describe('SuiteHeader', () => {
it('should close action panel if other action clicked (safari)', () => {
render(<SuiteHeader {...commonProps} />);
const headerPanel = screen.getByLabelText('Header Panel');
const profileActionButton = screen.getByRole('menuitem', { name: 'user' });
const profileActionButton = screen.getByRole('button', { name: 'user', label: 'user' });

userEvent.click(screen.getByRole('button', { name: APP_SWITCHER }));
expect(headerPanel).toHaveClass(`${prefix}--header-panel--expanded`);
Expand All @@ -1250,7 +1260,7 @@ describe('SuiteHeader', () => {
it('should close action dropdown if panel opened (safari)', () => {
render(<SuiteHeader {...commonProps} />);
const headerPanel = screen.getByLabelText('Header Panel');
const profileActionButton = screen.getByRole('menuitem', { name: 'user' });
const profileActionButton = screen.getByRole('button', { name: 'user', label: 'user' });

userEvent.click(profileActionButton);
expect(headerPanel).not.toHaveClass(`${prefix}--header-panel--expanded`);
Expand All @@ -1275,7 +1285,7 @@ describe('SuiteHeader', () => {
it('should close action menu if clicked outside (safari)', () => {
render(<SuiteHeader {...commonProps} />);
const headerPanel = screen.getByLabelText('Header Panel');
const profileActionButton = screen.getByRole('menuitem', { name: 'user' });
const profileActionButton = screen.getByRole('button', { name: 'user', label: 'user' });

expect(headerPanel).not.toHaveClass(`${prefix}--header-panel--expanded`);
expect(profileActionButton).toHaveAttribute('aria-expanded', 'false');
Expand All @@ -1290,8 +1300,10 @@ describe('SuiteHeader', () => {

it('should close action menu if clicked on other action (safari)', () => {
render(<SuiteHeader {...commonProps} />);
const profileActionButton = screen.getByRole('menuitem', { name: 'user' });
const helpActionButton = screen.getByRole('menuitem', { name: 'Help' });
const profileActionButton = screen.getByRole('button', { name: 'user', label: 'user' });
// screen.getByTestId('menuitem', { 'aria-label': 'user' });
const helpActionButton = screen.getByRole('button', { name: 'Help', label: 'Help' });
// screen.getByTestId('menuitem', { 'aria-label': 'Help' });

expect(helpActionButton).toHaveAttribute('aria-expanded', 'false');
userEvent.click(helpActionButton);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const SuiteHeaderAppSwitcher = ({
);
})}
{mergedApplications?.length === 0 ? (
<div className={`${baseClassName}--no-app`}>
<div className={`${baseClassName}--no-app`} role="listitem">
<div className="bee-icon-container">
<Bee32 />
<div className="bee-shadow" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ exports[`Storybook Snapshot tests and console checks Storyshots 1 - Watson IoT/U
/>
<div
className="iot--suite-header-app-switcher--no-app"
role="listitem"
>
<div
className="bee-icon-container"
Expand Down
Loading

0 comments on commit dcad3b6

Please sign in to comment.