mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-23 19:54:08 +00:00
Compare commits
12 Commits
users/sind
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05407b3e0f | ||
|
|
703218debf | ||
|
|
f83a2c4442 | ||
|
|
2ff01c6379 | ||
|
|
31385950dd | ||
|
|
6dce2632c8 | ||
|
|
80ad5f10d4 | ||
|
|
f02611c90e | ||
|
|
9646dfcf04 | ||
|
|
90f3c3a79e | ||
|
|
b922086cc0 | ||
|
|
375ec350dc |
24
.github/workflows/ci.yml
vendored
24
.github/workflows/ci.yml
vendored
@@ -201,18 +201,18 @@ jobs:
|
|||||||
GREMLIN_TESTACCOUNT_TOKEN=$(az account get-access-token --scope "https://github-e2etests-gremlin.documents.azure.com/.default" -o tsv --query accessToken)
|
GREMLIN_TESTACCOUNT_TOKEN=$(az account get-access-token --scope "https://github-e2etests-gremlin.documents.azure.com/.default" -o tsv --query accessToken)
|
||||||
echo "::add-mask::$GREMLIN_TESTACCOUNT_TOKEN"
|
echo "::add-mask::$GREMLIN_TESTACCOUNT_TOKEN"
|
||||||
echo GREMLIN_TESTACCOUNT_TOKEN=$GREMLIN_TESTACCOUNT_TOKEN >> $GITHUB_ENV
|
echo GREMLIN_TESTACCOUNT_TOKEN=$GREMLIN_TESTACCOUNT_TOKEN >> $GITHUB_ENV
|
||||||
# CASSANDRA_TESTACCOUNT_TOKEN=$(az account get-access-token --scope "https://github-e2etests-cassandra.documents.azure.com/.default" -o tsv --query accessToken)
|
CASSANDRA_TESTACCOUNT_TOKEN=$(az account get-access-token --scope "https://github-e2etests-cassandra.documents.azure.com/.default" -o tsv --query accessToken)
|
||||||
# echo "::add-mask::$CASSANDRA_TESTACCOUNT_TOKEN"
|
echo "::add-mask::$CASSANDRA_TESTACCOUNT_TOKEN"
|
||||||
# echo CASSANDRA_TESTACCOUNT_TOKEN=$CASSANDRA_TESTACCOUNT_TOKEN >> $GITHUB_ENV
|
echo CASSANDRA_TESTACCOUNT_TOKEN=$CASSANDRA_TESTACCOUNT_TOKEN >> $GITHUB_ENV
|
||||||
# MONGO_TESTACCOUNT_TOKEN=$(az account get-access-token --scope "https://github-e2etests-mongo.documents.azure.com/.default" -o tsv --query accessToken)
|
MONGO_TESTACCOUNT_TOKEN=$(az account get-access-token --scope "https://github-e2etests-mongo.documents.azure.com/.default" -o tsv --query accessToken)
|
||||||
# echo "::add-mask::$MONGO_TESTACCOUNT_TOKEN"
|
echo "::add-mask::$MONGO_TESTACCOUNT_TOKEN"
|
||||||
# echo MONGO_TESTACCOUNT_TOKEN=$MONGO_TESTACCOUNT_TOKEN >> $GITHUB_ENV
|
echo MONGO_TESTACCOUNT_TOKEN=$MONGO_TESTACCOUNT_TOKEN >> $GITHUB_ENV
|
||||||
# MONGO32_TESTACCOUNT_TOKEN=$(az account get-access-token --scope "https://github-e2etests-mongo32.documents.azure.com/.default" -o tsv --query accessToken)
|
MONGO32_TESTACCOUNT_TOKEN=$(az account get-access-token --scope "https://github-e2etests-mongo32.documents.azure.com/.default" -o tsv --query accessToken)
|
||||||
# echo "::add-mask::$MONGO32_TESTACCOUNT_TOKEN"
|
echo "::add-mask::$MONGO32_TESTACCOUNT_TOKEN"
|
||||||
# echo MONGO32_TESTACCOUNT_TOKEN=$MONGO32_TESTACCOUNT_TOKEN >> $GITHUB_ENV
|
echo MONGO32_TESTACCOUNT_TOKEN=$MONGO32_TESTACCOUNT_TOKEN >> $GITHUB_ENV
|
||||||
# MONGO_READONLY_TESTACCOUNT_TOKEN=$(az account get-access-token --scope "https://github-e2etests-mongo-readonly.documents.azure.com/.default" -o tsv --query accessToken)
|
MONGO_READONLY_TESTACCOUNT_TOKEN=$(az account get-access-token --scope "https://github-e2etests-mongo-readonly.documents.azure.com/.default" -o tsv --query accessToken)
|
||||||
# echo "::add-mask::$MONGO_READONLY_TESTACCOUNT_TOKEN"
|
echo "::add-mask::$MONGO_READONLY_TESTACCOUNT_TOKEN"
|
||||||
# echo MONGO_READONLY_TESTACCOUNT_TOKEN=$MONGO_READONLY_TESTACCOUNT_TOKEN >> $GITHUB_ENV
|
echo MONGO_READONLY_TESTACCOUNT_TOKEN=$MONGO_READONLY_TESTACCOUNT_TOKEN >> $GITHUB_ENV
|
||||||
- name: List test files for shard ${{ matrix['shardIndex'] }} of ${{ matrix['shardTotal']}}
|
- name: List test files for shard ${{ matrix['shardIndex'] }} of ${{ matrix['shardTotal']}}
|
||||||
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --list
|
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --list
|
||||||
- name: Run test shard ${{ matrix['shardIndex'] }} of ${{ matrix['shardTotal']}}
|
- name: Run test shard ${{ matrix['shardIndex'] }} of ${{ matrix['shardTotal']}}
|
||||||
|
|||||||
@@ -7,16 +7,27 @@ import { HttpStatusCodes } from "./Constants";
|
|||||||
import { logError } from "./Logger";
|
import { logError } from "./Logger";
|
||||||
import { sendMessage } from "./MessageHandler";
|
import { sendMessage } from "./MessageHandler";
|
||||||
|
|
||||||
export const handleError = (error: string | ARMError | Error, area: string, consoleErrorPrefix?: string): void => {
|
export interface HandleErrorOptions {
|
||||||
|
/** Optional redacted error to use for telemetry logging instead of the original error */
|
||||||
|
redactedError?: string | ARMError | Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handleError = (
|
||||||
|
error: string | ARMError | Error,
|
||||||
|
area: string,
|
||||||
|
consoleErrorPrefix?: string,
|
||||||
|
options?: HandleErrorOptions,
|
||||||
|
): void => {
|
||||||
const errorMessage = getErrorMessage(error);
|
const errorMessage = getErrorMessage(error);
|
||||||
const errorCode = error instanceof ARMError ? error.code : undefined;
|
const errorCode = error instanceof ARMError ? error.code : undefined;
|
||||||
|
|
||||||
// logs error to data explorer console
|
// logs error to data explorer console (always shows original, non-redacted message)
|
||||||
const consoleErrorMessage = consoleErrorPrefix ? `${consoleErrorPrefix}:\n ${errorMessage}` : errorMessage;
|
const consoleErrorMessage = consoleErrorPrefix ? `${consoleErrorPrefix}:\n ${errorMessage}` : errorMessage;
|
||||||
logConsoleError(consoleErrorMessage);
|
logConsoleError(consoleErrorMessage);
|
||||||
|
|
||||||
// logs error to both app insight and kusto
|
// logs error to both app insight and kusto (use redacted message if provided)
|
||||||
logError(errorMessage, area, errorCode);
|
const telemetryErrorMessage = options?.redactedError ? getErrorMessage(options.redactedError) : errorMessage;
|
||||||
|
logError(telemetryErrorMessage, area, errorCode);
|
||||||
|
|
||||||
// checks for errors caused by firewall and sends them to portal to handle
|
// checks for errors caused by firewall and sends them to portal to handle
|
||||||
sendNotificationForError(errorMessage, errorCode);
|
sendNotificationForError(errorMessage, errorCode);
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ export const deleteDocuments = async (
|
|||||||
documentIds: DocumentId[],
|
documentIds: DocumentId[],
|
||||||
abortSignal: AbortSignal,
|
abortSignal: AbortSignal,
|
||||||
): Promise<IBulkDeleteResult[]> => {
|
): Promise<IBulkDeleteResult[]> => {
|
||||||
const clearMessage = logConsoleProgress(`Deleting ${documentIds.length} ${getEntityName(true)}`);
|
const totalCount = documentIds.length;
|
||||||
|
const clearMessage = logConsoleProgress(`Deleting ${totalCount} ${getEntityName(true)}`);
|
||||||
try {
|
try {
|
||||||
const v2Container = await client().database(collection.databaseId).container(collection.id());
|
const v2Container = await client().database(collection.databaseId).container(collection.id());
|
||||||
|
|
||||||
@@ -83,11 +84,7 @@ export const deleteDocuments = async (
|
|||||||
const flatAllResult = Array.prototype.concat.apply([], allResult);
|
const flatAllResult = Array.prototype.concat.apply([], allResult);
|
||||||
return flatAllResult;
|
return flatAllResult;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(
|
handleError(error, "DeleteDocuments", `Error while deleting ${totalCount} ${getEntityName(totalCount > 1)}`);
|
||||||
error,
|
|
||||||
"DeleteDocuments",
|
|
||||||
`Error while deleting ${documentIds.length} ${getEntityName(documentIds.length > 1)}`,
|
|
||||||
);
|
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
clearMessage();
|
clearMessage();
|
||||||
|
|||||||
171
src/Common/dataAccess/queryDocumentsPage.test.ts
Normal file
171
src/Common/dataAccess/queryDocumentsPage.test.ts
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
import { redactSyntaxErrorMessage } from "./queryDocumentsPage";
|
||||||
|
|
||||||
|
/* Typical error to redact looks like this (the message property contains a JSON string with nested structure):
|
||||||
|
{
|
||||||
|
"message": "{\"code\":\"BadRequest\",\"message\":\"{\\\"errors\\\":[{\\\"severity\\\":\\\"Error\\\",\\\"location\\\":{\\\"start\\\":0,\\\"end\\\":5},\\\"code\\\":\\\"SC1001\\\",\\\"message\\\":\\\"Syntax error, incorrect syntax near 'Crazy'.\\\"}]}\\r\\nActivityId: d5424e10-51bd-46f7-9aec-7b40bed36f17, Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0\"}"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Helper to create the nested error structure that matches what the SDK returns
|
||||||
|
const createNestedError = (
|
||||||
|
errors: Array<{ severity?: string; location?: { start: number; end: number }; code: string; message: string }>,
|
||||||
|
activityId: string = "test-activity-id",
|
||||||
|
): { message: string } => {
|
||||||
|
const innerErrorsJson = JSON.stringify({ errors });
|
||||||
|
const innerMessage = `${innerErrorsJson}\r\n${activityId}`;
|
||||||
|
const outerJson = JSON.stringify({ code: "BadRequest", message: innerMessage });
|
||||||
|
return { message: outerJson };
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper to parse the redacted result
|
||||||
|
const parseRedactedResult = (result: { message: string }) => {
|
||||||
|
const outerParsed = JSON.parse(result.message);
|
||||||
|
const [innerErrorsJson, activityIdPart] = outerParsed.message.split("\r\n");
|
||||||
|
const innerErrors = JSON.parse(innerErrorsJson);
|
||||||
|
return { outerParsed, innerErrors, activityIdPart };
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("redactSyntaxErrorMessage", () => {
|
||||||
|
it("should redact SC1001 error message", () => {
|
||||||
|
const error = createNestedError(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
severity: "Error",
|
||||||
|
location: { start: 0, end: 5 },
|
||||||
|
code: "SC1001",
|
||||||
|
message: "Syntax error, incorrect syntax near 'Crazy'.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"ActivityId: d5424e10-51bd-46f7-9aec-7b40bed36f17",
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error) as { message: string };
|
||||||
|
const { outerParsed, innerErrors, activityIdPart } = parseRedactedResult(result);
|
||||||
|
|
||||||
|
expect(outerParsed.code).toBe("BadRequest");
|
||||||
|
expect(innerErrors.errors[0].message).toBe("__REDACTED__");
|
||||||
|
expect(activityIdPart).toContain("ActivityId: d5424e10-51bd-46f7-9aec-7b40bed36f17");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should redact SC2001 error message", () => {
|
||||||
|
const error = createNestedError(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
severity: "Error",
|
||||||
|
location: { start: 0, end: 10 },
|
||||||
|
code: "SC2001",
|
||||||
|
message: "Some sensitive syntax error message.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"ActivityId: abc123",
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error) as { message: string };
|
||||||
|
const { outerParsed, innerErrors, activityIdPart } = parseRedactedResult(result);
|
||||||
|
|
||||||
|
expect(outerParsed.code).toBe("BadRequest");
|
||||||
|
expect(innerErrors.errors[0].message).toBe("__REDACTED__");
|
||||||
|
expect(activityIdPart).toContain("ActivityId: abc123");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should redact multiple errors with SC1001 and SC2001 codes", () => {
|
||||||
|
const error = createNestedError(
|
||||||
|
[
|
||||||
|
{ severity: "Error", code: "SC1001", message: "First error" },
|
||||||
|
{ severity: "Error", code: "SC2001", message: "Second error" },
|
||||||
|
],
|
||||||
|
"ActivityId: xyz",
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error) as { message: string };
|
||||||
|
const { innerErrors } = parseRedactedResult(result);
|
||||||
|
|
||||||
|
expect(innerErrors.errors[0].message).toBe("__REDACTED__");
|
||||||
|
expect(innerErrors.errors[1].message).toBe("__REDACTED__");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not redact errors with other codes", () => {
|
||||||
|
const error = createNestedError(
|
||||||
|
[{ severity: "Error", code: "SC9999", message: "This should not be redacted." }],
|
||||||
|
"ActivityId: test123",
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error);
|
||||||
|
|
||||||
|
expect(result).toBe(error); // Should return original error unchanged
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not modify non-BadRequest errors", () => {
|
||||||
|
const innerMessage = JSON.stringify({ errors: [{ code: "SC1001", message: "Should not be redacted" }] });
|
||||||
|
const error = {
|
||||||
|
message: JSON.stringify({ code: "NotFound", message: innerMessage }),
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error);
|
||||||
|
|
||||||
|
expect(result).toBe(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle errors without message property", () => {
|
||||||
|
const error = { code: "BadRequest" };
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error);
|
||||||
|
|
||||||
|
expect(result).toBe(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle non-object errors", () => {
|
||||||
|
const stringError = "Simple string error";
|
||||||
|
const nullError: null = null;
|
||||||
|
const undefinedError: undefined = undefined;
|
||||||
|
|
||||||
|
expect(redactSyntaxErrorMessage(stringError)).toBe(stringError);
|
||||||
|
expect(redactSyntaxErrorMessage(nullError)).toBe(nullError);
|
||||||
|
expect(redactSyntaxErrorMessage(undefinedError)).toBe(undefinedError);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle malformed JSON in message", () => {
|
||||||
|
const error = {
|
||||||
|
message: "not valid json",
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error);
|
||||||
|
|
||||||
|
expect(result).toBe(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle message without ActivityId suffix", () => {
|
||||||
|
const innerErrorsJson = JSON.stringify({
|
||||||
|
errors: [{ severity: "Error", code: "SC1001", message: "Syntax error near something." }],
|
||||||
|
});
|
||||||
|
const error = {
|
||||||
|
message: JSON.stringify({ code: "BadRequest", message: innerErrorsJson + "\r\n" }),
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error) as { message: string };
|
||||||
|
const { innerErrors } = parseRedactedResult(result);
|
||||||
|
|
||||||
|
expect(innerErrors.errors[0].message).toBe("__REDACTED__");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should preserve other error properties", () => {
|
||||||
|
const baseError = createNestedError([{ code: "SC1001", message: "Error" }], "ActivityId: test");
|
||||||
|
const error = {
|
||||||
|
...baseError,
|
||||||
|
statusCode: 400,
|
||||||
|
additionalInfo: "extra data",
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error) as {
|
||||||
|
message: string;
|
||||||
|
statusCode: number;
|
||||||
|
additionalInfo: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result.statusCode).toBe(400);
|
||||||
|
expect(result.additionalInfo).toBe("extra data");
|
||||||
|
|
||||||
|
const { innerErrors } = parseRedactedResult(result);
|
||||||
|
expect(innerErrors.errors[0].message).toBe("__REDACTED__");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -4,6 +4,51 @@ import { getEntityName } from "../DocumentUtility";
|
|||||||
import { handleError } from "../ErrorHandlingUtils";
|
import { handleError } from "../ErrorHandlingUtils";
|
||||||
import { MinimalQueryIterator, nextPage } from "../IteratorUtilities";
|
import { MinimalQueryIterator, nextPage } from "../IteratorUtilities";
|
||||||
|
|
||||||
|
// Redact sensitive information from BadRequest errors with specific codes
|
||||||
|
export const redactSyntaxErrorMessage = (error: unknown): unknown => {
|
||||||
|
const codesToRedact = ["SC1001", "SC2001"];
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Handle error objects with a message property
|
||||||
|
if (error && typeof error === "object" && "message" in error) {
|
||||||
|
const errorObj = error as { code?: string; message?: string };
|
||||||
|
if (typeof errorObj.message === "string") {
|
||||||
|
// Parse the inner JSON from the message
|
||||||
|
const innerJson = JSON.parse(errorObj.message);
|
||||||
|
if (innerJson.code === "BadRequest" && typeof innerJson.message === "string") {
|
||||||
|
const [innerErrorsJson, activityIdPart] = innerJson.message.split("\r\n");
|
||||||
|
const innerErrorsObj = JSON.parse(innerErrorsJson);
|
||||||
|
if (Array.isArray(innerErrorsObj.errors)) {
|
||||||
|
let modified = false;
|
||||||
|
innerErrorsObj.errors = innerErrorsObj.errors.map((err: { code?: string; message?: string }) => {
|
||||||
|
if (err.code && codesToRedact.includes(err.code)) {
|
||||||
|
modified = true;
|
||||||
|
return { ...err, message: "__REDACTED__" };
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (modified) {
|
||||||
|
// Reconstruct the message with the redacted content
|
||||||
|
const redactedMessage = JSON.stringify(innerErrorsObj) + `\r\n${activityIdPart}`;
|
||||||
|
const redactedError = {
|
||||||
|
...error,
|
||||||
|
message: JSON.stringify({ ...innerJson, message: redactedMessage }),
|
||||||
|
body: undefined as unknown, // Clear body to avoid sensitive data
|
||||||
|
};
|
||||||
|
return redactedError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// If parsing fails, return the original error
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
};
|
||||||
|
|
||||||
export const queryDocumentsPage = async (
|
export const queryDocumentsPage = async (
|
||||||
resourceName: string,
|
resourceName: string,
|
||||||
documentsIterator: MinimalQueryIterator,
|
documentsIterator: MinimalQueryIterator,
|
||||||
@@ -18,7 +63,12 @@ export const queryDocumentsPage = async (
|
|||||||
logConsoleInfo(`Successfully fetched ${itemCount} ${entityName} for container ${resourceName}`);
|
logConsoleInfo(`Successfully fetched ${itemCount} ${entityName} for container ${resourceName}`);
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, "QueryDocumentsPage", `Failed to query ${entityName} for container ${resourceName}`);
|
// Redact sensitive information for telemetry while showing original in console
|
||||||
|
const redactedError = redactSyntaxErrorMessage(error);
|
||||||
|
|
||||||
|
handleError(error, "QueryDocumentsPage", `Failed to query ${entityName} for container ${resourceName}`, {
|
||||||
|
redactedError: redactedError as Error,
|
||||||
|
});
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
clearMessage();
|
clearMessage();
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ export type DataExploreMessageV3 =
|
|||||||
params: {
|
params: {
|
||||||
updateType: "created" | "deleted" | "settings";
|
updateType: "created" | "deleted" | "settings";
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: FabricMessageTypes.RestoreContainer;
|
||||||
|
params: [];
|
||||||
};
|
};
|
||||||
export interface GetCosmosTokenMessageOptions {
|
export interface GetCosmosTokenMessageOptions {
|
||||||
verb: "connect" | "delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace";
|
verb: "connect" | "delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace";
|
||||||
|
|||||||
@@ -184,5 +184,10 @@ export default {
|
|||||||
Skipped: "Cancelled",
|
Skipped: "Cancelled",
|
||||||
Cancelled: "Cancelled",
|
Cancelled: "Cancelled",
|
||||||
},
|
},
|
||||||
|
dialog: {
|
||||||
|
heading: "",
|
||||||
|
confirmButtonText: "Confirm",
|
||||||
|
cancelButtonText: "Cancel",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable jest/no-conditional-expect */
|
||||||
import "@testing-library/jest-dom";
|
import "@testing-library/jest-dom";
|
||||||
import { fireEvent, render, screen } from "@testing-library/react";
|
import { fireEvent, render, screen } from "@testing-library/react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
@@ -5,6 +6,20 @@ import { CopyJobActions, CopyJobMigrationType, CopyJobStatusType } from "../../E
|
|||||||
import { CopyJobType, HandleJobActionClickType } from "../../Types/CopyJobTypes";
|
import { CopyJobType, HandleJobActionClickType } from "../../Types/CopyJobTypes";
|
||||||
import CopyJobActionMenu from "./CopyJobActionMenu";
|
import CopyJobActionMenu from "./CopyJobActionMenu";
|
||||||
|
|
||||||
|
const mockShowOkCancelModalDialog = jest.fn();
|
||||||
|
const mockCloseDialog = jest.fn();
|
||||||
|
const mockOpenDialog = jest.fn();
|
||||||
|
|
||||||
|
jest.mock("../../../Controls/Dialog", () => ({
|
||||||
|
useDialog: {
|
||||||
|
getState: () => ({
|
||||||
|
showOkCancelModalDialog: mockShowOkCancelModalDialog,
|
||||||
|
closeDialog: mockCloseDialog,
|
||||||
|
openDialog: mockOpenDialog,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
jest.mock("../../ContainerCopyMessages", () => ({
|
jest.mock("../../ContainerCopyMessages", () => ({
|
||||||
__esModule: true,
|
__esModule: true,
|
||||||
default: {
|
default: {
|
||||||
@@ -18,6 +33,11 @@ jest.mock("../../ContainerCopyMessages", () => ({
|
|||||||
cancel: "Cancel",
|
cancel: "Cancel",
|
||||||
complete: "Complete",
|
complete: "Complete",
|
||||||
},
|
},
|
||||||
|
dialog: {
|
||||||
|
heading: "Confirm Action",
|
||||||
|
confirmButtonText: "Confirm",
|
||||||
|
cancelButtonText: "Cancel",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@@ -50,6 +70,9 @@ describe("CopyJobActionMenu", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
mockShowOkCancelModalDialog.mockClear();
|
||||||
|
mockCloseDialog.mockClear();
|
||||||
|
mockOpenDialog.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Component Rendering", () => {
|
describe("Component Rendering", () => {
|
||||||
@@ -266,7 +289,29 @@ describe("CopyJobActionMenu", () => {
|
|||||||
expect(mockHandleClick).toHaveBeenCalledWith(job, CopyJobActions.pause, expect.any(Function));
|
expect(mockHandleClick).toHaveBeenCalledWith(job, CopyJobActions.pause, expect.any(Function));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call handleClick when cancel action is clicked", () => {
|
it("should show confirmation dialog when cancel action is clicked", () => {
|
||||||
|
const job = createMockJob({ Name: "Test Job", Status: CopyJobStatusType.InProgress });
|
||||||
|
|
||||||
|
render(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
||||||
|
|
||||||
|
const actionButton = screen.getByRole("button", { name: "Actions" });
|
||||||
|
fireEvent.click(actionButton);
|
||||||
|
|
||||||
|
const cancelButton = screen.getByText("Cancel");
|
||||||
|
fireEvent.click(cancelButton);
|
||||||
|
|
||||||
|
expect(mockShowOkCancelModalDialog).toHaveBeenCalledWith(
|
||||||
|
"Confirm Action",
|
||||||
|
null,
|
||||||
|
"Confirm",
|
||||||
|
expect.any(Function),
|
||||||
|
"Cancel",
|
||||||
|
null,
|
||||||
|
expect.any(Object), // dialogBody content
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call handleClick when dialog is confirmed for cancel action", () => {
|
||||||
const job = createMockJob({ Status: CopyJobStatusType.InProgress });
|
const job = createMockJob({ Status: CopyJobStatusType.InProgress });
|
||||||
|
|
||||||
render(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
render(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
||||||
@@ -277,6 +322,9 @@ describe("CopyJobActionMenu", () => {
|
|||||||
const cancelButton = screen.getByText("Cancel");
|
const cancelButton = screen.getByText("Cancel");
|
||||||
fireEvent.click(cancelButton);
|
fireEvent.click(cancelButton);
|
||||||
|
|
||||||
|
const [, , , onOkCallback] = mockShowOkCancelModalDialog.mock.calls[0];
|
||||||
|
onOkCallback();
|
||||||
|
|
||||||
expect(mockHandleClick).toHaveBeenCalledWith(job, CopyJobActions.cancel, expect.any(Function));
|
expect(mockHandleClick).toHaveBeenCalledWith(job, CopyJobActions.cancel, expect.any(Function));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -294,7 +342,33 @@ describe("CopyJobActionMenu", () => {
|
|||||||
expect(mockHandleClick).toHaveBeenCalledWith(job, CopyJobActions.resume, expect.any(Function));
|
expect(mockHandleClick).toHaveBeenCalledWith(job, CopyJobActions.resume, expect.any(Function));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call handleClick when complete action is clicked", () => {
|
it("should show confirmation dialog when complete action is clicked", () => {
|
||||||
|
const job = createMockJob({
|
||||||
|
Name: "Test Online Job",
|
||||||
|
Status: CopyJobStatusType.InProgress,
|
||||||
|
Mode: CopyJobMigrationType.Online,
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
||||||
|
|
||||||
|
const actionButton = screen.getByRole("button", { name: "Actions" });
|
||||||
|
fireEvent.click(actionButton);
|
||||||
|
|
||||||
|
const completeButton = screen.getByText("Complete");
|
||||||
|
fireEvent.click(completeButton);
|
||||||
|
|
||||||
|
expect(mockShowOkCancelModalDialog).toHaveBeenCalledWith(
|
||||||
|
"Confirm Action",
|
||||||
|
null,
|
||||||
|
"Confirm",
|
||||||
|
expect.any(Function),
|
||||||
|
"Cancel",
|
||||||
|
null,
|
||||||
|
expect.any(Object), // dialogBody content
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call handleClick when dialog is confirmed for complete action", () => {
|
||||||
const job = createMockJob({
|
const job = createMockJob({
|
||||||
Status: CopyJobStatusType.InProgress,
|
Status: CopyJobStatusType.InProgress,
|
||||||
Mode: CopyJobMigrationType.Online,
|
Mode: CopyJobMigrationType.Online,
|
||||||
@@ -308,10 +382,87 @@ describe("CopyJobActionMenu", () => {
|
|||||||
const completeButton = screen.getByText("Complete");
|
const completeButton = screen.getByText("Complete");
|
||||||
fireEvent.click(completeButton);
|
fireEvent.click(completeButton);
|
||||||
|
|
||||||
|
const [, , , onOkCallback] = mockShowOkCancelModalDialog.mock.calls[0];
|
||||||
|
onOkCallback();
|
||||||
|
|
||||||
expect(mockHandleClick).toHaveBeenCalledWith(job, CopyJobActions.complete, expect.any(Function));
|
expect(mockHandleClick).toHaveBeenCalledWith(job, CopyJobActions.complete, expect.any(Function));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Dialog Body Content", () => {
|
||||||
|
it("should pass correct dialog body content for cancel action", () => {
|
||||||
|
const job = createMockJob({ Name: "MyTestJob", Status: CopyJobStatusType.InProgress });
|
||||||
|
|
||||||
|
render(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
||||||
|
|
||||||
|
const actionButton = screen.getByRole("button", { name: "Actions" });
|
||||||
|
fireEvent.click(actionButton);
|
||||||
|
|
||||||
|
const cancelButton = screen.getByText("Cancel");
|
||||||
|
fireEvent.click(cancelButton);
|
||||||
|
|
||||||
|
expect(mockShowOkCancelModalDialog).toHaveBeenCalledWith(
|
||||||
|
"Confirm Action",
|
||||||
|
null,
|
||||||
|
"Confirm",
|
||||||
|
expect.any(Function),
|
||||||
|
"Cancel",
|
||||||
|
null,
|
||||||
|
expect.objectContaining({
|
||||||
|
props: expect.objectContaining({
|
||||||
|
tokens: expect.any(Object),
|
||||||
|
children: expect.any(Array),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should pass correct dialog body content for complete action", () => {
|
||||||
|
const job = createMockJob({
|
||||||
|
Name: "OnlineTestJob",
|
||||||
|
Status: CopyJobStatusType.InProgress,
|
||||||
|
Mode: CopyJobMigrationType.Online,
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
||||||
|
|
||||||
|
const actionButton = screen.getByRole("button", { name: "Actions" });
|
||||||
|
fireEvent.click(actionButton);
|
||||||
|
|
||||||
|
const completeButton = screen.getByText("Complete");
|
||||||
|
fireEvent.click(completeButton);
|
||||||
|
|
||||||
|
expect(mockShowOkCancelModalDialog).toHaveBeenCalledWith(
|
||||||
|
"Confirm Action",
|
||||||
|
null,
|
||||||
|
"Confirm",
|
||||||
|
expect.any(Function),
|
||||||
|
"Cancel",
|
||||||
|
null,
|
||||||
|
expect.objectContaining({
|
||||||
|
props: expect.objectContaining({
|
||||||
|
tokens: expect.any(Object),
|
||||||
|
children: expect.any(Array),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not show dialog body for actions without confirmation", () => {
|
||||||
|
const job = createMockJob({ Status: CopyJobStatusType.InProgress });
|
||||||
|
|
||||||
|
render(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
||||||
|
|
||||||
|
const actionButton = screen.getByRole("button", { name: "Actions" });
|
||||||
|
fireEvent.click(actionButton);
|
||||||
|
|
||||||
|
const pauseButton = screen.getByText("Pause");
|
||||||
|
fireEvent.click(pauseButton);
|
||||||
|
|
||||||
|
expect(mockShowOkCancelModalDialog).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("Disabled States During Updates", () => {
|
describe("Disabled States During Updates", () => {
|
||||||
const TestComponentWrapper: React.FC<{
|
const TestComponentWrapper: React.FC<{
|
||||||
job: CopyJobType;
|
job: CopyJobType;
|
||||||
@@ -339,8 +490,13 @@ describe("CopyJobActionMenu", () => {
|
|||||||
const pauseButton = screen.getByText("Pause");
|
const pauseButton = screen.getByText("Pause");
|
||||||
fireEvent.click(pauseButton);
|
fireEvent.click(pauseButton);
|
||||||
fireEvent.click(actionButton);
|
fireEvent.click(actionButton);
|
||||||
const pauseButtonAfterClick = screen.getByText("Pause");
|
|
||||||
|
const pauseButtonAfterClick = screen.getByText("Pause").closest("button");
|
||||||
expect(pauseButtonAfterClick).toBeInTheDocument();
|
expect(pauseButtonAfterClick).toBeInTheDocument();
|
||||||
|
expect(pauseButtonAfterClick).toHaveAttribute("aria-disabled", "true");
|
||||||
|
|
||||||
|
const cancelButtonAfterClick = screen.getByText("Cancel").closest("button");
|
||||||
|
expect(cancelButtonAfterClick).toHaveAttribute("aria-disabled", "true");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not disable actions for different jobs when one is updating", () => {
|
it("should not disable actions for different jobs when one is updating", () => {
|
||||||
@@ -360,23 +516,7 @@ describe("CopyJobActionMenu", () => {
|
|||||||
expect(screen.getByText("Cancel")).toBeInTheDocument();
|
expect(screen.getByText("Cancel")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should properly handle multiple action types being disabled for the same job", () => {
|
it("should disable complete action when job is being updated", () => {
|
||||||
const job = createMockJob({ Status: CopyJobStatusType.InProgress });
|
|
||||||
render(<TestComponentWrapper job={job} />);
|
|
||||||
const actionButton = screen.getByRole("button", { name: "Actions" });
|
|
||||||
|
|
||||||
fireEvent.click(actionButton);
|
|
||||||
fireEvent.click(screen.getByText("Pause"));
|
|
||||||
|
|
||||||
fireEvent.click(actionButton);
|
|
||||||
fireEvent.click(screen.getByText("Cancel"));
|
|
||||||
|
|
||||||
fireEvent.click(actionButton);
|
|
||||||
expect(screen.getByText("Pause")).toBeInTheDocument();
|
|
||||||
expect(screen.getByText("Cancel")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should handle complete action disabled state for online jobs", () => {
|
|
||||||
const job = createMockJob({
|
const job = createMockJob({
|
||||||
Status: CopyJobStatusType.InProgress,
|
Status: CopyJobStatusType.InProgress,
|
||||||
Mode: CopyJobMigrationType.Online,
|
Mode: CopyJobMigrationType.Online,
|
||||||
@@ -390,8 +530,34 @@ describe("CopyJobActionMenu", () => {
|
|||||||
const completeButton = screen.getByText("Complete");
|
const completeButton = screen.getByText("Complete");
|
||||||
fireEvent.click(completeButton);
|
fireEvent.click(completeButton);
|
||||||
|
|
||||||
|
// Simulate dialog confirmation to trigger state update
|
||||||
|
const [, , , onOkCallback] = mockShowOkCancelModalDialog.mock.calls[0];
|
||||||
|
onOkCallback();
|
||||||
|
|
||||||
fireEvent.click(actionButton);
|
fireEvent.click(actionButton);
|
||||||
expect(screen.getByText("Complete")).toBeInTheDocument();
|
const completeButtonAfterClick = screen.getByText("Complete").closest("button");
|
||||||
|
expect(completeButtonAfterClick).toBeInTheDocument();
|
||||||
|
expect(completeButtonAfterClick).toHaveAttribute("aria-disabled", "true");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should disable complete action when any other action is being performed", () => {
|
||||||
|
const job = createMockJob({
|
||||||
|
Status: CopyJobStatusType.InProgress,
|
||||||
|
Mode: CopyJobMigrationType.Online,
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<TestComponentWrapper job={job} />);
|
||||||
|
|
||||||
|
const actionButton = screen.getByRole("button", { name: "Actions" });
|
||||||
|
fireEvent.click(actionButton);
|
||||||
|
|
||||||
|
const pauseButton = screen.getByText("Pause");
|
||||||
|
fireEvent.click(pauseButton);
|
||||||
|
fireEvent.click(actionButton);
|
||||||
|
|
||||||
|
const completeButtonAfterClick = screen.getByText("Complete").closest("button");
|
||||||
|
expect(completeButtonAfterClick).toBeInTheDocument();
|
||||||
|
expect(completeButtonAfterClick).toHaveAttribute("aria-disabled", "true");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -462,6 +628,7 @@ describe("CopyJobActionMenu", () => {
|
|||||||
|
|
||||||
expect(actionButton).toHaveAttribute("aria-label", "Actions");
|
expect(actionButton).toHaveAttribute("aria-label", "Actions");
|
||||||
expect(actionButton).toHaveAttribute("title", "Actions");
|
expect(actionButton).toHaveAttribute("title", "Actions");
|
||||||
|
expect(actionButton).toHaveAttribute("role", "button");
|
||||||
|
|
||||||
const moreIcon = actionButton.querySelector('[data-icon-name="More"]');
|
const moreIcon = actionButton.querySelector('[data-icon-name="More"]');
|
||||||
expect(moreIcon || actionButton).toBeInTheDocument();
|
expect(moreIcon || actionButton).toBeInTheDocument();
|
||||||
@@ -608,4 +775,129 @@ describe("CopyJobActionMenu", () => {
|
|||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Complete Coverage Tests", () => {
|
||||||
|
it("should handle all possible dialog scenarios", () => {
|
||||||
|
const dialogTests = [
|
||||||
|
{ action: CopyJobActions.cancel, status: CopyJobStatusType.InProgress, shouldShowDialog: true },
|
||||||
|
{
|
||||||
|
action: CopyJobActions.complete,
|
||||||
|
status: CopyJobStatusType.InProgress,
|
||||||
|
mode: CopyJobMigrationType.Online,
|
||||||
|
shouldShowDialog: true,
|
||||||
|
},
|
||||||
|
{ action: CopyJobActions.pause, status: CopyJobStatusType.InProgress, shouldShowDialog: false },
|
||||||
|
{ action: CopyJobActions.resume, status: CopyJobStatusType.Paused, shouldShowDialog: false },
|
||||||
|
];
|
||||||
|
|
||||||
|
dialogTests.forEach(({ action, status, mode = CopyJobMigrationType.Offline, shouldShowDialog }, index) => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
|
||||||
|
const job = createMockJob({ Status: status, Mode: mode, Name: `DialogTestJob${index}` });
|
||||||
|
const { unmount } = render(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
||||||
|
|
||||||
|
const actionButton = screen.getByRole("button", { name: "Actions" });
|
||||||
|
fireEvent.click(actionButton);
|
||||||
|
|
||||||
|
const actionText = action.charAt(0).toUpperCase() + action.slice(1);
|
||||||
|
if (screen.queryByText(actionText)) {
|
||||||
|
fireEvent.click(screen.getByText(actionText));
|
||||||
|
|
||||||
|
if (shouldShowDialog) {
|
||||||
|
expect(mockShowOkCancelModalDialog).toHaveBeenCalled();
|
||||||
|
} else {
|
||||||
|
expect(mockShowOkCancelModalDialog).not.toHaveBeenCalled();
|
||||||
|
expect(mockHandleClick).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should verify component handles state updates correctly", () => {
|
||||||
|
const job = createMockJob({ Status: CopyJobStatusType.InProgress });
|
||||||
|
const stateUpdater = jest.fn();
|
||||||
|
|
||||||
|
const testHandleClick: HandleJobActionClickType = (job, action, setUpdatingJobAction) => {
|
||||||
|
setUpdatingJobAction({ jobName: job.Name, action });
|
||||||
|
stateUpdater(job.Name, action);
|
||||||
|
};
|
||||||
|
|
||||||
|
render(<CopyJobActionMenu job={job} handleClick={testHandleClick} />);
|
||||||
|
|
||||||
|
const actionButton = screen.getByRole("button", { name: "Actions" });
|
||||||
|
fireEvent.click(actionButton);
|
||||||
|
|
||||||
|
const pauseButton = screen.getByText("Pause");
|
||||||
|
fireEvent.click(pauseButton);
|
||||||
|
|
||||||
|
expect(stateUpdater).toHaveBeenCalledWith(job.Name, CopyJobActions.pause);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Full Integration Coverage", () => {
|
||||||
|
it("should test complete workflow for cancel action with dialog", () => {
|
||||||
|
const job = createMockJob({ Name: "Integration Test Job", Status: CopyJobStatusType.InProgress });
|
||||||
|
render(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
||||||
|
|
||||||
|
const actionButton = screen.getByRole("button", { name: "Actions" });
|
||||||
|
expect(actionButton).toHaveAttribute("data-test", "CopyJobActionMenu/Button:Integration Test Job");
|
||||||
|
fireEvent.click(actionButton);
|
||||||
|
|
||||||
|
const cancelButton = screen.getByText("Cancel");
|
||||||
|
fireEvent.click(cancelButton);
|
||||||
|
|
||||||
|
expect(mockShowOkCancelModalDialog).toHaveBeenCalledWith(
|
||||||
|
"Confirm Action", // title
|
||||||
|
null, // subText
|
||||||
|
"Confirm", // confirmLabel
|
||||||
|
expect.any(Function), // onOk
|
||||||
|
"Cancel", // cancelLabel
|
||||||
|
null, // onCancel
|
||||||
|
expect.any(Object), // contentHtml (dialogBody)
|
||||||
|
);
|
||||||
|
|
||||||
|
const onOkCallback = mockShowOkCancelModalDialog.mock.calls[0][3];
|
||||||
|
onOkCallback();
|
||||||
|
|
||||||
|
expect(mockHandleClick).toHaveBeenCalledWith(job, CopyJobActions.cancel, expect.any(Function));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should test complete workflow for complete action with dialog", () => {
|
||||||
|
const job = createMockJob({
|
||||||
|
Name: "Online Integration Job",
|
||||||
|
Status: CopyJobStatusType.Running,
|
||||||
|
Mode: CopyJobMigrationType.Online,
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
||||||
|
|
||||||
|
const actionButton = screen.getByRole("button", { name: "Actions" });
|
||||||
|
fireEvent.click(actionButton);
|
||||||
|
|
||||||
|
const completeButton = screen.getByText("Complete");
|
||||||
|
fireEvent.click(completeButton);
|
||||||
|
|
||||||
|
expect(mockShowOkCancelModalDialog).toHaveBeenCalled();
|
||||||
|
|
||||||
|
const dialogContent = mockShowOkCancelModalDialog.mock.calls[0][6];
|
||||||
|
expect(dialogContent).toBeTruthy();
|
||||||
|
|
||||||
|
const onOkCallback = mockShowOkCancelModalDialog.mock.calls[0][3];
|
||||||
|
onOkCallback();
|
||||||
|
|
||||||
|
expect(mockHandleClick).toHaveBeenCalledWith(job, CopyJobActions.complete, expect.any(Function));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should maintain proper component lifecycle", () => {
|
||||||
|
const job = createMockJob({ Status: CopyJobStatusType.InProgress });
|
||||||
|
const { rerender, unmount } = render(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
||||||
|
|
||||||
|
rerender(<CopyJobActionMenu job={job} handleClick={mockHandleClick} />);
|
||||||
|
expect(screen.getByRole("button", { name: "Actions" })).toBeInTheDocument();
|
||||||
|
|
||||||
|
expect(() => unmount()).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { IconButton, IContextualMenuProps } from "@fluentui/react";
|
import { DirectionalHint, IconButton, IContextualMenuProps, Stack } from "@fluentui/react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { useDialog } from "../../../Controls/Dialog";
|
||||||
import ContainerCopyMessages from "../../ContainerCopyMessages";
|
import ContainerCopyMessages from "../../ContainerCopyMessages";
|
||||||
import { CopyJobActions, CopyJobMigrationType, CopyJobStatusType } from "../../Enums/CopyJobEnums";
|
import { CopyJobActions, CopyJobMigrationType, CopyJobStatusType } from "../../Enums/CopyJobEnums";
|
||||||
import { CopyJobType, HandleJobActionClickType } from "../../Types/CopyJobTypes";
|
import { CopyJobType, HandleJobActionClickType } from "../../Types/CopyJobTypes";
|
||||||
@@ -9,6 +10,28 @@ interface CopyJobActionMenuProps {
|
|||||||
handleClick: HandleJobActionClickType;
|
handleClick: HandleJobActionClickType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dialogBody = {
|
||||||
|
[CopyJobActions.cancel]: (jobName: string) => (
|
||||||
|
<Stack tokens={{ childrenGap: 10 }}>
|
||||||
|
<Stack.Item>
|
||||||
|
You are about to cancel <b>{jobName}</b> copy job.
|
||||||
|
</Stack.Item>
|
||||||
|
<Stack.Item>Cancelling will stop the job immediately.</Stack.Item>
|
||||||
|
</Stack>
|
||||||
|
),
|
||||||
|
[CopyJobActions.complete]: (jobName: string) => (
|
||||||
|
<Stack tokens={{ childrenGap: 10 }}>
|
||||||
|
<Stack.Item>
|
||||||
|
You are about to complete <b>{jobName}</b> copy job.
|
||||||
|
</Stack.Item>
|
||||||
|
<Stack.Item>
|
||||||
|
Once completed, continuous data copy will stop after any pending documents are processed. To maintain data
|
||||||
|
integrity, we recommend stopping updates to the source container before completing the job.
|
||||||
|
</Stack.Item>
|
||||||
|
</Stack>
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
const CopyJobActionMenu: React.FC<CopyJobActionMenuProps> = ({ job, handleClick }) => {
|
const CopyJobActionMenu: React.FC<CopyJobActionMenuProps> = ({ job, handleClick }) => {
|
||||||
const [updatingJobAction, setUpdatingJobAction] = React.useState<{ jobName: string; action: string } | null>(null);
|
const [updatingJobAction, setUpdatingJobAction] = React.useState<{ jobName: string; action: string } | null>(null);
|
||||||
if (
|
if (
|
||||||
@@ -22,9 +45,22 @@ const CopyJobActionMenu: React.FC<CopyJobActionMenuProps> = ({ job, handleClick
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const showActionConfirmationDialog = (job: CopyJobType, action: CopyJobActions): void => {
|
||||||
|
useDialog
|
||||||
|
.getState()
|
||||||
|
.showOkCancelModalDialog(
|
||||||
|
ContainerCopyMessages.MonitorJobs.dialog.heading,
|
||||||
|
null,
|
||||||
|
ContainerCopyMessages.MonitorJobs.dialog.confirmButtonText,
|
||||||
|
() => handleClick(job, action, setUpdatingJobAction),
|
||||||
|
ContainerCopyMessages.MonitorJobs.dialog.cancelButtonText,
|
||||||
|
null,
|
||||||
|
action in dialogBody ? dialogBody[action as keyof typeof dialogBody](job.Name) : null,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const getMenuItems = (): IContextualMenuProps["items"] => {
|
const getMenuItems = (): IContextualMenuProps["items"] => {
|
||||||
const isThisJobUpdating = updatingJobAction?.jobName === job.Name;
|
const isThisJobUpdating = updatingJobAction?.jobName === job.Name;
|
||||||
const updatingAction = updatingJobAction?.action;
|
|
||||||
|
|
||||||
const baseItems = [
|
const baseItems = [
|
||||||
{
|
{
|
||||||
@@ -32,21 +68,21 @@ const CopyJobActionMenu: React.FC<CopyJobActionMenuProps> = ({ job, handleClick
|
|||||||
text: ContainerCopyMessages.MonitorJobs.Actions.pause,
|
text: ContainerCopyMessages.MonitorJobs.Actions.pause,
|
||||||
iconProps: { iconName: "Pause" },
|
iconProps: { iconName: "Pause" },
|
||||||
onClick: () => handleClick(job, CopyJobActions.pause, setUpdatingJobAction),
|
onClick: () => handleClick(job, CopyJobActions.pause, setUpdatingJobAction),
|
||||||
disabled: isThisJobUpdating && updatingAction === CopyJobActions.pause,
|
disabled: isThisJobUpdating,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: CopyJobActions.cancel,
|
key: CopyJobActions.cancel,
|
||||||
text: ContainerCopyMessages.MonitorJobs.Actions.cancel,
|
text: ContainerCopyMessages.MonitorJobs.Actions.cancel,
|
||||||
iconProps: { iconName: "Cancel" },
|
iconProps: { iconName: "Cancel" },
|
||||||
onClick: () => handleClick(job, CopyJobActions.cancel, setUpdatingJobAction),
|
onClick: () => showActionConfirmationDialog(job, CopyJobActions.cancel),
|
||||||
disabled: isThisJobUpdating && updatingAction === CopyJobActions.cancel,
|
disabled: isThisJobUpdating,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: CopyJobActions.resume,
|
key: CopyJobActions.resume,
|
||||||
text: ContainerCopyMessages.MonitorJobs.Actions.resume,
|
text: ContainerCopyMessages.MonitorJobs.Actions.resume,
|
||||||
iconProps: { iconName: "Play" },
|
iconProps: { iconName: "Play" },
|
||||||
onClick: () => handleClick(job, CopyJobActions.resume, setUpdatingJobAction),
|
onClick: () => handleClick(job, CopyJobActions.resume, setUpdatingJobAction),
|
||||||
disabled: isThisJobUpdating && updatingAction === CopyJobActions.resume,
|
disabled: isThisJobUpdating,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -67,8 +103,8 @@ const CopyJobActionMenu: React.FC<CopyJobActionMenuProps> = ({ job, handleClick
|
|||||||
key: CopyJobActions.complete,
|
key: CopyJobActions.complete,
|
||||||
text: ContainerCopyMessages.MonitorJobs.Actions.complete,
|
text: ContainerCopyMessages.MonitorJobs.Actions.complete,
|
||||||
iconProps: { iconName: "CheckMark" },
|
iconProps: { iconName: "CheckMark" },
|
||||||
onClick: () => handleClick(job, CopyJobActions.complete, setUpdatingJobAction),
|
onClick: () => showActionConfirmationDialog(job, CopyJobActions.complete),
|
||||||
disabled: isThisJobUpdating && updatingAction === CopyJobActions.complete,
|
disabled: isThisJobUpdating,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return filteredItems;
|
return filteredItems;
|
||||||
@@ -86,8 +122,8 @@ const CopyJobActionMenu: React.FC<CopyJobActionMenuProps> = ({ job, handleClick
|
|||||||
data-test={`CopyJobActionMenu/Button:${job.Name}`}
|
data-test={`CopyJobActionMenu/Button:${job.Name}`}
|
||||||
role="button"
|
role="button"
|
||||||
iconProps={{ iconName: "More", styles: { root: { fontSize: "20px", fontWeight: "bold" } } }}
|
iconProps={{ iconName: "More", styles: { root: { fontSize: "20px", fontWeight: "bold" } } }}
|
||||||
menuProps={{ items: getMenuItems() }}
|
menuProps={{ items: getMenuItems(), directionalHint: DirectionalHint.leftTopEdge, directionalHintFixed: false }}
|
||||||
menuIconProps={{ iconName: "" }}
|
menuIconProps={{ iconName: "", className: "hidden" }}
|
||||||
ariaLabel={ContainerCopyMessages.MonitorJobs.Columns.actions}
|
ariaLabel={ContainerCopyMessages.MonitorJobs.Columns.actions}
|
||||||
title={ContainerCopyMessages.MonitorJobs.Columns.actions}
|
title={ContainerCopyMessages.MonitorJobs.Columns.actions}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -11,9 +11,17 @@ jest.mock("../../Actions/CopyJobActions", () => ({
|
|||||||
|
|
||||||
jest.mock("./CopyJobColumns", () => ({
|
jest.mock("./CopyJobColumns", () => ({
|
||||||
getColumns: jest.fn(() => [
|
getColumns: jest.fn(() => [
|
||||||
|
{
|
||||||
|
key: "LastUpdatedTime",
|
||||||
|
name: "Date & time",
|
||||||
|
fieldName: "LastUpdatedTime",
|
||||||
|
minWidth: 140,
|
||||||
|
maxWidth: 300,
|
||||||
|
isResizable: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: "Name",
|
key: "Name",
|
||||||
name: "Name",
|
name: "Job name",
|
||||||
fieldName: "Name",
|
fieldName: "Name",
|
||||||
minWidth: 140,
|
minWidth: 140,
|
||||||
maxWidth: 300,
|
maxWidth: 300,
|
||||||
@@ -165,6 +173,165 @@ describe("CopyJobsList", () => {
|
|||||||
expect(screen.getByTestId("action-menu-job-2")).toBeInTheDocument();
|
expect(screen.getByTestId("action-menu-job-2")).toBeInTheDocument();
|
||||||
expect(screen.getByTestId("action-menu-job-3")).toBeInTheDocument();
|
expect(screen.getByTestId("action-menu-job-3")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("renders filter TextField with data-test attribute", () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterTextField = document.querySelector('[data-test="CopyJobsList/FilterTextField"]');
|
||||||
|
expect(filterTextField).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders search TextField with correct placeholder", () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const searchInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
expect(searchInput).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Filtering", () => {
|
||||||
|
it("filters jobs by Name when text is entered", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Job 1" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 2")).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 3")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters jobs case-insensitively", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "test job 1" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 2")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows all jobs when filter text is empty", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Job 1" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.queryByText("Test Job 2")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
fireEvent.change(filterInput, { target: { value: "" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Test Job 2")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Test Job 3")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters jobs by Status across all columns", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: CopyJobStatusType.Running } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 2")).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 3")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters jobs by Mode across all columns", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Offline" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.queryByText("Test Job 1")).not.toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Test Job 2")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 3")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows no results when filter matches no jobs", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "NonExistentJob" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.queryByText("Test Job 1")).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 2")).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 3")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters by partial text match", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Test" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Test Job 2")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Test Job 3")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("resets pagination when filter changes", async () => {
|
||||||
|
const manyJobs: CopyJobType[] = Array.from({ length: 25 }, (_, i) => ({
|
||||||
|
...mockJobs[0],
|
||||||
|
ID: `job-${i + 1}`,
|
||||||
|
Name: `Test Job ${i + 1}`,
|
||||||
|
}));
|
||||||
|
|
||||||
|
render(<CopyJobsList jobs={manyJobs} handleActionClick={mockHandleActionClick} pageSize={10} />);
|
||||||
|
|
||||||
|
// Navigate to page 2
|
||||||
|
fireEvent.click(screen.getByLabelText("Go to next page"));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Showing 11 - 20 of 25 items")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Apply filter - should reset to page 1
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Job 1" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
// Filtered results show from the beginning
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("updates filtered count in pager", async () => {
|
||||||
|
const manyJobs: CopyJobType[] = Array.from({ length: 25 }, (_, i) => ({
|
||||||
|
...mockJobs[0],
|
||||||
|
ID: `job-${i + 1}`,
|
||||||
|
Name: i < 5 ? `Alpha Job ${i + 1}` : `Beta Job ${i + 1}`,
|
||||||
|
}));
|
||||||
|
|
||||||
|
render(<CopyJobsList jobs={manyJobs} handleActionClick={mockHandleActionClick} pageSize={10} />);
|
||||||
|
|
||||||
|
expect(screen.getByText("Showing 1 - 10 of 25 items")).toBeInTheDocument();
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Alpha" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.queryByText("Showing 1 - 10 of 25 items")).not.toBeInTheDocument();
|
||||||
|
// Pager should not be visible since filtered results (5) are less than page size (10)
|
||||||
|
expect(screen.queryByLabelText("Go to next page")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Pagination", () => {
|
describe("Pagination", () => {
|
||||||
@@ -342,7 +509,7 @@ describe("CopyJobsList", () => {
|
|||||||
|
|
||||||
describe("Component Props", () => {
|
describe("Component Props", () => {
|
||||||
it("uses default page size when not provided", () => {
|
it("uses default page size when not provided", () => {
|
||||||
const manyJobs: CopyJobType[] = Array.from({ length: 12 }, (_, i) => ({
|
const manyJobs: CopyJobType[] = Array.from({ length: 20 }, (_, i) => ({
|
||||||
...mockJobs[0],
|
...mockJobs[0],
|
||||||
ID: `job-${i + 1}`,
|
ID: `job-${i + 1}`,
|
||||||
Name: `Test Job ${i + 1}`,
|
Name: `Test Job ${i + 1}`,
|
||||||
@@ -351,7 +518,7 @@ describe("CopyJobsList", () => {
|
|||||||
render(<CopyJobsList jobs={manyJobs} handleActionClick={mockHandleActionClick} />);
|
render(<CopyJobsList jobs={manyJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
expect(screen.getByLabelText("Go to next page")).toBeInTheDocument();
|
expect(screen.getByLabelText("Go to next page")).toBeInTheDocument();
|
||||||
expect(screen.getByText("Showing 1 - 10 of 12 items")).toBeInTheDocument();
|
expect(screen.getByText("Showing 1 - 15 of 20 items")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes correct props to getColumns function", async () => {
|
it("passes correct props to getColumns function", async () => {
|
||||||
@@ -440,7 +607,33 @@ describe("CopyJobsList", () => {
|
|||||||
render(<CopyJobsList jobs={largeJobsList} handleActionClick={mockHandleActionClick} />);
|
render(<CopyJobsList jobs={largeJobsList} handleActionClick={mockHandleActionClick} />);
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
|
|
||||||
expect(screen.getByText("Showing 1 - 10 of 1000 items")).toBeInTheDocument();
|
expect(screen.getByText("Showing 1 - 15 of 1000 items")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles filtering with null or undefined values gracefully", async () => {
|
||||||
|
const jobsWithNullValues: CopyJobType[] = [
|
||||||
|
{
|
||||||
|
...mockJobs[0],
|
||||||
|
ID: "job-with-values",
|
||||||
|
Name: "Valid Job",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...mockJobs[1],
|
||||||
|
ID: "job-null-name",
|
||||||
|
Name: undefined as unknown as string,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
render(<CopyJobsList jobs={jobsWithNullValues} handleActionClick={mockHandleActionClick} />);
|
||||||
|
}).not.toThrow();
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Valid" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Valid Job")).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ import {
|
|||||||
Stack,
|
Stack,
|
||||||
Sticky,
|
Sticky,
|
||||||
StickyPositionType,
|
StickyPositionType,
|
||||||
|
TextField,
|
||||||
} from "@fluentui/react";
|
} from "@fluentui/react";
|
||||||
import React, { useEffect } from "react";
|
import React, { useEffect, useMemo } from "react";
|
||||||
import Pager from "../../../../Common/Pager";
|
import Pager from "../../../../Common/Pager";
|
||||||
import { useThemeStore } from "../../../../hooks/useTheme";
|
import { useThemeStore } from "../../../../hooks/useTheme";
|
||||||
import { getThemeTokens } from "../../../Theme/ThemeUtil";
|
import { getThemeTokens } from "../../../Theme/ThemeUtil";
|
||||||
@@ -30,9 +31,15 @@ interface CopyJobsListProps {
|
|||||||
const styles = {
|
const styles = {
|
||||||
container: { height: "100%" } as React.CSSProperties,
|
container: { height: "100%" } as React.CSSProperties,
|
||||||
stackItem: { position: "relative", marginBottom: "20px" } as React.CSSProperties,
|
stackItem: { position: "relative", marginBottom: "20px" } as React.CSSProperties,
|
||||||
|
filterContainer: {
|
||||||
|
margin: "15px 5px",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const PAGE_SIZE = 10;
|
const PAGE_SIZE = 15;
|
||||||
|
|
||||||
|
// Columns to search across
|
||||||
|
const searchableFields = ["Name", "Status", "LastUpdatedTime", "Mode"];
|
||||||
|
|
||||||
const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pageSize = PAGE_SIZE }) => {
|
const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pageSize = PAGE_SIZE }) => {
|
||||||
const isDarkMode = useThemeStore((state) => state.isDarkMode);
|
const isDarkMode = useThemeStore((state) => state.isDarkMode);
|
||||||
@@ -41,6 +48,23 @@ const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pa
|
|||||||
const [sortedJobs, setSortedJobs] = React.useState<CopyJobType[]>(jobs);
|
const [sortedJobs, setSortedJobs] = React.useState<CopyJobType[]>(jobs);
|
||||||
const [sortedColumnKey, setSortedColumnKey] = React.useState<string | undefined>(undefined);
|
const [sortedColumnKey, setSortedColumnKey] = React.useState<string | undefined>(undefined);
|
||||||
const [isSortedDescending, setIsSortedDescending] = React.useState<boolean>(false);
|
const [isSortedDescending, setIsSortedDescending] = React.useState<boolean>(false);
|
||||||
|
const [filterText, setFilterText] = React.useState<string>("");
|
||||||
|
|
||||||
|
const filteredJobs = useMemo(() => {
|
||||||
|
if (!filterText) {
|
||||||
|
return sortedJobs;
|
||||||
|
}
|
||||||
|
const lowerFilterText = filterText.toLowerCase();
|
||||||
|
return sortedJobs.filter((job: any) => {
|
||||||
|
return searchableFields.some((field) => {
|
||||||
|
const value = job[field];
|
||||||
|
if (value === undefined || value === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return String(value).toLowerCase().includes(lowerFilterText);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, [sortedJobs, filterText]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSortedJobs(jobs);
|
setSortedJobs(jobs);
|
||||||
@@ -64,7 +88,15 @@ const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pa
|
|||||||
setStartIndex(0);
|
setStartIndex(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
const columns: IColumn[] = getColumns(handleSort, handleActionClick, sortedColumnKey, isSortedDescending);
|
const sortableColumns: IColumn[] = getColumns(handleSort, handleActionClick, sortedColumnKey, isSortedDescending);
|
||||||
|
|
||||||
|
const handleFilterTextChange = (
|
||||||
|
_event: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>,
|
||||||
|
newValue?: string,
|
||||||
|
) => {
|
||||||
|
setFilterText(newValue || "");
|
||||||
|
setStartIndex(0);
|
||||||
|
};
|
||||||
|
|
||||||
const _handleRowClick = (job: CopyJobType) => {
|
const _handleRowClick = (job: CopyJobType) => {
|
||||||
openCopyJobDetailsPanel(job);
|
openCopyJobDetailsPanel(job);
|
||||||
@@ -81,14 +113,25 @@ const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pa
|
|||||||
return (
|
return (
|
||||||
<div style={styles.container}>
|
<div style={styles.container}>
|
||||||
<Stack verticalFill={true}>
|
<Stack verticalFill={true}>
|
||||||
|
<Stack.Item>
|
||||||
|
<div style={styles.filterContainer}>
|
||||||
|
<TextField
|
||||||
|
data-test="CopyJobsList/FilterTextField"
|
||||||
|
placeholder="Search jobs..."
|
||||||
|
ariaLabel="Search jobs"
|
||||||
|
value={filterText}
|
||||||
|
onChange={handleFilterTextChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Stack.Item>
|
||||||
<Stack.Item verticalFill={true} grow={1} shrink={1} style={styles.stackItem}>
|
<Stack.Item verticalFill={true} grow={1} shrink={1} style={styles.stackItem}>
|
||||||
<ScrollablePane scrollbarVisibility={ScrollbarVisibility.auto}>
|
<ScrollablePane scrollbarVisibility={ScrollbarVisibility.auto}>
|
||||||
<ShimmeredDetailsList
|
<ShimmeredDetailsList
|
||||||
className="CopyJobListContainer"
|
className="CopyJobListContainer"
|
||||||
onRenderRow={_onRenderRow}
|
onRenderRow={_onRenderRow}
|
||||||
checkboxVisibility={2}
|
checkboxVisibility={2}
|
||||||
columns={columns}
|
columns={sortableColumns}
|
||||||
items={sortedJobs.slice(startIndex, startIndex + pageSize)}
|
items={filteredJobs.slice(startIndex, startIndex + pageSize)}
|
||||||
enableShimmer={false}
|
enableShimmer={false}
|
||||||
constrainMode={ConstrainMode.unconstrained}
|
constrainMode={ConstrainMode.unconstrained}
|
||||||
layoutMode={DetailsListLayoutMode.justified}
|
layoutMode={DetailsListLayoutMode.justified}
|
||||||
@@ -117,12 +160,12 @@ const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pa
|
|||||||
/>
|
/>
|
||||||
</ScrollablePane>
|
</ScrollablePane>
|
||||||
</Stack.Item>
|
</Stack.Item>
|
||||||
{sortedJobs.length > pageSize && (
|
{filteredJobs.length > pageSize && (
|
||||||
<Stack.Item>
|
<Stack.Item>
|
||||||
<Pager
|
<Pager
|
||||||
disabled={false}
|
disabled={false}
|
||||||
startIndex={startIndex}
|
startIndex={startIndex}
|
||||||
totalCount={sortedJobs.length}
|
totalCount={filteredJobs.length}
|
||||||
pageSize={pageSize}
|
pageSize={pageSize}
|
||||||
onLoadPage={(startIdx /* pageSize */) => {
|
onLoadPage={(startIdx /* pageSize */) => {
|
||||||
setStartIndex(startIdx);
|
setStartIndex(startIdx);
|
||||||
|
|||||||
@@ -1,5 +1,27 @@
|
|||||||
@import "../../../less/Common/Constants.less";
|
@import "../../../less/Common/Constants.less";
|
||||||
|
|
||||||
|
.themedTextFieldStyles() {
|
||||||
|
.ms-TextField {
|
||||||
|
.ms-TextField-fieldGroup {
|
||||||
|
background-color: var(--colorNeutralBackground1);
|
||||||
|
border-color: var(--colorNeutralStroke1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ms-TextField-field {
|
||||||
|
color: var(--colorNeutralForeground1);
|
||||||
|
background-color: var(--colorNeutralBackground1);
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: var(--colorNeutralForeground4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ms-Label {
|
||||||
|
color: var(--colorNeutralForeground1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Common theme-aware classes
|
// Common theme-aware classes
|
||||||
.themeText {
|
.themeText {
|
||||||
color: var(--colorNeutralForeground1);
|
color: var(--colorNeutralForeground1);
|
||||||
@@ -119,25 +141,8 @@
|
|||||||
filter: invert(1);
|
filter: invert(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.ms-TextField {
|
.themedTextFieldStyles();
|
||||||
.ms-TextField-fieldGroup {
|
|
||||||
background-color: var(--colorNeutralBackground1);
|
|
||||||
border-color: var(--colorNeutralStroke1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.ms-TextField-field {
|
|
||||||
color: var(--colorNeutralForeground1);
|
|
||||||
background-color: var(--colorNeutralBackground1);
|
|
||||||
|
|
||||||
&::placeholder {
|
|
||||||
color: var(--colorNeutralForeground4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.ms-Label {
|
|
||||||
color: var(--colorNeutralForeground1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.migrationTypeDescription {
|
.migrationTypeDescription {
|
||||||
p {
|
p {
|
||||||
color: var(--colorNeutralForeground1);
|
color: var(--colorNeutralForeground1);
|
||||||
@@ -173,6 +178,11 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|
||||||
|
body.isDarkMode & {
|
||||||
|
.themedTextFieldStyles();
|
||||||
|
}
|
||||||
|
|
||||||
.ms-DetailsList {
|
.ms-DetailsList {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
AddGlobalSecondaryIndexPanelProps,
|
AddGlobalSecondaryIndexPanelProps,
|
||||||
} from "Explorer/Panes/AddGlobalSecondaryIndexPanel/AddGlobalSecondaryIndexPanel";
|
} from "Explorer/Panes/AddGlobalSecondaryIndexPanel/AddGlobalSecondaryIndexPanel";
|
||||||
import { useDatabases } from "Explorer/useDatabases";
|
import { useDatabases } from "Explorer/useDatabases";
|
||||||
import { isFabric, isFabricNative } from "Platform/Fabric/FabricUtil";
|
import { isFabric, isFabricNative, openRestoreContainerDialog } from "Platform/Fabric/FabricUtil";
|
||||||
import { Action } from "Shared/Telemetry/TelemetryConstants";
|
import { Action } from "Shared/Telemetry/TelemetryConstants";
|
||||||
import { traceOpen } from "Shared/Telemetry/TelemetryProcessor";
|
import { traceOpen } from "Shared/Telemetry/TelemetryProcessor";
|
||||||
import { ReactTabKind, useTabs } from "hooks/useTabs";
|
import { ReactTabKind, useTabs } from "hooks/useTabs";
|
||||||
@@ -35,6 +35,7 @@ import StoredProcedure from "./Tree/StoredProcedure";
|
|||||||
import Trigger from "./Tree/Trigger";
|
import Trigger from "./Tree/Trigger";
|
||||||
import UserDefinedFunction from "./Tree/UserDefinedFunction";
|
import UserDefinedFunction from "./Tree/UserDefinedFunction";
|
||||||
import { useSelectedNode } from "./useSelectedNode";
|
import { useSelectedNode } from "./useSelectedNode";
|
||||||
|
import { extractFeatures } from "../Platform/Hosted/extractFeatures";
|
||||||
|
|
||||||
export interface CollectionContextMenuButtonParams {
|
export interface CollectionContextMenuButtonParams {
|
||||||
databaseId: string;
|
databaseId: string;
|
||||||
@@ -60,6 +61,17 @@ export const createDatabaseContextMenu = (container: Explorer, databaseId: strin
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (isFabricNative() && !userContext.fabricContext?.isReadOnly) {
|
||||||
|
const features = extractFeatures();
|
||||||
|
if (features?.enableRestoreContainer) {
|
||||||
|
items.push({
|
||||||
|
iconSrc: AddCollectionIcon,
|
||||||
|
onClick: () => openRestoreContainerDialog(),
|
||||||
|
label: `Restore ${getCollectionName()}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!isFabricNative() && (userContext.apiType !== "Tables" || userContext.features.enableSDKoperations)) {
|
if (!isFabricNative() && (userContext.apiType !== "Tables" || userContext.features.enableSDKoperations)) {
|
||||||
items.push({
|
items.push({
|
||||||
iconSrc: DeleteDatabaseIcon,
|
iconSrc: DeleteDatabaseIcon,
|
||||||
|
|||||||
@@ -54,6 +54,6 @@
|
|||||||
.mainButtonsContainer {
|
.mainButtonsContainer {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0 16px;
|
gap: 0 16px;
|
||||||
margin-bottom: 10px
|
margin: 40px auto
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,6 +164,23 @@ export const SplashScreen: React.FC<SplashScreenProps> = ({ explorer }) => {
|
|||||||
const container = explorer;
|
const container = explorer;
|
||||||
const subscriptions: Array<{ dispose: () => void }> = [];
|
const subscriptions: Array<{ dispose: () => void }> = [];
|
||||||
|
|
||||||
|
let title: string;
|
||||||
|
let subtitle: string;
|
||||||
|
|
||||||
|
switch (userContext.apiType) {
|
||||||
|
case "Postgres":
|
||||||
|
title = "Welcome to Azure Cosmos DB for PostgreSQL";
|
||||||
|
subtitle = "Get started with our sample datasets, documentation, and additional tools.";
|
||||||
|
break;
|
||||||
|
case "VCoreMongo":
|
||||||
|
title = "Welcome to Azure DocumentDB (with MongoDB compatibility)";
|
||||||
|
subtitle = "Get started with our sample datasets, documentation, and additional tools.";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
title = "Welcome to Azure Cosmos DB";
|
||||||
|
subtitle = "Globally distributed, multi-model database service for any scale";
|
||||||
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
{
|
{
|
||||||
@@ -902,10 +919,11 @@ export const SplashScreen: React.FC<SplashScreenProps> = ({ explorer }) => {
|
|||||||
return (
|
return (
|
||||||
<div className={styles.splashScreenContainer}>
|
<div className={styles.splashScreenContainer}>
|
||||||
<div className={styles.splashScreen}>
|
<div className={styles.splashScreen}>
|
||||||
<h2 className={styles.title} role="heading" aria-label="Welcome to Azure Cosmos DB">
|
<h2 className={styles.title} role="heading" aria-label={title}>
|
||||||
Welcome to Azure Cosmos DB<span className="activePatch"></span>
|
{title}
|
||||||
|
<span className="activePatch"></span>
|
||||||
</h2>
|
</h2>
|
||||||
<div className={styles.subtitle}>Globally distributed, multi-model database service for any scale</div>
|
<div className={styles.subtitle}>{subtitle}</div>
|
||||||
{getSplashScreenButtons()}
|
{getSplashScreenButtons()}
|
||||||
{useCarousel.getState().showCoachMark && (
|
{useCarousel.getState().showCoachMark && (
|
||||||
<Coachmark
|
<Coachmark
|
||||||
|
|||||||
@@ -105,9 +105,12 @@ const App = (): JSX.Element => {
|
|||||||
// Scenario-based health tracking: start ApplicationLoad and complete phases.
|
// Scenario-based health tracking: start ApplicationLoad and complete phases.
|
||||||
const { startScenario, completePhase } = useMetricScenario();
|
const { startScenario, completePhase } = useMetricScenario();
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
// Only start scenario after config is initialized to avoid race conditions
|
||||||
|
// with message handlers that depend on configContext.platform
|
||||||
|
if (config) {
|
||||||
startScenario(MetricScenario.ApplicationLoad);
|
startScenario(MetricScenario.ApplicationLoad);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
}
|
||||||
}, []);
|
}, [config, startScenario]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (explorer) {
|
if (explorer) {
|
||||||
@@ -128,6 +131,7 @@ const App = (): JSX.Element => {
|
|||||||
<>
|
<>
|
||||||
<ContainerCopyPanel explorer={explorer} />
|
<ContainerCopyPanel explorer={explorer} />
|
||||||
<SidePanel />
|
<SidePanel />
|
||||||
|
<Dialog />
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<DivExplorer explorer={explorer} />
|
<DivExplorer explorer={explorer} />
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
import { initializeIcons } from "@fluentui/react";
|
|
||||||
import "bootstrap/dist/css/bootstrap.css";
|
|
||||||
import React from "react";
|
|
||||||
import * as ReactDOM from "react-dom";
|
|
||||||
import { configContext, initializeConfiguration } from "../ConfigContext";
|
|
||||||
import { GalleryHeaderComponent } from "../Explorer/Controls/Header/GalleryHeaderComponent";
|
|
||||||
import { GalleryTab } from "../Explorer/Controls/NotebookGallery/GalleryViewerComponent";
|
|
||||||
import {
|
|
||||||
NotebookViewerComponent,
|
|
||||||
NotebookViewerComponentProps,
|
|
||||||
} from "../Explorer/Controls/NotebookViewer/NotebookViewerComponent";
|
|
||||||
import * as FileSystemUtil from "../Explorer/Notebook/FileSystemUtil";
|
|
||||||
import { IGalleryItem, JunoClient } from "../Juno/JunoClient";
|
|
||||||
import * as GalleryUtils from "../Utils/GalleryUtils";
|
|
||||||
|
|
||||||
const onInit = async () => {
|
|
||||||
initializeIcons();
|
|
||||||
await initializeConfiguration();
|
|
||||||
const galleryViewerProps = GalleryUtils.getGalleryViewerProps(window.location.search);
|
|
||||||
const notebookViewerProps = GalleryUtils.getNotebookViewerProps(window.location.search);
|
|
||||||
let backNavigationText: string;
|
|
||||||
let onBackClick: () => void;
|
|
||||||
if (galleryViewerProps.selectedTab !== undefined) {
|
|
||||||
backNavigationText = GalleryUtils.getTabTitle(galleryViewerProps.selectedTab);
|
|
||||||
onBackClick = () =>
|
|
||||||
(window.location.href = `${configContext.hostedExplorerURL}gallery.html?tab=${
|
|
||||||
GalleryTab[galleryViewerProps.selectedTab]
|
|
||||||
}`);
|
|
||||||
}
|
|
||||||
const hideInputs = notebookViewerProps.hideInputs;
|
|
||||||
|
|
||||||
const notebookUrl = decodeURIComponent(notebookViewerProps.notebookUrl);
|
|
||||||
|
|
||||||
const galleryItemId = notebookViewerProps.galleryItemId;
|
|
||||||
let galleryItem: IGalleryItem;
|
|
||||||
|
|
||||||
if (galleryItemId) {
|
|
||||||
const junoClient = new JunoClient();
|
|
||||||
const galleryItemJunoResponse = await junoClient.getNotebookInfo(galleryItemId);
|
|
||||||
galleryItem = galleryItemJunoResponse.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The main purpose of hiding the prompt is to hide everything when hiding inputs.
|
|
||||||
// It is generally not very useful to just hide the prompt.
|
|
||||||
const hidePrompts = hideInputs;
|
|
||||||
|
|
||||||
render(notebookUrl, backNavigationText, hideInputs, hidePrompts, galleryItem, onBackClick);
|
|
||||||
};
|
|
||||||
|
|
||||||
const render = (
|
|
||||||
notebookUrl: string,
|
|
||||||
backNavigationText: string,
|
|
||||||
hideInputs?: boolean,
|
|
||||||
hidePrompts?: boolean,
|
|
||||||
galleryItem?: IGalleryItem,
|
|
||||||
onBackClick?: () => void,
|
|
||||||
) => {
|
|
||||||
const props: NotebookViewerComponentProps = {
|
|
||||||
junoClient: galleryItem ? new JunoClient() : undefined,
|
|
||||||
notebookUrl,
|
|
||||||
galleryItem,
|
|
||||||
backNavigationText,
|
|
||||||
hideInputs,
|
|
||||||
hidePrompts,
|
|
||||||
onBackClick: onBackClick,
|
|
||||||
onTagClick: undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (galleryItem) {
|
|
||||||
document.title = FileSystemUtil.stripExtension(galleryItem.name, "ipynb");
|
|
||||||
}
|
|
||||||
|
|
||||||
const element = (
|
|
||||||
<>
|
|
||||||
<header>
|
|
||||||
<GalleryHeaderComponent />
|
|
||||||
</header>
|
|
||||||
<div style={{ marginLeft: 120, marginRight: 120 }}>
|
|
||||||
<NotebookViewerComponent {...props} />
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
ReactDOM.render(element, document.getElementById("notebookContent"));
|
|
||||||
};
|
|
||||||
|
|
||||||
// Entry point
|
|
||||||
window.addEventListener("load", onInit);
|
|
||||||
@@ -105,6 +105,12 @@ const requestAndStoreAccessToken = async (): Promise<void> => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const openRestoreContainerDialog = (): void => {
|
||||||
|
if (isFabricNative()) {
|
||||||
|
sendCachedDataMessage(FabricMessageTypes.RestoreContainer, []);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check token validity and schedule a refresh if necessary
|
* Check token validity and schedule a refresh if necessary
|
||||||
* @param tokenTimestamp
|
* @param tokenTimestamp
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ export type Features = {
|
|||||||
readonly disableConnectionStringLogin: boolean;
|
readonly disableConnectionStringLogin: boolean;
|
||||||
readonly enableContainerCopy: boolean;
|
readonly enableContainerCopy: boolean;
|
||||||
readonly enableCloudShell: boolean;
|
readonly enableCloudShell: boolean;
|
||||||
|
readonly enableRestoreContainer: boolean; // only for Fabric
|
||||||
|
|
||||||
// can be set via both flight and feature flag
|
// can be set via both flight and feature flag
|
||||||
autoscaleDefault: boolean;
|
autoscaleDefault: boolean;
|
||||||
@@ -93,7 +94,7 @@ export function extractFeatures(given = new URLSearchParams(window.location.sear
|
|||||||
notebookBasePath: get("notebookbasepath"),
|
notebookBasePath: get("notebookbasepath"),
|
||||||
notebookServerToken: get("notebookservertoken"),
|
notebookServerToken: get("notebookservertoken"),
|
||||||
notebookServerUrl: get("notebookserverurl"),
|
notebookServerUrl: get("notebookserverurl"),
|
||||||
sandboxNotebookOutputs: "true" === get("sandboxnotebookoutputs", "true"),
|
sandboxNotebookOutputs: true,
|
||||||
selfServeType: get("selfservetype"),
|
selfServeType: get("selfservetype"),
|
||||||
showMinRUSurvey: "true" === get("showminrusurvey"),
|
showMinRUSurvey: "true" === get("showminrusurvey"),
|
||||||
ttl90Days: "true" === get("ttl90days"),
|
ttl90Days: "true" === get("ttl90days"),
|
||||||
@@ -111,6 +112,7 @@ export function extractFeatures(given = new URLSearchParams(window.location.sear
|
|||||||
enablePriorityBasedExecution: "true" === get("enableprioritybasedexecution"),
|
enablePriorityBasedExecution: "true" === get("enableprioritybasedexecution"),
|
||||||
disableConnectionStringLogin: "true" === get("disableconnectionstringlogin"),
|
disableConnectionStringLogin: "true" === get("disableconnectionstringlogin"),
|
||||||
enableContainerCopy: "true" === get("enablecontainercopy"),
|
enableContainerCopy: "true" === get("enablecontainercopy"),
|
||||||
|
enableRestoreContainer: "true" === get("enablerestorecontainer"),
|
||||||
enableCloudShell: true,
|
enableCloudShell: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ describe("AuthorizationUtils", () => {
|
|||||||
enableKoResourceTree: false,
|
enableKoResourceTree: false,
|
||||||
enableThroughputBuckets: false,
|
enableThroughputBuckets: false,
|
||||||
hostedDataExplorer: false,
|
hostedDataExplorer: false,
|
||||||
sandboxNotebookOutputs: false,
|
sandboxNotebookOutputs: true,
|
||||||
showMinRUSurvey: false,
|
showMinRUSurvey: false,
|
||||||
ttl90Days: false,
|
ttl90Days: false,
|
||||||
enableThroughputCap: false,
|
enableThroughputCap: false,
|
||||||
@@ -43,6 +43,7 @@ describe("AuthorizationUtils", () => {
|
|||||||
partitionKeyDefault: false,
|
partitionKeyDefault: false,
|
||||||
partitionKeyDefault2: false,
|
partitionKeyDefault2: false,
|
||||||
notebooksDownBanner: false,
|
notebooksDownBanner: false,
|
||||||
|
enableRestoreContainer: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,505 +0,0 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
||||||
import { expect, Frame, Locator, Page, test } from "@playwright/test";
|
|
||||||
import { set } from "lodash";
|
|
||||||
import { truncateName } from "../../src/Explorer/ContainerCopy/CopyJobUtils";
|
|
||||||
import {
|
|
||||||
ContainerCopy,
|
|
||||||
getAccountName,
|
|
||||||
getDropdownItemByNameOrPosition,
|
|
||||||
interceptAndInspectApiRequest,
|
|
||||||
TestAccount,
|
|
||||||
waitForApiResponse,
|
|
||||||
} from "../fx";
|
|
||||||
import { createMultipleTestContainers } from "../testData";
|
|
||||||
|
|
||||||
let page: Page;
|
|
||||||
let wrapper: Locator = null!;
|
|
||||||
let panel: Locator = null!;
|
|
||||||
let frame: Frame = null!;
|
|
||||||
let expectedCopyJobNameInitial: string = null!;
|
|
||||||
let expectedJobName: string = "";
|
|
||||||
let targetAccountName: string = "";
|
|
||||||
let expectedSourceAccountName: string = "";
|
|
||||||
let expectedSubscriptionName: string = "";
|
|
||||||
const VISIBLE_TIMEOUT_MS = 30 * 1000;
|
|
||||||
|
|
||||||
test.describe.configure({ mode: "serial" });
|
|
||||||
|
|
||||||
test.describe("Container Copy", () => {
|
|
||||||
test.beforeAll("Container Copy - Before All", async ({ browser }) => {
|
|
||||||
await createMultipleTestContainers({ accountType: TestAccount.SQLContainerCopyOnly, containerCount: 3 });
|
|
||||||
|
|
||||||
page = await browser.newPage();
|
|
||||||
({ wrapper, frame } = await ContainerCopy.open(page, TestAccount.SQLContainerCopyOnly));
|
|
||||||
expectedJobName = `test_job_${Date.now()}`;
|
|
||||||
targetAccountName = getAccountName(TestAccount.SQLContainerCopyOnly);
|
|
||||||
});
|
|
||||||
|
|
||||||
test.afterEach("Container Copy - After Each", async () => {
|
|
||||||
await page.unroute(/.*/, (route) => route.continue());
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Loading and verifying the content of the page", async () => {
|
|
||||||
expect(wrapper).not.toBeNull();
|
|
||||||
await expect(wrapper.getByTestId("CommandBar/Button:Create Copy Job")).toBeVisible({ timeout: VISIBLE_TIMEOUT_MS });
|
|
||||||
await expect(wrapper.getByTestId("CommandBar/Button:Refresh")).toBeVisible({ timeout: VISIBLE_TIMEOUT_MS });
|
|
||||||
await expect(wrapper.getByTestId("CommandBar/Button:Feedback")).toBeVisible({ timeout: VISIBLE_TIMEOUT_MS });
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Successfully create a copy job for offline migration", async () => {
|
|
||||||
expect(wrapper).not.toBeNull();
|
|
||||||
// Loading and verifying subscription & account dropdown
|
|
||||||
|
|
||||||
const createCopyJobButton = wrapper.getByTestId("CommandBar/Button:Create Copy Job");
|
|
||||||
await createCopyJobButton.click();
|
|
||||||
panel = frame.getByTestId("Panel:Create copy job");
|
|
||||||
await expect(panel).toBeVisible();
|
|
||||||
|
|
||||||
await page.waitForTimeout(10 * 1000);
|
|
||||||
|
|
||||||
const subscriptionDropdown = panel.getByTestId("subscription-dropdown");
|
|
||||||
|
|
||||||
const expectedAccountName = targetAccountName;
|
|
||||||
expectedSubscriptionName = await subscriptionDropdown.locator("span.ms-Dropdown-title").innerText();
|
|
||||||
|
|
||||||
await subscriptionDropdown.click();
|
|
||||||
const subscriptionItem = await getDropdownItemByNameOrPosition(
|
|
||||||
frame,
|
|
||||||
{ name: expectedSubscriptionName },
|
|
||||||
{ ariaLabel: "Subscription" },
|
|
||||||
);
|
|
||||||
await subscriptionItem.click();
|
|
||||||
|
|
||||||
// Load account dropdown based on selected subscription
|
|
||||||
|
|
||||||
const accountDropdown = panel.getByTestId("account-dropdown");
|
|
||||||
await expect(accountDropdown).toHaveText(new RegExp(expectedAccountName));
|
|
||||||
await accountDropdown.click();
|
|
||||||
|
|
||||||
const accountItem = await getDropdownItemByNameOrPosition(
|
|
||||||
frame,
|
|
||||||
{ name: expectedAccountName },
|
|
||||||
{ ariaLabel: "Account" },
|
|
||||||
);
|
|
||||||
await accountItem.click();
|
|
||||||
|
|
||||||
// Verifying online or offline migration functionality
|
|
||||||
/**
|
|
||||||
* This test verifies the functionality of the migration type radio that toggles between
|
|
||||||
* online and offline container copy modes. It ensures that:
|
|
||||||
* 1. When online mode is selected, the user is directed to a permissions screen
|
|
||||||
* 2. When offline mode is selected, the user bypasses the permissions screen
|
|
||||||
* 3. The UI correctly reflects the selected migration type throughout the workflow
|
|
||||||
*/
|
|
||||||
const migrationTypeContainer = panel.getByTestId("migration-type");
|
|
||||||
const onlineCopyRadioButton = migrationTypeContainer.getByRole("radio", { name: /Online mode/i });
|
|
||||||
await onlineCopyRadioButton.click({ force: true });
|
|
||||||
|
|
||||||
await expect(migrationTypeContainer.getByTestId("migration-type-description-online")).toBeVisible();
|
|
||||||
|
|
||||||
await panel.getByRole("button", { name: "Next" }).click();
|
|
||||||
|
|
||||||
await expect(panel.getByTestId("Panel:AssignPermissionsContainer")).toBeVisible();
|
|
||||||
await expect(panel.getByText("Online container copy", { exact: true })).toBeVisible();
|
|
||||||
await panel.getByRole("button", { name: "Previous" }).click();
|
|
||||||
|
|
||||||
const offlineCopyRadioButton = migrationTypeContainer.getByRole("radio", { name: /Offline mode/i });
|
|
||||||
await offlineCopyRadioButton.click({ force: true });
|
|
||||||
|
|
||||||
await expect(migrationTypeContainer.getByTestId("migration-type-description-offline")).toBeVisible();
|
|
||||||
|
|
||||||
await panel.getByRole("button", { name: "Next" }).click();
|
|
||||||
|
|
||||||
await expect(panel.getByTestId("Panel:SelectSourceAndTargetContainers")).toBeVisible();
|
|
||||||
await expect(panel.getByTestId("Panel:AssignPermissionsContainer")).not.toBeVisible();
|
|
||||||
|
|
||||||
// Verifying source and target container selection
|
|
||||||
|
|
||||||
const sourceContainerDropdown = panel.getByTestId("source-containerDropdown");
|
|
||||||
expect(sourceContainerDropdown).toBeVisible();
|
|
||||||
await expect(sourceContainerDropdown).toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
|
||||||
|
|
||||||
const sourceDatabaseDropdown = panel.getByTestId("source-databaseDropdown");
|
|
||||||
await sourceDatabaseDropdown.click();
|
|
||||||
|
|
||||||
const sourceDbDropdownItem = await getDropdownItemByNameOrPosition(
|
|
||||||
frame,
|
|
||||||
{ position: 0 },
|
|
||||||
{ ariaLabel: "Database" },
|
|
||||||
);
|
|
||||||
await sourceDbDropdownItem.click();
|
|
||||||
|
|
||||||
await expect(sourceContainerDropdown).not.toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
|
||||||
await sourceContainerDropdown.click();
|
|
||||||
const sourceContainerDropdownItem = await getDropdownItemByNameOrPosition(
|
|
||||||
frame,
|
|
||||||
{ position: 0 },
|
|
||||||
{ ariaLabel: "Container" },
|
|
||||||
);
|
|
||||||
await sourceContainerDropdownItem.click();
|
|
||||||
|
|
||||||
const targetContainerDropdown = panel.getByTestId("target-containerDropdown");
|
|
||||||
expect(targetContainerDropdown).toBeVisible();
|
|
||||||
await expect(targetContainerDropdown).toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
|
||||||
|
|
||||||
const targetDatabaseDropdown = panel.getByTestId("target-databaseDropdown");
|
|
||||||
await targetDatabaseDropdown.click();
|
|
||||||
const targetDbDropdownItem = await getDropdownItemByNameOrPosition(
|
|
||||||
frame,
|
|
||||||
{ position: 0 },
|
|
||||||
{ ariaLabel: "Database" },
|
|
||||||
);
|
|
||||||
await targetDbDropdownItem.click();
|
|
||||||
|
|
||||||
await expect(targetContainerDropdown).not.toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
|
||||||
await targetContainerDropdown.click();
|
|
||||||
const targetContainerDropdownItem1 = await getDropdownItemByNameOrPosition(
|
|
||||||
frame,
|
|
||||||
{ position: 0 },
|
|
||||||
{ ariaLabel: "Container" },
|
|
||||||
);
|
|
||||||
await targetContainerDropdownItem1.click();
|
|
||||||
|
|
||||||
await panel.getByRole("button", { name: "Next" }).click();
|
|
||||||
|
|
||||||
const errorContainer = panel.getByTestId("Panel:ErrorContainer");
|
|
||||||
await expect(errorContainer).toBeVisible();
|
|
||||||
await expect(errorContainer).toHaveText(/Source and destination containers cannot be the same/i);
|
|
||||||
|
|
||||||
// Reselect target container to be different from source container
|
|
||||||
await targetContainerDropdown.click();
|
|
||||||
const targetContainerDropdownItem2 = await getDropdownItemByNameOrPosition(
|
|
||||||
frame,
|
|
||||||
{ position: 1 },
|
|
||||||
{ ariaLabel: "Container" },
|
|
||||||
);
|
|
||||||
await targetContainerDropdownItem2.click();
|
|
||||||
|
|
||||||
const selectedSourceDatabase = await sourceDatabaseDropdown.innerText();
|
|
||||||
const selectedSourceContainer = await sourceContainerDropdown.innerText();
|
|
||||||
const selectedTargetDatabase = await targetDatabaseDropdown.innerText();
|
|
||||||
const selectedTargetContainer = await targetContainerDropdown.innerText();
|
|
||||||
expectedCopyJobNameInitial = `${truncateName(selectedSourceDatabase)}.${truncateName(
|
|
||||||
selectedSourceContainer,
|
|
||||||
)}_${truncateName(selectedTargetDatabase)}.${truncateName(selectedTargetContainer)}`;
|
|
||||||
|
|
||||||
await panel.getByRole("button", { name: "Next" }).click();
|
|
||||||
|
|
||||||
await expect(errorContainer).not.toBeVisible();
|
|
||||||
await expect(panel.getByTestId("Panel:PreviewCopyJob")).toBeVisible();
|
|
||||||
|
|
||||||
// Verifying the preview of the copy job
|
|
||||||
const previewContainer = panel.getByTestId("Panel:PreviewCopyJob");
|
|
||||||
await expect(previewContainer).toBeVisible();
|
|
||||||
await expect(previewContainer.getByTestId("source-subscription-name")).toHaveText(expectedSubscriptionName);
|
|
||||||
await expect(previewContainer.getByTestId("source-account-name")).toHaveText(expectedAccountName);
|
|
||||||
const jobNameInput = previewContainer.getByTestId("job-name-textfield");
|
|
||||||
await expect(jobNameInput).toHaveValue(new RegExp(expectedCopyJobNameInitial));
|
|
||||||
const primaryBtn = panel.getByRole("button", { name: "Copy", exact: true });
|
|
||||||
await expect(primaryBtn).not.toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
|
||||||
|
|
||||||
await jobNameInput.fill("test job name");
|
|
||||||
await expect(primaryBtn).toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
|
||||||
|
|
||||||
// Testing API request interception with duplicate job name
|
|
||||||
const duplicateJobName = "test-job-name-1";
|
|
||||||
await jobNameInput.fill(duplicateJobName);
|
|
||||||
|
|
||||||
const copyButton = panel.getByRole("button", { name: "Copy", exact: true });
|
|
||||||
const expectedErrorMessage = `Duplicate job name '${duplicateJobName}'`;
|
|
||||||
await interceptAndInspectApiRequest(
|
|
||||||
page,
|
|
||||||
`${expectedAccountName}/dataTransferJobs/${duplicateJobName}`,
|
|
||||||
"PUT",
|
|
||||||
new Error(expectedErrorMessage),
|
|
||||||
(url?: string) => url?.includes(duplicateJobName) ?? false,
|
|
||||||
);
|
|
||||||
|
|
||||||
let errorThrown = false;
|
|
||||||
try {
|
|
||||||
await copyButton.click();
|
|
||||||
await page.waitForTimeout(2000);
|
|
||||||
} catch (error: any) {
|
|
||||||
errorThrown = true;
|
|
||||||
expect(error.message).toContain("not allowed");
|
|
||||||
}
|
|
||||||
if (!errorThrown) {
|
|
||||||
const errorContainer = panel.getByTestId("Panel:ErrorContainer");
|
|
||||||
await expect(errorContainer).toBeVisible();
|
|
||||||
await expect(errorContainer).toHaveText(new RegExp(expectedErrorMessage, "i"));
|
|
||||||
}
|
|
||||||
|
|
||||||
await expect(panel).toBeVisible();
|
|
||||||
|
|
||||||
// Testing API request success with valid job name and verifying copy job creation
|
|
||||||
|
|
||||||
const validJobName = expectedJobName;
|
|
||||||
|
|
||||||
const copyJobCreationPromise = waitForApiResponse(
|
|
||||||
page,
|
|
||||||
`${expectedAccountName}/dataTransferJobs/${validJobName}`,
|
|
||||||
"PUT",
|
|
||||||
);
|
|
||||||
|
|
||||||
await jobNameInput.fill(validJobName);
|
|
||||||
await expect(copyButton).not.toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
|
||||||
|
|
||||||
await copyButton.click();
|
|
||||||
|
|
||||||
const response = await copyJobCreationPromise;
|
|
||||||
expect(response.ok()).toBe(true);
|
|
||||||
|
|
||||||
await expect(panel).not.toBeVisible({ timeout: 10000 });
|
|
||||||
|
|
||||||
const jobsListContainer = wrapper.locator(".CopyJobListContainer .ms-DetailsList-contentWrapper .ms-List-page");
|
|
||||||
await jobsListContainer.waitFor({ state: "visible" });
|
|
||||||
|
|
||||||
const jobItem = jobsListContainer.getByText(validJobName);
|
|
||||||
await jobItem.waitFor({ state: "visible" });
|
|
||||||
await expect(jobItem).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Verify Online or Offline Container Copy Permissions Panel", async () => {
|
|
||||||
expect(wrapper).not.toBeNull();
|
|
||||||
|
|
||||||
// Opening the Create Copy Job panel again to verify initial state
|
|
||||||
const createCopyJobButton = wrapper.getByTestId("CommandBar/Button:Create Copy Job");
|
|
||||||
await createCopyJobButton.click();
|
|
||||||
panel = frame.getByTestId("Panel:Create copy job");
|
|
||||||
await expect(panel).toBeVisible();
|
|
||||||
await expect(panel.getByRole("heading", { name: "Create copy job" })).toBeVisible();
|
|
||||||
|
|
||||||
// select different account dropdown
|
|
||||||
|
|
||||||
const accountDropdown = panel.getByTestId("account-dropdown");
|
|
||||||
await accountDropdown.click();
|
|
||||||
|
|
||||||
const dropdownItemsWrapper = frame.locator("div.ms-Dropdown-items");
|
|
||||||
expect(await dropdownItemsWrapper.getAttribute("aria-label")).toEqual("Account");
|
|
||||||
|
|
||||||
const allDropdownItems = await dropdownItemsWrapper.locator(`button.ms-Dropdown-item[role='option']`).all();
|
|
||||||
|
|
||||||
const filteredItems = [];
|
|
||||||
for (const item of allDropdownItems) {
|
|
||||||
const testContent = (await item.textContent()) ?? "";
|
|
||||||
if (testContent.trim() !== targetAccountName.trim()) {
|
|
||||||
filteredItems.push(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filteredItems.length > 0) {
|
|
||||||
const firstDropdownItem = filteredItems[0];
|
|
||||||
expectedSourceAccountName = (await firstDropdownItem.textContent()) ?? "";
|
|
||||||
await firstDropdownItem.click();
|
|
||||||
} else {
|
|
||||||
throw new Error("No dropdown items available after filtering");
|
|
||||||
}
|
|
||||||
|
|
||||||
const migrationTypeContainer = panel.getByTestId("migration-type");
|
|
||||||
const onlineCopyRadioButton = migrationTypeContainer.getByRole("radio", { name: /Online mode/i });
|
|
||||||
await onlineCopyRadioButton.click({ force: true });
|
|
||||||
|
|
||||||
await panel.getByRole("button", { name: "Next" }).click();
|
|
||||||
|
|
||||||
// Verifying Assign Permissions panel for online copy
|
|
||||||
|
|
||||||
const permissionScreen = panel.getByTestId("Panel:AssignPermissionsContainer");
|
|
||||||
await expect(permissionScreen).toBeVisible();
|
|
||||||
|
|
||||||
await expect(permissionScreen.getByText("Online container copy", { exact: true })).toBeVisible();
|
|
||||||
await expect(permissionScreen.getByText("Cross-account container copy", { exact: true })).toBeVisible();
|
|
||||||
|
|
||||||
// Verify Point-in-Time Restore timer and refresh button workflow
|
|
||||||
|
|
||||||
await page.route(`**/Microsoft.DocumentDB/databaseAccounts/${expectedSourceAccountName}**`, async (route) => {
|
|
||||||
const mockData = {
|
|
||||||
identity: {
|
|
||||||
type: "SystemAssigned",
|
|
||||||
principalId: "00-11-22-33",
|
|
||||||
},
|
|
||||||
properties: {
|
|
||||||
defaultIdentity: "SystemAssignedIdentity",
|
|
||||||
backupPolicy: {
|
|
||||||
type: "Continuous",
|
|
||||||
},
|
|
||||||
capabilities: [{ name: "EnableOnlineContainerCopy" }],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
if (route.request().method() === "GET") {
|
|
||||||
const response = await route.fetch();
|
|
||||||
const actualData = await response.json();
|
|
||||||
const mergedData = { ...actualData };
|
|
||||||
|
|
||||||
set(mergedData, "identity", mockData.identity);
|
|
||||||
set(mergedData, "properties.defaultIdentity", mockData.properties.defaultIdentity);
|
|
||||||
set(mergedData, "properties.backupPolicy", mockData.properties.backupPolicy);
|
|
||||||
set(mergedData, "properties.capabilities", mockData.properties.capabilities);
|
|
||||||
|
|
||||||
await route.fulfill({
|
|
||||||
status: 200,
|
|
||||||
contentType: "application/json",
|
|
||||||
body: JSON.stringify(mergedData),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await route.continue();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await expect(permissionScreen).toBeVisible();
|
|
||||||
|
|
||||||
const expandedOnlineAccordionHeader = permissionScreen
|
|
||||||
.getByTestId("permission-group-container-onlineConfigs")
|
|
||||||
.locator("button[aria-expanded='true']");
|
|
||||||
await expect(expandedOnlineAccordionHeader).toBeVisible();
|
|
||||||
|
|
||||||
const accordionItem = expandedOnlineAccordionHeader
|
|
||||||
.locator("xpath=ancestor::*[contains(@class, 'fui-AccordionItem') or contains(@data-test, 'accordion-item')]")
|
|
||||||
.first();
|
|
||||||
|
|
||||||
const accordionPanel = accordionItem
|
|
||||||
.locator("[role='tabpanel'], .fui-AccordionPanel, [data-test*='panel']")
|
|
||||||
.first();
|
|
||||||
|
|
||||||
await page.clock.install({ time: new Date("2024-01-01T10:00:00Z") });
|
|
||||||
|
|
||||||
const pitrBtn = accordionPanel.getByTestId("pointInTimeRestore:PrimaryBtn");
|
|
||||||
await expect(pitrBtn).toBeVisible();
|
|
||||||
await pitrBtn.click();
|
|
||||||
|
|
||||||
page.context().on("page", async (newPage) => {
|
|
||||||
const expectedUrlEndPattern = new RegExp(
|
|
||||||
`/providers/Microsoft.(DocumentDB|DocumentDb)/databaseAccounts/${expectedSourceAccountName}/backupRestore`,
|
|
||||||
);
|
|
||||||
expect(newPage.url()).toMatch(expectedUrlEndPattern);
|
|
||||||
await newPage.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
const loadingOverlay = frame.locator("[data-test='loading-overlay']");
|
|
||||||
await expect(loadingOverlay).toBeVisible();
|
|
||||||
|
|
||||||
const refreshBtn = accordionPanel.getByTestId("pointInTimeRestore:RefreshBtn");
|
|
||||||
await expect(refreshBtn).not.toBeVisible();
|
|
||||||
|
|
||||||
// Fast forward time by 11 minutes (11 * 60 * 1000ms = 660000ms)
|
|
||||||
await page.clock.fastForward(11 * 60 * 1000);
|
|
||||||
|
|
||||||
await expect(refreshBtn).toBeVisible();
|
|
||||||
await expect(pitrBtn).not.toBeVisible();
|
|
||||||
|
|
||||||
// Veify Popover & Loading Overlay on permission screen with API mocks and accordion interactions
|
|
||||||
|
|
||||||
await page.route(
|
|
||||||
`**/Microsoft.DocumentDB/databaseAccounts/${expectedSourceAccountName}/sqlRoleAssignments*`,
|
|
||||||
async (route) => {
|
|
||||||
await route.fulfill({
|
|
||||||
status: 200,
|
|
||||||
contentType: "application/json",
|
|
||||||
body: JSON.stringify({
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
principalId: "00-11-22-33",
|
|
||||||
roleDefinitionId: `Microsoft.DocumentDB/databaseAccounts/${expectedSourceAccountName}/77-88-99`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
await page.route("**/Microsoft.DocumentDB/databaseAccounts/*/77-88-99**", async (route) => {
|
|
||||||
await route.fulfill({
|
|
||||||
status: 200,
|
|
||||||
contentType: "application/json",
|
|
||||||
body: JSON.stringify({
|
|
||||||
value: [
|
|
||||||
{
|
|
||||||
name: "00000000-0000-0000-0000-000000000001",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
await page.route(`**/Microsoft.DocumentDB/databaseAccounts/${targetAccountName}**`, async (route) => {
|
|
||||||
const mockData = {
|
|
||||||
identity: {
|
|
||||||
type: "SystemAssigned",
|
|
||||||
principalId: "00-11-22-33",
|
|
||||||
},
|
|
||||||
properties: {
|
|
||||||
defaultIdentity: "SystemAssignedIdentity",
|
|
||||||
backupPolicy: {
|
|
||||||
type: "Continuous",
|
|
||||||
},
|
|
||||||
capabilities: [{ name: "EnableOnlineContainerCopy" }],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (route.request().method() === "PATCH") {
|
|
||||||
await route.fulfill({
|
|
||||||
status: 200,
|
|
||||||
contentType: "application/json",
|
|
||||||
body: JSON.stringify({ status: "Succeeded" }),
|
|
||||||
});
|
|
||||||
} else if (route.request().method() === "GET") {
|
|
||||||
// Get the actual response and merge with mock data
|
|
||||||
const response = await route.fetch();
|
|
||||||
const actualData = await response.json();
|
|
||||||
const mergedData = { ...actualData };
|
|
||||||
set(mergedData, "identity", mockData.identity);
|
|
||||||
set(mergedData, "properties.defaultIdentity", mockData.properties.defaultIdentity);
|
|
||||||
set(mergedData, "properties.backupPolicy", mockData.properties.backupPolicy);
|
|
||||||
set(mergedData, "properties.capabilities", mockData.properties.capabilities);
|
|
||||||
|
|
||||||
await route.fulfill({
|
|
||||||
status: 200,
|
|
||||||
contentType: "application/json",
|
|
||||||
body: JSON.stringify(mergedData),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await route.continue();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await expect(permissionScreen).toBeVisible();
|
|
||||||
|
|
||||||
const expandedCrossAccordionHeader = permissionScreen
|
|
||||||
.getByTestId("permission-group-container-crossAccountConfigs")
|
|
||||||
.locator("button[aria-expanded='true']");
|
|
||||||
await expect(expandedCrossAccordionHeader).toBeVisible();
|
|
||||||
|
|
||||||
const crossAccordionItem = expandedCrossAccordionHeader
|
|
||||||
.locator("xpath=ancestor::*[contains(@class, 'fui-AccordionItem') or contains(@data-test, 'accordion-item')]")
|
|
||||||
.first();
|
|
||||||
|
|
||||||
const crossAccordionPanel = crossAccordionItem
|
|
||||||
.locator("[role='tabpanel'], .fui-AccordionPanel, [data-test*='panel']")
|
|
||||||
.first();
|
|
||||||
|
|
||||||
const toggleButton = crossAccordionPanel.getByTestId("btn-toggle");
|
|
||||||
await expect(toggleButton).toBeVisible();
|
|
||||||
await toggleButton.click();
|
|
||||||
|
|
||||||
const popover = frame.locator("[data-test='popover-container']");
|
|
||||||
await expect(popover).toBeVisible();
|
|
||||||
|
|
||||||
const yesButton = popover.getByRole("button", { name: /Yes/i });
|
|
||||||
const noButton = popover.getByRole("button", { name: /No/i });
|
|
||||||
await expect(yesButton).toBeVisible();
|
|
||||||
await expect(noButton).toBeVisible();
|
|
||||||
|
|
||||||
await yesButton.click();
|
|
||||||
|
|
||||||
await expect(loadingOverlay).toBeVisible();
|
|
||||||
|
|
||||||
await expect(loadingOverlay).toBeHidden({ timeout: 10 * 1000 });
|
|
||||||
await expect(popover).toBeHidden({ timeout: 10 * 1000 });
|
|
||||||
|
|
||||||
await panel.getByRole("button", { name: "Cancel" }).click();
|
|
||||||
});
|
|
||||||
|
|
||||||
test.afterAll("Container Copy - After All", async () => {
|
|
||||||
await page.unroute(/.*/, (route) => route.continue());
|
|
||||||
await page.close();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
262
test/sql/containercopy/offlineMigration.spec.ts
Normal file
262
test/sql/containercopy/offlineMigration.spec.ts
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
import { expect, Frame, Locator, Page, test } from "@playwright/test";
|
||||||
|
import { truncateName } from "../../../src/Explorer/ContainerCopy/CopyJobUtils";
|
||||||
|
import {
|
||||||
|
ContainerCopy,
|
||||||
|
getAccountName,
|
||||||
|
getDropdownItemByNameOrPosition,
|
||||||
|
interceptAndInspectApiRequest,
|
||||||
|
TestAccount,
|
||||||
|
waitForApiResponse,
|
||||||
|
} from "../../fx";
|
||||||
|
import { createMultipleTestContainers } from "../../testData";
|
||||||
|
|
||||||
|
test.describe("Container Copy - Offline Migration", () => {
|
||||||
|
let page: Page;
|
||||||
|
let wrapper: Locator;
|
||||||
|
let panel: Locator;
|
||||||
|
let frame: Frame;
|
||||||
|
let expectedJobName: string;
|
||||||
|
let targetAccountName: string;
|
||||||
|
let expectedSubscriptionName: string;
|
||||||
|
let expectedCopyJobNameInitial: string;
|
||||||
|
|
||||||
|
test.beforeEach("Setup for offline migration test", async ({ browser }) => {
|
||||||
|
await createMultipleTestContainers({ accountType: TestAccount.SQLContainerCopyOnly, containerCount: 2 });
|
||||||
|
|
||||||
|
page = await browser.newPage();
|
||||||
|
({ wrapper, frame } = await ContainerCopy.open(page, TestAccount.SQLContainerCopyOnly));
|
||||||
|
expectedJobName = `offline_test_job_${Date.now()}`;
|
||||||
|
targetAccountName = getAccountName(TestAccount.SQLContainerCopyOnly);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach("Cleanup after offline migration test", async () => {
|
||||||
|
await page.unroute(/.*/, (route) => route.continue());
|
||||||
|
await page.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Successfully create and manage offline migration copy job", async () => {
|
||||||
|
expect(wrapper).not.toBeNull();
|
||||||
|
await wrapper.locator(".commandBarContainer").waitFor({ state: "visible" });
|
||||||
|
|
||||||
|
// Open Create Copy Job panel
|
||||||
|
const createCopyJobButton = wrapper.getByTestId("CommandBar/Button:Create Copy Job");
|
||||||
|
await expect(createCopyJobButton).toBeVisible();
|
||||||
|
await createCopyJobButton.click();
|
||||||
|
panel = frame.getByTestId("Panel:Create copy job");
|
||||||
|
await expect(panel).toBeVisible();
|
||||||
|
|
||||||
|
// Reduced wait time for better performance
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
|
// Setup subscription and account
|
||||||
|
const subscriptionDropdown = panel.getByTestId("subscription-dropdown");
|
||||||
|
const expectedAccountName = targetAccountName;
|
||||||
|
expectedSubscriptionName = await subscriptionDropdown.locator("span.ms-Dropdown-title").innerText();
|
||||||
|
|
||||||
|
await subscriptionDropdown.click();
|
||||||
|
const subscriptionItem = await getDropdownItemByNameOrPosition(
|
||||||
|
frame,
|
||||||
|
{ name: expectedSubscriptionName },
|
||||||
|
{ ariaLabel: "Subscription" },
|
||||||
|
);
|
||||||
|
await subscriptionItem.click();
|
||||||
|
|
||||||
|
// Select account
|
||||||
|
const accountDropdown = panel.getByTestId("account-dropdown");
|
||||||
|
await expect(accountDropdown).toHaveText(new RegExp(expectedAccountName));
|
||||||
|
await accountDropdown.click();
|
||||||
|
|
||||||
|
const accountItem = await getDropdownItemByNameOrPosition(
|
||||||
|
frame,
|
||||||
|
{ name: expectedAccountName },
|
||||||
|
{ ariaLabel: "Account" },
|
||||||
|
);
|
||||||
|
await accountItem.click();
|
||||||
|
|
||||||
|
// Test offline migration mode toggle functionality
|
||||||
|
const migrationTypeContainer = panel.getByTestId("migration-type");
|
||||||
|
|
||||||
|
// First test online mode (should show permissions screen)
|
||||||
|
const onlineCopyRadioButton = migrationTypeContainer.getByRole("radio", { name: /Online mode/i });
|
||||||
|
await onlineCopyRadioButton.click({ force: true });
|
||||||
|
await expect(migrationTypeContainer.getByTestId("migration-type-description-online")).toBeVisible();
|
||||||
|
|
||||||
|
await panel.getByRole("button", { name: "Next" }).click();
|
||||||
|
await expect(panel.getByTestId("Panel:AssignPermissionsContainer")).toBeVisible();
|
||||||
|
await expect(panel.getByText("Online container copy", { exact: true })).toBeVisible();
|
||||||
|
|
||||||
|
// Go back and switch to offline mode
|
||||||
|
await panel.getByRole("button", { name: "Previous" }).click();
|
||||||
|
|
||||||
|
const offlineCopyRadioButton = migrationTypeContainer.getByRole("radio", { name: /Offline mode/i });
|
||||||
|
await offlineCopyRadioButton.click({ force: true });
|
||||||
|
await expect(migrationTypeContainer.getByTestId("migration-type-description-offline")).toBeVisible();
|
||||||
|
|
||||||
|
await panel.getByRole("button", { name: "Next" }).click();
|
||||||
|
|
||||||
|
// Verify we skip permissions screen in offline mode
|
||||||
|
await expect(panel.getByTestId("Panel:SelectSourceAndTargetContainers")).toBeVisible();
|
||||||
|
await expect(panel.getByTestId("Panel:AssignPermissionsContainer")).not.toBeVisible();
|
||||||
|
|
||||||
|
// Test source and target container selection with validation
|
||||||
|
const sourceContainerDropdown = panel.getByTestId("source-containerDropdown");
|
||||||
|
expect(sourceContainerDropdown).toBeVisible();
|
||||||
|
await expect(sourceContainerDropdown).toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
||||||
|
|
||||||
|
// Select source database first (containers are disabled until database is selected)
|
||||||
|
const sourceDatabaseDropdown = panel.getByTestId("source-databaseDropdown");
|
||||||
|
await sourceDatabaseDropdown.click();
|
||||||
|
const sourceDbDropdownItem = await getDropdownItemByNameOrPosition(
|
||||||
|
frame,
|
||||||
|
{ position: 0 },
|
||||||
|
{ ariaLabel: "Database" },
|
||||||
|
);
|
||||||
|
await sourceDbDropdownItem.click();
|
||||||
|
|
||||||
|
// Now container dropdown should be enabled
|
||||||
|
await expect(sourceContainerDropdown).not.toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
||||||
|
await sourceContainerDropdown.click();
|
||||||
|
const sourceContainerDropdownItem = await getDropdownItemByNameOrPosition(
|
||||||
|
frame,
|
||||||
|
{ position: 0 },
|
||||||
|
{ ariaLabel: "Container" },
|
||||||
|
);
|
||||||
|
await sourceContainerDropdownItem.click();
|
||||||
|
|
||||||
|
// Test target container selection
|
||||||
|
const targetContainerDropdown = panel.getByTestId("target-containerDropdown");
|
||||||
|
expect(targetContainerDropdown).toBeVisible();
|
||||||
|
await expect(targetContainerDropdown).toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
||||||
|
|
||||||
|
const targetDatabaseDropdown = panel.getByTestId("target-databaseDropdown");
|
||||||
|
await targetDatabaseDropdown.click();
|
||||||
|
const targetDbDropdownItem = await getDropdownItemByNameOrPosition(
|
||||||
|
frame,
|
||||||
|
{ position: 0 },
|
||||||
|
{ ariaLabel: "Database" },
|
||||||
|
);
|
||||||
|
await targetDbDropdownItem.click();
|
||||||
|
|
||||||
|
await expect(targetContainerDropdown).not.toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
||||||
|
await targetContainerDropdown.click();
|
||||||
|
|
||||||
|
// First try selecting the same container (should show error)
|
||||||
|
const targetContainerDropdownItem1 = await getDropdownItemByNameOrPosition(
|
||||||
|
frame,
|
||||||
|
{ position: 0 },
|
||||||
|
{ ariaLabel: "Container" },
|
||||||
|
);
|
||||||
|
await targetContainerDropdownItem1.click();
|
||||||
|
|
||||||
|
await panel.getByRole("button", { name: "Next" }).click();
|
||||||
|
|
||||||
|
// Verify validation error for same source and target containers
|
||||||
|
const errorContainer = panel.getByTestId("Panel:ErrorContainer");
|
||||||
|
await expect(errorContainer).toBeVisible();
|
||||||
|
await expect(errorContainer).toHaveText(/Source and destination containers cannot be the same/i);
|
||||||
|
|
||||||
|
// Select different target container
|
||||||
|
await targetContainerDropdown.click();
|
||||||
|
const targetContainerDropdownItem2 = await getDropdownItemByNameOrPosition(
|
||||||
|
frame,
|
||||||
|
{ position: 1 },
|
||||||
|
{ ariaLabel: "Container" },
|
||||||
|
);
|
||||||
|
await targetContainerDropdownItem2.click();
|
||||||
|
|
||||||
|
// Generate expected job name based on selections
|
||||||
|
const selectedSourceDatabase = await sourceDatabaseDropdown.innerText();
|
||||||
|
const selectedSourceContainer = await sourceContainerDropdown.innerText();
|
||||||
|
const selectedTargetDatabase = await targetDatabaseDropdown.innerText();
|
||||||
|
const selectedTargetContainer = await targetContainerDropdown.innerText();
|
||||||
|
expectedCopyJobNameInitial = `${truncateName(selectedSourceDatabase)}.${truncateName(
|
||||||
|
selectedSourceContainer,
|
||||||
|
)}_${truncateName(selectedTargetDatabase)}.${truncateName(selectedTargetContainer)}`;
|
||||||
|
|
||||||
|
await panel.getByRole("button", { name: "Next" }).click();
|
||||||
|
|
||||||
|
// Error should disappear and preview should be visible
|
||||||
|
await expect(errorContainer).not.toBeVisible();
|
||||||
|
await expect(panel.getByTestId("Panel:PreviewCopyJob")).toBeVisible();
|
||||||
|
|
||||||
|
// Verify job preview details
|
||||||
|
const previewContainer = panel.getByTestId("Panel:PreviewCopyJob");
|
||||||
|
await expect(previewContainer).toBeVisible();
|
||||||
|
await expect(previewContainer.getByTestId("source-subscription-name")).toHaveText(expectedSubscriptionName);
|
||||||
|
await expect(previewContainer.getByTestId("source-account-name")).toHaveText(expectedAccountName);
|
||||||
|
|
||||||
|
const jobNameInput = previewContainer.getByTestId("job-name-textfield");
|
||||||
|
await expect(jobNameInput).toHaveValue(new RegExp(expectedCopyJobNameInitial));
|
||||||
|
|
||||||
|
const primaryBtn = panel.getByRole("button", { name: "Copy", exact: true });
|
||||||
|
await expect(primaryBtn).not.toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
||||||
|
|
||||||
|
// Test invalid job name validation (spaces not allowed)
|
||||||
|
await jobNameInput.fill("test job name");
|
||||||
|
await expect(primaryBtn).toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
||||||
|
|
||||||
|
// Test duplicate job name error handling
|
||||||
|
const duplicateJobName = "test-job-name-1";
|
||||||
|
await jobNameInput.fill(duplicateJobName);
|
||||||
|
|
||||||
|
const copyButton = panel.getByRole("button", { name: "Copy", exact: true });
|
||||||
|
const expectedErrorMessage = `Duplicate job name '${duplicateJobName}'`;
|
||||||
|
|
||||||
|
await interceptAndInspectApiRequest(
|
||||||
|
page,
|
||||||
|
`${expectedAccountName}/dataTransferJobs/${duplicateJobName}`,
|
||||||
|
"PUT",
|
||||||
|
new Error(expectedErrorMessage),
|
||||||
|
(url?: string) => url?.includes(duplicateJobName) ?? false,
|
||||||
|
);
|
||||||
|
|
||||||
|
let errorThrown = false;
|
||||||
|
try {
|
||||||
|
await copyButton.click();
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
} catch (error: any) {
|
||||||
|
errorThrown = true;
|
||||||
|
expect(error.message).toContain("not allowed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!errorThrown) {
|
||||||
|
const errorContainer = panel.getByTestId("Panel:ErrorContainer");
|
||||||
|
await expect(errorContainer).toBeVisible();
|
||||||
|
await expect(errorContainer).toHaveText(new RegExp(expectedErrorMessage, "i"));
|
||||||
|
}
|
||||||
|
|
||||||
|
await expect(panel).toBeVisible();
|
||||||
|
|
||||||
|
// Test successful job creation with valid job name
|
||||||
|
const validJobName = expectedJobName;
|
||||||
|
|
||||||
|
const copyJobCreationPromise = waitForApiResponse(
|
||||||
|
page,
|
||||||
|
`${expectedAccountName}/dataTransferJobs/${validJobName}`,
|
||||||
|
"PUT",
|
||||||
|
);
|
||||||
|
|
||||||
|
await jobNameInput.fill(validJobName);
|
||||||
|
await expect(copyButton).not.toHaveClass(/(^|\s)is-disabled(\s|$)/);
|
||||||
|
|
||||||
|
await copyButton.click();
|
||||||
|
|
||||||
|
const response = await copyJobCreationPromise;
|
||||||
|
expect(response.ok()).toBe(true);
|
||||||
|
|
||||||
|
// Verify panel closes and job appears in the list
|
||||||
|
await expect(panel).not.toBeVisible();
|
||||||
|
|
||||||
|
const filterTextField = wrapper.getByTestId("CopyJobsList/FilterTextField");
|
||||||
|
await filterTextField.waitFor({ state: "visible" });
|
||||||
|
await filterTextField.fill(validJobName);
|
||||||
|
|
||||||
|
const jobsListContainer = wrapper.locator(".CopyJobListContainer .ms-DetailsList-contentWrapper .ms-List-page");
|
||||||
|
await jobsListContainer.waitFor({ state: "visible" });
|
||||||
|
|
||||||
|
const jobItem = jobsListContainer.getByText(validJobName);
|
||||||
|
await jobItem.waitFor({ state: "visible" });
|
||||||
|
await expect(jobItem).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
189
test/sql/containercopy/onlineMigration.spec.ts
Normal file
189
test/sql/containercopy/onlineMigration.spec.ts
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
import { expect, Frame, Locator, Page, test } from "@playwright/test";
|
||||||
|
import {
|
||||||
|
ContainerCopy,
|
||||||
|
getAccountName,
|
||||||
|
getDropdownItemByNameOrPosition,
|
||||||
|
TestAccount,
|
||||||
|
waitForApiResponse,
|
||||||
|
} from "../../fx";
|
||||||
|
import { createMultipleTestContainers } from "../../testData";
|
||||||
|
|
||||||
|
test.describe("Container Copy - Online Migration", () => {
|
||||||
|
let page: Page;
|
||||||
|
let wrapper: Locator;
|
||||||
|
let panel: Locator;
|
||||||
|
let frame: Frame;
|
||||||
|
let targetAccountName: string;
|
||||||
|
|
||||||
|
test.beforeEach("Setup for online migration test", async ({ browser }) => {
|
||||||
|
await createMultipleTestContainers({ accountType: TestAccount.SQLContainerCopyOnly, containerCount: 2 });
|
||||||
|
|
||||||
|
page = await browser.newPage();
|
||||||
|
({ wrapper, frame } = await ContainerCopy.open(page, TestAccount.SQLContainerCopyOnly));
|
||||||
|
targetAccountName = getAccountName(TestAccount.SQLContainerCopyOnly);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach("Cleanup after online migration test", async () => {
|
||||||
|
await page.unroute(/.*/, (route) => route.continue());
|
||||||
|
await page.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Successfully create and manage online migration copy job", async () => {
|
||||||
|
expect(wrapper).not.toBeNull();
|
||||||
|
await wrapper.locator(".commandBarContainer").waitFor({ state: "visible" });
|
||||||
|
|
||||||
|
// Open Create Copy Job panel
|
||||||
|
const createCopyJobButton = wrapper.getByTestId("CommandBar/Button:Create Copy Job");
|
||||||
|
await expect(createCopyJobButton).toBeVisible();
|
||||||
|
await createCopyJobButton.click();
|
||||||
|
panel = frame.getByTestId("Panel:Create copy job");
|
||||||
|
await expect(panel).toBeVisible();
|
||||||
|
|
||||||
|
// Reduced wait time for better performance
|
||||||
|
await page.waitForTimeout(1000);
|
||||||
|
|
||||||
|
// Enable online migration mode
|
||||||
|
const migrationTypeContainer = panel.getByTestId("migration-type");
|
||||||
|
const onlineCopyRadioButton = migrationTypeContainer.getByRole("radio", { name: /Online mode/i });
|
||||||
|
await onlineCopyRadioButton.click({ force: true });
|
||||||
|
|
||||||
|
await expect(migrationTypeContainer.getByTestId("migration-type-description-online")).toBeVisible();
|
||||||
|
|
||||||
|
await panel.getByRole("button", { name: "Next" }).click();
|
||||||
|
|
||||||
|
// Verify permissions screen is shown for online migration
|
||||||
|
const permissionScreen = panel.getByTestId("Panel:AssignPermissionsContainer");
|
||||||
|
await expect(permissionScreen).toBeVisible();
|
||||||
|
await expect(permissionScreen.getByText("Online container copy", { exact: true })).toBeVisible();
|
||||||
|
|
||||||
|
// Skip permissions setup and proceed to container selection
|
||||||
|
await panel.getByRole("button", { name: "Next" }).click();
|
||||||
|
|
||||||
|
// Configure source and target containers for online migration
|
||||||
|
const sourceDatabaseDropdown = panel.getByTestId("source-databaseDropdown");
|
||||||
|
await sourceDatabaseDropdown.click();
|
||||||
|
const sourceDbDropdownItem = await getDropdownItemByNameOrPosition(
|
||||||
|
frame,
|
||||||
|
{ position: 0 },
|
||||||
|
{ ariaLabel: "Database" },
|
||||||
|
);
|
||||||
|
await sourceDbDropdownItem.click();
|
||||||
|
|
||||||
|
const sourceContainerDropdown = panel.getByTestId("source-containerDropdown");
|
||||||
|
await sourceContainerDropdown.click();
|
||||||
|
const sourceContainerDropdownItem = await getDropdownItemByNameOrPosition(
|
||||||
|
frame,
|
||||||
|
{ position: 0 },
|
||||||
|
{ ariaLabel: "Container" },
|
||||||
|
);
|
||||||
|
await sourceContainerDropdownItem.click();
|
||||||
|
|
||||||
|
const targetDatabaseDropdown = panel.getByTestId("target-databaseDropdown");
|
||||||
|
await targetDatabaseDropdown.click();
|
||||||
|
const targetDbDropdownItem = await getDropdownItemByNameOrPosition(
|
||||||
|
frame,
|
||||||
|
{ position: 0 },
|
||||||
|
{ ariaLabel: "Database" },
|
||||||
|
);
|
||||||
|
await targetDbDropdownItem.click();
|
||||||
|
|
||||||
|
const targetContainerDropdown = panel.getByTestId("target-containerDropdown");
|
||||||
|
await targetContainerDropdown.click();
|
||||||
|
const targetContainerDropdownItem = await getDropdownItemByNameOrPosition(
|
||||||
|
frame,
|
||||||
|
{ position: 1 },
|
||||||
|
{ ariaLabel: "Container" },
|
||||||
|
);
|
||||||
|
await targetContainerDropdownItem.click();
|
||||||
|
|
||||||
|
await panel.getByRole("button", { name: "Next" }).click();
|
||||||
|
|
||||||
|
// Verify job preview and create the online migration job
|
||||||
|
const previewContainer = panel.getByTestId("Panel:PreviewCopyJob");
|
||||||
|
await expect(previewContainer.getByTestId("source-account-name")).toHaveText(targetAccountName);
|
||||||
|
|
||||||
|
const jobNameInput = previewContainer.getByTestId("job-name-textfield");
|
||||||
|
const onlineMigrationJobName = await jobNameInput.inputValue();
|
||||||
|
|
||||||
|
const copyButton = panel.getByRole("button", { name: "Copy", exact: true });
|
||||||
|
|
||||||
|
const copyJobCreationPromise = waitForApiResponse(
|
||||||
|
page,
|
||||||
|
`${targetAccountName}/dataTransferJobs/${onlineMigrationJobName}`,
|
||||||
|
"PUT",
|
||||||
|
);
|
||||||
|
await copyButton.click();
|
||||||
|
await page.waitForTimeout(1000); // Reduced wait time
|
||||||
|
|
||||||
|
const response = await copyJobCreationPromise;
|
||||||
|
expect(response.ok()).toBe(true);
|
||||||
|
|
||||||
|
// Verify panel closes and job appears in the list
|
||||||
|
await expect(panel).not.toBeVisible();
|
||||||
|
|
||||||
|
const filterTextField = wrapper.getByTestId("CopyJobsList/FilterTextField");
|
||||||
|
await filterTextField.waitFor({ state: "visible" });
|
||||||
|
await filterTextField.fill(onlineMigrationJobName);
|
||||||
|
|
||||||
|
const jobsListContainer = wrapper.locator(".CopyJobListContainer .ms-DetailsList-contentWrapper .ms-List-page");
|
||||||
|
await jobsListContainer.waitFor({ state: "visible" });
|
||||||
|
|
||||||
|
let jobRow, statusCell, actionMenuButton;
|
||||||
|
jobRow = jobsListContainer.locator(".ms-DetailsRow", { hasText: onlineMigrationJobName });
|
||||||
|
statusCell = jobRow.locator("[data-automationid='DetailsRowCell'][data-automation-key='CopyJobStatus']");
|
||||||
|
await jobRow.waitFor({ state: "visible" });
|
||||||
|
|
||||||
|
// Verify job status changes to queued state
|
||||||
|
await expect(statusCell).toContainText(/running|queued|pending/i);
|
||||||
|
|
||||||
|
// Test job lifecycle management through action menu
|
||||||
|
actionMenuButton = wrapper.getByTestId(`CopyJobActionMenu/Button:${onlineMigrationJobName}`);
|
||||||
|
await actionMenuButton.click();
|
||||||
|
|
||||||
|
// Test pause functionality
|
||||||
|
const pauseAction = frame.locator(".ms-ContextualMenu-list button:has-text('Pause')");
|
||||||
|
await pauseAction.click();
|
||||||
|
|
||||||
|
const pauseResponse = await waitForApiResponse(
|
||||||
|
page,
|
||||||
|
`${targetAccountName}/dataTransferJobs/${onlineMigrationJobName}/pause`,
|
||||||
|
"POST",
|
||||||
|
);
|
||||||
|
expect(pauseResponse.ok()).toBe(true);
|
||||||
|
|
||||||
|
// Verify job status changes to paused
|
||||||
|
jobRow = jobsListContainer.locator(".ms-DetailsRow", { hasText: onlineMigrationJobName });
|
||||||
|
await jobRow.waitFor({ state: "visible", timeout: 5000 });
|
||||||
|
statusCell = jobRow.locator("[data-automationid='DetailsRowCell'][data-automation-key='CopyJobStatus']");
|
||||||
|
await expect(statusCell).toContainText(/paused/i, { timeout: 5000 });
|
||||||
|
await page.waitForTimeout(1000);
|
||||||
|
|
||||||
|
// Test cancel job functionality
|
||||||
|
actionMenuButton = wrapper.getByTestId(`CopyJobActionMenu/Button:${onlineMigrationJobName}`);
|
||||||
|
await actionMenuButton.click();
|
||||||
|
await frame.locator(".ms-ContextualMenu-list button:has-text('Cancel')").click();
|
||||||
|
|
||||||
|
// Verify cancellation confirmation dialog
|
||||||
|
await expect(frame.locator(".ms-Dialog-main")).toBeVisible({ timeout: 2000 });
|
||||||
|
await expect(frame.locator(".ms-Dialog-main")).toContainText(onlineMigrationJobName);
|
||||||
|
|
||||||
|
const cancelDialogButton = frame.locator(".ms-Dialog-main").getByTestId("DialogButton:Cancel");
|
||||||
|
await expect(cancelDialogButton).toBeVisible();
|
||||||
|
await cancelDialogButton.click();
|
||||||
|
await expect(frame.locator(".ms-Dialog-main")).not.toBeVisible();
|
||||||
|
|
||||||
|
actionMenuButton = wrapper.getByTestId(`CopyJobActionMenu/Button:${onlineMigrationJobName}`);
|
||||||
|
await actionMenuButton.click();
|
||||||
|
await frame.locator(".ms-ContextualMenu-list button:has-text('Cancel')").click();
|
||||||
|
|
||||||
|
const confirmDialogButton = frame.locator(".ms-Dialog-main").getByTestId("DialogButton:Confirm");
|
||||||
|
await expect(confirmDialogButton).toBeVisible();
|
||||||
|
await confirmDialogButton.click();
|
||||||
|
|
||||||
|
// Verify final job status is cancelled
|
||||||
|
jobRow = jobsListContainer.locator(".ms-DetailsRow", { hasText: onlineMigrationJobName });
|
||||||
|
statusCell = jobRow.locator("[data-automationid='DetailsRowCell'][data-automation-key='CopyJobStatus']");
|
||||||
|
await expect(statusCell).toContainText(/cancelled/i, { timeout: 5000 });
|
||||||
|
});
|
||||||
|
});
|
||||||
270
test/sql/containercopy/permissionsScreen.spec.ts
Normal file
270
test/sql/containercopy/permissionsScreen.spec.ts
Normal file
@@ -0,0 +1,270 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
import { expect, Frame, Locator, Page, test } from "@playwright/test";
|
||||||
|
import { set } from "lodash";
|
||||||
|
import { ContainerCopy, getAccountName, TestAccount } from "../../fx";
|
||||||
|
|
||||||
|
const VISIBLE_TIMEOUT_MS = 30 * 1000;
|
||||||
|
|
||||||
|
test.describe("Container Copy - Permission Screen Verification", () => {
|
||||||
|
let page: Page;
|
||||||
|
let wrapper: Locator;
|
||||||
|
let panel: Locator;
|
||||||
|
let frame: Frame;
|
||||||
|
let targetAccountName: string;
|
||||||
|
let expectedSourceAccountName: string;
|
||||||
|
|
||||||
|
test.beforeEach("Setup for each test", async ({ browser }) => {
|
||||||
|
page = await browser.newPage();
|
||||||
|
({ wrapper, frame } = await ContainerCopy.open(page, TestAccount.SQLContainerCopyOnly));
|
||||||
|
targetAccountName = getAccountName(TestAccount.SQLContainerCopyOnly);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach("Cleanup after each test", async () => {
|
||||||
|
await page.unroute(/.*/, (route) => route.continue());
|
||||||
|
await page.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Verify online container copy permissions panel functionality", async () => {
|
||||||
|
expect(wrapper).not.toBeNull();
|
||||||
|
|
||||||
|
// Verify all command bar buttons are visible
|
||||||
|
await wrapper.locator(".commandBarContainer").waitFor({ state: "visible", timeout: VISIBLE_TIMEOUT_MS });
|
||||||
|
|
||||||
|
const createCopyJobButton = wrapper.getByTestId("CommandBar/Button:Create Copy Job");
|
||||||
|
await expect(createCopyJobButton).toBeVisible();
|
||||||
|
await expect(wrapper.getByTestId("CommandBar/Button:Refresh")).toBeVisible();
|
||||||
|
await expect(wrapper.getByTestId("CommandBar/Button:Feedback")).toBeVisible();
|
||||||
|
|
||||||
|
// Open the Create Copy Job panel
|
||||||
|
await createCopyJobButton.click();
|
||||||
|
panel = frame.getByTestId("Panel:Create copy job");
|
||||||
|
await expect(panel).toBeVisible();
|
||||||
|
await expect(panel.getByRole("heading", { name: "Create copy job" })).toBeVisible();
|
||||||
|
|
||||||
|
// Select a different account for cross-account testing
|
||||||
|
const accountDropdown = panel.getByTestId("account-dropdown");
|
||||||
|
await accountDropdown.click();
|
||||||
|
|
||||||
|
const dropdownItemsWrapper = frame.locator("div.ms-Dropdown-items");
|
||||||
|
expect(await dropdownItemsWrapper.getAttribute("aria-label")).toEqual("Account");
|
||||||
|
|
||||||
|
const allDropdownItems = await dropdownItemsWrapper.locator(`button.ms-Dropdown-item[role='option']`).all();
|
||||||
|
|
||||||
|
const filteredItems = [];
|
||||||
|
for (const item of allDropdownItems) {
|
||||||
|
const testContent = (await item.textContent()) ?? "";
|
||||||
|
if (testContent.trim() !== targetAccountName.trim()) {
|
||||||
|
filteredItems.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filteredItems.length > 0) {
|
||||||
|
const firstDropdownItem = filteredItems[0];
|
||||||
|
expectedSourceAccountName = (await firstDropdownItem.textContent()) ?? "";
|
||||||
|
await firstDropdownItem.click();
|
||||||
|
} else {
|
||||||
|
throw new Error("No dropdown items available after filtering");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable online migration mode
|
||||||
|
const migrationTypeContainer = panel.getByTestId("migration-type");
|
||||||
|
const onlineCopyRadioButton = migrationTypeContainer.getByRole("radio", { name: /Online mode/i });
|
||||||
|
await onlineCopyRadioButton.click({ force: true });
|
||||||
|
await expect(migrationTypeContainer.getByTestId("migration-type-description-online")).toBeVisible();
|
||||||
|
|
||||||
|
await panel.getByRole("button", { name: "Next" }).click();
|
||||||
|
|
||||||
|
// Verify Assign Permissions panel for online copy
|
||||||
|
const permissionScreen = panel.getByTestId("Panel:AssignPermissionsContainer");
|
||||||
|
await expect(permissionScreen).toBeVisible();
|
||||||
|
await expect(permissionScreen.getByText("Online container copy", { exact: true })).toBeVisible();
|
||||||
|
await expect(permissionScreen.getByText("Cross-account container copy", { exact: true })).toBeVisible();
|
||||||
|
|
||||||
|
// Setup API mocking for the source account
|
||||||
|
await page.route(`**/Microsoft.DocumentDB/databaseAccounts/${expectedSourceAccountName}**`, async (route) => {
|
||||||
|
const mockData = {
|
||||||
|
identity: {
|
||||||
|
type: "SystemAssigned",
|
||||||
|
principalId: "00-11-22-33",
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
defaultIdentity: "SystemAssignedIdentity",
|
||||||
|
backupPolicy: {
|
||||||
|
type: "Continuous",
|
||||||
|
},
|
||||||
|
capabilities: [{ name: "EnableOnlineContainerCopy" }],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (route.request().method() === "GET") {
|
||||||
|
const response = await route.fetch();
|
||||||
|
const actualData = await response.json();
|
||||||
|
const mergedData = { ...actualData };
|
||||||
|
|
||||||
|
set(mergedData, "identity", mockData.identity);
|
||||||
|
set(mergedData, "properties.defaultIdentity", mockData.properties.defaultIdentity);
|
||||||
|
set(mergedData, "properties.backupPolicy", mockData.properties.backupPolicy);
|
||||||
|
set(mergedData, "properties.capabilities", mockData.properties.capabilities);
|
||||||
|
|
||||||
|
await route.fulfill({
|
||||||
|
status: 200,
|
||||||
|
contentType: "application/json",
|
||||||
|
body: JSON.stringify(mergedData),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await route.continue();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify Point-in-Time Restore functionality
|
||||||
|
const expandedOnlineAccordionHeader = permissionScreen
|
||||||
|
.getByTestId("permission-group-container-onlineConfigs")
|
||||||
|
.locator("button[aria-expanded='true']");
|
||||||
|
await expect(expandedOnlineAccordionHeader).toBeVisible();
|
||||||
|
|
||||||
|
const accordionItem = expandedOnlineAccordionHeader
|
||||||
|
.locator("xpath=ancestor::*[contains(@class, 'fui-AccordionItem') or contains(@data-test, 'accordion-item')]")
|
||||||
|
.first();
|
||||||
|
|
||||||
|
const accordionPanel = accordionItem
|
||||||
|
.locator("[role='tabpanel'], .fui-AccordionPanel, [data-test*='panel']")
|
||||||
|
.first();
|
||||||
|
|
||||||
|
// Install clock mock and test PITR functionality
|
||||||
|
await page.clock.install({ time: new Date("2024-01-01T10:00:00Z") });
|
||||||
|
|
||||||
|
const pitrBtn = accordionPanel.getByTestId("pointInTimeRestore:PrimaryBtn");
|
||||||
|
await expect(pitrBtn).toBeVisible();
|
||||||
|
await pitrBtn.click({ force: true });
|
||||||
|
|
||||||
|
// Verify new page opens with correct URL pattern
|
||||||
|
page.context().on("page", async (newPage) => {
|
||||||
|
const expectedUrlEndPattern = new RegExp(
|
||||||
|
`/providers/Microsoft.(DocumentDB|DocumentDb)/databaseAccounts/${expectedSourceAccountName}/backupRestore`,
|
||||||
|
);
|
||||||
|
expect(newPage.url()).toMatch(expectedUrlEndPattern);
|
||||||
|
await newPage.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
const loadingOverlay = frame.locator("[data-test='loading-overlay']");
|
||||||
|
await expect(loadingOverlay).toBeVisible();
|
||||||
|
|
||||||
|
const refreshBtn = accordionPanel.getByTestId("pointInTimeRestore:RefreshBtn");
|
||||||
|
await expect(refreshBtn).not.toBeVisible();
|
||||||
|
|
||||||
|
// Fast forward time by 11 minutes
|
||||||
|
await page.clock.fastForward(11 * 60 * 1000);
|
||||||
|
|
||||||
|
await expect(refreshBtn).toBeVisible({ timeout: 5000 });
|
||||||
|
await expect(pitrBtn).not.toBeVisible();
|
||||||
|
|
||||||
|
// Setup additional API mocks for role assignments and permissions
|
||||||
|
await page.route(
|
||||||
|
`**/Microsoft.DocumentDB/databaseAccounts/${expectedSourceAccountName}/sqlRoleAssignments*`,
|
||||||
|
async (route) => {
|
||||||
|
await route.fulfill({
|
||||||
|
status: 200,
|
||||||
|
contentType: "application/json",
|
||||||
|
body: JSON.stringify({
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
principalId: "00-11-22-33",
|
||||||
|
roleDefinitionId: `Microsoft.DocumentDB/databaseAccounts/${expectedSourceAccountName}/77-88-99`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
await page.route("**/Microsoft.DocumentDB/databaseAccounts/*/77-88-99**", async (route) => {
|
||||||
|
await route.fulfill({
|
||||||
|
status: 200,
|
||||||
|
contentType: "application/json",
|
||||||
|
body: JSON.stringify({
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: "00000000-0000-0000-0000-000000000001",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.route(`**/Microsoft.DocumentDB/databaseAccounts/${targetAccountName}**`, async (route) => {
|
||||||
|
const mockData = {
|
||||||
|
identity: {
|
||||||
|
type: "SystemAssigned",
|
||||||
|
principalId: "00-11-22-33",
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
defaultIdentity: "SystemAssignedIdentity",
|
||||||
|
backupPolicy: {
|
||||||
|
type: "Continuous",
|
||||||
|
},
|
||||||
|
capabilities: [{ name: "EnableOnlineContainerCopy" }],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (route.request().method() === "PATCH") {
|
||||||
|
await route.fulfill({
|
||||||
|
status: 200,
|
||||||
|
contentType: "application/json",
|
||||||
|
body: JSON.stringify({ status: "Succeeded" }),
|
||||||
|
});
|
||||||
|
} else if (route.request().method() === "GET") {
|
||||||
|
const response = await route.fetch();
|
||||||
|
const actualData = await response.json();
|
||||||
|
const mergedData = { ...actualData };
|
||||||
|
set(mergedData, "identity", mockData.identity);
|
||||||
|
set(mergedData, "properties.defaultIdentity", mockData.properties.defaultIdentity);
|
||||||
|
set(mergedData, "properties.backupPolicy", mockData.properties.backupPolicy);
|
||||||
|
set(mergedData, "properties.capabilities", mockData.properties.capabilities);
|
||||||
|
|
||||||
|
await route.fulfill({
|
||||||
|
status: 200,
|
||||||
|
contentType: "application/json",
|
||||||
|
body: JSON.stringify(mergedData),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await route.continue();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify cross-account permissions functionality
|
||||||
|
const expandedCrossAccordionHeader = permissionScreen
|
||||||
|
.getByTestId("permission-group-container-crossAccountConfigs")
|
||||||
|
.locator("button[aria-expanded='true']");
|
||||||
|
await expect(expandedCrossAccordionHeader).toBeVisible();
|
||||||
|
|
||||||
|
const crossAccordionItem = expandedCrossAccordionHeader
|
||||||
|
.locator("xpath=ancestor::*[contains(@class, 'fui-AccordionItem') or contains(@data-test, 'accordion-item')]")
|
||||||
|
.first();
|
||||||
|
|
||||||
|
const crossAccordionPanel = crossAccordionItem
|
||||||
|
.locator("[role='tabpanel'], .fui-AccordionPanel, [data-test*='panel']")
|
||||||
|
.first();
|
||||||
|
|
||||||
|
const toggleButton = crossAccordionPanel.getByTestId("btn-toggle");
|
||||||
|
await expect(toggleButton).toBeVisible();
|
||||||
|
await toggleButton.click({ force: true });
|
||||||
|
|
||||||
|
// Verify popover functionality
|
||||||
|
const popover = frame.locator("[data-test='popover-container']");
|
||||||
|
await expect(popover).toBeVisible();
|
||||||
|
|
||||||
|
const yesButton = popover.getByRole("button", { name: /Yes/i });
|
||||||
|
const noButton = popover.getByRole("button", { name: /No/i });
|
||||||
|
await expect(yesButton).toBeVisible();
|
||||||
|
await expect(noButton).toBeVisible();
|
||||||
|
|
||||||
|
await yesButton.click({ force: true });
|
||||||
|
|
||||||
|
// Verify loading states
|
||||||
|
await expect(loadingOverlay).toBeVisible();
|
||||||
|
await expect(loadingOverlay).toBeHidden({ timeout: 10 * 1000 });
|
||||||
|
await expect(popover).toBeHidden({ timeout: 10 * 1000 });
|
||||||
|
|
||||||
|
// Cancel the panel to clean up
|
||||||
|
await panel.getByRole("button", { name: "Cancel" }).click({ force: true });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -10,7 +10,7 @@ let CONTAINER_ID: string;
|
|||||||
|
|
||||||
// Set up test database and container with data before all tests
|
// Set up test database and container with data before all tests
|
||||||
test.beforeAll(async () => {
|
test.beforeAll(async () => {
|
||||||
testContainer = await createTestSQLContainer(true);
|
testContainer = await createTestSQLContainer({ includeTestData: true });
|
||||||
DATABASE_ID = testContainer.database.id;
|
DATABASE_ID = testContainer.database.id;
|
||||||
CONTAINER_ID = testContainer.container.id;
|
CONTAINER_ID = testContainer.container.id;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user