From e64101c255519d6181ac675fe7e96cb344826451 Mon Sep 17 00:00:00 2001 From: Alban Bailly <130582365+abailly-akamai@users.noreply.github.com> Date: Sat, 29 Jun 2024 12:04:39 -0400 Subject: [PATCH] refactor: [M3-8291] - Enforce Factory.each to start increment at `1` (#10619) * Initial commit - save work * save progress * save progress * last one * comment and cleanup * cleanup * Added changeset: Enforce Factory.each to start increment at 1 * exclude cypress for now * comment * Going the proxy route in order to satisfy cypress * feedback @dwiley-akamai @mjac0bs * Remove hard-coded plan type labels in test assertions * feedback @bnussman-akamai * small cleanup --------- Co-authored-by: Joe D'Amore --- .../pr-10619-tech-stories-1719459021760.md | 5 ++ .../e2e/core/kubernetes/lke-update.spec.ts | 45 ++++++++----- .../EnhancedNumberInput.tsx | 8 +-- .../ImageSelect/ImageSelect.test.tsx | 10 +-- .../StackScript/StackScript.test.tsx | 2 +- packages/manager/src/factories/account.ts | 2 +- .../src/factories/accountAgreements.ts | 2 +- .../src/factories/accountAvailability.ts | 2 +- .../manager/src/factories/accountLogin.ts | 2 +- .../src/factories/accountMaintenance.ts | 2 +- .../manager/src/factories/accountOAuth.ts | 2 +- .../manager/src/factories/accountPayment.ts | 2 +- .../manager/src/factories/accountSettings.ts | 2 +- .../manager/src/factories/accountUsers.ts | 2 +- packages/manager/src/factories/aclb.ts | 2 +- packages/manager/src/factories/betas.ts | 2 +- packages/manager/src/factories/billing.ts | 2 +- packages/manager/src/factories/config.ts | 2 +- packages/manager/src/factories/databases.ts | 2 +- packages/manager/src/factories/disk.ts | 2 +- packages/manager/src/factories/domain.ts | 2 +- .../manager/src/factories/entityTransfers.ts | 2 +- packages/manager/src/factories/events.ts | 2 +- .../manager/src/factories/factoryProxy.ts | 32 ++++++++++ .../manager/src/factories/featureFlags.ts | 2 +- packages/manager/src/factories/firewalls.ts | 2 +- packages/manager/src/factories/grants.ts | 2 +- packages/manager/src/factories/images.ts | 2 +- packages/manager/src/factories/kernels.ts | 2 +- .../src/factories/kubernetesCluster.ts | 2 +- .../factories/linodeConfigInterfaceFactory.ts | 2 +- .../manager/src/factories/linodeConfigs.ts | 2 +- packages/manager/src/factories/linodes.ts | 2 +- .../manager/src/factories/longviewClient.ts | 2 +- .../manager/src/factories/longviewDisks.ts | 2 +- .../manager/src/factories/longviewProcess.ts | 2 +- .../manager/src/factories/longviewResponse.ts | 2 +- .../manager/src/factories/longviewService.ts | 2 +- .../src/factories/longviewSubscription.ts | 2 +- .../src/factories/longviewTopProcesses.ts | 2 +- packages/manager/src/factories/managed.ts | 2 +- packages/manager/src/factories/networking.ts | 2 +- .../manager/src/factories/nodebalancer.ts | 2 +- .../manager/src/factories/notification.ts | 2 +- packages/manager/src/factories/oauth.ts | 2 +- .../manager/src/factories/objectStorage.ts | 2 +- .../manager/src/factories/placementGroups.ts | 2 +- packages/manager/src/factories/preferences.ts | 2 +- packages/manager/src/factories/profile.ts | 2 +- .../manager/src/factories/promotionalOffer.ts | 2 +- packages/manager/src/factories/regions.ts | 2 +- .../manager/src/factories/stackscripts.ts | 2 +- packages/manager/src/factories/statusPage.ts | 2 +- packages/manager/src/factories/subnets.ts | 2 +- packages/manager/src/factories/support.ts | 2 +- packages/manager/src/factories/tags.ts | 2 +- packages/manager/src/factories/types.ts | 2 +- packages/manager/src/factories/vlans.ts | 2 +- packages/manager/src/factories/volume.ts | 2 +- packages/manager/src/factories/vpcs.ts | 2 +- .../BillingActivityPanel.test.tsx | 4 +- .../shared/CloudPulseResourcesSelect.test.tsx | 20 +++--- ...atabaseResizeCurrentConfiguration.test.tsx | 2 +- .../FirewallLanding/FirewallRow.test.tsx | 2 +- .../src/features/Images/ImageSelect.test.tsx | 6 +- .../ImagesLanding/EditImageDrawer.test.tsx | 2 +- .../ImagesLanding/RebuildImageDrawer.test.tsx | 2 +- .../src/features/Images/utils.test.tsx | 12 ++-- .../ClusterList/KubernetesClusterRow.test.tsx | 10 +-- .../KubeCheckoutBar/KubeCheckoutBar.test.tsx | 29 +++++---- .../ResizeNodePoolDrawer.test.tsx | 16 ++++- .../StackScriptDetailsDialog.test.tsx | 4 +- .../SelectLinodePanel.test.tsx | 8 +-- .../SelectLinodeRow.test.tsx | 16 ++++- .../Linodes/LinodesCreate/utilities.test.ts | 22 +++---- .../Linodes/LinodesLanding/utils.test.ts | 11 ++-- .../LongviewLanding/LongviewLanding.test.tsx | 7 ++- .../BucketLanding/BucketLanding.test.tsx | 2 +- .../PlacementGroupsRow.test.tsx | 63 ++++++++++--------- .../VPCs/VPCDetail/SubnetLinodeRow.test.tsx | 2 +- .../features/VPCs/VPCLanding/VPCRow.test.tsx | 7 ++- .../manager/src/features/VPCs/utils.test.ts | 12 ++-- .../src/utilities/mapIdsToDevices.test.ts | 29 +++++---- 83 files changed, 302 insertions(+), 196 deletions(-) create mode 100644 packages/manager/.changeset/pr-10619-tech-stories-1719459021760.md create mode 100644 packages/manager/src/factories/factoryProxy.ts diff --git a/packages/manager/.changeset/pr-10619-tech-stories-1719459021760.md b/packages/manager/.changeset/pr-10619-tech-stories-1719459021760.md new file mode 100644 index 00000000000..7bd3fb5ae3d --- /dev/null +++ b/packages/manager/.changeset/pr-10619-tech-stories-1719459021760.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tech Stories +--- + +Make `Factory.each` start incrementing at 1 instead of 0 ([#10619](https://github.com/linode/manager/pull/10619)) diff --git a/packages/manager/cypress/e2e/core/kubernetes/lke-update.spec.ts b/packages/manager/cypress/e2e/core/kubernetes/lke-update.spec.ts index 9d89090ff43..e576ff2ffcd 100644 --- a/packages/manager/cypress/e2e/core/kubernetes/lke-update.spec.ts +++ b/packages/manager/cypress/e2e/core/kubernetes/lke-update.spec.ts @@ -4,6 +4,7 @@ import { kubeLinodeFactory, linodeFactory, } from 'src/factories'; +import { extendType } from 'src/utilities/extendType'; import { latestKubernetesVersion } from 'support/constants/lke'; import { mockGetCluster, @@ -785,6 +786,7 @@ describe('LKE cluster updates for DC-specific prices', () => { */ it('can resize pools with DC-specific prices', () => { const dcSpecificPricingRegion = getRegionById('us-east'); + const mockPlanType = extendType(dcPricingMockLinodeTypes[0]); const mockCluster = kubernetesClusterFactory.build({ k8s_version: latestKubernetesVersion, @@ -796,7 +798,7 @@ describe('LKE cluster updates for DC-specific prices', () => { const mockNodePoolResized = nodePoolFactory.build({ count: 3, - type: dcPricingMockLinodeTypes[0].id, + type: mockPlanType.id, nodes: kubeLinodeFactory.buildList(3), }); @@ -812,19 +814,19 @@ describe('LKE cluster updates for DC-specific prices', () => { id: node.instance_id ?? undefined, ipv4: [randomIp()], region: dcSpecificPricingRegion.id, - type: dcPricingMockLinodeTypes[0].id, + type: mockPlanType.id, }); } ); - const mockNodePoolDrawerTitle = 'Resize Pool: Linode 0 GB Plan'; + const mockNodePoolDrawerTitle = `Resize Pool: ${mockPlanType.formattedLabel} Plan`; mockGetCluster(mockCluster).as('getCluster'); mockGetClusterPools(mockCluster.id, [mockNodePoolInitial]).as( 'getNodePools' ); mockGetLinodes(mockLinodes).as('getLinodes'); - mockGetLinodeType(dcPricingMockLinodeTypes[0]).as('getLinodeType'); + mockGetLinodeType(mockPlanType).as('getLinodeType'); mockGetKubernetesVersions().as('getVersions'); mockGetDashboardUrl(mockCluster.id); mockGetApiEndpoints(mockCluster.id); @@ -938,15 +940,17 @@ describe('LKE cluster updates for DC-specific prices', () => { }, }); + const mockPlanType = extendType(dcPricingMockLinodeTypes[0]); + const mockNewNodePool = nodePoolFactory.build({ count: 2, - type: dcPricingMockLinodeTypes[0].id, + type: mockPlanType.id, nodes: kubeLinodeFactory.buildList(2), }); const mockNodePool = nodePoolFactory.build({ count: 1, - type: dcPricingMockLinodeTypes[0].id, + type: mockPlanType.id, nodes: kubeLinodeFactory.buildList(1), }); @@ -954,7 +958,7 @@ describe('LKE cluster updates for DC-specific prices', () => { mockGetClusterPools(mockCluster.id, [mockNodePool]).as('getNodePools'); mockGetKubernetesVersions().as('getVersions'); mockAddNodePool(mockCluster.id, mockNewNodePool).as('addNodePool'); - mockGetLinodeType(dcPricingMockLinodeTypes[0]).as('getLinodeType'); + mockGetLinodeType(mockPlanType).as('getLinodeType'); mockGetLinodeTypes(dcPricingMockLinodeTypes); mockGetDashboardUrl(mockCluster.id); mockGetApiEndpoints(mockCluster.id); @@ -963,7 +967,9 @@ describe('LKE cluster updates for DC-specific prices', () => { cy.wait(['@getCluster', '@getNodePools', '@getVersions', '@getLinodeType']); // Assert that initial node pool is shown on the page. - cy.findByText('Linode 0 GB', { selector: 'h2' }).should('be.visible'); + cy.findByText(mockPlanType.formattedLabel, { selector: 'h2' }).should( + 'be.visible' + ); // Confirm total price is listed in Kube Specs. cy.findByText('$14.40/month').should('be.visible'); @@ -987,7 +993,7 @@ describe('LKE cluster updates for DC-specific prices', () => { .should('be.visible') .should('be.enabled') .click(); - cy.findByText('Linode 0 GB') + cy.findByText(mockPlanType.formattedLabel) .should('be.visible') .closest('tr') .within(() => { @@ -1024,6 +1030,7 @@ describe('LKE cluster updates for DC-specific prices', () => { */ it('can resize pools with region prices of $0', () => { const dcSpecificPricingRegion = getRegionById('us-southeast'); + const mockPlanType = extendType(dcPricingMockLinodeTypes[2]); const mockCluster = kubernetesClusterFactory.build({ k8s_version: latestKubernetesVersion, @@ -1035,7 +1042,7 @@ describe('LKE cluster updates for DC-specific prices', () => { const mockNodePoolResized = nodePoolFactory.build({ count: 3, - type: dcPricingMockLinodeTypes[2].id, + type: mockPlanType.id, nodes: kubeLinodeFactory.buildList(3), }); @@ -1051,19 +1058,19 @@ describe('LKE cluster updates for DC-specific prices', () => { id: node.instance_id ?? undefined, ipv4: [randomIp()], region: dcSpecificPricingRegion.id, - type: dcPricingMockLinodeTypes[2].id, + type: mockPlanType.id, }); } ); - const mockNodePoolDrawerTitle = 'Resize Pool: Linode 2 GB Plan'; + const mockNodePoolDrawerTitle = `Resize Pool: ${mockPlanType.formattedLabel} Plan`; mockGetCluster(mockCluster).as('getCluster'); mockGetClusterPools(mockCluster.id, [mockNodePoolInitial]).as( 'getNodePools' ); mockGetLinodes(mockLinodes).as('getLinodes'); - mockGetLinodeType(dcPricingMockLinodeTypes[2]).as('getLinodeType'); + mockGetLinodeType(mockPlanType).as('getLinodeType'); mockGetKubernetesVersions().as('getVersions'); mockGetDashboardUrl(mockCluster.id); mockGetApiEndpoints(mockCluster.id); @@ -1160,6 +1167,8 @@ describe('LKE cluster updates for DC-specific prices', () => { it('can add node pools with region prices of $0', () => { const dcSpecificPricingRegion = getRegionById('us-southeast'); + const mockPlanType = extendType(dcPricingMockLinodeTypes[2]); + const mockCluster = kubernetesClusterFactory.build({ k8s_version: latestKubernetesVersion, region: dcSpecificPricingRegion.id, @@ -1170,13 +1179,13 @@ describe('LKE cluster updates for DC-specific prices', () => { const mockNewNodePool = nodePoolFactory.build({ count: 2, - type: dcPricingMockLinodeTypes[2].id, + type: mockPlanType.id, nodes: kubeLinodeFactory.buildList(2), }); const mockNodePool = nodePoolFactory.build({ count: 1, - type: dcPricingMockLinodeTypes[2].id, + type: mockPlanType.id, nodes: kubeLinodeFactory.buildList(1), }); @@ -1184,7 +1193,7 @@ describe('LKE cluster updates for DC-specific prices', () => { mockGetClusterPools(mockCluster.id, [mockNodePool]).as('getNodePools'); mockGetKubernetesVersions().as('getVersions'); mockAddNodePool(mockCluster.id, mockNewNodePool).as('addNodePool'); - mockGetLinodeType(dcPricingMockLinodeTypes[2]).as('getLinodeType'); + mockGetLinodeType(mockPlanType).as('getLinodeType'); mockGetLinodeTypes(dcPricingMockLinodeTypes); mockGetDashboardUrl(mockCluster.id); mockGetApiEndpoints(mockCluster.id); @@ -1193,7 +1202,9 @@ describe('LKE cluster updates for DC-specific prices', () => { cy.wait(['@getCluster', '@getNodePools', '@getVersions', '@getLinodeType']); // Assert that initial node pool is shown on the page. - cy.findByText('Linode 2 GB', { selector: 'h2' }).should('be.visible'); + cy.findByText(mockPlanType.formattedLabel, { selector: 'h2' }).should( + 'be.visible' + ); // Confirm total price of $0 is listed in Kube Specs. cy.findByText('$0.00/month').should('be.visible'); diff --git a/packages/manager/src/components/EnhancedNumberInput/EnhancedNumberInput.tsx b/packages/manager/src/components/EnhancedNumberInput/EnhancedNumberInput.tsx index 9f291496d6b..6d8d47f0307 100644 --- a/packages/manager/src/components/EnhancedNumberInput/EnhancedNumberInput.tsx +++ b/packages/manager/src/components/EnhancedNumberInput/EnhancedNumberInput.tsx @@ -1,22 +1,22 @@ -import { Box } from 'src/components/Box'; import { styled } from '@mui/material/styles'; import * as React from 'react'; import Minus from 'src/assets/icons/LKEminusSign.svg'; import Plus from 'src/assets/icons/LKEplusSign.svg'; +import { Box } from 'src/components/Box'; import { Button } from 'src/components/Button/Button'; import { TextField } from 'src/components/TextField'; const sxTextFieldBase = { '&::-webkit-inner-spin-button': { - '-webkit-appearance': 'none', + WebkitAppearance: 'none', margin: 0, }, '&::-webkit-outer-spin-button': { - '-webkit-appearance': 'none', + WebkitAppearance: 'none', margin: 0, }, - '-moz-appearance': 'textfield', + MozAppearance: 'textfield', padding: '0 8px', textAlign: 'right', }; diff --git a/packages/manager/src/components/ImageSelect/ImageSelect.test.tsx b/packages/manager/src/components/ImageSelect/ImageSelect.test.tsx index 664525d5383..65eb904c708 100644 --- a/packages/manager/src/components/ImageSelect/ImageSelect.test.tsx +++ b/packages/manager/src/components/ImageSelect/ImageSelect.test.tsx @@ -36,7 +36,7 @@ describe('imagesToGroupedItems', () => { isCloudInitCompatible: false, isDistributedCompatible: false, label: 'Slackware 14.1', - value: 'private/4', + value: 'private/5', }, { className: 'fl-tux', @@ -44,13 +44,15 @@ describe('imagesToGroupedItems', () => { isCloudInitCompatible: false, isDistributedCompatible: false, label: 'Slackware 14.1', - value: 'private/5', + value: 'private/6', }, ], }, ]; + expect(imagesToGroupedItems(images)).toStrictEqual(expected); }); + it('should add suffix `deprecated` to images at end of life ', () => { const images = [ ...imageFactory.buildList(2, { @@ -76,7 +78,7 @@ describe('imagesToGroupedItems', () => { isCloudInitCompatible: false, isDistributedCompatible: false, label: 'Debian 9 (deprecated)', - value: 'private/6', + value: 'private/7', }, { className: 'fl-tux', @@ -84,7 +86,7 @@ describe('imagesToGroupedItems', () => { isCloudInitCompatible: false, isDistributedCompatible: false, label: 'Debian 9 (deprecated)', - value: 'private/7', + value: 'private/8', }, ], }, diff --git a/packages/manager/src/components/StackScript/StackScript.test.tsx b/packages/manager/src/components/StackScript/StackScript.test.tsx index e6ccb1e4e11..f8b642cd540 100644 --- a/packages/manager/src/components/StackScript/StackScript.test.tsx +++ b/packages/manager/src/components/StackScript/StackScript.test.tsx @@ -8,7 +8,7 @@ import { StackScript } from './StackScript'; describe('StackScript', () => { it('should render the StackScript label, id, and username', () => { - const stackScript = stackScriptFactory.build(); + const stackScript = stackScriptFactory.build({ id: 1234 }); renderWithTheme(); expect(screen.getByText(stackScript.label)).toBeInTheDocument(); diff --git a/packages/manager/src/factories/account.ts b/packages/manager/src/factories/account.ts index 770b4098e4d..eace884c756 100644 --- a/packages/manager/src/factories/account.ts +++ b/packages/manager/src/factories/account.ts @@ -3,7 +3,7 @@ import { ActivePromotion, RegionalNetworkUtilization, } from '@linode/api-v4/lib/account/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const promoFactory = Factory.Sync.makeFactory({ credit_monthly_cap: '20.00', diff --git a/packages/manager/src/factories/accountAgreements.ts b/packages/manager/src/factories/accountAgreements.ts index abc9eabeb94..e14f1db920f 100644 --- a/packages/manager/src/factories/accountAgreements.ts +++ b/packages/manager/src/factories/accountAgreements.ts @@ -1,5 +1,5 @@ import { Agreements } from '@linode/api-v4/lib/account'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const accountAgreementsFactory = Factory.Sync.makeFactory({ eu_model: false, diff --git a/packages/manager/src/factories/accountAvailability.ts b/packages/manager/src/factories/accountAvailability.ts index 7f1cff796a0..3196a439674 100644 --- a/packages/manager/src/factories/accountAvailability.ts +++ b/packages/manager/src/factories/accountAvailability.ts @@ -1,5 +1,5 @@ import { AccountAvailability } from '@linode/api-v4'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { pickRandom } from 'src/utilities/random'; diff --git a/packages/manager/src/factories/accountLogin.ts b/packages/manager/src/factories/accountLogin.ts index 878519a2c43..e4f36ab9cce 100644 --- a/packages/manager/src/factories/accountLogin.ts +++ b/packages/manager/src/factories/accountLogin.ts @@ -1,5 +1,5 @@ import { AccountLogin } from '@linode/api-v4'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const accountLoginFactory = Factory.Sync.makeFactory({ datetime: '2021-05-21T14:27:51', diff --git a/packages/manager/src/factories/accountMaintenance.ts b/packages/manager/src/factories/accountMaintenance.ts index 11223cf6c16..987769b936a 100644 --- a/packages/manager/src/factories/accountMaintenance.ts +++ b/packages/manager/src/factories/accountMaintenance.ts @@ -1,5 +1,5 @@ import { AccountMaintenance } from '@linode/api-v4/lib/account/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { pickRandom, randomDate } from 'src/utilities/random'; diff --git a/packages/manager/src/factories/accountOAuth.ts b/packages/manager/src/factories/accountOAuth.ts index 277632864ba..37c380efea6 100644 --- a/packages/manager/src/factories/accountOAuth.ts +++ b/packages/manager/src/factories/accountOAuth.ts @@ -1,5 +1,5 @@ import { OAuthClient } from '@linode/api-v4'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const oauthClientFactory = Factory.Sync.makeFactory({ id: Factory.each((id) => String(id)), diff --git a/packages/manager/src/factories/accountPayment.ts b/packages/manager/src/factories/accountPayment.ts index 392d3cc94c2..844613a1367 100644 --- a/packages/manager/src/factories/accountPayment.ts +++ b/packages/manager/src/factories/accountPayment.ts @@ -1,5 +1,5 @@ import { PaymentMethod } from '@linode/api-v4'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const paymentMethodFactory = Factory.Sync.makeFactory({ created: '2021-05-21T14:27:51', diff --git a/packages/manager/src/factories/accountSettings.ts b/packages/manager/src/factories/accountSettings.ts index 4c7f9a073af..5b9d320bf66 100644 --- a/packages/manager/src/factories/accountSettings.ts +++ b/packages/manager/src/factories/accountSettings.ts @@ -1,5 +1,5 @@ import { AccountSettings } from '@linode/api-v4/lib/account/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const accountSettingsFactory = Factory.Sync.makeFactory( { diff --git a/packages/manager/src/factories/accountUsers.ts b/packages/manager/src/factories/accountUsers.ts index 664cf75bd8b..49e8e968db1 100644 --- a/packages/manager/src/factories/accountUsers.ts +++ b/packages/manager/src/factories/accountUsers.ts @@ -1,5 +1,5 @@ import { User } from '@linode/api-v4'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const accountUserFactory = Factory.Sync.makeFactory({ email: 'support@linode.com', diff --git a/packages/manager/src/factories/aclb.ts b/packages/manager/src/factories/aclb.ts index 7a3779e4ebc..1ca143ec038 100644 --- a/packages/manager/src/factories/aclb.ts +++ b/packages/manager/src/factories/aclb.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { pickRandom } from 'src/utilities/random'; diff --git a/packages/manager/src/factories/betas.ts b/packages/manager/src/factories/betas.ts index c50e76f2a28..80041895527 100644 --- a/packages/manager/src/factories/betas.ts +++ b/packages/manager/src/factories/betas.ts @@ -1,5 +1,5 @@ import { Beta, AccountBeta } from '@linode/api-v4'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { DateTime } from 'luxon'; export const betaFactory = Factory.Sync.makeFactory({ diff --git a/packages/manager/src/factories/billing.ts b/packages/manager/src/factories/billing.ts index dbbf732a8cf..f14b7e80c97 100644 --- a/packages/manager/src/factories/billing.ts +++ b/packages/manager/src/factories/billing.ts @@ -5,7 +5,7 @@ import { PaymentResponse, } from '@linode/api-v4/lib/account'; import { APIWarning } from '@linode/api-v4/lib/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const invoiceItemFactory = Factory.Sync.makeFactory({ amount: 5, diff --git a/packages/manager/src/factories/config.ts b/packages/manager/src/factories/config.ts index a98b0e798d5..72199f914f1 100644 --- a/packages/manager/src/factories/config.ts +++ b/packages/manager/src/factories/config.ts @@ -1,5 +1,5 @@ import { Config } from '@linode/api-v4/lib/linodes/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const configFactory = Factory.Sync.makeFactory({ comments: '', diff --git a/packages/manager/src/factories/databases.ts b/packages/manager/src/factories/databases.ts index 36264eeb324..b9188b54d62 100644 --- a/packages/manager/src/factories/databases.ts +++ b/packages/manager/src/factories/databases.ts @@ -8,7 +8,7 @@ import { MySQLReplicationType, PostgresReplicationType, } from '@linode/api-v4/lib/databases/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { v4 } from 'uuid'; import { pickRandom, randomDate } from 'src/utilities/random'; diff --git a/packages/manager/src/factories/disk.ts b/packages/manager/src/factories/disk.ts index 9aef8fe3c1c..0ee25de8cea 100644 --- a/packages/manager/src/factories/disk.ts +++ b/packages/manager/src/factories/disk.ts @@ -1,5 +1,5 @@ import { Disk } from '@linode/api-v4/lib/linodes/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const linodeDiskFactory = Factory.Sync.makeFactory({ created: '2018-01-01', diff --git a/packages/manager/src/factories/domain.ts b/packages/manager/src/factories/domain.ts index f0b2bad1c13..3244d825b7f 100644 --- a/packages/manager/src/factories/domain.ts +++ b/packages/manager/src/factories/domain.ts @@ -4,7 +4,7 @@ import { DomainRecord, ZoneFile, } from '@linode/api-v4/lib/domains/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const domainFactory = Factory.Sync.makeFactory({ axfr_ips: [], diff --git a/packages/manager/src/factories/entityTransfers.ts b/packages/manager/src/factories/entityTransfers.ts index 826f2889400..a785fbf0c45 100644 --- a/packages/manager/src/factories/entityTransfers.ts +++ b/packages/manager/src/factories/entityTransfers.ts @@ -2,7 +2,7 @@ import { EntityTransfer, TransferEntities, } from '@linode/api-v4/lib/entity-transfers/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { DateTime } from 'luxon'; import { v4 } from 'uuid'; diff --git a/packages/manager/src/factories/events.ts b/packages/manager/src/factories/events.ts index 3b74a662149..f0dd62292bb 100644 --- a/packages/manager/src/factories/events.ts +++ b/packages/manager/src/factories/events.ts @@ -1,5 +1,5 @@ import { Entity, Event } from '@linode/api-v4/lib/account/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { DateTime } from 'luxon'; export const entityFactory = Factory.Sync.makeFactory({ diff --git a/packages/manager/src/factories/factoryProxy.ts b/packages/manager/src/factories/factoryProxy.ts new file mode 100644 index 00000000000..437f443b27a --- /dev/null +++ b/packages/manager/src/factories/factoryProxy.ts @@ -0,0 +1,32 @@ +import * as Factory from 'factory.ts'; + +const originalEach = Factory.each; + +/** + * This file is a proxy for the factory.ts library. + * + * We Override the `each` method of the factory.ts library to start the index from 1 + * This prevents a a variety of issues with entity IDs being falsy when starting from 0. + * + * As a result, `Factory` must be imported from the `factoryProxy` file. ex: + * `import Factory from 'src/factories/factoryProxy';` + */ +const factoryProxyHandler = { + get( + target: typeof Factory, + prop: keyof typeof Factory, + receiver: typeof Factory + ) { + if (prop === 'each') { + return (fn: (index: number) => number | string) => { + return originalEach((i) => { + return fn(i + 1); + }); + }; + } + + return Reflect.get(target, prop, receiver); + }, +}; + +export default new Proxy(Factory, factoryProxyHandler); diff --git a/packages/manager/src/factories/featureFlags.ts b/packages/manager/src/factories/featureFlags.ts index 0c7589388e6..2a7e64d93db 100644 --- a/packages/manager/src/factories/featureFlags.ts +++ b/packages/manager/src/factories/featureFlags.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { ProductInformationBannerFlag } from 'src/featureFlags'; diff --git a/packages/manager/src/factories/firewalls.ts b/packages/manager/src/factories/firewalls.ts index 5d70b52d97c..5c72caa6d61 100644 --- a/packages/manager/src/factories/firewalls.ts +++ b/packages/manager/src/factories/firewalls.ts @@ -5,7 +5,7 @@ import { FirewallRuleType, FirewallRules, } from '@linode/api-v4/lib/firewalls/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const firewallRuleFactory = Factory.Sync.makeFactory({ action: 'DROP', diff --git a/packages/manager/src/factories/grants.ts b/packages/manager/src/factories/grants.ts index d1cd55caba0..bfa53a7de8b 100644 --- a/packages/manager/src/factories/grants.ts +++ b/packages/manager/src/factories/grants.ts @@ -1,5 +1,5 @@ import { Grant, Grants } from '@linode/api-v4/lib/account'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const grantFactory = Factory.Sync.makeFactory({ id: Factory.each((i) => i), diff --git a/packages/manager/src/factories/images.ts b/packages/manager/src/factories/images.ts index 18a6246e599..85255aacb17 100644 --- a/packages/manager/src/factories/images.ts +++ b/packages/manager/src/factories/images.ts @@ -1,5 +1,5 @@ import { Image } from '@linode/api-v4/lib/images/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const imageFactory = Factory.Sync.makeFactory({ capabilities: [], diff --git a/packages/manager/src/factories/kernels.ts b/packages/manager/src/factories/kernels.ts index 316704080ee..ad1f0418993 100644 --- a/packages/manager/src/factories/kernels.ts +++ b/packages/manager/src/factories/kernels.ts @@ -1,5 +1,5 @@ import { Kernel } from '@linode/api-v4'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const kernelFactory = Factory.Sync.makeFactory({ id: Factory.each((i) => `kernel-${i}`), diff --git a/packages/manager/src/factories/kubernetesCluster.ts b/packages/manager/src/factories/kubernetesCluster.ts index c2ca312899a..5bf468c00fe 100644 --- a/packages/manager/src/factories/kubernetesCluster.ts +++ b/packages/manager/src/factories/kubernetesCluster.ts @@ -6,7 +6,7 @@ import { KubernetesVersion, PoolNodeResponse, } from '@linode/api-v4/lib/kubernetes/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { v4 } from 'uuid'; export const kubeLinodeFactory = Factory.Sync.makeFactory({ diff --git a/packages/manager/src/factories/linodeConfigInterfaceFactory.ts b/packages/manager/src/factories/linodeConfigInterfaceFactory.ts index 914551a8fa6..4f041afec55 100644 --- a/packages/manager/src/factories/linodeConfigInterfaceFactory.ts +++ b/packages/manager/src/factories/linodeConfigInterfaceFactory.ts @@ -1,5 +1,5 @@ import { Interface } from '@linode/api-v4/lib/linodes/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const LinodeConfigInterfaceFactory = Factory.Sync.makeFactory( { diff --git a/packages/manager/src/factories/linodeConfigs.ts b/packages/manager/src/factories/linodeConfigs.ts index 66c2ec0de7a..08c64f8f2d9 100644 --- a/packages/manager/src/factories/linodeConfigs.ts +++ b/packages/manager/src/factories/linodeConfigs.ts @@ -1,5 +1,5 @@ import { Config } from '@linode/api-v4/lib/linodes/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { LinodeConfigInterfaceFactory, diff --git a/packages/manager/src/factories/linodes.ts b/packages/manager/src/factories/linodes.ts index 735dac98182..41adb044a39 100644 --- a/packages/manager/src/factories/linodes.ts +++ b/packages/manager/src/factories/linodes.ts @@ -12,7 +12,7 @@ import { Stats, StatsData, } from '@linode/api-v4/lib/linodes/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { placementGroupFactory } from './placementGroups'; diff --git a/packages/manager/src/factories/longviewClient.ts b/packages/manager/src/factories/longviewClient.ts index 9de4845d034..f146da0e0c5 100644 --- a/packages/manager/src/factories/longviewClient.ts +++ b/packages/manager/src/factories/longviewClient.ts @@ -1,5 +1,5 @@ import { Apps, LongviewClient } from '@linode/api-v4/lib/longview'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const longviewAppsFactory = Factory.Sync.makeFactory({ apache: false, diff --git a/packages/manager/src/factories/longviewDisks.ts b/packages/manager/src/factories/longviewDisks.ts index 5a5dc8ca1fc..ea43a79a5ac 100644 --- a/packages/manager/src/factories/longviewDisks.ts +++ b/packages/manager/src/factories/longviewDisks.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { Disk, diff --git a/packages/manager/src/factories/longviewProcess.ts b/packages/manager/src/factories/longviewProcess.ts index 0da3ab24193..cc465b690f1 100644 --- a/packages/manager/src/factories/longviewProcess.ts +++ b/packages/manager/src/factories/longviewProcess.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { LongviewProcesses, diff --git a/packages/manager/src/factories/longviewResponse.ts b/packages/manager/src/factories/longviewResponse.ts index fa992343ae9..427b3809c5d 100644 --- a/packages/manager/src/factories/longviewResponse.ts +++ b/packages/manager/src/factories/longviewResponse.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { LongviewResponse } from 'src/features/Longview/request.types'; import { AllData, LongviewPackage } from 'src/features/Longview/request.types'; diff --git a/packages/manager/src/factories/longviewService.ts b/packages/manager/src/factories/longviewService.ts index ff3462c7fd5..fbc8978a36e 100644 --- a/packages/manager/src/factories/longviewService.ts +++ b/packages/manager/src/factories/longviewService.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { LongviewPort, diff --git a/packages/manager/src/factories/longviewSubscription.ts b/packages/manager/src/factories/longviewSubscription.ts index 4fe2d140d9c..6e63fe5bf35 100644 --- a/packages/manager/src/factories/longviewSubscription.ts +++ b/packages/manager/src/factories/longviewSubscription.ts @@ -2,7 +2,7 @@ import { ActiveLongviewPlan, LongviewSubscription, } from '@linode/api-v4/lib/longview/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const longviewSubscriptionFactory = Factory.Sync.makeFactory( { diff --git a/packages/manager/src/factories/longviewTopProcesses.ts b/packages/manager/src/factories/longviewTopProcesses.ts index ee51a280775..22cd669ce31 100644 --- a/packages/manager/src/factories/longviewTopProcesses.ts +++ b/packages/manager/src/factories/longviewTopProcesses.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { LongviewTopProcesses, diff --git a/packages/manager/src/factories/managed.ts b/packages/manager/src/factories/managed.ts index 9652ce62c11..daceda4dabf 100644 --- a/packages/manager/src/factories/managed.ts +++ b/packages/manager/src/factories/managed.ts @@ -9,7 +9,7 @@ import { ManagedServiceMonitor, ManagedStats, } from '@linode/api-v4/lib/managed/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const contactFactory = Factory.Sync.makeFactory({ email: Factory.each((i) => `john.doe.${i}@example.com`), diff --git a/packages/manager/src/factories/networking.ts b/packages/manager/src/factories/networking.ts index 7580e12be81..74a29840383 100644 --- a/packages/manager/src/factories/networking.ts +++ b/packages/manager/src/factories/networking.ts @@ -1,5 +1,5 @@ import { IPAddress } from '@linode/api-v4/lib/networking'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const ipAddressFactory = Factory.Sync.makeFactory({ address: Factory.each((id) => `192.168.1.${id}`), diff --git a/packages/manager/src/factories/nodebalancer.ts b/packages/manager/src/factories/nodebalancer.ts index 0be6b30b428..711289d7abf 100644 --- a/packages/manager/src/factories/nodebalancer.ts +++ b/packages/manager/src/factories/nodebalancer.ts @@ -3,7 +3,7 @@ import { NodeBalancerConfig, NodeBalancerConfigNode, } from '@linode/api-v4/lib/nodebalancers/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const nodeBalancerFactory = Factory.Sync.makeFactory({ client_conn_throttle: 0, diff --git a/packages/manager/src/factories/notification.ts b/packages/manager/src/factories/notification.ts index 45d146243ef..16f59842c5c 100644 --- a/packages/manager/src/factories/notification.ts +++ b/packages/manager/src/factories/notification.ts @@ -1,5 +1,5 @@ import { Entity, Notification } from '@linode/api-v4/lib/account'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { DateTime } from 'luxon'; const generateEntity = ( diff --git a/packages/manager/src/factories/oauth.ts b/packages/manager/src/factories/oauth.ts index be6b64dd528..e2151eb62d5 100644 --- a/packages/manager/src/factories/oauth.ts +++ b/packages/manager/src/factories/oauth.ts @@ -1,5 +1,5 @@ import { Token } from '@linode/api-v4/lib/profile/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const appTokenFactory = Factory.Sync.makeFactory({ created: '2020-01-01T12:00:00', diff --git a/packages/manager/src/factories/objectStorage.ts b/packages/manager/src/factories/objectStorage.ts index a45038cc9ee..6d5d7411f34 100644 --- a/packages/manager/src/factories/objectStorage.ts +++ b/packages/manager/src/factories/objectStorage.ts @@ -4,7 +4,7 @@ import { ObjectStorageKey, ObjectStorageObject, } from '@linode/api-v4/lib/object-storage/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const objectStorageBucketFactory = Factory.Sync.makeFactory( { diff --git a/packages/manager/src/factories/placementGroups.ts b/packages/manager/src/factories/placementGroups.ts index 03d89ba1009..c3fa3b8dfea 100644 --- a/packages/manager/src/factories/placementGroups.ts +++ b/packages/manager/src/factories/placementGroups.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { pickRandom } from 'src/utilities/random'; diff --git a/packages/manager/src/factories/preferences.ts b/packages/manager/src/factories/preferences.ts index 06deb6125b6..3072b842b4b 100644 --- a/packages/manager/src/factories/preferences.ts +++ b/packages/manager/src/factories/preferences.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { ManagerPreferences } from 'src/types/ManagerPreferences'; diff --git a/packages/manager/src/factories/profile.ts b/packages/manager/src/factories/profile.ts index 8bbb442f188..b16a34dc49e 100644 --- a/packages/manager/src/factories/profile.ts +++ b/packages/manager/src/factories/profile.ts @@ -4,7 +4,7 @@ import { SecurityQuestionsData, UserPreferences, } from '@linode/api-v4/lib/profile'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const profileFactory = Factory.Sync.makeFactory({ authentication_type: 'password', diff --git a/packages/manager/src/factories/promotionalOffer.ts b/packages/manager/src/factories/promotionalOffer.ts index b68eaa0f1d4..e401266b511 100644 --- a/packages/manager/src/factories/promotionalOffer.ts +++ b/packages/manager/src/factories/promotionalOffer.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { PromotionalOffer } from 'src/featureFlags'; diff --git a/packages/manager/src/factories/regions.ts b/packages/manager/src/factories/regions.ts index 16387addac8..369e3e1f09f 100644 --- a/packages/manager/src/factories/regions.ts +++ b/packages/manager/src/factories/regions.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import type { Country, diff --git a/packages/manager/src/factories/stackscripts.ts b/packages/manager/src/factories/stackscripts.ts index 9406658d0b8..090db396c83 100644 --- a/packages/manager/src/factories/stackscripts.ts +++ b/packages/manager/src/factories/stackscripts.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import type { StackScript, diff --git a/packages/manager/src/factories/statusPage.ts b/packages/manager/src/factories/statusPage.ts index 6781cbb2e87..f485eee7069 100644 --- a/packages/manager/src/factories/statusPage.ts +++ b/packages/manager/src/factories/statusPage.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import { v4 } from 'uuid'; import { diff --git a/packages/manager/src/factories/subnets.ts b/packages/manager/src/factories/subnets.ts index 4e8bc5c5796..3b0f4e7f145 100644 --- a/packages/manager/src/factories/subnets.ts +++ b/packages/manager/src/factories/subnets.ts @@ -2,7 +2,7 @@ import { Subnet, SubnetAssignedLinodeData, } from '@linode/api-v4/lib/vpcs/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; // NOTE: Changing to fixed array length for the interfaces and linodes fields of the // subnetAssignedLinodeDataFactory and subnetFactory respectively -- see [M3-7227] for more details diff --git a/packages/manager/src/factories/support.ts b/packages/manager/src/factories/support.ts index 524ed6c0c1f..7fddfe1f36e 100644 --- a/packages/manager/src/factories/support.ts +++ b/packages/manager/src/factories/support.ts @@ -1,5 +1,5 @@ import { SupportReply, SupportTicket } from '@linode/api-v4/lib/support/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const supportTicketFactory = Factory.Sync.makeFactory({ attachments: [], diff --git a/packages/manager/src/factories/tags.ts b/packages/manager/src/factories/tags.ts index 6c1699952bc..07fc150d870 100644 --- a/packages/manager/src/factories/tags.ts +++ b/packages/manager/src/factories/tags.ts @@ -1,5 +1,5 @@ import { Tag } from '@linode/api-v4/lib/tags/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const tagFactory = Factory.Sync.makeFactory({ label: Factory.each((id) => `tag-${id + 1}`), diff --git a/packages/manager/src/factories/types.ts b/packages/manager/src/factories/types.ts index 192c8219ec2..4b7cb8f755e 100644 --- a/packages/manager/src/factories/types.ts +++ b/packages/manager/src/factories/types.ts @@ -1,4 +1,4 @@ -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; import type { LinodeType } from '@linode/api-v4/lib/linodes/types'; import type { PriceType } from '@linode/api-v4/src/types'; diff --git a/packages/manager/src/factories/vlans.ts b/packages/manager/src/factories/vlans.ts index ec6b5154920..0ee8708c553 100644 --- a/packages/manager/src/factories/vlans.ts +++ b/packages/manager/src/factories/vlans.ts @@ -1,5 +1,5 @@ import { VLAN } from '@linode/api-v4/lib/vlans/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const VLANFactory = Factory.Sync.makeFactory({ cidr_block: '10.0.0.0/24', diff --git a/packages/manager/src/factories/volume.ts b/packages/manager/src/factories/volume.ts index 5b7b6b52c14..5a127893af9 100644 --- a/packages/manager/src/factories/volume.ts +++ b/packages/manager/src/factories/volume.ts @@ -1,5 +1,5 @@ import { Volume, VolumeRequestPayload } from '@linode/api-v4/lib/volumes/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const volumeFactory = Factory.Sync.makeFactory({ created: '2018-01-01', diff --git a/packages/manager/src/factories/vpcs.ts b/packages/manager/src/factories/vpcs.ts index f3d66072b2a..5584639f695 100644 --- a/packages/manager/src/factories/vpcs.ts +++ b/packages/manager/src/factories/vpcs.ts @@ -1,5 +1,5 @@ import { VPC } from '@linode/api-v4/lib/vpcs/types'; -import * as Factory from 'factory.ts'; +import Factory from 'src/factories/factoryProxy'; export const vpcFactory = Factory.Sync.makeFactory({ created: '2023-07-12T16:08:53', diff --git a/packages/manager/src/features/Billing/BillingPanels/BillingActivityPanel/BillingActivityPanel.test.tsx b/packages/manager/src/features/Billing/BillingPanels/BillingActivityPanel/BillingActivityPanel.test.tsx index 8f17374c8b2..ba8d988fd30 100644 --- a/packages/manager/src/features/Billing/BillingPanels/BillingActivityPanel/BillingActivityPanel.test.tsx +++ b/packages/manager/src/features/Billing/BillingPanels/BillingActivityPanel/BillingActivityPanel.test.tsx @@ -63,10 +63,10 @@ describe('BillingActivityPanel', () => { ); await waitFor(() => { - getByText('Invoice #0'); getByText('Invoice #1'); - getByTestId(`payment-0`); + getByText('Invoice #2'); getByTestId(`payment-1`); + getByTestId(`payment-2`); }); }); diff --git a/packages/manager/src/features/CloudPulse/shared/CloudPulseResourcesSelect.test.tsx b/packages/manager/src/features/CloudPulse/shared/CloudPulseResourcesSelect.test.tsx index 41ece50f4f1..26c797e231f 100644 --- a/packages/manager/src/features/CloudPulse/shared/CloudPulseResourcesSelect.test.tsx +++ b/packages/manager/src/features/CloudPulse/shared/CloudPulseResourcesSelect.test.tsx @@ -51,12 +51,12 @@ describe('CloudPulseResourcesSelect component tests', () => { fireEvent.click(screen.getByRole('button', { name: 'Open' })); expect( screen.getByRole('option', { - name: 'linode-0', + name: 'linode-1', }) ).toBeInTheDocument(); expect( screen.getByRole('option', { - name: 'linode-1', + name: 'linode-2', }) ).toBeInTheDocument(); }); @@ -79,12 +79,12 @@ describe('CloudPulseResourcesSelect component tests', () => { fireEvent.click(screen.getByRole('option', { name: SELECT_ALL })); expect( screen.getByRole('option', { - name: 'linode-2', + name: 'linode-3', }) ).toHaveAttribute(ARIA_SELECTED, 'true'); expect( screen.getByRole('option', { - name: 'linode-3', + name: 'linode-4', }) ).toHaveAttribute(ARIA_SELECTED, 'true'); }); @@ -108,12 +108,12 @@ describe('CloudPulseResourcesSelect component tests', () => { fireEvent.click(screen.getByRole('option', { name: 'Deselect All' })); expect( screen.getByRole('option', { - name: 'linode-4', + name: 'linode-5', }) ).toHaveAttribute(ARIA_SELECTED, 'false'); expect( screen.getByRole('option', { - name: 'linode-5', + name: 'linode-6', }) ).toHaveAttribute(ARIA_SELECTED, 'false'); }); @@ -133,22 +133,22 @@ describe('CloudPulseResourcesSelect component tests', () => { /> ); fireEvent.click(screen.getByRole('button', { name: 'Open' })); - fireEvent.click(screen.getByRole('option', { name: 'linode-6' })); fireEvent.click(screen.getByRole('option', { name: 'linode-7' })); + fireEvent.click(screen.getByRole('option', { name: 'linode-8' })); expect( screen.getByRole('option', { - name: 'linode-6', + name: 'linode-7', }) ).toHaveAttribute(ARIA_SELECTED, 'true'); expect( screen.getByRole('option', { - name: 'linode-7', + name: 'linode-8', }) ).toHaveAttribute(ARIA_SELECTED, 'true'); expect( screen.getByRole('option', { - name: 'linode-8', + name: 'linode-9', }) ).toHaveAttribute(ARIA_SELECTED, 'false'); expect( diff --git a/packages/manager/src/features/Databases/DatabaseDetail/DatabaseResize/DatabaseResizeCurrentConfiguration.test.tsx b/packages/manager/src/features/Databases/DatabaseDetail/DatabaseResize/DatabaseResizeCurrentConfiguration.test.tsx index 3ad5df36400..c94327ec954 100644 --- a/packages/manager/src/features/Databases/DatabaseDetail/DatabaseResize/DatabaseResizeCurrentConfiguration.test.tsx +++ b/packages/manager/src/features/Databases/DatabaseDetail/DatabaseResize/DatabaseResizeCurrentConfiguration.test.tsx @@ -63,7 +63,7 @@ describe('database current configuration section', () => { getByText('1 GB'); getByText('CPUs'); - getByText('2'); + getByText('4'); getByText('Total Disk Size'); getByText('15 GB'); diff --git a/packages/manager/src/features/Firewalls/FirewallLanding/FirewallRow.test.tsx b/packages/manager/src/features/Firewalls/FirewallLanding/FirewallRow.test.tsx index 7128c1ecb87..e24fcdc7924 100644 --- a/packages/manager/src/features/Firewalls/FirewallLanding/FirewallRow.test.tsx +++ b/packages/manager/src/features/Firewalls/FirewallLanding/FirewallRow.test.tsx @@ -58,7 +58,7 @@ describe('FirewallRow', () => { const { getByTestId, getByText } = render( wrapWithTableBody() ); - getByTestId('firewall-row-0'); + getByTestId('firewall-row-1'); getByText(firewall.label); getByText(capitalize(firewall.status)); getByText(getRuleString(getCountOfRules(firewall.rules))); diff --git a/packages/manager/src/features/Images/ImageSelect.test.tsx b/packages/manager/src/features/Images/ImageSelect.test.tsx index cf49ce439ea..58f40b9a9a3 100644 --- a/packages/manager/src/features/Images/ImageSelect.test.tsx +++ b/packages/manager/src/features/Images/ImageSelect.test.tsx @@ -49,6 +49,7 @@ describe('ImageSelect', () => { expect(items[0]).toHaveProperty('label', groupNameMap.recommended); expect(items[0].options).toHaveLength(2); }); + it('should handle multiple groups', () => { const items = getImagesOptions([ recommendedImage1, @@ -60,12 +61,14 @@ describe('ImageSelect', () => { const deleted = items.find((item) => item.label === groupNameMap.deleted); expect(deleted!.options).toHaveLength(1); }); + it('should properly format GroupType options as RS Item type', () => { const category = getImagesOptions([recommendedImage1])[0]; const option = category.options[0]; expect(option).toHaveProperty('label', recommendedImage1.label); expect(option).toHaveProperty('value', recommendedImage1.id); }); + it('should handle empty input', () => { expect(getImagesOptions([])).toEqual([]); }); @@ -74,8 +77,9 @@ describe('ImageSelect', () => { describe('ImageSelect component', () => { it('should render', () => { const { getByText } = renderWithTheme(); - getByText(/image-0/i); + getByText(/image-1(?!\d)/i); }); + it('should display an error', () => { const imageError = 'An error'; const { getByText } = renderWithTheme( diff --git a/packages/manager/src/features/Images/ImagesLanding/EditImageDrawer.test.tsx b/packages/manager/src/features/Images/ImagesLanding/EditImageDrawer.test.tsx index 4ee4a28ba84..b02932582f1 100644 --- a/packages/manager/src/features/Images/ImagesLanding/EditImageDrawer.test.tsx +++ b/packages/manager/src/features/Images/ImagesLanding/EditImageDrawer.test.tsx @@ -52,7 +52,7 @@ describe('EditImageDrawer', () => { fireEvent.click(getByText('Save Changes')); await waitFor(() => { - expect(mockUpdateImage).toHaveBeenCalledWith('private/0', { + expect(mockUpdateImage).toHaveBeenCalledWith('private/1', { description: 'test description', label: 'test-image-label', tags: ['new-tag'], diff --git a/packages/manager/src/features/Images/ImagesLanding/RebuildImageDrawer.test.tsx b/packages/manager/src/features/Images/ImagesLanding/RebuildImageDrawer.test.tsx index 25892bbe05e..b2ddbb5aa01 100644 --- a/packages/manager/src/features/Images/ImagesLanding/RebuildImageDrawer.test.tsx +++ b/packages/manager/src/features/Images/ImagesLanding/RebuildImageDrawer.test.tsx @@ -53,7 +53,7 @@ describe('RebuildImageDrawer', () => { expect(mockHistoryPush).toBeCalledWith({ pathname: '/linodes/1/rebuild', - search: 'selectedImageId=private%2F0', + search: 'selectedImageId=private%2F1', }); }); }); diff --git a/packages/manager/src/features/Images/utils.test.tsx b/packages/manager/src/features/Images/utils.test.tsx index 81dc5f25783..eba0b26ca23 100644 --- a/packages/manager/src/features/Images/utils.test.tsx +++ b/packages/manager/src/features/Images/utils.test.tsx @@ -13,6 +13,7 @@ describe('getImageLabelForLinode', () => { }); expect(getImageLabelForLinode(linode, images)).toBe('Cool Image'); }); + it('falls back to the linodes image id if there is no match in the images array', () => { const linode = linodeFactory.build({ image: 'public/cool-image', @@ -23,6 +24,7 @@ describe('getImageLabelForLinode', () => { }); expect(getImageLabelForLinode(linode, images)).toBe('public/cool-image'); }); + it('returns null if the linode does not have an image', () => { const linode = linodeFactory.build({ image: null, @@ -36,9 +38,11 @@ describe('getEventsForImages', () => { it('sorts events by image', () => { imageFactory.resetSequenceNumber(); const images = imageFactory.buildList(3); - const successfulEvent = eventFactory.build({ secondary_entity: { id: 0 } }); + const successfulEvent = eventFactory.build({ + secondary_entity: { id: 1 }, + }); const failedEvent = eventFactory.build({ - entity: { id: 1 }, + entity: { id: 2 }, status: 'failed', }); const unrelatedEvent = eventFactory.build(); @@ -46,8 +50,8 @@ describe('getEventsForImages', () => { expect( getEventsForImages(images, [successfulEvent, failedEvent, unrelatedEvent]) ).toEqual({ - ['private/0']: successfulEvent, - ['private/1']: failedEvent, + ['private/1']: successfulEvent, + ['private/2']: failedEvent, }); }); }); diff --git a/packages/manager/src/features/Kubernetes/ClusterList/KubernetesClusterRow.test.tsx b/packages/manager/src/features/Kubernetes/ClusterList/KubernetesClusterRow.test.tsx index f914a962fd2..8a9d945d3b2 100644 --- a/packages/manager/src/features/Kubernetes/ClusterList/KubernetesClusterRow.test.tsx +++ b/packages/manager/src/features/Kubernetes/ClusterList/KubernetesClusterRow.test.tsx @@ -3,10 +3,12 @@ import * as React from 'react'; import { kubernetesClusterFactory, regionFactory } from 'src/factories'; import { makeResourcePage } from 'src/mocks/serverHandlers'; -import { http, HttpResponse, server } from 'src/mocks/testServer'; +import { HttpResponse, http, server } from 'src/mocks/testServer'; import { wrapWithTableBody, wrapWithTheme } from 'src/utilities/testHelpers'; -import { KubernetesClusterRow, Props } from './KubernetesClusterRow'; +import { KubernetesClusterRow } from './KubernetesClusterRow'; + +import type { Props } from './KubernetesClusterRow'; const cluster = kubernetesClusterFactory.build({ region: 'us-central' }); @@ -36,11 +38,11 @@ describe('ClusterRow component', () => { }) ); - const { getByText, findByText } = render( + const { findByText, getByText } = render( wrapWithTableBody() ); - getByText('cluster-0'); + getByText('cluster-1'); await findByText('Fake Region, NC'); }); diff --git a/packages/manager/src/features/Kubernetes/KubeCheckoutBar/KubeCheckoutBar.test.tsx b/packages/manager/src/features/Kubernetes/KubeCheckoutBar/KubeCheckoutBar.test.tsx index 60e58baa7cc..f9770335db0 100644 --- a/packages/manager/src/features/Kubernetes/KubeCheckoutBar/KubeCheckoutBar.test.tsx +++ b/packages/manager/src/features/Kubernetes/KubeCheckoutBar/KubeCheckoutBar.test.tsx @@ -1,7 +1,6 @@ -import { waitForElementToBeRemoved } from '@testing-library/react'; import * as React from 'react'; -import { regionFactory } from 'src/factories'; +import { regionFactory, typeFactory } from 'src/factories'; import { nodePoolFactory } from 'src/factories/kubernetesCluster'; import { UNKNOWN_PRICE } from 'src/utilities/pricing/constants'; import { LKE_CREATE_CLUSTER_CHECKOUT_MESSAGE } from 'src/utilities/pricing/constants'; @@ -32,13 +31,23 @@ const renderComponent = (_props: Props) => renderWithTheme(); describe('KubeCheckoutBar', () => { + beforeAll(() => { + vi.mock('src/queries/types', async () => { + const actual = await vi.importActual('src/queries/types'); + return { + ...actual, + useSpecificTypes: vi + .fn() + .mockImplementation(() => [{ data: typeFactory.build() }]), + }; + }); + }); + it('should render helper text and disable create button until a region has been selected', async () => { - const { findByText, getByTestId, getByText } = renderWithTheme( + const { findByText, getByText } = renderWithTheme( ); - await waitForElementToBeRemoved(getByTestId('circle-progress')); - await findByText(LKE_CREATE_CLUSTER_CHECKOUT_MESSAGE); expect(getByText('Create Cluster').closest('button')).toHaveAttribute( 'aria-disabled', @@ -47,9 +56,7 @@ describe('KubeCheckoutBar', () => { }); it('should render a section for each pool', async () => { - const { getByTestId, queryAllByTestId } = renderComponent(props); - - await waitForElementToBeRemoved(getByTestId('circle-progress')); + const { queryAllByTestId } = renderComponent(props); expect(queryAllByTestId('node-pool-summary')).toHaveLength(pools.length); }); @@ -90,7 +97,7 @@ describe('KubeCheckoutBar', () => { ); // 5 node pools * 3 linodes per pool * 12 per linode * 20% increase for Jakarta + 72 per month per cluster for HA - await findByText(/\$180\.00/); + await findByText(/\$183\.00/); }); it('should display the DC-Specific total price of the cluster for a region with a price increase with HA selection', async () => { @@ -104,7 +111,7 @@ describe('KubeCheckoutBar', () => { ); // 5 node pools * 3 linodes per pool * 12 per linode * 20% increase for Jakarta + 72 per month per cluster for HA - await findByText(/\$252\.00/); + await findByText(/\$255\.00/); }); it('should display UNKNOWN_PRICE for HA when not available and show total price of cluster as the sum of the node pools', async () => { @@ -118,7 +125,7 @@ describe('KubeCheckoutBar', () => { ); // 5 node pools * 3 linodes per pool * 12 per linode * 20% increase for Jakarta + UNKNOWN_PRICE - await findByText(/\$180\.00/); + await findByText(/\$183\.00/); getByText(/\$--.--\/month/); }); }); diff --git a/packages/manager/src/features/Kubernetes/KubernetesClusterDetail/NodePoolsDisplay/ResizeNodePoolDrawer.test.tsx b/packages/manager/src/features/Kubernetes/KubernetesClusterDetail/NodePoolsDisplay/ResizeNodePoolDrawer.test.tsx index bd6e2ad6352..3bf7367eef6 100644 --- a/packages/manager/src/features/Kubernetes/KubernetesClusterDetail/NodePoolsDisplay/ResizeNodePoolDrawer.test.tsx +++ b/packages/manager/src/features/Kubernetes/KubernetesClusterDetail/NodePoolsDisplay/ResizeNodePoolDrawer.test.tsx @@ -1,16 +1,28 @@ import { fireEvent } from '@testing-library/react'; import * as React from 'react'; -import { nodePoolFactory } from 'src/factories/kubernetesCluster'; +import { nodePoolFactory, typeFactory } from 'src/factories'; import { renderWithTheme } from 'src/utilities/testHelpers'; -import { Props, ResizeNodePoolDrawer } from './ResizeNodePoolDrawer'; +import { ResizeNodePoolDrawer } from './ResizeNodePoolDrawer'; + +import type { Props } from './ResizeNodePoolDrawer'; const pool = nodePoolFactory.build({ type: 'g6-standard-1', }); const smallPool = nodePoolFactory.build({ count: 2 }); +vi.mock('src/queries/types', async () => { + const actual = await vi.importActual('src/queries/types'); + return { + ...actual, + useSpecificTypes: vi + .fn() + .mockReturnValue([{ data: typeFactory.build({ label: 'Linode 1 GB' }) }]), + }; +}); + const props: Props = { kubernetesClusterId: 1, kubernetesRegionId: 'us-east', diff --git a/packages/manager/src/features/Linodes/LinodeCreatev2/Tabs/StackScripts/StackScriptDetailsDialog.test.tsx b/packages/manager/src/features/Linodes/LinodeCreatev2/Tabs/StackScripts/StackScriptDetailsDialog.test.tsx index c1be7504701..056051ece2b 100644 --- a/packages/manager/src/features/Linodes/LinodeCreatev2/Tabs/StackScripts/StackScriptDetailsDialog.test.tsx +++ b/packages/manager/src/features/Linodes/LinodeCreatev2/Tabs/StackScripts/StackScriptDetailsDialog.test.tsx @@ -8,7 +8,9 @@ import { StackScriptDetailsDialog } from './StackScriptDetailsDialog'; describe('StackScriptDetailsDialog', () => { it('should render StackScript data from the API', async () => { - const stackscript = stackScriptFactory.build(); + const stackscript = stackScriptFactory.build({ + id: 1234, + }); server.use( http.get('*/v4/linode/stackscripts/:id', () => { diff --git a/packages/manager/src/features/Linodes/LinodesCreate/SelectLinodePanel/SelectLinodePanel.test.tsx b/packages/manager/src/features/Linodes/LinodesCreate/SelectLinodePanel/SelectLinodePanel.test.tsx index 6fd81d073f0..653a1f3980d 100644 --- a/packages/manager/src/features/Linodes/LinodesCreate/SelectLinodePanel/SelectLinodePanel.test.tsx +++ b/packages/manager/src/features/Linodes/LinodesCreate/SelectLinodePanel/SelectLinodePanel.test.tsx @@ -72,7 +72,7 @@ describe('SelectLinodePanel (table, desktop)', () => { fireEvent.click(radioInput); expect(mockOnSelect).toHaveBeenCalledWith( - 0, + 1, defaultProps.linodes[0].type, defaultProps.linodes[0].specs.disk ); @@ -115,7 +115,7 @@ describe('SelectLinodePanel (table, desktop)', () => { setupMocks(); const { container, findAllByRole } = renderWithTheme( - + ); expect( @@ -171,7 +171,7 @@ describe('SelectLinodePanel (cards, mobile)', () => { fireEvent.click(selectionCard); expect(mockOnSelect).toHaveBeenCalledWith( - 0, + 1, defaultProps.linodes[0].type, defaultProps.linodes[0].specs.disk ); @@ -201,7 +201,7 @@ describe('SelectLinodePanel (cards, mobile)', () => { setupMocks(); const { container } = renderWithTheme( - + ); expect( diff --git a/packages/manager/src/features/Linodes/LinodesCreate/SelectLinodePanel/SelectLinodeRow.test.tsx b/packages/manager/src/features/Linodes/LinodesCreate/SelectLinodePanel/SelectLinodeRow.test.tsx index 3c2b7922b93..0570941b93f 100644 --- a/packages/manager/src/features/Linodes/LinodesCreate/SelectLinodePanel/SelectLinodeRow.test.tsx +++ b/packages/manager/src/features/Linodes/LinodesCreate/SelectLinodePanel/SelectLinodeRow.test.tsx @@ -1,12 +1,22 @@ import { fireEvent } from '@testing-library/react'; import * as React from 'react'; -import { imageFactory } from 'src/factories'; -import { linodeFactory } from 'src/factories/linodes'; -import { http, HttpResponse, server } from 'src/mocks/testServer'; + +import { imageFactory, linodeFactory, typeFactory } from 'src/factories'; +import { HttpResponse, http, server } from 'src/mocks/testServer'; import { renderWithTheme, wrapWithTableBody } from 'src/utilities/testHelpers'; import { SelectLinodeRow } from './SelectLinodeRow'; +vi.mock('src/queries/types', async () => { + const actual = await vi.importActual('src/queries/types'); + return { + ...actual, + useTypeQuery: vi.fn().mockReturnValue({ + data: typeFactory.build({ label: 'Linode 1 GB' }), + }), + }; +}); + describe('SelectLinodeRow', () => { const handlePowerOff = vi.fn(); const handleSelection = vi.fn(); diff --git a/packages/manager/src/features/Linodes/LinodesCreate/utilities.test.ts b/packages/manager/src/features/Linodes/LinodesCreate/utilities.test.ts index 8a18835cce1..150809adfdf 100644 --- a/packages/manager/src/features/Linodes/LinodesCreate/utilities.test.ts +++ b/packages/manager/src/features/Linodes/LinodesCreate/utilities.test.ts @@ -50,28 +50,26 @@ describe('trimOneClickFromLabel', () => { }); describe('filterOneClickApps', () => { - const baseAppIds = [1, 2, 3, 4]; + const baseAppIds = [2, 3, 4, 5]; const newApps = { - 5: 'New App 1', - 6: 'New App 2', - 7: 'New App 3', - 8: 'New App 4', + 6: 'New App 1', + 7: 'New App 2', + 8: 'New App 3', + 9: 'New App 4', }; - const stackScript = stackScriptFactory.build(); - - // id: 1,2,3,4 + // id: 2,3,4,5 const queryResultsWithHelpers: StackScript[] = [ ...stackScriptFactory.buildList(3), - { ...stackScript, id: 4, label: 'StackScript Helpers' }, + stackScriptFactory.build({ label: 'StackScript Helpers' }), ]; - // id: 5,6,7,8 + // id: 6,7,8,9 const queryResultsWithoutHelpers: StackScript[] = stackScriptFactory.buildList( 4 ); it('filters OneClickApps and trims labels, excluding StackScripts with Helpers', () => { - // feeding 4 Ids (1,2,3,4) getting 3 back + // feeding 4 Ids (2,3,4,5) getting 3 back const filteredOCAsWithHelpersLabel = filterOneClickApps({ baseAppIds, newApps, @@ -79,7 +77,7 @@ describe('filterOneClickApps', () => { }); expect(filteredOCAsWithHelpersLabel.length).toBe(3); - // feeding 4 Ids (5,6,7,8) getting 4 back + // feeding 4 Ids (6,7,8,9) getting 4 back const filteredOCAsWithoutHelpersLabel = filterOneClickApps({ baseAppIds, newApps, diff --git a/packages/manager/src/features/Linodes/LinodesLanding/utils.test.ts b/packages/manager/src/features/Linodes/LinodesLanding/utils.test.ts index bf1a98e828d..043894100ed 100644 --- a/packages/manager/src/features/Linodes/LinodesLanding/utils.test.ts +++ b/packages/manager/src/features/Linodes/LinodesLanding/utils.test.ts @@ -1,10 +1,11 @@ -import { parseMaintenanceStartTime, getVPCsFromLinodeConfigs } from './utils'; import { - configFactory, LinodeConfigInterfaceFactory, LinodeConfigInterfaceFactoryWithVPC, + configFactory, } from 'src/factories'; +import { getVPCsFromLinodeConfigs, parseMaintenanceStartTime } from './utils'; + describe('Linode Landing Utilites', () => { it('should return "Maintenance Window Unknown" for invalid dates', () => { expect(parseMaintenanceStartTime('inVALid DATE')).toBe( @@ -52,18 +53,18 @@ describe('Linode Landing Utilites', () => { ...configFactory.buildList(3), config, ]); - expect(vpcIds).toEqual([2, 3]); + expect(vpcIds).toEqual([3, 4]); }); it('returns unique vpc ids (no duplicates)', () => { const vpcInterface = LinodeConfigInterfaceFactoryWithVPC.build({ - vpc_id: 2, + vpc_id: 3, }); const config = configFactory.build({ interfaces: [...vpcInterfaceList, vpcInterface], }); const vpcIds = getVPCsFromLinodeConfigs([config]); - expect(vpcIds).toEqual([2, 3]); + expect(vpcIds).toEqual([3, 4]); }); }); }); diff --git a/packages/manager/src/features/Longview/LongviewLanding/LongviewLanding.test.tsx b/packages/manager/src/features/Longview/LongviewLanding/LongviewLanding.test.tsx index 1ff3d36970f..0035b1657b2 100644 --- a/packages/manager/src/features/Longview/LongviewLanding/LongviewLanding.test.tsx +++ b/packages/manager/src/features/Longview/LongviewLanding/LongviewLanding.test.tsx @@ -1,4 +1,3 @@ -import { LongviewClient } from '@linode/api-v4/lib/longview'; import { fireEvent, waitFor } from '@testing-library/react'; import * as React from 'react'; @@ -11,13 +10,15 @@ import { renderWithTheme } from 'src/utilities/testHelpers'; import { LongviewClients, - LongviewClientsCombinedProps, filterLongviewClientsByQuery, sortClientsBy, sortFunc, } from './LongviewClients'; import { LongviewLanding } from './LongviewLanding'; +import type { LongviewClientsCombinedProps } from './LongviewClients'; +import type { LongviewClient } from '@linode/api-v4/lib/longview'; + afterEach(() => { vi.clearAllMocks(); }); @@ -54,7 +55,7 @@ const props: LongviewClientsCombinedProps = { describe('Utility Functions', () => { it('should properly filter longview clients by query', () => { expect(filterLongviewClientsByQuery('client-1', clients, {})).toEqual([ - clients[1], + clients[0], ]), expect(filterLongviewClientsByQuery('client', clients, {})).toEqual( clients diff --git a/packages/manager/src/features/ObjectStorage/BucketLanding/BucketLanding.test.tsx b/packages/manager/src/features/ObjectStorage/BucketLanding/BucketLanding.test.tsx index ded2bc7bfaf..cc46045d6c4 100644 --- a/packages/manager/src/features/ObjectStorage/BucketLanding/BucketLanding.test.tsx +++ b/packages/manager/src/features/ObjectStorage/BucketLanding/BucketLanding.test.tsx @@ -73,7 +73,7 @@ describe('ObjectStorageLanding', () => { // Mock Buckets server.use( http.get( - '*/object-storage/buckets/cluster-0', + '*/object-storage/buckets/cluster-1', () => { return HttpResponse.json([{ reason: 'Cluster offline!' }], { status: 500, diff --git a/packages/manager/src/features/PlacementGroups/PlacementGroupsLanding/PlacementGroupsRow.test.tsx b/packages/manager/src/features/PlacementGroups/PlacementGroupsLanding/PlacementGroupsRow.test.tsx index 8e289b32aed..d84a2b78b46 100644 --- a/packages/manager/src/features/PlacementGroups/PlacementGroupsLanding/PlacementGroupsRow.test.tsx +++ b/packages/manager/src/features/PlacementGroups/PlacementGroupsLanding/PlacementGroupsRow.test.tsx @@ -1,8 +1,10 @@ import * as React from 'react'; -import { regionFactory } from 'src/factories'; -import { linodeFactory } from 'src/factories'; -import { placementGroupFactory } from 'src/factories'; +import { + linodeFactory, + placementGroupFactory, + regionFactory, +} from 'src/factories'; import { renderWithTheme, resizeScreenSize, @@ -14,41 +16,44 @@ import { PlacementGroupsRow } from './PlacementGroupsRow'; const handleDeletePlacementGroupMock = vi.fn(); const handleEditPlacementGroupMock = vi.fn(); +const linode = linodeFactory.build({ + label: 'linode-1', + region: 'us-east', +}); + +const placementGroup = placementGroupFactory.build({ + affinity_type: 'anti_affinity:local', + id: 1, + is_compliant: false, + label: 'group 1', + members: [ + { + is_compliant: true, + linode_id: 1, + }, + ], + region: 'us-east', +}); + +const region = regionFactory.build({ + country: 'us', + id: 'us-east', + label: 'Newark, NJ', + status: 'ok', +}); + describe('PlacementGroupsRow', () => { it('renders the columns with proper data', () => { resizeScreenSize(1200); - const { getByRole, getByTestId, getByText } = renderWithTheme( wrapWithTableBody( ) ); diff --git a/packages/manager/src/features/VPCs/VPCDetail/SubnetLinodeRow.test.tsx b/packages/manager/src/features/VPCs/VPCDetail/SubnetLinodeRow.test.tsx index 3f582284da8..c51eb4d5fad 100644 --- a/packages/manager/src/features/VPCs/VPCDetail/SubnetLinodeRow.test.tsx +++ b/packages/manager/src/features/VPCs/VPCDetail/SubnetLinodeRow.test.tsx @@ -68,7 +68,7 @@ describe('SubnetLinodeRow', () => { handlePowerActionsLinode={handlePowerActionsLinode} handleUnassignLinode={handleUnassignLinode} linodeId={linodeFactory1.id} - subnetId={0} + subnetId={1} /> ) ); diff --git a/packages/manager/src/features/VPCs/VPCLanding/VPCRow.test.tsx b/packages/manager/src/features/VPCs/VPCLanding/VPCRow.test.tsx index e06568255c2..4bdae3ef5b8 100644 --- a/packages/manager/src/features/VPCs/VPCLanding/VPCRow.test.tsx +++ b/packages/manager/src/features/VPCs/VPCLanding/VPCRow.test.tsx @@ -2,13 +2,18 @@ import { fireEvent } from '@testing-library/react'; import * as React from 'react'; import { vpcFactory } from 'src/factories/vpcs'; -import { renderWithTheme, wrapWithTableBody } from 'src/utilities/testHelpers'; +import { + renderWithTheme, + resizeScreenSize, + wrapWithTableBody, +} from 'src/utilities/testHelpers'; import { VPCRow } from './VPCRow'; describe('VPC Table Row', () => { it('should render a VPC row', () => { const vpc = vpcFactory.build(); + resizeScreenSize(1600); const { getAllByText, getByText } = renderWithTheme( wrapWithTableBody( diff --git a/packages/manager/src/features/VPCs/utils.test.ts b/packages/manager/src/features/VPCs/utils.test.ts index c572b42ad6a..90e4ea5e2da 100644 --- a/packages/manager/src/features/VPCs/utils.test.ts +++ b/packages/manager/src/features/VPCs/utils.test.ts @@ -50,7 +50,7 @@ describe('getUniqueLinodesFromSubnets', () => { expect(getUniqueLinodesFromSubnets(subnets0)).toBe(0); expect(getUniqueLinodesFromSubnets(subnets1)).toBe(4); expect(getUniqueLinodesFromSubnets(subnets2)).toBe(2); - expect(getUniqueLinodesFromSubnets(subnets3)).toBe(7); + expect(getUniqueLinodesFromSubnets(subnets3)).toBe(6); }); }); @@ -60,15 +60,15 @@ describe('getSubnetInterfaceFromConfigs', () => { const singleConfig = linodeConfigFactory.build({ interfaces }); const configs = [linodeConfigFactory.build(), singleConfig]; - const subnetInterface1 = getSubnetInterfaceFromConfigs(configs, 1); + const subnetInterface1 = getSubnetInterfaceFromConfigs(configs, 2); expect(subnetInterface1).toEqual(interfaces[0]); - const subnetInterface2 = getSubnetInterfaceFromConfigs(configs, 2); + const subnetInterface2 = getSubnetInterfaceFromConfigs(configs, 3); expect(subnetInterface2).toEqual(interfaces[1]); - const subnetInterface3 = getSubnetInterfaceFromConfigs(configs, 3); + const subnetInterface3 = getSubnetInterfaceFromConfigs(configs, 4); expect(subnetInterface3).toEqual(interfaces[2]); - const subnetInterface4 = getSubnetInterfaceFromConfigs(configs, 4); + const subnetInterface4 = getSubnetInterfaceFromConfigs(configs, 5); expect(subnetInterface4).toEqual(interfaces[3]); - const subnetInterface5 = getSubnetInterfaceFromConfigs(configs, 5); + const subnetInterface5 = getSubnetInterfaceFromConfigs(configs, 6); expect(subnetInterface5).toEqual(interfaces[4]); }); diff --git a/packages/manager/src/utilities/mapIdsToDevices.test.ts b/packages/manager/src/utilities/mapIdsToDevices.test.ts index 1f8a43091a4..af30a9537d1 100644 --- a/packages/manager/src/utilities/mapIdsToDevices.test.ts +++ b/packages/manager/src/utilities/mapIdsToDevices.test.ts @@ -1,46 +1,51 @@ -import { Linode } from '@linode/api-v4'; -import { NodeBalancer } from '@linode/api-v4'; - -import { linodeFactory } from 'src/factories'; import { nodeBalancerFactory } from 'src/factories'; +import { linodeFactory } from 'src/factories'; import { mapIdsToDevices } from './mapIdsToDevices'; +import type { NodeBalancer } from '@linode/api-v4'; +import type { Linode } from '@linode/api-v4'; + describe('mapIdsToDevices', () => { const linodes = linodeFactory.buildList(5); const nodebalancers = nodeBalancerFactory.buildList(5); + it('works with a single Linode ID', () => { - expect(mapIdsToDevices(1, linodes)).toBe(linodes[1]); + expect(mapIdsToDevices(1, linodes)).toBe(linodes[0]); }); + it('works with a single NodeBalancer ID', () => { expect(mapIdsToDevices(1, nodebalancers)).toBe( - nodebalancers[1] + nodebalancers[0] ); }); + it('works with a multiple Linode IDs', () => { - expect(mapIdsToDevices([0, 1, 2], linodes)).toEqual([ + expect(mapIdsToDevices([1, 2, 3], linodes)).toEqual([ linodes[0], linodes[1], linodes[2], ]); }); + it('works with a multiple NodeBalancer IDs', () => { - expect(mapIdsToDevices([0, 1, 2], nodebalancers)).toEqual([ + expect(mapIdsToDevices([1, 2, 3], nodebalancers)).toEqual([ nodebalancers[0], nodebalancers[1], nodebalancers[2], ]); }); + it('omits missing IDs', () => { expect(mapIdsToDevices(99, linodes)).toBe(null); expect(mapIdsToDevices(99, nodebalancers)).toBe(null); - expect(mapIdsToDevices([0, 99, 2], linodes)).toEqual([ + expect(mapIdsToDevices([1, 99, 2], linodes)).toEqual([ linodes[0], - linodes[2], + linodes[1], ]); - expect(mapIdsToDevices([0, 99, 2], nodebalancers)).toEqual([ + expect(mapIdsToDevices([1, 99, 2], nodebalancers)).toEqual([ nodebalancers[0], - nodebalancers[2], + nodebalancers[1], ]); }); });