Skip to content

Commit

Permalink
test: [M3-9040] - Unit tests to validate aria-labels of Action Menu f…
Browse files Browse the repository at this point in the history
…or Linode IPs and ranges (#11448)

* Add unit tests coverage for ip action menu

* Added changeset: Add unit tests to validate aria-labels of Action Menu for Linode IPs & ranges
  • Loading branch information
pmakode-akamai authored Dec 23, 2024
1 parent ab2943b commit 8cea97c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11448-tests-1734703218321.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Add unit tests to validate aria-labels of Action Menu for Linode IPs & ranges ([#11448](https://github.com/linode/manager/pull/11448))
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import * as React from 'react';

import { ipAddressFactory } from 'src/factories/networking';
import { renderWithTheme, resizeScreenSize } from 'src/utilities/testHelpers';

import { LinodeNetworkingActionMenu } from './LinodeNetworkingActionMenu';

import type { IPRange } from '@linode/api-v4';

describe('LinodeNetworkingActionMenu', () => {
beforeAll(() => {
// Set width to 1279px (< 1280px) to ensure the Action menu is visible.
resizeScreenSize(1279);
});

const mockLinodeIPv4 = ipAddressFactory.buildList(1, {
public: true,
type: 'ipv4',
})[0];

const mockLinodeIPv6Range: IPRange = {
prefix: 64,
range: '2600:3c00:e000:0000::',
region: 'us-west',
route_target: '2a01:7e00::f03c:93ff:fe6e:1233',
};

const props = {
isOnlyPublicIP: true,
isVPCOnlyLinode: false,
onEdit: vi.fn(),
onRemove: vi.fn(),
readOnly: false,
};

it('should display the correct aria-label for the IP address action menu', () => {
const { getByRole } = renderWithTheme(
<LinodeNetworkingActionMenu
{...props}
ipAddress={mockLinodeIPv4}
ipType="IPv4 – Public"
/>
);

const actionMenuButton = getByRole('button');
expect(actionMenuButton).toHaveAttribute(
'aria-label',
`Action menu for IP Address ${mockLinodeIPv4.address}`
);
});

it('should display the correct aria-label for the IP range action menu', () => {
const { getByRole } = renderWithTheme(
<LinodeNetworkingActionMenu
{...props}
ipAddress={mockLinodeIPv6Range}
ipType="IPv6 – Range"
/>
);

const actionMenuButton = getByRole('button');
expect(actionMenuButton).toHaveAttribute(
'aria-label',
`Action menu for IP Address ${mockLinodeIPv6Range.range}`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ export const LinodeNetworkingActionMenu = (props: Props) => {
)}
</>
) : (
<Box sx={{ height: 40 }}></Box>
<Box sx={{ height: 40 }} />
);
};

0 comments on commit 8cea97c

Please sign in to comment.