mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-09 04:25:57 +00:00
refactor scale setup and tear down to be within each test
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { expect, Locator, test } from "@playwright/test";
|
import { expect, Locator, Page, test } from "@playwright/test";
|
||||||
import {
|
import {
|
||||||
CommandBarButton,
|
CommandBarButton,
|
||||||
DataExplorer,
|
DataExplorer,
|
||||||
@@ -9,118 +9,111 @@ import {
|
|||||||
} from "../../fx";
|
} from "../../fx";
|
||||||
import { createTestSQLContainer, TestContainerContext } from "../../testData";
|
import { createTestSQLContainer, TestContainerContext } from "../../testData";
|
||||||
|
|
||||||
test.describe.serial("Autoscale and Manual throughput", () => {
|
test.describe("Autoscale and Manual throughput", () => {
|
||||||
let context: TestContainerContext = null!;
|
const withScaleTab = async (
|
||||||
let explorer: DataExplorer = null!;
|
page: Page,
|
||||||
|
run: (args: { context: TestContainerContext; explorer: DataExplorer }) => Promise<void>,
|
||||||
|
): Promise<void> => {
|
||||||
|
const context = await createTestSQLContainer();
|
||||||
|
try {
|
||||||
|
const explorer = await DataExplorer.open(page, TestAccount.SQL);
|
||||||
|
|
||||||
test.beforeEach("Create Test Database & Open container settings", async ({ page }) => {
|
await explorer.openScaleAndSettings(context);
|
||||||
context = await createTestSQLContainer();
|
await explorer.frame.getByTestId("settings-tab-header/ScaleTab").click();
|
||||||
explorer = await DataExplorer.open(page, TestAccount.SQL);
|
|
||||||
|
|
||||||
// Click Scale & Settings and open Scale tab
|
await run({ context, explorer });
|
||||||
await explorer.openScaleAndSettings(context);
|
} finally {
|
||||||
const scaleTab = explorer.frame.getByTestId("settings-tab-header/ScaleTab");
|
await context.dispose();
|
||||||
await scaleTab.click();
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
test.afterEach("Delete Test Database", async () => {
|
const getThroughputInput = (explorer: DataExplorer, type: "manual" | "autopilot"): Locator => {
|
||||||
await context?.dispose();
|
|
||||||
});
|
|
||||||
|
|
||||||
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`);
|
return explorer.frame.getByTestId(`${type}-throughput-input`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getThroughputInputErrorMessage = (type: "manual" | "autopilot"): Locator => {
|
const getThroughputInputErrorMessage = (explorer: DataExplorer, type: "manual" | "autopilot"): Locator => {
|
||||||
return explorer.frame.getByTestId(`${type}-throughput-input-error`);
|
return explorer.frame.getByTestId(`${type}-throughput-input-error`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const switchManualToAutoscaleThroughput = async (): Promise<void> => {
|
const switchManualToAutoscaleThroughput = async (explorer: DataExplorer, containerId: string): Promise<void> => {
|
||||||
const autoscaleRadioButton = explorer.frame.getByText("Autoscale", { exact: true });
|
const autoscaleRadioButton = explorer.frame.getByText("Autoscale", { exact: true });
|
||||||
await autoscaleRadioButton.click();
|
await autoscaleRadioButton.click();
|
||||||
|
|
||||||
await expect(explorer.commandBarButton(CommandBarButton.Save)).toBeEnabled();
|
await expect(explorer.commandBarButton(CommandBarButton.Save)).toBeEnabled();
|
||||||
await explorer.commandBarButton(CommandBarButton.Save).click();
|
await explorer.commandBarButton(CommandBarButton.Save).click();
|
||||||
await expect(explorer.getConsoleMessage()).toContainText(
|
|
||||||
`Successfully updated offer for collection ${context.container.id}`,
|
await expect(explorer.getConsoleMessage()).toContainText(`Successfully updated offer for collection ${containerId}`, {
|
||||||
{
|
timeout: ONE_MINUTE_MS,
|
||||||
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",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user