From ec75d8cdcfde57fea0e4c748155ca768661a0206 Mon Sep 17 00:00:00 2001 From: Mason Hu Date: Tue, 28 Nov 2023 18:23:58 +0200 Subject: [PATCH] chore(tests) created tests for instance and profile panels WD-7370 Signed-off-by: Mason Hu --- tests/helpers/instancePanel.ts | 64 ++++++++++++++++++++++++++++ tests/helpers/profileSummaryPanel.ts | 36 ++++++++++++++++ tests/instance-panel.spec.ts | 40 +++++++++++++++++ tests/profile-summary-panel.spec.ts | 27 ++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 tests/helpers/instancePanel.ts create mode 100644 tests/helpers/profileSummaryPanel.ts create mode 100644 tests/instance-panel.spec.ts create mode 100644 tests/profile-summary-panel.spec.ts diff --git a/tests/helpers/instancePanel.ts b/tests/helpers/instancePanel.ts new file mode 100644 index 0000000000..20eaa96b77 --- /dev/null +++ b/tests/helpers/instancePanel.ts @@ -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); +}; diff --git a/tests/helpers/profileSummaryPanel.ts b/tests/helpers/profileSummaryPanel.ts new file mode 100644 index 0000000000..7ef4e963b2 --- /dev/null +++ b/tests/helpers/profileSummaryPanel.ts @@ -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); +}; diff --git a/tests/instance-panel.spec.ts b/tests/instance-panel.spec.ts new file mode 100644 index 0000000000..9188ac8917 --- /dev/null +++ b/tests/instance-panel.spec.ts @@ -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); +}); diff --git a/tests/profile-summary-panel.spec.ts b/tests/profile-summary-panel.spec.ts new file mode 100644 index 0000000000..5da72effaf --- /dev/null +++ b/tests/profile-summary-panel.spec.ts @@ -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); +});