Skip to content

Commit 0076fcd

Browse files
committed
Passing unit tests: VPCSubnetsTable, SubnetLinodeRow, and LinodeEntityDetailBody
1 parent 61c59fb commit 0076fcd

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

packages/manager/src/features/Linodes/LinodeEntityDetailBody.test.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,26 @@ import {
66
subnetFactory,
77
vpcFactory,
88
} from 'src/factories';
9-
import { renderWithTheme } from 'src/utilities/testHelpers';
9+
import { mockMatchMedia, renderWithTheme } from 'src/utilities/testHelpers';
1010

1111
import { LinodeEntityDetailBody } from './LinodeEntityDetailBody';
1212

1313
import type { BodyProps } from './LinodeEntityDetailBody';
1414

15+
beforeAll(() => mockMatchMedia());
16+
17+
const queryMocks = vi.hoisted(() => ({
18+
useAccount: vi.fn().mockReturnValue({}),
19+
}));
20+
21+
vi.mock('@linode/queries', async () => {
22+
const actual = await vi.importActual('@linode/queries');
23+
return {
24+
...actual,
25+
useAccount: queryMocks.useAccount,
26+
};
27+
});
28+
1529
describe('LinodeEntityDetailBody', () => {
1630
const baseProps: BodyProps = {
1731
encryptionStatus: 'enabled',
@@ -82,6 +96,12 @@ describe('LinodeEntityDetailBody', () => {
8296
});
8397

8498
it('renders VPC IPv4 and VPC IPv6 for a linode assigned to a Dual Stack VPC', () => {
99+
queryMocks.useAccount.mockReturnValue({
100+
data: {
101+
capabilities: ['VPC Dual Stack'],
102+
},
103+
});
104+
85105
const subnet = subnetFactory.build({
86106
id: 1,
87107
linodes: [subnetAssignedLinodeDataFactory.build({ id: 1 })],

packages/manager/src/features/VPCs/VPCDetail/SubnetLinodeRow.test.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const queryMocks = vi.hoisted(() => ({
3232
useLinodeConfigQuery: vi.fn().mockReturnValue({}),
3333
useLinodeInterfaceQuery: vi.fn().mockReturnValue({}),
3434
useLinodeInterfaceFirewallsQuery: vi.fn().mockReturnValue({}),
35+
useAccount: vi.fn().mockReturnValue({}),
3536
}));
3637

3738
vi.mock('@linode/queries', async () => {
@@ -44,6 +45,7 @@ vi.mock('@linode/queries', async () => {
4445
useLinodeInterfaceQuery: queryMocks.useLinodeInterfaceQuery,
4546
useLinodeInterfaceFirewallsQuery:
4647
queryMocks.useLinodeInterfaceFirewallsQuery,
48+
useAccount: queryMocks.useAccount,
4749
};
4850
});
4951

@@ -206,7 +208,13 @@ describe('SubnetLinodeRow', () => {
206208
expect(firewall).toBeVisible();
207209
});
208210

209-
it('should display the VPC IPv6 and VPC IPv6 Ranges when vpcIpv6 feature flag is enabled (config/legacy interface)', async () => {
211+
it('should display the VPC IPv6 and VPC IPv6 Ranges when vpcIpv6 feature flag is enabled and user has VPC Dual Stack account capability (config/legacy interface)', async () => {
212+
queryMocks.useAccount.mockReturnValue({
213+
data: {
214+
capabilities: ['VPC Dual Stack'],
215+
},
216+
});
217+
210218
const linodeFactory1 = linodeFactory.build({ id: 1, label: 'linode-1' });
211219
const subnetFactory1 = subnetFactory.build({ id: 1, label: 'subnet-1' });
212220
const config = linodeConfigFactory.build({
@@ -242,7 +250,13 @@ describe('SubnetLinodeRow', () => {
242250
await findByText('2001:db8::/64');
243251
});
244252

245-
it('should display the VPC IPv6 and VPC IPv6 Ranges when vpcIpv6 feature flag is enabled (Linode Interface)', async () => {
253+
it('should display the VPC IPv6 and VPC IPv6 Ranges when vpcIpv6 feature flag is enabled and user has VPC Dual Stack account capability (Linode Interface)', async () => {
254+
queryMocks.useAccount.mockReturnValue({
255+
data: {
256+
capabilities: ['VPC Dual Stack'],
257+
},
258+
});
259+
246260
const linodeFactory1 = linodeFactory.build({ id: 1, label: 'linode-1' });
247261
const vpcLinodeInterface = linodeInterfaceFactoryDualStackVPC.build({
248262
id: 1,

packages/manager/src/features/VPCs/VPCDetail/VPCSubnetsTable.test.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { screen, waitForElementToBeRemoved } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33
import * as React from 'react';
44

5-
import { firewallSettingsFactory } from 'src/factories';
5+
import { accountFactory, firewallSettingsFactory } from 'src/factories';
66
import {
77
subnetAssignedLinodeDataFactory,
88
subnetFactory,
99
} from 'src/factories/subnets';
10+
import { http, HttpResponse, server } from 'src/mocks/testServer';
1011
import { mockMatchMedia, renderWithTheme } from 'src/utilities/testHelpers';
1112

1213
import { VPCSubnetsTable } from './VPCSubnetsTable';
@@ -199,6 +200,10 @@ describe('VPC Subnets table', () => {
199200

200201
// @TODO VPC IPv6: Remove this assertion once VPC IPv6 is fully rolled out
201202
it('renders VPC IPv6 and VPC IPv6 Ranges columns in Linode table when vpcIpv6 feature flag is enabled', async () => {
203+
const account = accountFactory.build({
204+
capabilities: ['VPC Dual Stack'],
205+
});
206+
202207
const subnet = subnetFactory.build({
203208
linodes: [subnetAssignedLinodeDataFactory.build({ id: 1 })],
204209
});
@@ -209,6 +214,12 @@ describe('VPC Subnets table', () => {
209214
},
210215
});
211216

217+
server.use(
218+
http.get('*/account', () => {
219+
return HttpResponse.json(account);
220+
})
221+
);
222+
212223
renderWithTheme(
213224
<VPCSubnetsTable
214225
isVPCLKEEnterpriseCluster={false}

0 commit comments

Comments
 (0)