From 1736e24429cdacccf8fa5de046fec09d5265d712 Mon Sep 17 00:00:00 2001 From: Asier Isayas Date: Mon, 29 Dec 2025 17:13:22 -0500 Subject: [PATCH] when disposing of database during playwright test, refresh tree to remove deleted database --- .../changePartitionKey.spec.ts | 2 +- test/sql/scaleAndSettings/scale.spec.ts | 188 +++++++++--------- test/testData.ts | 9 +- 3 files changed, 105 insertions(+), 94 deletions(-) diff --git a/test/sql/scaleAndSettings/changePartitionKey.spec.ts b/test/sql/scaleAndSettings/changePartitionKey.spec.ts index da9b422ef..21cd219ac 100644 --- a/test/sql/scaleAndSettings/changePartitionKey.spec.ts +++ b/test/sql/scaleAndSettings/changePartitionKey.spec.ts @@ -24,7 +24,7 @@ test.describe("Change Partition Key", () => { }); test.afterAll("Delete Test Database", async () => { - await context?.dispose(); + await context?.dispose(explorer); }); test("Change partition key path", async () => { diff --git a/test/sql/scaleAndSettings/scale.spec.ts b/test/sql/scaleAndSettings/scale.spec.ts index 40531572a..4d0d30ddf 100644 --- a/test/sql/scaleAndSettings/scale.spec.ts +++ b/test/sql/scaleAndSettings/scale.spec.ts @@ -1,4 +1,4 @@ -import { expect, Locator, Page, test } from "@playwright/test"; +import { expect, Locator, test } from "@playwright/test"; import { CommandBarButton, DataExplorer, @@ -10,113 +10,117 @@ import { import { createTestSQLContainer, TestContainerContext } from "../../testData"; test.describe("Autoscale and Manual throughput", () => { - const withScaleTab = async ( - page: Page, - run: (args: { context: TestContainerContext; explorer: DataExplorer }) => Promise, - ): Promise => { - const context = await createTestSQLContainer(); - try { - const explorer = await DataExplorer.open(page, TestAccount.SQL); + let context: TestContainerContext = null!; + let explorer: DataExplorer = null!; - await explorer.openScaleAndSettings(context); - await explorer.frame.getByTestId("settings-tab-header/ScaleTab").click(); + test.beforeEach("Create Test Database & Open container settings", async ({ page }) => { + context = await createTestSQLContainer(); + explorer = await DataExplorer.open(page, TestAccount.SQL); - await run({ context, explorer }); - } finally { - await context.dispose(); - } - }; + // Click Scale & Settings and open Scale tab + await explorer.openScaleAndSettings(context); + const scaleTab = explorer.frame.getByTestId("settings-tab-header/ScaleTab"); + await scaleTab.click(); + }); - const getThroughputInput = (explorer: DataExplorer, type: "manual" | "autopilot"): Locator => { + test.afterEach("Delete Test Database", async () => { + await context?.dispose(explorer); + }); + + test("Update autoscale max throughput", async () => { + // By default the created container has manual throughput (Containers created via JS SDK v4.7.0 cannot be created with autoscale throughput) + await switchManualToAutoscaleThroughput(); + + // Update autoscale max throughput + await getThroughputInput("autopilot").fill(TEST_AUTOSCALE_MAX_THROUGHPUT_RU_2K.toString()); + + // Save + await explorer.commandBarButton(CommandBarButton.Save).click(); + + // Read console message + await expect(explorer.getConsoleMessage()).toContainText( + `Successfully updated offer for collection ${context.container.id}`, + { + timeout: 2 * ONE_MINUTE_MS, + }, + ); + }); + + test("Update autoscale max throughput passed allowed limit", async () => { + // By default the created container has manual throughput (Containers created via JS SDK v4.7.0 cannot be created with autoscale throughput) + await switchManualToAutoscaleThroughput(); + + // Get soft allowed max throughput and remove commas + const softAllowedMaxThroughputString = await explorer.frame + .getByTestId("soft-allowed-maximum-throughput") + .innerText(); + const softAllowedMaxThroughput = Number(softAllowedMaxThroughputString.replace(/,/g, "")); + + // Try to set autoscale max throughput above allowed limit + await getThroughputInput("autopilot").fill((softAllowedMaxThroughput * 10).toString()); + await expect(explorer.commandBarButton(CommandBarButton.Save)).toBeDisabled(); + await expect(getThroughputInputErrorMessage("autopilot")).toContainText( + "This update isn't possible because it would increase the total throughput", + ); + }); + + test("Update autoscale max throughput with invalid increment", async () => { + // By default the created container has manual throughput (Containers created via JS SDK v4.7.0 cannot be created with autoscale throughput) + await switchManualToAutoscaleThroughput(); + + // Try to set autoscale max throughput with invalid increment + await getThroughputInput("autopilot").fill("1100"); + await expect(explorer.commandBarButton(CommandBarButton.Save)).toBeDisabled(); + await expect(getThroughputInputErrorMessage("autopilot")).toContainText( + "Throughput value must be in increments of 1000", + ); + }); + + test("Update manual throughput", async () => { + await getThroughputInput("manual").fill(TEST_MANUAL_THROUGHPUT_RU_2K.toString()); + await explorer.commandBarButton(CommandBarButton.Save).click(); + await expect(explorer.getConsoleMessage()).toContainText( + `Successfully updated offer for collection ${context.container.id}`, + { + timeout: 2 * ONE_MINUTE_MS, + }, + ); + }); + + test("Update manual throughput passed allowed limit", async () => { + // Get soft allowed max throughput and remove commas + const softAllowedMaxThroughputString = await explorer.frame + .getByTestId("soft-allowed-maximum-throughput") + .innerText(); + const softAllowedMaxThroughput = Number(softAllowedMaxThroughputString.replace(/,/g, "")); + + // Try to set manual throughput above allowed limit + await getThroughputInput("manual").fill((softAllowedMaxThroughput * 10).toString()); + await expect(explorer.commandBarButton(CommandBarButton.Save)).toBeDisabled(); + await expect(getThroughputInputErrorMessage("manual")).toContainText( + "This update isn't possible because it would increase the total throughput", + ); + }); + + // Helper methods + const getThroughputInput = (type: "manual" | "autopilot"): Locator => { return explorer.frame.getByTestId(`${type}-throughput-input`); }; - const getThroughputInputErrorMessage = (explorer: DataExplorer, type: "manual" | "autopilot"): Locator => { + const getThroughputInputErrorMessage = (type: "manual" | "autopilot"): Locator => { return explorer.frame.getByTestId(`${type}-throughput-input-error`); }; - const switchManualToAutoscaleThroughput = async (explorer: DataExplorer, containerId: string): Promise => { + const switchManualToAutoscaleThroughput = async (): Promise => { const autoscaleRadioButton = explorer.frame.getByText("Autoscale", { exact: true }); await autoscaleRadioButton.click(); - await expect(explorer.commandBarButton(CommandBarButton.Save)).toBeEnabled(); await explorer.commandBarButton(CommandBarButton.Save).click(); - await expect(explorer.getConsoleMessage()).toContainText( - `Successfully updated offer for collection ${containerId}`, + `Successfully updated offer for collection ${context.container.id}`, { timeout: ONE_MINUTE_MS, }, ); }; - - test("Update autoscale max throughput", async ({ page }) => { - await withScaleTab(page, async ({ context, explorer }) => { - await switchManualToAutoscaleThroughput(explorer, context.container.id); - - await getThroughputInput(explorer, "autopilot").fill(TEST_AUTOSCALE_MAX_THROUGHPUT_RU_2K.toString()); - await explorer.commandBarButton(CommandBarButton.Save).click(); - - await expect(explorer.getConsoleMessage()).toContainText( - `Successfully updated offer for collection ${context.container.id}`, - { timeout: 2 * ONE_MINUTE_MS }, - ); - }); - }); - - test("Update autoscale max throughput passed allowed limit", async ({ page }) => { - await withScaleTab(page, async ({ context, explorer }) => { - await switchManualToAutoscaleThroughput(explorer, context.container.id); - - const softAllowedMaxThroughputString = await explorer.frame - .getByTestId("soft-allowed-maximum-throughput") - .innerText(); - const softAllowedMaxThroughput = Number(softAllowedMaxThroughputString.replace(/,/g, "")); - - await getThroughputInput(explorer, "autopilot").fill((softAllowedMaxThroughput * 10).toString()); - await expect(explorer.commandBarButton(CommandBarButton.Save)).toBeDisabled(); - await expect(getThroughputInputErrorMessage(explorer, "autopilot")).toContainText( - "This update isn't possible because it would increase the total throughput", - ); - }); - }); - - test("Update autoscale max throughput with invalid increment", async ({ page }) => { - await withScaleTab(page, async ({ context, explorer }) => { - await switchManualToAutoscaleThroughput(explorer, context.container.id); - - await getThroughputInput(explorer, "autopilot").fill("1100"); - await expect(explorer.commandBarButton(CommandBarButton.Save)).toBeDisabled(); - await expect(getThroughputInputErrorMessage(explorer, "autopilot")).toContainText( - "Throughput value must be in increments of 1000", - ); - }); - }); - - test("Update manual throughput", async ({ page }) => { - await withScaleTab(page, async ({ context, explorer }) => { - await getThroughputInput(explorer, "manual").fill(TEST_MANUAL_THROUGHPUT_RU_2K.toString()); - await explorer.commandBarButton(CommandBarButton.Save).click(); - - await expect(explorer.getConsoleMessage()).toContainText( - `Successfully updated offer for collection ${context.container.id}`, - { timeout: 2 * ONE_MINUTE_MS }, - ); - }); - }); - - test("Update manual throughput passed allowed limit", async ({ page }) => { - await withScaleTab(page, async ({ explorer }) => { - const softAllowedMaxThroughputString = await explorer.frame - .getByTestId("soft-allowed-maximum-throughput") - .innerText(); - const softAllowedMaxThroughput = Number(softAllowedMaxThroughputString.replace(/,/g, "")); - - await getThroughputInput(explorer, "manual").fill((softAllowedMaxThroughput * 10).toString()); - await expect(explorer.commandBarButton(CommandBarButton.Save)).toBeDisabled(); - await expect(getThroughputInputErrorMessage(explorer, "manual")).toContainText( - "This update isn't possible because it would increase the total throughput", - ); - }); - }); -}); +}); \ No newline at end of file diff --git a/test/testData.ts b/test/testData.ts index 9729a90b4..647f6307b 100644 --- a/test/testData.ts +++ b/test/testData.ts @@ -5,6 +5,7 @@ import { BulkOperationType, Container, CosmosClient, CosmosClientOptions, Databa import { AzureIdentityCredentialAdapter } from "@azure/ms-rest-js"; import { + DataExplorer, generateUniqueName, getAccountName, getAzureCLICredentials, @@ -69,8 +70,14 @@ export class TestContainerContext { public testData: Map, ) {} - async dispose() { + async dispose(explorer: DataExplorer) { await this.database.delete(); + + // refresh tree to remove deleted database + if (explorer) { + const refreshButton = explorer.frame.getByTestId("Sidebar/RefreshButton"); + await refreshButton.click(); + } } }