Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests for new dashboard view #862

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/e2e/10-landing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ test('Brief check of landing pages', async({ page, ui, nav }) => {

// Recommended policies stats
await expect1m(page.getByText('Active 1 of 1 Pods / 100%')).toBeVisible()
await expect1m(page.getByText('Active 0 of 0 Namespaced Policies / 0%')).toBeVisible()
await expect1m(page.getByText('Active 6 of 6 Global Policies / 100%')).toBeVisible()
await expect1m(page.getByText('0 Namespace Policies')).toBeVisible()
await expect1m(page.getByText('6 Cluster Policies')).toBeVisible()
})

await test.step('Policy Servers Landing Page', async() => {
Expand Down
22 changes: 13 additions & 9 deletions tests/e2e/20-kubewarden.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('Namespace 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('Namespace 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('Namespace 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('Namespace 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()
})
})
10 changes: 7 additions & 3 deletions tests/e2e/pages/kubewarden.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' | 'Namespace Policies' | 'Cluster Policies'

export interface AppVersion {
app: string
Expand All @@ -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 Namespace Policy')
this.createCapBtn = this.ui.button('Create Cluster Policy')

const head = this.page.locator('div.head')
this.currentApp = head.locator('div.head-version')
Expand All @@ -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')
}
Expand Down