mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-05-15 09:47: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 "@testing-library/jest-dom";
|
||||||
import { render, screen } from "@testing-library/react";
|
import { render, screen } from "@testing-library/react";
|
||||||
import { Keys, t } from "Localization";
|
|
||||||
import { DatabaseModel } from "Contracts/DataModels";
|
import { DatabaseModel } from "Contracts/DataModels";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import Explorer from "../../../../../Explorer/Explorer";
|
import Explorer from "../../../../../Explorer/Explorer";
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import { render, screen } from "@testing-library/react";
|
import { render, screen } from "@testing-library/react";
|
||||||
|
import { DatabaseAccount } from "Contracts/DataModels";
|
||||||
import {
|
import {
|
||||||
PartitionKeyComponent,
|
PartitionKeyComponent,
|
||||||
PartitionKeyComponentProps,
|
PartitionKeyComponentProps,
|
||||||
} from "Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent";
|
} from "Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent";
|
||||||
|
import * as useDataTransferJobs from "hooks/useDataTransferJobs";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { updateUserContext } from "UserContext";
|
import { updateUserContext } from "UserContext";
|
||||||
import { DatabaseAccount } from "Contracts/DataModels";
|
|
||||||
import { DataTransferJobGetResults } from "Utils/arm/generatedClients/dataTransferService/types";
|
import { DataTransferJobGetResults } from "Utils/arm/generatedClients/dataTransferService/types";
|
||||||
|
import Explorer from "../../../Explorer";
|
||||||
|
|
||||||
jest.mock("Common/dataAccess/dataTransfers", () => ({
|
jest.mock("Common/dataAccess/dataTransfers", () => ({
|
||||||
cancelDataTransferJob: jest.fn().mockResolvedValue(undefined),
|
cancelDataTransferJob: jest.fn().mockResolvedValue(undefined),
|
||||||
@@ -67,7 +69,6 @@ const mockOnlineJob = {
|
|||||||
|
|
||||||
describe("PartitionKeyComponent", () => {
|
describe("PartitionKeyComponent", () => {
|
||||||
const setupTest = () => {
|
const setupTest = () => {
|
||||||
const Explorer = require("Explorer/Explorer");
|
|
||||||
const explorer = new Explorer();
|
const explorer = new Explorer();
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const mockDatabase = {} as any as import("../../../../Contracts/ViewModels").Database;
|
const mockDatabase = {} as any as import("../../../../Contracts/ViewModels").Database;
|
||||||
@@ -116,7 +117,7 @@ describe("PartitionKeyComponent", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("shows cancel button for offline job in progress", () => {
|
it("shows cancel button for offline job in progress", () => {
|
||||||
jest.spyOn(require("hooks/useDataTransferJobs"), "useDataTransferJobs").mockReturnValue({
|
jest.spyOn(useDataTransferJobs, "useDataTransferJobs").mockReturnValue({
|
||||||
dataTransferJobs: [mockOfflineJob],
|
dataTransferJobs: [mockOfflineJob],
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -127,7 +128,7 @@ describe("PartitionKeyComponent", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("shows ellipsis action menu for online job in progress", () => {
|
it("shows ellipsis action menu for online job in progress", () => {
|
||||||
jest.spyOn(require("hooks/useDataTransferJobs"), "useDataTransferJobs").mockReturnValue({
|
jest.spyOn(useDataTransferJobs, "useDataTransferJobs").mockReturnValue({
|
||||||
dataTransferJobs: [mockOnlineJob],
|
dataTransferJobs: [mockOnlineJob],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -192,14 +192,7 @@ export const PartitionKeyComponent: React.FC<PartitionKeyComponentProps> = ({
|
|||||||
|
|
||||||
useDialog
|
useDialog
|
||||||
.getState()
|
.getState()
|
||||||
.showOkCancelModalDialog(
|
.showOkCancelModalDialog("", null, t(Keys.common.confirm), onConfirm, t(Keys.common.cancel), null, dialogBody);
|
||||||
"",
|
|
||||||
null,
|
|
||||||
t(Keys.common.confirm),
|
|
||||||
onConfirm,
|
|
||||||
t(Keys.common.cancel),
|
|
||||||
null,
|
|
||||||
dialogBody);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getOnlineJobMenuProps = (currentJob: DataTransferJobGetResults): IContextualMenuProps => {
|
const getOnlineJobMenuProps = (currentJob: DataTransferJobGetResults): IContextualMenuProps => {
|
||||||
@@ -288,9 +281,9 @@ export const PartitionKeyComponent: React.FC<PartitionKeyComponentProps> = ({
|
|||||||
const processedCountString =
|
const processedCountString =
|
||||||
totalCount > 0
|
totalCount > 0
|
||||||
? t(Keys.controls.settings.partitionKeyEditor.documentsProcessed, {
|
? t(Keys.controls.settings.partitionKeyEditor.documentsProcessed, {
|
||||||
processedCount: String(processedCount),
|
processedCount: String(processedCount),
|
||||||
totalCount: String(totalCount),
|
totalCount: String(totalCount),
|
||||||
})
|
})
|
||||||
: "";
|
: "";
|
||||||
return `${portalDataTransferJob?.properties?.status} ${processedCountString}`;
|
return `${portalDataTransferJob?.properties?.status} ${processedCountString}`;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -283,12 +283,13 @@ export const getPartitionKeyPlaceHolder = (apiType: string, index?: number): str
|
|||||||
case "Gremlin":
|
case "Gremlin":
|
||||||
return t(Keys.controls.settings.partitionKey.gremlinPlaceholder);
|
return t(Keys.controls.settings.partitionKey.gremlinPlaceholder);
|
||||||
case "SQL":
|
case "SQL":
|
||||||
return `${index === undefined
|
return `${
|
||||||
|
index === undefined
|
||||||
? t(Keys.controls.settings.partitionKey.sqlFirstPartitionKey)
|
? t(Keys.controls.settings.partitionKey.sqlFirstPartitionKey)
|
||||||
: index === 0
|
: index === 0
|
||||||
? t(Keys.controls.settings.partitionKey.sqlSecondPartitionKey)
|
? t(Keys.controls.settings.partitionKey.sqlSecondPartitionKey)
|
||||||
: t(Keys.controls.settings.partitionKey.sqlThirdPartitionKey)
|
: t(Keys.controls.settings.partitionKey.sqlThirdPartitionKey)
|
||||||
}`;
|
}`;
|
||||||
default:
|
default:
|
||||||
return t(Keys.controls.settings.partitionKey.defaultPlaceholder);
|
return t(Keys.controls.settings.partitionKey.defaultPlaceholder);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,26 @@
|
|||||||
import { fireEvent, render, screen } from "@testing-library/react";
|
import { act, fireEvent, render, screen } from "@testing-library/react";
|
||||||
import { CopyJobMigrationType } from "Explorer/ContainerCopy/Enums/CopyJobEnums";
|
import { initiateDataTransfer } from "Common/dataAccess/dataTransfers";
|
||||||
import * as React from "react";
|
import { DatabaseAccount } from "Contracts/DataModels";
|
||||||
import * as ViewModels from "Contracts/ViewModels";
|
import * as ViewModels from "Contracts/ViewModels";
|
||||||
import Explorer from "Explorer/Explorer";
|
import Explorer from "Explorer/Explorer";
|
||||||
|
import * as React from "react";
|
||||||
|
import { updateUserContext } from "UserContext";
|
||||||
import { ChangePartitionKeyPane } from "./ChangePartitionKeyPane";
|
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", () => ({
|
jest.mock("Common/dataAccess/createCollection", () => ({
|
||||||
createCollection: jest.fn().mockResolvedValue({}),
|
createCollection: jest.fn().mockResolvedValue({}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
jest.mock("Common/dataAccess/readDatabases", () => ({
|
||||||
|
readDatabases: jest.fn().mockResolvedValue([]),
|
||||||
|
}));
|
||||||
|
|
||||||
jest.mock("Common/dataAccess/dataTransfers", () => ({
|
jest.mock("Common/dataAccess/dataTransfers", () => ({
|
||||||
initiateDataTransfer: jest.fn().mockResolvedValue({}),
|
initiateDataTransfer: jest.fn().mockResolvedValue({}),
|
||||||
}));
|
}));
|
||||||
@@ -184,18 +194,25 @@ describe("ChangePartitionKeyPane", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("passes mode to initiateDataTransfer when submitting", async () => {
|
it("passes mode to initiateDataTransfer when submitting", async () => {
|
||||||
const { initiateDataTransfer } = require("Common/dataAccess/dataTransfers");
|
const mockInitiateDataTransfer = jest.mocked(initiateDataTransfer);
|
||||||
renderPane();
|
// 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)
|
// Fill in partition key (required for createContainer — state starts undefined)
|
||||||
const form = document.querySelector("form");
|
const partitionKeyInput = container.querySelector("#addCollection-partitionKeyValue") as HTMLInputElement;
|
||||||
if (form) {
|
expect(partitionKeyInput).not.toBeNull();
|
||||||
fireEvent.submit(form);
|
fireEvent.change(partitionKeyInput, { target: { value: "/myKey" } });
|
||||||
}
|
|
||||||
|
|
||||||
// The mode should be Offline (capitalized for ARM API)
|
const form = container.querySelector("form");
|
||||||
if (initiateDataTransfer.mock.calls.length > 0) {
|
expect(form).not.toBeNull();
|
||||||
expect(initiateDataTransfer.mock.calls[0][0].mode).toBe("Offline");
|
|
||||||
}
|
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