mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-05-14 17:27:30 +01:00
Fixing some issues found by lint
This commit is contained in:
-1
@@ -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";
|
||||
|
||||
@@ -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],
|
||||
});
|
||||
|
||||
|
||||
@@ -192,14 +192,7 @@ export const PartitionKeyComponent: React.FC<PartitionKeyComponentProps> = ({
|
||||
|
||||
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<PartitionKeyComponentProps> = ({
|
||||
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}`;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user