From f28e50472e0d33ec7ed1aa9e5591273208ddfe4e Mon Sep 17 00:00:00 2001 From: Chuck Skelton Date: Thu, 7 May 2026 16:54:37 -0700 Subject: [PATCH] Fixing unit tests --- .../DefaultManagedIdentity.test.tsx.snap | 15 ++++++---- .../PartitionKeyComponent.test.tsx | 16 +++++----- .../ChangePartitionKeyPane.tsx | 30 +------------------ 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/__snapshots__/DefaultManagedIdentity.test.tsx.snap b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/__snapshots__/DefaultManagedIdentity.test.tsx.snap index 4ee687043..e2e9cf3fb 100644 --- a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/__snapshots__/DefaultManagedIdentity.test.tsx.snap +++ b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/AssignPermissions/__snapshots__/DefaultManagedIdentity.test.tsx.snap @@ -9,7 +9,8 @@ exports[`DefaultManagedIdentity Edge Cases should handle missing account name gr class="toggle-label" > Set the system-assigned managed identity as default for "" by switching it on. -   + +  
@@ -72,7 +73,8 @@ exports[`DefaultManagedIdentity Edge Cases should handle null account 1`] = ` class="toggle-label" > Set the system-assigned managed identity as default for "" by switching it on. -   + +  
@@ -135,7 +137,8 @@ exports[`DefaultManagedIdentity Loading States should render loading state snaps class="toggle-label" > Set the system-assigned managed identity as default for "test-cosmos-account" by switching it on. -   + +  
@@ -227,7 +230,8 @@ exports[`DefaultManagedIdentity Rendering should render correctly with default s class="toggle-label" > Set the system-assigned managed identity as default for "test-cosmos-account" by switching it on. -   + +  
@@ -290,7 +294,8 @@ exports[`DefaultManagedIdentity Toggle Interactions should render toggle with ch class="toggle-label" > Set the system-assigned managed identity as default for "test-cosmos-account" by switching it on. -   + +  
diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.test.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.test.tsx index c2d5aa8c2..90bae91e2 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.test.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.test.tsx @@ -1,10 +1,10 @@ -import { render, screen } from "@testing-library/react"; +import { render, screen, waitFor } from "@testing-library/react"; import { DatabaseAccount } from "Contracts/DataModels"; import { PartitionKeyComponent, PartitionKeyComponentProps, } from "Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent"; -import * as useDataTransferJobs from "hooks/useDataTransferJobs"; +import { useDataTransferJobs } from "hooks/useDataTransferJobs"; import React from "react"; import { updateUserContext } from "UserContext"; import { DataTransferJobGetResults } from "Utils/arm/generatedClients/dataTransferService/types"; @@ -19,7 +19,7 @@ jest.mock("Common/dataAccess/dataTransfers", () => ({ })); jest.mock("hooks/useDataTransferJobs", () => ({ - useDataTransferJobs: () => ({ dataTransferJobs: [] }), + useDataTransferJobs: jest.fn(() => ({ dataTransferJobs: [] })), refreshDataTransferJobs: jest.fn().mockResolvedValue(undefined), })); @@ -117,7 +117,7 @@ describe("PartitionKeyComponent", () => { }); it("shows cancel button for offline job in progress", () => { - jest.spyOn(useDataTransferJobs, "useDataTransferJobs").mockReturnValue({ + (useDataTransferJobs as jest.Mock).mockReturnValue({ dataTransferJobs: [mockOfflineJob], }); @@ -127,13 +127,15 @@ describe("PartitionKeyComponent", () => { expect(container.querySelector("[data-test='online-job-action-menu']")).toBeNull(); }); - it("shows ellipsis action menu for online job in progress", () => { - jest.spyOn(useDataTransferJobs, "useDataTransferJobs").mockReturnValue({ + it("shows ellipsis action menu for online job in progress", async () => { + (useDataTransferJobs as jest.Mock).mockReturnValue({ dataTransferJobs: [mockOnlineJob], }); const { props } = setupTest(); const { container } = render(); - expect(container.querySelector("[data-test='online-job-action-menu']")).toBeTruthy(); + await waitFor(() => { + expect(container.querySelector("[data-test='online-job-action-menu']")).toBeTruthy(); + }); }); }); diff --git a/src/Explorer/Panes/ChangePartitionKeyPane/ChangePartitionKeyPane.tsx b/src/Explorer/Panes/ChangePartitionKeyPane/ChangePartitionKeyPane.tsx index 21734a344..883566dc5 100644 --- a/src/Explorer/Panes/ChangePartitionKeyPane/ChangePartitionKeyPane.tsx +++ b/src/Explorer/Panes/ChangePartitionKeyPane/ChangePartitionKeyPane.tsx @@ -2,7 +2,6 @@ import { DefaultButton, DirectionalHint, Dropdown, - IChoiceGroupOption, IDropdownOption, Icon, IconButton, @@ -24,7 +23,7 @@ import { createCollection } from "Common/dataAccess/createCollection"; import { DataTransferParams, initiateDataTransfer } from "Common/dataAccess/dataTransfers"; import * as DataModels from "Contracts/DataModels"; import * as ViewModels from "Contracts/ViewModels"; -import { BackupPolicyType, CopyJobMigrationType } from "Explorer/ContainerCopy/Enums/CopyJobEnums"; +import { BackupPolicyType } from "Explorer/ContainerCopy/Enums/CopyJobEnums"; import { getPartitionKeyName, getPartitionKeyPlaceHolder, @@ -50,33 +49,6 @@ export interface ChangePartitionKeyPaneProps { onClose: () => Promise; } -const migrationTypeOptions: IChoiceGroupOption[] = [ - { - key: CopyJobMigrationType.Offline, - text: t(Keys.containerCopy.migrationType.offline.title), - styles: { root: { width: "33%" } }, - }, - { - key: CopyJobMigrationType.Online, - text: t(Keys.containerCopy.migrationType.online.title), - styles: { root: { width: "33%" } }, - }, -]; - -const choiceGroupStyles = { - flexContainer: { display: "flex" as const }, - root: { - selectors: { - ".ms-ChoiceField": { - color: "var(--colorNeutralForeground1)", - }, - ".ms-ChoiceField-field:hover .ms-ChoiceFieldLabel": { - color: "var(--colorNeutralForeground1)", - }, - }, - }, -}; - const checkPitrEnabled = (account: DataModels.DatabaseAccount): boolean => { return account?.properties?.backupPolicy?.type === BackupPolicyType.Continuous; };