mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-31 07:34:17 +00:00
fix tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { expect, test } from "@playwright/test";
|
import { expect, test } from "@playwright/test";
|
||||||
|
|
||||||
import { existsSync, unlinkSync, writeFileSync } from "fs";
|
import { existsSync, mkdtempSync, rmdirSync, unlinkSync, writeFileSync } from "fs";
|
||||||
|
import { tmpdir } from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { CommandBarButton, DataExplorer, DocumentsTab, ONE_MINUTE_MS, TestAccount } from "../fx";
|
import { CommandBarButton, DataExplorer, DocumentsTab, ONE_MINUTE_MS, TestAccount } from "../fx";
|
||||||
import {
|
import {
|
||||||
@@ -108,9 +109,13 @@ for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
|||||||
|
|
||||||
test.describe.serial("Upload Item", () => {
|
test.describe.serial("Upload Item", () => {
|
||||||
let context: TestContainerContext = null!;
|
let context: TestContainerContext = null!;
|
||||||
const uploadDocumentFilePath: string = path.join(__dirname, "uploadDocument.json");
|
let uploadDocumentDirPath: string = null!;
|
||||||
|
let uploadDocumentFilePath: string = null!;
|
||||||
|
|
||||||
test.beforeAll("Create Test database and open documents tab", async ({ browser }) => {
|
test.beforeAll("Create Test database and open documents tab", async ({ browser }) => {
|
||||||
|
uploadDocumentDirPath = mkdtempSync(path.join(tmpdir(), "upload-document-"));
|
||||||
|
uploadDocumentFilePath = path.join(uploadDocumentDirPath, "uploadDocument.json");
|
||||||
|
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
context = await createTestSQLContainer();
|
context = await createTestSQLContainer();
|
||||||
explorer = await DataExplorer.open(page, TestAccount.SQL);
|
explorer = await DataExplorer.open(page, TestAccount.SQL);
|
||||||
@@ -124,10 +129,13 @@ test.describe.serial("Upload Item", () => {
|
|||||||
await containerMenuNode.element.click();
|
await containerMenuNode.element.click();
|
||||||
});
|
});
|
||||||
|
|
||||||
test.afterAll("Delete Test Database and uploadDocument.json", async () => {
|
test.afterAll("Delete Test Database and uploadDocument temp folder", async () => {
|
||||||
if (existsSync(uploadDocumentFilePath)) {
|
if (existsSync(uploadDocumentFilePath)) {
|
||||||
unlinkSync(uploadDocumentFilePath);
|
unlinkSync(uploadDocumentFilePath);
|
||||||
}
|
}
|
||||||
|
if (existsSync(uploadDocumentDirPath)) {
|
||||||
|
rmdirSync(uploadDocumentDirPath);
|
||||||
|
}
|
||||||
if (!process.env.CI) {
|
if (!process.env.CI) {
|
||||||
await context?.dispose();
|
await context?.dispose();
|
||||||
}
|
}
|
||||||
@@ -193,9 +201,9 @@ test.describe.serial("Upload Item", () => {
|
|||||||
await uploadButton.click();
|
await uploadButton.click();
|
||||||
|
|
||||||
// Verify upload failure message
|
// Verify upload failure message
|
||||||
const fileUploadStatusExpected: string = "Unexpected non-whitespace character after JSON";
|
|
||||||
const fileUploadErrorList = explorer.frame.getByLabel("error list");
|
const fileUploadErrorList = explorer.frame.getByLabel("error list");
|
||||||
await expect(fileUploadErrorList).toContainText(fileUploadStatusExpected, {
|
// The parsing error will show up differently in different browsers so just check for the word "JSON"
|
||||||
|
await expect(fileUploadErrorList).toContainText("JSON", {
|
||||||
timeout: ONE_MINUTE_MS,
|
timeout: ONE_MINUTE_MS,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -96,14 +96,13 @@ test.describe("Computed Properties", () => {
|
|||||||
|
|
||||||
const clearComputedPropertiesTextBoxContent = async ({ page }: { page: Page }): Promise<void> => {
|
const clearComputedPropertiesTextBoxContent = async ({ page }: { page: Page }): Promise<void> => {
|
||||||
// Get computed properties text box
|
// Get computed properties text box
|
||||||
const computedPropertiesTextBox = explorer.frame.getByRole("textbox", { name: "Computed properties" });
|
await explorer.frame.waitForSelector(".monaco-scrollable-element", { state: "visible" });
|
||||||
await computedPropertiesTextBox.waitFor();
|
|
||||||
const computedPropertiesEditor = explorer.frame.getByTestId("computed-properties-editor");
|
const computedPropertiesEditor = explorer.frame.getByTestId("computed-properties-editor");
|
||||||
await computedPropertiesEditor.click();
|
await computedPropertiesEditor.click();
|
||||||
|
|
||||||
// Clear existing content
|
// Clear existing content (Ctrl+A + Backspace does not work with webkit)
|
||||||
const isMac: boolean = process.platform === "darwin";
|
for (let i = 0; i < 100; i++) {
|
||||||
await page.keyboard.press(isMac ? "Meta+A" : "Control+A");
|
await page.keyboard.press("Backspace");
|
||||||
await page.keyboard.press("Backspace");
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ test.describe("Stored Procedures", () => {
|
|||||||
await context?.dispose();
|
await context?.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Add, execute, and delete stored procedure", async () => {
|
test("Add, execute, and delete stored procedure", async ({}, testInfo) => {
|
||||||
// Open container context menu and click New Stored Procedure
|
// Open container context menu and click New Stored Procedure
|
||||||
const containerNode = await explorer.waitForContainerNode(context.database.id, context.container.id);
|
const containerNode = await explorer.waitForContainerNode(context.database.id, context.container.id);
|
||||||
await containerNode.openContextMenu();
|
await containerNode.openContextMenu();
|
||||||
@@ -27,7 +27,7 @@ test.describe("Stored Procedures", () => {
|
|||||||
// Type stored procedure id and use stock procedure
|
// Type stored procedure id and use stock procedure
|
||||||
const storedProcedureIdTextBox = explorer.frame.getByLabel("Stored procedure id");
|
const storedProcedureIdTextBox = explorer.frame.getByLabel("Stored procedure id");
|
||||||
await storedProcedureIdTextBox.isVisible();
|
await storedProcedureIdTextBox.isVisible();
|
||||||
const storedProcedureName = "stored-procedure-1";
|
const storedProcedureName = `stored-procedure-${testInfo.testId}`;
|
||||||
await storedProcedureIdTextBox.fill(storedProcedureName);
|
await storedProcedureIdTextBox.fill(storedProcedureName);
|
||||||
|
|
||||||
const saveButton = explorer.commandBarButton(CommandBarButton.Save);
|
const saveButton = explorer.commandBarButton(CommandBarButton.Save);
|
||||||
@@ -48,7 +48,9 @@ test.describe("Stored Procedures", () => {
|
|||||||
await executeSidePanelButton.click();
|
await executeSidePanelButton.click();
|
||||||
|
|
||||||
const executeStoredProcedureResult = explorer.frame.getByLabel("Execute stored procedure result");
|
const executeStoredProcedureResult = explorer.frame.getByLabel("Execute stored procedure result");
|
||||||
await expect(executeStoredProcedureResult).toBeVisible();
|
await expect(executeStoredProcedureResult).toBeAttached({
|
||||||
|
timeout: ONE_MINUTE_MS,
|
||||||
|
});
|
||||||
|
|
||||||
// Delete stored procedure
|
// Delete stored procedure
|
||||||
await containerNode.expand();
|
await containerNode.expand();
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ test.describe("Triggers", () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
test("Add and delete trigger", async ({ page }) => {
|
test("Add and delete trigger", async ({ page }, testInfo) => {
|
||||||
// Open container context menu and click New Trigger
|
// Open container context menu and click New Trigger
|
||||||
const containerNode = await explorer.waitForContainerNode(context.database.id, context.container.id);
|
const containerNode = await explorer.waitForContainerNode(context.database.id, context.container.id);
|
||||||
await containerNode.openContextMenu();
|
await containerNode.openContextMenu();
|
||||||
@@ -40,7 +40,7 @@ test.describe("Triggers", () => {
|
|||||||
|
|
||||||
// Assign Trigger id
|
// Assign Trigger id
|
||||||
const triggerIdTextBox = explorer.frame.getByLabel("Trigger Id");
|
const triggerIdTextBox = explorer.frame.getByLabel("Trigger Id");
|
||||||
const triggerId: string = "validateItemTimestamp";
|
const triggerId: string = `validateItemTimestamp-${testInfo.testId}`;
|
||||||
await triggerIdTextBox.fill(triggerId);
|
await triggerIdTextBox.fill(triggerId);
|
||||||
|
|
||||||
// Create Trigger body that validates item timestamp
|
// Create Trigger body that validates item timestamp
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ test.describe("User Defined Functions", () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
test("Add, execute, and delete user defined function", async ({ page }) => {
|
test("Add, execute, and delete user defined function", async ({ page }, testInfo) => {
|
||||||
// Open container context menu and click New UDF
|
// Open container context menu and click New UDF
|
||||||
const containerNode = await explorer.waitForContainerNode(context.database.id, context.container.id);
|
const containerNode = await explorer.waitForContainerNode(context.database.id, context.container.id);
|
||||||
await containerNode.openContextMenu();
|
await containerNode.openContextMenu();
|
||||||
@@ -33,7 +33,7 @@ test.describe("User Defined Functions", () => {
|
|||||||
|
|
||||||
// Assign UDF id
|
// Assign UDF id
|
||||||
const udfIdTextBox = explorer.frame.getByLabel("User Defined Function Id");
|
const udfIdTextBox = explorer.frame.getByLabel("User Defined Function Id");
|
||||||
const udfId: string = "extractDocumentId";
|
const udfId: string = `extractDocumentId-${testInfo.testId}`;
|
||||||
await udfIdTextBox.fill(udfId);
|
await udfIdTextBox.fill(udfId);
|
||||||
|
|
||||||
// Create UDF body that extracts the document id from a document
|
// Create UDF body that extracts the document id from a document
|
||||||
|
|||||||
Reference in New Issue
Block a user