Skip to content

Commit 2f5f243

Browse files
authored
chore(a11yaudit): remove unneeded nav/aria-label from Popover, update tests (#7745)
1 parent d8b6c8f commit 2f5f243

File tree

7 files changed

+52
-48
lines changed

7 files changed

+52
-48
lines changed

src/components/GenSwitcher/GenSwitcher.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ export const GenSwitcher = ({ isGen1, testId }: GenSwitcherProps) => {
2424
{isGen1 ? 'Gen 1' : 'Gen 2'}
2525
<VisuallyHidden>Open Amplify generation navigation</VisuallyHidden>
2626
</Popover.Trigger>
27-
<Popover.List
28-
ariaLabel="Amplify generation navigation"
29-
anchor="left"
30-
className="gen-switcher__list"
31-
>
27+
<Popover.List anchor="left" className="gen-switcher__list">
3228
<Popover.ListItem href={`/${currentPlatform}`} current={!isGen1}>
3329
Gen 2 {isGen1 ? '' : <IconCheck className="gen-switcher__check" />}
3430
</Popover.ListItem>

src/components/GetStartedPopover/GetStartedPopover.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ export type GetStartedLinksType = {
1616
type GetStartedPopoverType = {
1717
platform: Platform | typeof DEFAULT_PLATFORM;
1818
getStartedLinks: GetStartedLinksType[];
19+
testId?: string;
1920
};
2021

2122
export const GetStartedPopover = ({
2223
platform,
23-
getStartedLinks
24+
getStartedLinks,
25+
testId
2426
}: GetStartedPopoverType) => {
2527
const isGen1Page = useIsGen1Page();
2628

@@ -47,7 +49,7 @@ export const GetStartedPopover = ({
4749
Toggle getting started guides navigation
4850
</VisuallyHidden>
4951
</Popover.Trigger>
50-
<Popover.List ariaLabel="Getting started guides for other platforms">
52+
<Popover.List testId={testId ? `${testId}-popoverList` : ''}>
5153
{getStartedLinks.map((link, index) => {
5254
return (
5355
<Popover.ListItem

src/components/GetStartedPopover/__tests__/GetStartedPopover.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jest.mock('next/router', () => routerMock);
2727

2828
describe('GetStartedPopover', () => {
2929
const getStartedHref = '/[platform]/start/quickstart/';
30+
const testId = 'getStartedTestId';
31+
const popoverTestId = `${testId}-popoverList`;
3032
const getStartedLinks = [
3133
{
3234
title: 'React',
@@ -112,7 +114,11 @@ describe('GetStartedPopover', () => {
112114
];
113115

114116
const component = (
115-
<GetStartedPopover platform={'react'} getStartedLinks={getStartedLinks} />
117+
<GetStartedPopover
118+
testId={testId}
119+
platform={'react'}
120+
getStartedLinks={getStartedLinks}
121+
/>
116122
);
117123

118124
const componentWithGeneratedLinks = (
@@ -149,9 +155,7 @@ describe('GetStartedPopover', () => {
149155
const button = await screen.findByRole('button', {
150156
name: 'Toggle getting started guides navigation'
151157
});
152-
const dropdown = await screen.findByRole('navigation', {
153-
name: 'Getting started guides for other platforms'
154-
});
158+
const dropdown = screen.getByTestId(popoverTestId);
155159

156160
expect(dropdown.classList).not.toContain('popover--expanded');
157161
userEvent.click(button);
@@ -180,9 +184,7 @@ describe('GetStartedPopover', () => {
180184
const button = await screen.findByRole('button', {
181185
name: 'Toggle getting started guides navigation'
182186
});
183-
const dropdown = await screen.findByRole('navigation', {
184-
name: 'Getting started guides for other platforms'
185-
});
187+
const dropdown = screen.getByTestId(popoverTestId);
186188

187189
userEvent.click(button);
188190
expect(dropdown.classList).toContain('popover--expanded');
@@ -195,9 +197,7 @@ describe('GetStartedPopover', () => {
195197
const button = await screen.findByRole('button', {
196198
name: 'Toggle getting started guides navigation'
197199
});
198-
const dropdown = await screen.findByRole('navigation', {
199-
name: 'Getting started guides for other platforms'
200-
});
200+
const dropdown = screen.getByTestId(popoverTestId);
201201
const platformOptions =
202202
document.getElementsByClassName('popover-list__link');
203203

src/components/PlatformNavigator/__tests__/PlatformNavigator.test.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@ const flatDirectoryMock = {
2626
jest.mock('@/directory/flatDirectory.json', () => flatDirectoryMock);
2727

2828
describe('PlatformNavigator', () => {
29+
const testId = 'platformNavTestId';
30+
const popoverTestId = `${testId}-popoverList`;
31+
2932
const component = (
30-
<PlatformNavigator currentPlatform={'react'} isGen1={false} />
33+
<PlatformNavigator
34+
testId={testId}
35+
currentPlatform={'react'}
36+
isGen1={false}
37+
/>
3138
);
3239

3340
it('should render the PlatformNavigator component', async () => {
@@ -71,7 +78,7 @@ describe('PlatformNavigator', () => {
7178
render(component);
7279

7380
const platformButton = await screen.getByRole('button');
74-
const popover = await screen.getByRole('navigation');
81+
const popover = screen.getByTestId(popoverTestId);
7582
const popoverFirstItem = popover.children[0].children[1];
7683
userEvent.click(platformButton);
7784
userEvent.tab();
@@ -84,19 +91,31 @@ describe('PlatformNavigator', () => {
8491
});
8592

8693
it('should use current pathname when platform exists for that path', async () => {
87-
render(<PlatformNavigator currentPlatform={'react'} isGen1={false} />);
94+
render(
95+
<PlatformNavigator
96+
testId={testId}
97+
currentPlatform={'react'}
98+
isGen1={false}
99+
/>
100+
);
88101

89-
const popover = await screen.getByRole('navigation');
102+
const popover = screen.getByTestId(popoverTestId);
90103
const popoverFirstItem = popover.children[0].children[0];
91104
expect(popoverFirstItem.children[0].getAttribute('href')).toBe(
92105
'/react/build-ui/figma-to-code'
93106
);
94107
});
95108

96109
it('should use platform root url when platform does not exist for current pathname', async () => {
97-
render(<PlatformNavigator currentPlatform={'react'} isGen1={false} />);
110+
render(
111+
<PlatformNavigator
112+
testId={testId}
113+
currentPlatform={'react'}
114+
isGen1={false}
115+
/>
116+
);
98117

99-
const popover = await screen.getByRole('navigation');
118+
const popover = screen.getByTestId(popoverTestId);
100119

101120
// Flutter
102121
const popoverFirstItem = popover.children[0].children[6];

src/components/PlatformNavigator/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import {
1414
type PlatformNavigatorProps = {
1515
currentPlatform: Platform;
1616
isGen1: boolean;
17+
testId?: string;
1718
};
1819

1920
export function PlatformNavigator({
2021
currentPlatform,
21-
isGen1
22+
isGen1,
23+
testId
2224
}: PlatformNavigatorProps) {
2325
const { pathname } = useRouter();
2426

@@ -57,7 +59,7 @@ export function PlatformNavigator({
5759
{platformTitle}
5860
</Popover.Trigger>
5961
<Popover.List
60-
ariaLabel="Supported frameworks and languages"
62+
testId={testId ? `${testId}-popoverList` : ''}
6163
anchor="left"
6264
fullWidth={true}
6365
>

src/components/Popover/PopoverList.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@ import { usePopover } from './usePopover';
55
interface PopoverListProps extends ViewProps {
66
anchor?: 'left' | 'right';
77
fullWidth?: boolean;
8-
/**
9-
* @description
10-
* Accessible label for the nav item. Required since we are using a <nav> element.
11-
*/
12-
ariaLabel: string;
138
}
149

1510
export const PopoverList = ({
16-
ariaLabel,
1711
children,
1812
className,
1913
anchor = 'right',
@@ -33,8 +27,7 @@ export const PopoverList = ({
3327
},
3428
className
3529
)}
36-
as="nav"
37-
aria-label={ariaLabel}
30+
as="div"
3831
id={navId}
3932
tabIndex={-1}
4033
ref={contentRef}

src/components/Popover/__tests__/Popover.test.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import userEvent from '@testing-library/user-event';
55

66
describe('Popover', () => {
77
const popoverTestId = 'popoverTestId';
8+
const popoverListTestId = 'popoverListTestId';
89
const triggerLabel = 'Popover trigger';
9-
const navLabel = 'Test list';
1010
const popover = (
1111
<Popover testId={popoverTestId}>
1212
<Popover.Trigger>{triggerLabel}</Popover.Trigger>
13-
<Popover.List ariaLabel={navLabel}>
13+
<Popover.List testId={popoverListTestId}>
1414
<Popover.ListItem href="">List item 1</Popover.ListItem>
1515
<Popover.ListItem href="">List item 2</Popover.ListItem>
1616
<Popover.ListItem href="">List item 3</Popover.ListItem>
@@ -25,7 +25,7 @@ describe('Popover', () => {
2525
const popoverTrigger = screen.getByRole('button', {
2626
name: triggerLabel
2727
});
28-
const popoverList = screen.getByRole('navigation', { name: navLabel });
28+
const popoverList = screen.getByTestId(popoverListTestId);
2929

3030
expect(popoverWrapper).toBeInTheDocument();
3131
expect(popoverTrigger).toBeInTheDocument();
@@ -37,9 +37,7 @@ describe('Popover', () => {
3737
const button = await screen.findByRole('button', {
3838
name: triggerLabel
3939
});
40-
const dropdown = await screen.findByRole('navigation', {
41-
name: navLabel
42-
});
40+
const dropdown = screen.getByTestId(popoverListTestId);
4341

4442
userEvent.click(button);
4543
expect(dropdown.classList).toContain('popover--expanded');
@@ -54,9 +52,7 @@ describe('Popover', () => {
5452
const button = await screen.findByRole('button', {
5553
name: triggerLabel
5654
});
57-
const dropdown = await screen.findByRole('navigation', {
58-
name: navLabel
59-
});
55+
const dropdown = screen.getByTestId(popoverListTestId);
6056

6157
userEvent.click(document.body);
6258
expect(dropdown.classList).not.toContain('popover--expanded');
@@ -73,9 +69,7 @@ describe('Popover', () => {
7369
const button = await screen.findByRole('button', {
7470
name: triggerLabel
7571
});
76-
const dropdown = await screen.findByRole('navigation', {
77-
name: navLabel
78-
});
72+
const dropdown = screen.getByTestId(popoverListTestId);
7973
const externalButton = await screen.findByRole('button', {
8074
name: 'External button'
8175
});
@@ -106,9 +100,7 @@ describe('Popover', () => {
106100
const button = await screen.findByRole('button', {
107101
name: triggerLabel
108102
});
109-
const dropdown = await screen.findByRole('navigation', {
110-
name: navLabel
111-
});
103+
const dropdown = screen.getByTestId(popoverListTestId);
112104
const externalButton = await screen.findByRole('button', {
113105
name: 'External button'
114106
});

0 commit comments

Comments
 (0)