mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-19 08:51:24 +00:00
Pk missing fix (#2107)
* fix partition key missing not being able to load the document * Implement E2E tests for documents with different partitionkeys * Implement E2E tests for documents with different partitionkeys * Implement E2E tests for documents with different partitionkeys * Updated snapshot * Updated tests for MongoRU and add create/delete tests * Fixing system partition key showing up in Data Explorer
This commit is contained in:
93
test/sql/document.spec.ts
Normal file
93
test/sql/document.spec.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
import { DataExplorer, DocumentsTab, TestAccount } from "../fx";
|
||||
import { retry, setPartitionKeys } from "../testData";
|
||||
import { documentTestCases } from "./testCases";
|
||||
|
||||
let explorer: DataExplorer = null!;
|
||||
let documentsTab: DocumentsTab = null!;
|
||||
|
||||
for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
||||
test.describe(`Test SQL Documents with ${name}`, () => {
|
||||
test.beforeEach("Open documents tab", async ({ page }) => {
|
||||
explorer = await DataExplorer.open(page, TestAccount.SQLReadOnly);
|
||||
|
||||
const containerNode = await explorer.waitForContainerNode(databaseId, containerId);
|
||||
await containerNode.expand();
|
||||
|
||||
const containerMenuNode = await explorer.waitForContainerItemsNode(databaseId, containerId);
|
||||
await containerMenuNode.element.click();
|
||||
|
||||
documentsTab = explorer.documentsTab("tab0");
|
||||
|
||||
await documentsTab.documentsFilter.waitFor();
|
||||
await documentsTab.documentsListPane.waitFor();
|
||||
await expect(documentsTab.resultsEditor.locator).toBeAttached({ timeout: 60 * 1000 });
|
||||
});
|
||||
|
||||
for (const document of documents) {
|
||||
const { documentId: docId, partitionKeys } = document;
|
||||
test.describe(`Document ID: ${docId}`, () => {
|
||||
test(`should load and view document ${docId}`, async () => {
|
||||
const span = documentsTab.documentsListPane.getByText(docId, { exact: true }).nth(0);
|
||||
await span.waitFor();
|
||||
await expect(span).toBeVisible();
|
||||
|
||||
await span.click();
|
||||
await expect(documentsTab.resultsEditor.locator).toBeAttached({ timeout: 60 * 1000 });
|
||||
|
||||
const resultText = await documentsTab.resultsEditor.text();
|
||||
const resultData = JSON.parse(resultText!);
|
||||
expect(resultText).not.toBeNull();
|
||||
expect(resultData?.id).toEqual(docId);
|
||||
});
|
||||
test(`should be able to create and delete new document from ${docId}`, async ({ page }) => {
|
||||
const span = documentsTab.documentsListPane.getByText(docId, { exact: true }).nth(0);
|
||||
await span.waitFor();
|
||||
await expect(span).toBeVisible();
|
||||
|
||||
await span.click();
|
||||
let newDocumentId;
|
||||
await page.waitForTimeout(5000);
|
||||
await retry(async () => {
|
||||
// const discardButton = await explorer.waitForCommandBarButton("Discard", 5000);
|
||||
// if (await discardButton.isEnabled()) {
|
||||
// await discardButton.click();
|
||||
// }
|
||||
const newDocumentButton = await explorer.waitForCommandBarButton("New Item", 5000);
|
||||
await expect(newDocumentButton).toBeVisible();
|
||||
await expect(newDocumentButton).toBeEnabled();
|
||||
await newDocumentButton.click();
|
||||
|
||||
await expect(documentsTab.resultsEditor.locator).toBeAttached({ timeout: 60 * 1000 });
|
||||
|
||||
newDocumentId = `${Date.now().toString()}-delete`;
|
||||
|
||||
const newDocument = {
|
||||
id: newDocumentId,
|
||||
...setPartitionKeys(partitionKeys || []),
|
||||
};
|
||||
|
||||
await documentsTab.resultsEditor.setText(JSON.stringify(newDocument));
|
||||
const saveButton = await explorer.waitForCommandBarButton("Save", 5000);
|
||||
await saveButton.click({ timeout: 5000 });
|
||||
}, 3);
|
||||
|
||||
const newSpan = documentsTab.documentsListPane.getByText(newDocumentId, { exact: true }).nth(0);
|
||||
await newSpan.waitFor();
|
||||
await newSpan.click();
|
||||
await expect(documentsTab.resultsEditor.locator).toBeAttached({ timeout: 60 * 1000 });
|
||||
|
||||
const deleteButton = await explorer.waitForCommandBarButton("Delete", 5000);
|
||||
await deleteButton.click();
|
||||
|
||||
const deleteDialogButton = await explorer.waitForDialogButton("Delete", 5000);
|
||||
await deleteDialogButton.click();
|
||||
|
||||
const deletedSpan = documentsTab.documentsListPane.getByText(newDocumentId, { exact: true }).nth(0);
|
||||
await expect(deletedSpan).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
235
test/sql/testCases.ts
Normal file
235
test/sql/testCases.ts
Normal file
@@ -0,0 +1,235 @@
|
||||
import { DocumentTestCase } from "../testData";
|
||||
|
||||
export const documentTestCases: DocumentTestCase[] = [
|
||||
{
|
||||
name: "System Partition Key",
|
||||
databaseId: "e2etests-sql-readonly",
|
||||
containerId: "systemPartitionKey",
|
||||
documents: [{ documentId: "systempartition", partitionKeys: [] }],
|
||||
},
|
||||
{
|
||||
name: "Single Partition Key",
|
||||
databaseId: "e2etests-sql-readonly",
|
||||
containerId: "singlePartitionKey",
|
||||
documents: [
|
||||
{
|
||||
documentId: "singlePartitionKey",
|
||||
partitionKeys: [{ key: "/singlePartitionKey", value: "singlePartitionKey" }],
|
||||
},
|
||||
{
|
||||
documentId: "singlePartitionKey_empty_string",
|
||||
partitionKeys: [{ key: "/singlePartitionKey", value: "" }],
|
||||
},
|
||||
{
|
||||
documentId: "singlePartitionKey_null",
|
||||
partitionKeys: [{ key: "/singlePartitionKey", value: null }],
|
||||
},
|
||||
{
|
||||
documentId: "singlePartitionKey_missing",
|
||||
partitionKeys: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Single Nested Partition Key",
|
||||
databaseId: "e2etests-sql-readonly",
|
||||
containerId: "singleNestedPartitionKey",
|
||||
documents: [
|
||||
{
|
||||
documentId: "singlePartitionKey_nested",
|
||||
partitionKeys: [{ key: "/singlePartitionKey/nested", value: "nestedValue" }],
|
||||
},
|
||||
{
|
||||
documentId: "singlePartitionKey_nested_empty_string",
|
||||
partitionKeys: [{ key: "/singlePartitionKey/nested", value: "" }],
|
||||
},
|
||||
{
|
||||
documentId: "singlePartitionKey_nested_null",
|
||||
partitionKeys: [{ key: "/singlePartitionKey/nested", value: null }],
|
||||
},
|
||||
{
|
||||
documentId: "singlePartitionKey_nested_missing",
|
||||
partitionKeys: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "2-Level Hierarchical Partition Key",
|
||||
databaseId: "e2etests-sql-readonly",
|
||||
containerId: "twoLevelPartitionKey",
|
||||
documents: [
|
||||
{
|
||||
documentId: "twoLevelPartitionKey_value_empty",
|
||||
partitionKeys: [
|
||||
{ key: "/twoLevelPartitionKey_1", value: "value" },
|
||||
{ key: "/twoLevelPartitionKey_2", value: "" },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "twoLevelPartitionKey_value_null",
|
||||
partitionKeys: [
|
||||
{ key: "/twoLevelPartitionKey_1", value: "value" },
|
||||
{ key: "/twoLevelPartitionKey_2", value: null },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "twoLevelPartitionKey_value_missing",
|
||||
partitionKeys: [{ key: "/twoLevelPartitionKey_1", value: "value" }],
|
||||
},
|
||||
{
|
||||
documentId: "twoLevelPartitionKey_empty_null",
|
||||
partitionKeys: [
|
||||
{ key: "/twoLevelPartitionKey_1", value: "" },
|
||||
{ key: "/twoLevelPartitionKey_2", value: null },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "twoLevelPartitionKey_null_missing",
|
||||
partitionKeys: [{ key: "/twoLevelPartitionKey_1", value: null }],
|
||||
},
|
||||
{
|
||||
documentId: "twoLevelPartitionKey_missing_value",
|
||||
partitionKeys: [{ key: "/twoLevelPartitionKey_2", value: "value" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "2-Level Hierarchical Nested Partition Key",
|
||||
databaseId: "e2etests-sql-readonly",
|
||||
containerId: "twoLevelNestedPartitionKey",
|
||||
documents: [
|
||||
{
|
||||
documentId: "twoLevelNestedPartitionKey_nested_value_empty",
|
||||
partitionKeys: [
|
||||
{ key: "/twoLevelNestedPartitionKey/nested", value: "value" },
|
||||
{ key: "/twoLevelNestedPartitionKey/nested_value/nested", value: "" },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "twoLevelNestedPartitionKey_nested_null_missing",
|
||||
partitionKeys: [{ key: "/twoLevelNestedPartitionKey/nested", value: null }],
|
||||
},
|
||||
{
|
||||
documentId: "twoLevelNestedPartitionKey_nested_missing_value",
|
||||
partitionKeys: [{ key: "/twoLevelNestedPartitionKey/nested_value/nested", value: "value" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "3-Level Hierarchical Partition Key",
|
||||
databaseId: "e2etests-sql-readonly",
|
||||
containerId: "threeLevelPartitionKey",
|
||||
documents: [
|
||||
{
|
||||
documentId: "threeLevelPartitionKey_value_empty_null",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1", value: "value" },
|
||||
{ key: "/threeLevelPartitionKey_2", value: "" },
|
||||
{ key: "/threeLevelPartitionKey_3", value: null },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelPartitionKey_value_null_missing",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1", value: "value" },
|
||||
{ key: "/threeLevelPartitionKey_2", value: null },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelPartitionKey_value_missing_null",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1", value: "value" },
|
||||
{ key: "/threeLevelPartitionKey_3", value: null },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelPartitionKey_null_empty_value",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1", value: null },
|
||||
{ key: "/threeLevelPartitionKey_2", value: "" },
|
||||
{ key: "/threeLevelPartitionKey_3", value: "value" },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelPartitionKey_missing_value_value",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_2", value: "value" },
|
||||
{ key: "/threeLevelPartitionKey_3", value: "value" },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelPartitionKey_empty_value_missing",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1", value: "" },
|
||||
{ key: "/threeLevelPartitionKey_2", value: "value" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "3-Level Nested Hierarchical Partition Key",
|
||||
databaseId: "e2etests-sql-readonly",
|
||||
containerId: "threeLevelNestedPartitionKey",
|
||||
documents: [
|
||||
{
|
||||
documentId: "threeLevelNestedPartitionKey_nested_empty_value_null",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_key", value: "" },
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_key", value: "value" },
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_3/nested_key", value: null },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelNestedPartitionKey_nested_null_value_missing",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_key", value: null },
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_key", value: "value" },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelNestedPartitionKey_nested_missing_value_null",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_key", value: "value" },
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_3/nested_key", value: null },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelNestedPartitionKey_nested_null_empty_missing",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_key", value: null },
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_key", value: "" },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelNestedPartitionKey_nested_value_missing_empty",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_key", value: "value" },
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_3/nested_key", value: "" },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelNestedPartitionKey_nested_missing_null_empty",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_key", value: null },
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_3/nested_key", value: "" },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelNestedPartitionKey_nested_empty_null_value",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_key", value: "" },
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_key", value: null },
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_3/nested_key", value: "value" },
|
||||
],
|
||||
},
|
||||
{
|
||||
documentId: "threeLevelNestedPartitionKey_nested_value_null_empty",
|
||||
partitionKeys: [
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_key", value: "value" },
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_key", value: null },
|
||||
{ key: "/threeLevelPartitionKey_1/nested/nested_2/nested_3/nested_key", value: "" },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user