From dfe10c8d52d41f1b4b0b72c539479e208ea65d26 Mon Sep 17 00:00:00 2001 From: Martin Kravec Date: Fri, 16 Aug 2024 21:18:25 +0200 Subject: [PATCH] Update tests for new dashboard view Signed-off-by: Martin Kravec --- tests/e2e/10-landing.spec.ts | 4 ++-- tests/e2e/20-kubewarden.spec.ts | 22 +++++++++++++--------- tests/e2e/pages/kubewarden.page.ts | 10 +++++++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/e2e/10-landing.spec.ts b/tests/e2e/10-landing.spec.ts index 5fa9a42f..c8080d71 100644 --- a/tests/e2e/10-landing.spec.ts +++ b/tests/e2e/10-landing.spec.ts @@ -11,9 +11,9 @@ test('Brief check of landing pages', async({ page, ui, nav }) => { await expect(head.getByText(/App Version:\s+v[1-9][0-9.]+[0-9]/)).toBeVisible() // Recommended policies stats + await expect1m(page.getByText('0Namespaced Policies')).toBeVisible() + await expect1m(page.getByText('6Cluster Policies')).toBeVisible() await expect1m(page.getByText('Active1 of 1 Pods / 100%')).toBeVisible() - await expect1m(page.getByText('Active0 of 0 Namespaced Policies / 0%')).toBeVisible() - await expect1m(page.getByText('Active6 of 6 Global Policies / 100%')).toBeVisible() }) await test.step('Policy Servers Landing Page', async() => { diff --git a/tests/e2e/20-kubewarden.spec.ts b/tests/e2e/20-kubewarden.spec.ts index fa993cf9..a8e08b11 100644 --- a/tests/e2e/20-kubewarden.spec.ts +++ b/tests/e2e/20-kubewarden.spec.ts @@ -22,37 +22,41 @@ test('Stats reflect resource changes', async({ page, nav }) => { const ps = { name: 'kw-policyserver' } const policy: Policy = { title: 'Pod Privileged Policy', name: 'kw-policy-privpod', server: ps.name } + // Get initial counts await nav.explorer('Kubewarden') + const psCount = await kwPage.getCount('Policy Servers').textContent() || 'Empty' const psStats = await kwPage.getStats('Policy Servers').textContent() || 'Empty' - const apStats = await kwPage.getStats('Admission Policies').textContent() || 'Empty' - const capStats = await kwPage.getStats('Cluster Admission Policies').textContent() || 'Empty' + const apCount = await kwPage.getCount('Namespaced Policies').textContent() || 'Empty' + const capCount = await kwPage.getCount('Cluster Policies').textContent() || 'Empty' - await test.step('Policy Server stats', async() => { + await test.step('Policy Server counter++', async() => { await kwPage.createPsBtn.click() await psPage.create(ps, { navigate: false }) await nav.explorer('Kubewarden') + await expect(kwPage.getCount('Policy Servers')).toHaveText((+psCount + 1).toString()) await expect2m(kwPage.getStats('Policy Servers').getByText(statsPlusOne(psStats))).toBeVisible() }) - await test.step('Admission Policies stats', async() => { + await test.step('Namespaced Policy counter++', async() => { await kwPage.createApBtn.click() await apPage.create(policy, { navigate: false }) await nav.explorer('Kubewarden') - await expect2m(kwPage.getStats('Admission Policies').getByText(statsPlusOne(apStats))).toBeVisible() + await expect(kwPage.getCount('Namespaced Policies')).toHaveText((+apCount + 1).toString()) }) - await test.step('Cluster Admission Policies stats', async() => { + await test.step('Cluster Policy counter++', async() => { await kwPage.createCapBtn.click() await capPage.create(policy, { navigate: false }) await nav.explorer('Kubewarden') - await expect2m(kwPage.getStats('Cluster Admission Policies').getByText(statsPlusOne(capStats))).toBeVisible() + await expect(kwPage.getCount('Cluster Policies')).toHaveText((+capCount + 1).toString()) }) await test.step('Stats after deleting resources ', async() => { await psPage.delete(ps.name) await nav.explorer('Kubewarden') + await expect(kwPage.getCount('Namespaced Policies')).toHaveText(apCount) + await expect(kwPage.getCount('Cluster Policies')).toHaveText(capCount) + await expect(kwPage.getCount('Policy Servers')).toHaveText(psCount) await expect2m(kwPage.getStats('Policy Servers').getByText(psStats)).toBeVisible() - await expect2m(kwPage.getStats('Admission Policies').getByText(apStats)).toBeVisible() - await expect2m(kwPage.getStats('Cluster Admission Policies').getByText(capStats)).toBeVisible() }) }) diff --git a/tests/e2e/pages/kubewarden.page.ts b/tests/e2e/pages/kubewarden.page.ts index dd1d6b96..2e1a901a 100644 --- a/tests/e2e/pages/kubewarden.page.ts +++ b/tests/e2e/pages/kubewarden.page.ts @@ -4,7 +4,7 @@ import { BasePage } from '../rancher/basepage' import { Shell } from '../components/kubectl-shell' import { step } from '../rancher/rancher-test' -type Pane = 'Policy Servers' | 'Admission Policies' | 'Cluster Admission Policies' +type Pane = 'Policy Servers' | 'Namespaced Policies' | 'Cluster Policies' export interface AppVersion { app: string @@ -25,8 +25,8 @@ export class KubewardenPage extends BasePage { constructor(page: Page) { super(page) this.createPsBtn = this.ui.button('Create Policy Server') - this.createApBtn = this.ui.button('Create Admission Policy') - this.createCapBtn = this.ui.button('Create Cluster Admission Policy') + this.createApBtn = this.ui.button('Create Namespaced Policy') + this.createCapBtn = this.ui.button('Create Cluster Policy') const head = this.page.locator('div.head') this.currentApp = head.locator('div.head-version') @@ -46,6 +46,10 @@ export class KubewardenPage extends BasePage { }) } + getCount(pane: Pane) { + return this.getPane(pane).locator('span.count') + } + getStats(pane: Pane) { return this.getPane(pane).locator('span.numbers-stats') }