From f4bdb895178b57501345d4918367cd755d724d3d Mon Sep 17 00:00:00 2001 From: Chuck Skelton Date: Wed, 6 May 2026 11:43:27 -0700 Subject: [PATCH] Fixing some issues found by lint --- .../SelectSourceAndTargetContainers.test.tsx | 1 - .../PartitionKeyComponent.test.tsx | 9 ++-- .../PartitionKeyComponent.tsx | 15 ++---- .../Controls/Settings/SettingsUtils.tsx | 9 ++-- .../ChangePartitionKeyPane.test.tsx | 49 +++++++++++++------ 5 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/SelectSourceAndTargetContainers/SelectSourceAndTargetContainers.test.tsx b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/SelectSourceAndTargetContainers/SelectSourceAndTargetContainers.test.tsx index 1f51304c3..ca08abf4a 100644 --- a/src/Explorer/ContainerCopy/CreateCopyJob/Screens/SelectSourceAndTargetContainers/SelectSourceAndTargetContainers.test.tsx +++ b/src/Explorer/ContainerCopy/CreateCopyJob/Screens/SelectSourceAndTargetContainers/SelectSourceAndTargetContainers.test.tsx @@ -1,6 +1,5 @@ import "@testing-library/jest-dom"; import { render, screen } from "@testing-library/react"; -import { Keys, t } from "Localization"; import { DatabaseModel } from "Contracts/DataModels"; import React from "react"; import Explorer from "../../../../../Explorer/Explorer"; diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.test.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.test.tsx index 74961648e..c2d5aa8c2 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.test.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.test.tsx @@ -1,12 +1,14 @@ import { render, screen } 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 React from "react"; import { updateUserContext } from "UserContext"; -import { DatabaseAccount } from "Contracts/DataModels"; import { DataTransferJobGetResults } from "Utils/arm/generatedClients/dataTransferService/types"; +import Explorer from "../../../Explorer"; jest.mock("Common/dataAccess/dataTransfers", () => ({ cancelDataTransferJob: jest.fn().mockResolvedValue(undefined), @@ -67,7 +69,6 @@ const mockOnlineJob = { describe("PartitionKeyComponent", () => { const setupTest = () => { - const Explorer = require("Explorer/Explorer"); const explorer = new Explorer(); // eslint-disable-next-line @typescript-eslint/no-explicit-any const mockDatabase = {} as any as import("../../../../Contracts/ViewModels").Database; @@ -116,7 +117,7 @@ describe("PartitionKeyComponent", () => { }); it("shows cancel button for offline job in progress", () => { - jest.spyOn(require("hooks/useDataTransferJobs"), "useDataTransferJobs").mockReturnValue({ + jest.spyOn(useDataTransferJobs, "useDataTransferJobs").mockReturnValue({ dataTransferJobs: [mockOfflineJob], }); @@ -127,7 +128,7 @@ describe("PartitionKeyComponent", () => { }); it("shows ellipsis action menu for online job in progress", () => { - jest.spyOn(require("hooks/useDataTransferJobs"), "useDataTransferJobs").mockReturnValue({ + jest.spyOn(useDataTransferJobs, "useDataTransferJobs").mockReturnValue({ dataTransferJobs: [mockOnlineJob], }); diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.tsx index 320013b26..975156d56 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent.tsx @@ -192,14 +192,7 @@ export const PartitionKeyComponent: React.FC = ({ useDialog .getState() - .showOkCancelModalDialog( - "", - null, - t(Keys.common.confirm), - onConfirm, - t(Keys.common.cancel), - null, - dialogBody); + .showOkCancelModalDialog("", null, t(Keys.common.confirm), onConfirm, t(Keys.common.cancel), null, dialogBody); }; const getOnlineJobMenuProps = (currentJob: DataTransferJobGetResults): IContextualMenuProps => { @@ -288,9 +281,9 @@ export const PartitionKeyComponent: React.FC = ({ const processedCountString = totalCount > 0 ? t(Keys.controls.settings.partitionKeyEditor.documentsProcessed, { - processedCount: String(processedCount), - totalCount: String(totalCount), - }) + processedCount: String(processedCount), + totalCount: String(totalCount), + }) : ""; return `${portalDataTransferJob?.properties?.status} ${processedCountString}`; }; diff --git a/src/Explorer/Controls/Settings/SettingsUtils.tsx b/src/Explorer/Controls/Settings/SettingsUtils.tsx index d19e9d3ae..5bb49fa95 100644 --- a/src/Explorer/Controls/Settings/SettingsUtils.tsx +++ b/src/Explorer/Controls/Settings/SettingsUtils.tsx @@ -283,12 +283,13 @@ export const getPartitionKeyPlaceHolder = (apiType: string, index?: number): str case "Gremlin": return t(Keys.controls.settings.partitionKey.gremlinPlaceholder); case "SQL": - return `${index === undefined + return `${ + index === undefined ? t(Keys.controls.settings.partitionKey.sqlFirstPartitionKey) : index === 0 - ? t(Keys.controls.settings.partitionKey.sqlSecondPartitionKey) - : t(Keys.controls.settings.partitionKey.sqlThirdPartitionKey) - }`; + ? t(Keys.controls.settings.partitionKey.sqlSecondPartitionKey) + : t(Keys.controls.settings.partitionKey.sqlThirdPartitionKey) + }`; default: return t(Keys.controls.settings.partitionKey.defaultPlaceholder); } diff --git a/src/Explorer/Panes/ChangePartitionKeyPane/ChangePartitionKeyPane.test.tsx b/src/Explorer/Panes/ChangePartitionKeyPane/ChangePartitionKeyPane.test.tsx index 50da20ae6..67b9a2c0d 100644 --- a/src/Explorer/Panes/ChangePartitionKeyPane/ChangePartitionKeyPane.test.tsx +++ b/src/Explorer/Panes/ChangePartitionKeyPane/ChangePartitionKeyPane.test.tsx @@ -1,16 +1,26 @@ -import { fireEvent, render, screen } from "@testing-library/react"; -import { CopyJobMigrationType } from "Explorer/ContainerCopy/Enums/CopyJobEnums"; -import * as React from "react"; +import { act, fireEvent, render, screen } from "@testing-library/react"; +import { initiateDataTransfer } from "Common/dataAccess/dataTransfers"; +import { DatabaseAccount } from "Contracts/DataModels"; import * as ViewModels from "Contracts/ViewModels"; import Explorer from "Explorer/Explorer"; +import * as React from "react"; +import { updateUserContext } from "UserContext"; import { ChangePartitionKeyPane } from "./ChangePartitionKeyPane"; -import { userContext, updateUserContext } from "UserContext"; -import { DatabaseAccount } from "Contracts/DataModels"; + +jest.mock("Common/ErrorHandlingUtils", () => ({ + handleError: jest.fn(), + getErrorMessage: jest.fn().mockReturnValue("error"), + getErrorStack: jest.fn().mockReturnValue(""), +})); jest.mock("Common/dataAccess/createCollection", () => ({ createCollection: jest.fn().mockResolvedValue({}), })); +jest.mock("Common/dataAccess/readDatabases", () => ({ + readDatabases: jest.fn().mockResolvedValue([]), +})); + jest.mock("Common/dataAccess/dataTransfers", () => ({ initiateDataTransfer: jest.fn().mockResolvedValue({}), })); @@ -184,18 +194,25 @@ describe("ChangePartitionKeyPane", () => { }); it("passes mode to initiateDataTransfer when submitting", async () => { - const { initiateDataTransfer } = require("Common/dataAccess/dataTransfers"); - renderPane(); + const mockInitiateDataTransfer = jest.mocked(initiateDataTransfer); + // Mock refreshAllDatabases on the prototype to catch all calls + const refreshSpy = jest.spyOn(Explorer.prototype, "refreshAllDatabases").mockResolvedValue(); + const { container } = renderPane(); - // Submit form with offline mode (default) - const form = document.querySelector("form"); - if (form) { - fireEvent.submit(form); - } + // Fill in partition key (required for createContainer — state starts undefined) + const partitionKeyInput = container.querySelector("#addCollection-partitionKeyValue") as HTMLInputElement; + expect(partitionKeyInput).not.toBeNull(); + fireEvent.change(partitionKeyInput, { target: { value: "/myKey" } }); - // The mode should be Offline (capitalized for ARM API) - if (initiateDataTransfer.mock.calls.length > 0) { - expect(initiateDataTransfer.mock.calls[0][0].mode).toBe("Offline"); - } + const form = container.querySelector("form"); + expect(form).not.toBeNull(); + + await act(async () => { + fireEvent.submit(form!); + }); + + expect(mockInitiateDataTransfer).toHaveBeenCalled(); + expect(mockInitiateDataTransfer.mock.calls[0][0].mode).toBe("Offline"); + refreshSpy.mockRestore(); }); });