Skip to content

Commit 1ce71d6

Browse files
committed
added unit tests for the SubnetNodebalancerRow component
1 parent ce0d7b2 commit 1ce71d6

File tree

3 files changed

+113
-3
lines changed

3 files changed

+113
-3
lines changed

packages/manager/src/factories/subnets.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Factory } from '@linode/utilities';
33
import type {
44
Subnet,
55
SubnetAssignedLinodeData,
6+
SubnetAssignedNodeBalancerData,
67
} from '@linode/api-v4/lib/vpcs/types';
78

89
// NOTE: Changing to fixed array length for the interfaces and linodes fields of the
@@ -20,6 +21,12 @@ export const subnetAssignedLinodeDataFactory =
2021
),
2122
});
2223

24+
export const subnetAssignedNodebalancerDataFactory =
25+
Factory.Sync.makeFactory<SubnetAssignedNodeBalancerData>({
26+
id: Factory.each((i) => i),
27+
ipv4_range: Factory.each((i) => `192.168.${i}.0/30`),
28+
});
29+
2330
export const subnetFactory = Factory.Sync.makeFactory<Subnet>({
2431
created: '2023-07-12T16:08:53',
2532
id: Factory.each((i) => i),
@@ -32,6 +39,12 @@ export const subnetFactory = Factory.Sync.makeFactory<Subnet>({
3239
})
3340
)
3441
),
35-
nodebalancers: [],
42+
nodebalancers: Factory.each((i) =>
43+
Array.from({ length: 3 }, (_, arrIdx) =>
44+
subnetAssignedNodebalancerDataFactory.build({
45+
id: i * 10 + arrIdx,
46+
})
47+
)
48+
),
3649
updated: '2023-07-12T16:08:53',
3750
});
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { waitFor, waitForElementToBeRemoved } from '@testing-library/react';
2+
import * as React from 'react';
3+
import { afterAll, afterEach, beforeAll, describe, it } from 'vitest';
4+
5+
import {
6+
firewallFactory,
7+
subnetAssignedNodebalancerDataFactory,
8+
} from 'src/factories';
9+
import { makeResourcePage } from 'src/mocks/serverHandlers';
10+
import { http, HttpResponse, server } from 'src/mocks/testServer';
11+
import {
12+
mockMatchMedia,
13+
renderWithTheme,
14+
wrapWithTableBody,
15+
} from 'src/utilities/testHelpers';
16+
17+
import { SubnetNodeBalancerRow } from './SubnetNodebalancerRow';
18+
19+
const LOADING_TEST_ID = 'circle-progress';
20+
21+
beforeAll(() => mockMatchMedia());
22+
afterEach(() => server.resetHandlers());
23+
afterAll(() => server.close());
24+
25+
describe('SubnetNodeBalancerRow', () => {
26+
const nodebalancer = {
27+
id: 123,
28+
label: 'test-nodebalancer',
29+
};
30+
31+
const configs = [
32+
{ nodes_status: { up: 3, down: 1 } },
33+
{ nodes_status: { up: 2, down: 2 } },
34+
];
35+
36+
const firewalls = makeResourcePage(
37+
firewallFactory.buildList(1, { label: 'mock-firewall' })
38+
);
39+
40+
const subnetNodebalancer = subnetAssignedNodebalancerDataFactory.build({
41+
id: nodebalancer.id,
42+
ipv4_range: '192.168.99.0/30',
43+
});
44+
45+
it('renders loading state', async () => {
46+
const { getByTestId } = renderWithTheme(
47+
wrapWithTableBody(
48+
<SubnetNodeBalancerRow
49+
ipv4={subnetNodebalancer.ipv4_range}
50+
nodeBalancerId={subnetNodebalancer.id}
51+
/>
52+
)
53+
);
54+
55+
expect(getByTestId(LOADING_TEST_ID)).toBeInTheDocument();
56+
await waitForElementToBeRemoved(() => getByTestId(LOADING_TEST_ID));
57+
});
58+
59+
it('renders nodebalancer row with data', async () => {
60+
server.use(
61+
http.get('*/nodebalancers/:id', () => {
62+
return HttpResponse.json(nodebalancer);
63+
}),
64+
http.get('*/nodebalancers/:id/configs', () => {
65+
return HttpResponse.json(configs);
66+
}),
67+
http.get('*/nodebalancers/:id/firewalls', () => {
68+
return HttpResponse.json(firewalls);
69+
})
70+
);
71+
72+
const { getByText, getByRole } = renderWithTheme(
73+
wrapWithTableBody(
74+
<SubnetNodeBalancerRow
75+
ipv4={subnetNodebalancer.ipv4_range}
76+
nodeBalancerId={nodebalancer.id}
77+
/>
78+
)
79+
);
80+
81+
await waitFor(() => {
82+
expect(getByText(nodebalancer.label)).toBeInTheDocument();
83+
});
84+
85+
expect(getByText(subnetNodebalancer.ipv4_range)).toBeInTheDocument();
86+
expect(getByText('mock-firewall')).toBeInTheDocument();
87+
88+
const nodebalancerLink = getByRole('link', {
89+
name: nodebalancer.label,
90+
});
91+
92+
expect(nodebalancerLink).toHaveAttribute(
93+
'href',
94+
`/nodebalancers/${nodebalancer.id}/summary`
95+
);
96+
});
97+
});

packages/manager/src/features/VPCs/VPCDetail/SubnetNodebalancerRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const SubnetNodeBalancerRow = ({
5050
if (nodebalancerLoading || !nodebalancer) {
5151
return (
5252
<TableRow hover={hover}>
53-
<TableCell colSpan={6}>
53+
<TableCell colSpan={6} style={{ justifyItems: 'center' }}>
5454
<CircleProgress size="sm" />
5555
</TableCell>
5656
</TableRow>
@@ -60,7 +60,7 @@ export const SubnetNodeBalancerRow = ({
6060
if (nodebalancerError) {
6161
return (
6262
<TableRow data-testid="subnet-nodebalancer-row-error" hover={hover}>
63-
<TableCell colSpan={5} style={{ paddingLeft: 24 }}>
63+
<TableCell colSpan={6} style={{ justifyItems: 'center' }}>
6464
<Box alignItems="center" display="flex">
6565
<ErrorOutline
6666
data-qa-error-icon

0 commit comments

Comments
 (0)