Compare commits

..

1 Commits

Author SHA1 Message Date
Copilot
4c9dea0913 Add Playwright E2E tests for Indexing Policy (#2358)
* Initial plan

* Add Playwright test for Indexing Policy

Co-authored-by: sakshigupta12feb <206070758+sakshigupta12feb@users.noreply.github.com>

* Refactor Indexing Policy test to use Editor helper class

Co-authored-by: sakshigupta12feb <206070758+sakshigupta12feb@users.noreply.github.com>

* Address code review feedback - add helper function and improve editor handling

Co-authored-by: sakshigupta12feb <206070758+sakshigupta12feb@users.noreply.github.com>

* Further simplify code by using helper function consistently

Co-authored-by: sakshigupta12feb <206070758+sakshigupta12feb@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sakshigupta12feb <206070758+sakshigupta12feb@users.noreply.github.com>
2026-01-27 21:50:07 +05:30
5 changed files with 173 additions and 76 deletions

View File

@@ -16,7 +16,7 @@ import {
import { useIndexingPolicyStore } from "Explorer/Tabs/QueryTab/ResultsView"; import { useIndexingPolicyStore } from "Explorer/Tabs/QueryTab/ResultsView";
import { useDatabases } from "Explorer/useDatabases"; import { useDatabases } from "Explorer/useDatabases";
import { isFabricNative } from "Platform/Fabric/FabricUtil"; import { isFabricNative } from "Platform/Fabric/FabricUtil";
import { isVectorSearchEnabled } from "Utils/CapabilityUtils"; import { isCapabilityEnabled, isVectorSearchEnabled } from "Utils/CapabilityUtils";
import { isRunningOnPublicCloud } from "Utils/CloudUtils"; import { isRunningOnPublicCloud } from "Utils/CloudUtils";
import * as React from "react"; import * as React from "react";
import DiscardIcon from "../../../../images/discard.svg"; import DiscardIcon from "../../../../images/discard.svg";
@@ -70,7 +70,6 @@ import {
getMongoNotification, getMongoNotification,
getTabTitle, getTabTitle,
hasDatabaseSharedThroughput, hasDatabaseSharedThroughput,
isDataMaskingEnabled,
isDirty, isDirty,
parseConflictResolutionMode, parseConflictResolutionMode,
parseConflictResolutionProcedure, parseConflictResolutionProcedure,
@@ -1074,8 +1073,8 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
newCollection.fullTextPolicy = this.state.fullTextPolicy; newCollection.fullTextPolicy = this.state.fullTextPolicy;
// Only send data masking policy if it was modified (dirty) and data masking is enabled // Only send data masking policy if it was modified (dirty)
if (this.state.isDataMaskingDirty && isDataMaskingEnabled(this.collection.dataMaskingPolicy?.())) { if (this.state.isDataMaskingDirty && isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking)) {
newCollection.dataMaskingPolicy = this.state.dataMaskingContent; newCollection.dataMaskingPolicy = this.state.dataMaskingContent;
} }
@@ -1464,7 +1463,15 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
}); });
} }
if (isDataMaskingEnabled(this.collection.dataMaskingPolicy?.())) { // Check if DDM should be enabled
const shouldEnableDDM = (): boolean => {
const hasDataMaskingCapability = isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking);
const isSqlAccount = userContext.apiType === "SQL";
return isSqlAccount && hasDataMaskingCapability; // Only show for SQL accounts with DDM capability
};
if (shouldEnableDDM()) {
const dataMaskingComponentProps: DataMaskingComponentProps = { const dataMaskingComponentProps: DataMaskingComponentProps = {
shouldDiscardDataMasking: this.state.shouldDiscardDataMasking, shouldDiscardDataMasking: this.state.shouldDiscardDataMasking,
resetShouldDiscardDataMasking: this.resetShouldDiscardDataMasking, resetShouldDiscardDataMasking: this.resetShouldDiscardDataMasking,

View File

@@ -1,10 +1,12 @@
import { MessageBar, MessageBarType, Stack } from "@fluentui/react"; import { MessageBar, MessageBarType, Stack } from "@fluentui/react";
import * as monaco from "monaco-editor"; import * as monaco from "monaco-editor";
import * as React from "react"; import * as React from "react";
import * as Constants from "../../../../Common/Constants";
import * as DataModels from "../../../../Contracts/DataModels"; import * as DataModels from "../../../../Contracts/DataModels";
import { isCapabilityEnabled } from "../../../../Utils/CapabilityUtils";
import { loadMonaco } from "../../../LazyMonaco"; import { loadMonaco } from "../../../LazyMonaco";
import { titleAndInputStackProps, unsavedEditorWarningMessage } from "../SettingsRenderUtils"; import { titleAndInputStackProps, unsavedEditorWarningMessage } from "../SettingsRenderUtils";
import { isDataMaskingEnabled, isDirty as isContentDirty } from "../SettingsUtils"; import { isDirty as isContentDirty } from "../SettingsUtils";
export interface DataMaskingComponentProps { export interface DataMaskingComponentProps {
shouldDiscardDataMasking: boolean; shouldDiscardDataMasking: boolean;
@@ -138,7 +140,7 @@ export class DataMaskingComponent extends React.Component<DataMaskingComponentPr
}; };
public render(): JSX.Element { public render(): JSX.Element {
if (!isDataMaskingEnabled(this.props.dataMaskingContent)) { if (!isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking)) {
return null; return null;
} }

View File

@@ -2,8 +2,6 @@ import * as Constants from "../../../Common/Constants";
import * as DataModels from "../../../Contracts/DataModels"; import * as DataModels from "../../../Contracts/DataModels";
import * as ViewModels from "../../../Contracts/ViewModels"; import * as ViewModels from "../../../Contracts/ViewModels";
import { isFabricNative } from "../../../Platform/Fabric/FabricUtil"; import { isFabricNative } from "../../../Platform/Fabric/FabricUtil";
import { userContext } from "../../../UserContext";
import { isCapabilityEnabled } from "../../../Utils/CapabilityUtils";
import { MongoIndex } from "../../../Utils/arm/generatedClients/cosmos/types"; import { MongoIndex } from "../../../Utils/arm/generatedClients/cosmos/types";
const zeroValue = 0; const zeroValue = 0;
@@ -90,19 +88,6 @@ export const hasDatabaseSharedThroughput = (collection: ViewModels.Collection):
return database?.isDatabaseShared() && !collection.offer(); return database?.isDatabaseShared() && !collection.offer();
}; };
export const isDataMaskingEnabled = (dataMaskingPolicy?: DataModels.DataMaskingPolicy): boolean => {
const isSqlAccount = userContext.apiType === "SQL";
if (!isSqlAccount) {
return false;
}
const hasDataMaskingCapability = isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking);
const hasDataMaskingPolicyFromCollection =
dataMaskingPolicy?.includedPaths?.length > 0 || dataMaskingPolicy?.excludedPaths?.length > 0;
return hasDataMaskingCapability || hasDataMaskingPolicyFromCollection;
};
export const parseConflictResolutionMode = (modeFromBackend: string): DataModels.ConflictResolutionMode => { export const parseConflictResolutionMode = (modeFromBackend: string): DataModels.ConflictResolutionMode => {
// Backend can contain different casing as it does case-insensitive comparisson // Backend can contain different casing as it does case-insensitive comparisson
if (!modeFromBackend) { if (!modeFromBackend) {

View File

@@ -604,60 +604,6 @@ exports[`SettingsComponent renders 1`] = `
/> />
</Stack> </Stack>
</PivotItem> </PivotItem>
<PivotItem
headerButtonProps={
{
"data-test": "settings-tab-header/DataMaskingTab",
}
}
headerText="Masking Policy (preview)"
itemKey="DataMaskingTab"
key="DataMaskingTab"
style={
{
"backgroundColor": "var(--colorNeutralBackground1)",
"color": "var(--colorNeutralForeground1)",
"marginTop": 20,
}
}
>
<Stack
styles={
{
"root": {
"backgroundColor": "var(--colorNeutralBackground1)",
"color": "var(--colorNeutralForeground1)",
},
}
}
>
<DataMaskingComponent
dataMaskingContent={
{
"excludedPaths": [
"/excludedPath",
],
"includedPaths": [],
"isPolicyEnabled": true,
}
}
dataMaskingContentBaseline={
{
"excludedPaths": [
"/excludedPath",
],
"includedPaths": [],
"isPolicyEnabled": true,
}
}
onDataMaskingContentChange={[Function]}
onDataMaskingDirtyChange={[Function]}
resetShouldDiscardDataMasking={[Function]}
shouldDiscardDataMasking={false}
validationErrors={[]}
/>
</Stack>
</PivotItem>
<PivotItem <PivotItem
headerButtonProps={ headerButtonProps={
{ {

View File

@@ -0,0 +1,157 @@
import { expect, test } from "@playwright/test";
import { CommandBarButton, DataExplorer, Editor, ONE_MINUTE_MS, TestAccount } from "../../fx";
import { createTestSQLContainer, TestContainerContext } from "../../testData";
test.describe("Indexing Policy under Scale & Settings", () => {
let context: TestContainerContext = null!;
let explorer: DataExplorer = null!;
// Helper function to get the indexing policy editor
const getIndexingPolicyEditor = (): Editor => {
const editorContainer = explorer.frame.locator(".settingsV2Editor");
return new Editor(explorer.frame, editorContainer);
};
test.beforeAll("Create Test Database & Open Indexing Policy tab", async ({ browser }) => {
context = await createTestSQLContainer();
const page = await browser.newPage();
explorer = await DataExplorer.open(page, TestAccount.SQL);
// Click Scale & Settings and open Indexing Policy tab
await explorer.openScaleAndSettings(context);
const indexingPolicyTab = explorer.frame.getByTestId("settings-tab-header/IndexingPolicyTab");
await indexingPolicyTab.click();
});
test.afterAll("Delete Test Database", async () => {
await context?.dispose();
});
test("Verify Indexing Policy tab is visible", async () => {
const indexingPolicyTab = explorer.frame.getByTestId("settings-tab-header/IndexingPolicyTab");
await expect(indexingPolicyTab).toBeVisible();
});
test("Verify Indexing Policy editor is present", async () => {
// The Monaco editor is rendered in a div with class settingsV2Editor
const editorContainer = explorer.frame.locator(".settingsV2Editor");
await expect(editorContainer).toBeVisible();
// Verify the editor has content (default indexing policy) using Editor helper
const editor = getIndexingPolicyEditor();
const editorContent = await editor.text();
expect(editorContent).toBeTruthy();
});
test("Update Indexing Policy - Change automatic to false", async () => {
// Use helper function to get editor instance
const editor = getIndexingPolicyEditor();
// Verify the Monaco editor is visible
const editorElement = explorer.frame.locator(".settingsV2Editor").locator(".monaco-editor");
await expect(editorElement).toBeVisible();
// Get current indexing policy content
const currentContent = await editor.text();
expect(currentContent).toBeTruthy();
const indexingPolicy = JSON.parse(currentContent as string);
// Verify default policy structure
expect(indexingPolicy).toHaveProperty("automatic");
expect(indexingPolicy).toHaveProperty("indexingMode");
// Modify the indexing policy - change automatic to false
indexingPolicy.automatic = false;
const updatedContent = JSON.stringify(indexingPolicy, null, 4);
// Set the new content in the editor
await editor.setText(updatedContent);
// Verify the warning message appears for unsaved changes
const warningMessage = explorer.frame.locator(".ms-MessageBar--warning");
await expect(warningMessage).toBeVisible({ timeout: 5000 });
// Save the changes
await explorer.commandBarButton(CommandBarButton.Save).click();
// Verify success message
await expect(explorer.getConsoleHeaderStatus()).toContainText(
`Successfully updated container ${context.container.id}`,
{
timeout: 2 * ONE_MINUTE_MS,
},
);
// Verify warning message is no longer visible after save
await expect(warningMessage).not.toBeVisible({ timeout: 5000 });
});
test("Update Indexing Policy - Change indexingMode to lazy", async () => {
// Use helper function to get editor instance
const editor = getIndexingPolicyEditor();
// Verify the Monaco editor is visible
const editorElement = explorer.frame.locator(".settingsV2Editor").locator(".monaco-editor");
await expect(editorElement).toBeVisible();
// Get current indexing policy content
const currentContent = await editor.text();
expect(currentContent).toBeTruthy();
const indexingPolicy = JSON.parse(currentContent as string);
// Modify the indexing policy - change indexingMode to lazy
indexingPolicy.indexingMode = "lazy";
const updatedContent = JSON.stringify(indexingPolicy, null, 4);
// Set the new content in the editor
await editor.setText(updatedContent);
// Verify the warning message appears
const warningMessage = explorer.frame.locator(".ms-MessageBar--warning");
await expect(warningMessage).toBeVisible({ timeout: 5000 });
// Save the changes
await explorer.commandBarButton(CommandBarButton.Save).click();
// Verify success message
await expect(explorer.getConsoleHeaderStatus()).toContainText(
`Successfully updated container ${context.container.id}`,
{
timeout: 2 * ONE_MINUTE_MS,
},
);
});
test("Update Indexing Policy - Revert automatic to true", async () => {
// Use helper function to get editor instance
const editor = getIndexingPolicyEditor();
// Verify the Monaco editor is visible
const editorElement = explorer.frame.locator(".settingsV2Editor").locator(".monaco-editor");
await expect(editorElement).toBeVisible();
// Get current indexing policy content
const currentContent = await editor.text();
expect(currentContent).toBeTruthy();
const indexingPolicy = JSON.parse(currentContent as string);
// Revert the changes - set automatic back to true and indexingMode to consistent
indexingPolicy.automatic = true;
indexingPolicy.indexingMode = "consistent";
const updatedContent = JSON.stringify(indexingPolicy, null, 4);
// Set the new content in the editor
await editor.setText(updatedContent);
// Save the changes
await explorer.commandBarButton(CommandBarButton.Save).click();
// Verify success message
await expect(explorer.getConsoleHeaderStatus()).toContainText(
`Successfully updated container ${context.container.id}`,
{
timeout: 2 * ONE_MINUTE_MS,
},
);
});
});