Skip to content

Commit

Permalink
chore(tests) created tests for instance and profile panels WD-7370
Browse files Browse the repository at this point in the history
Signed-off-by: Mason Hu <[email protected]>
  • Loading branch information
mas-who committed Nov 28, 2023
1 parent 1c2828e commit ccf07a8
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/helpers/instancePanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Page, expect } from "@playwright/test";
import { TIMEOUT } from "./constants";

export const openInstancePanel = async (page: Page, instance: string) => {
await page.goto("/ui/");
const instanceRow = page.getByRole("row", { name: instance }).first();
await instanceRow.waitFor({ state: "visible" });
const cells = instanceRow.locator(":has-text('Container')");
await cells.click();
const instanceDetailPanel = page.locator("css=.detail-panel", {
hasText: "instance summary",
});
await expect(instanceDetailPanel).toBeVisible(TIMEOUT);
};

export const closeInstancePanel = async (page: Page) => {
const closeButton = page.locator("css=button[aria-label=Close]");
await closeButton.click();
const instanceDetailPanel = page.locator("css=.detail-panel", {
hasText: "instance summary",
});
await expect(instanceDetailPanel).toHaveCount(0, TIMEOUT);
};

export const startInstanceFromPanel = async (page: Page, instance: string) => {
const instanceDetailPanel = page.locator("css=.detail-panel", {
hasText: "instance summary",
});
const startButton = instanceDetailPanel.locator("css=button[title=Start]");
await startButton.click();
await page.waitForSelector(`text=Instance ${instance} started.`, TIMEOUT);
};

export const stopInstanceFromPanel = async (page: Page, instance: string) => {
const instanceDetailPanel = page.locator("css=.detail-panel", {
hasText: "instance summary",
});
const stopButton = instanceDetailPanel.locator("css=button[title=Stop]");
await stopButton.click();
const confirmModal = page.locator("css=.p-modal");
await confirmModal.waitFor({ state: "visible" });
const confirmStopButton = confirmModal.locator("css=button", {
hasText: "Stop",
});
await confirmStopButton.click();
await page.waitForSelector(`text=Instance ${instance} stopped.`, TIMEOUT);
};

export const navigateToInstanceDetails = async (
page: Page,
instance: string,
) => {
const instanceDetailPanel = page.locator("css=.detail-panel", {
hasText: "instance summary",
});
const detailLink = instanceDetailPanel.locator("css=a", {
hasText: instance,
});
await detailLink.click();
const instanceDetailTitle = page.locator("css=.instance-detail-title", {
hasText: instance,
});
await expect(instanceDetailTitle).toBeVisible(TIMEOUT);
};
36 changes: 36 additions & 0 deletions tests/helpers/profileSummaryPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Page, expect } from "@playwright/test";
import { TIMEOUT } from "./constants";

export const openProfileSummaryPanel = async (page: Page, profile: string) => {
const profileRow = page.locator("css=tr[role=row]", { hasText: profile });
await profileRow.waitFor({ state: "visible" });
const cells = await profileRow.locator("css=td").all();
await cells[1].click();
const profileSummaryPanel = page.locator("css=.detail-panel", {
hasText: "profile summary",
});
await expect(profileSummaryPanel).toBeVisible(TIMEOUT);
};

export const closeProfileSummaryPanel = async (page: Page) => {
const closeButton = page.locator("css=button[aria-label=Close]");
await closeButton.click();
const profileSummaryPanel = page.locator("css=.detail-panel", {
hasText: "profile summary",
});
await expect(profileSummaryPanel).toHaveCount(0, TIMEOUT);
};

export const navigateToProfileDetails = async (page: Page, profile: string) => {
const profileSummaryPanel = page.locator("css=.detail-panel", {
hasText: "profile summary",
});
const detailLink = profileSummaryPanel.locator("css=a", {
hasText: profile,
});
await detailLink.click();
const profileDetailTitle = page.locator("css=.p-panel__title", {
hasText: profile,
});
await expect(profileDetailTitle).toBeVisible(TIMEOUT);
};
40 changes: 40 additions & 0 deletions tests/instance-panel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { test } from "@playwright/test";
import {
createInstance,
deleteInstance,
randomInstanceName,
} from "./helpers/instances";
// eslint-disable-next-line prettier/prettier
import {
closeInstancePanel,
navigateToInstanceDetails,
openInstancePanel,
startInstanceFromPanel,
stopInstanceFromPanel,
} from "./helpers/instancePanel";

test("instance panel open and close", async ({ page }) => {
const instance = randomInstanceName();
await createInstance(page, instance);
await openInstancePanel(page, instance);
await closeInstancePanel(page);
await deleteInstance(page, instance);
});

test("start and stop instance from panel", async ({ page }) => {
const instance = randomInstanceName();
await createInstance(page, instance);
await openInstancePanel(page, instance);
await startInstanceFromPanel(page, instance);
await stopInstanceFromPanel(page, instance);
await closeInstancePanel(page);
await deleteInstance(page, instance);
});

test("navigate to instance details from panel", async ({ page }) => {
const instance = randomInstanceName();
await createInstance(page, instance);
await openInstancePanel(page, instance);
await navigateToInstanceDetails(page, instance);
await deleteInstance(page, instance);
});
27 changes: 27 additions & 0 deletions tests/profile-summary-panel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { test } from "@playwright/test";
import {
createProfile,
deleteProfile,
randomProfileName,
} from "./helpers/profile";
import {
openProfileSummaryPanel,
closeProfileSummaryPanel,
navigateToProfileDetails,
} from "./helpers/profileSummaryPanel";

test("profile summary panel open and close", async ({ page }) => {
const profile = randomProfileName();
await createProfile(page, profile);
await openProfileSummaryPanel(page, profile);
await closeProfileSummaryPanel(page);
await deleteProfile(page, profile);
});

test("navigate to profile detail from panel", async ({ page }) => {
const profile = randomProfileName();
await createProfile(page, profile);
await openProfileSummaryPanel(page, profile);
await navigateToProfileDetails(page, profile);
await deleteProfile(page, profile);
});

0 comments on commit ccf07a8

Please sign in to comment.