|
| 1 | +import { createBdd } from "playwright-bdd"; |
| 2 | +import { expect } from "playwright/test"; |
| 3 | +import { ToolbarTable } from "../../helpers/ToolbarTable"; |
| 4 | +import { SearchPage } from "../../helpers/SearchPage"; |
| 5 | + |
| 6 | +export const { Given, When, Then } = createBdd(); |
| 7 | + |
| 8 | +const VULN_TABLE_NAME = "vulnerability table"; |
| 9 | +const COLUMN_LABELS = ["ID", "Title", "Discovery", "Release", "Score", "CWE"]; |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +Given( |
| 14 | + "User visits Advisory details Page of {string}", |
| 15 | + async ({ page }, advisoryName) => { |
| 16 | + const searchPage = new SearchPage(page, "Advisories"); |
| 17 | + await searchPage.dedicatedSearch(advisoryName); |
| 18 | + await page.getByRole("link", { name: advisoryName, exact: true }).click(); |
| 19 | + } |
| 20 | +); |
| 21 | + |
| 22 | +Then( |
| 23 | + "User navigates to the Vulnerabilites tab on the Advisory Overview page", |
| 24 | + async ({ page }) => { |
| 25 | + await page.getByRole("tab", { name: "Vulnerabilities" }).click(); |
| 26 | + } |
| 27 | +); |
| 28 | + |
| 29 | +Then("Pagination of Vulnerabilities list works", async ({ page }) => { |
| 30 | + const toolbarTable = new ToolbarTable(page, VULN_TABLE_NAME); |
| 31 | + const vulnTableTopPagination = `xpath=//div[@id="vulnerability-table-pagination-top"]`; |
| 32 | + await toolbarTable.verifyPagination(vulnTableTopPagination); |
| 33 | +}); |
| 34 | + |
| 35 | +Then( |
| 36 | + "A list of all active vulnerabilites tied to the advisory should display", |
| 37 | + async ({ page }) => { |
| 38 | + const totalItemsLocator = page |
| 39 | + .locator( |
| 40 | + "#vulnerability-table-pagination-top .pf-v6-c-pagination__page-menu" |
| 41 | + ) |
| 42 | + .first(); |
| 43 | + |
| 44 | + await expect(totalItemsLocator).toBeVisible(); |
| 45 | + |
| 46 | + const totalText = await totalItemsLocator.textContent(); |
| 47 | + const match = totalText?.match(/of\s+(\d+)/); |
| 48 | + expect(match, "unable to parse pagination total").not.toBeNull(); |
| 49 | + |
| 50 | + const total = Number(match![1]); |
| 51 | + expect(total).toBeGreaterThan(0); |
| 52 | + } |
| 53 | +); |
| 54 | + |
| 55 | +Then( |
| 56 | + "The ID, Title, Discovery, Release, Score and CWE information should be visible for each vulnerability", |
| 57 | + async ({ page }) => { |
| 58 | + for (const label of COLUMN_LABELS) { |
| 59 | + const header = page.getByRole("columnheader", { name: label }); |
| 60 | + if (await header.count()) { |
| 61 | + await expect(header).toBeVisible(); |
| 62 | + } else { |
| 63 | + await expect(page.getByRole("button", { name: label })).toBeVisible(); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | +); |
| 68 | + |
| 69 | +Then( |
| 70 | + "The vulnerabilities should be sorted by ID by default", |
| 71 | + async ({ page }) => { |
| 72 | + const toolbarTable = new ToolbarTable(page, VULN_TABLE_NAME); |
| 73 | + await toolbarTable.verifyTableIsSortedBy("ID"); |
| 74 | + } |
| 75 | +); |
| 76 | + |
| 77 | +Then( |
| 78 | + "User visits Vulnerability details Page of {string} by clicking it", |
| 79 | + async ({ page }, vulnerabilityID) => { |
| 80 | + const link = page.getByRole("link", { name: vulnerabilityID }); |
| 81 | + |
| 82 | + await Promise.all([ |
| 83 | + page.waitForURL(new RegExp(`/vulnerabilities/${vulnerabilityID}$`)), |
| 84 | + link.click(), |
| 85 | + ]); |
| 86 | + |
| 87 | + await expect( |
| 88 | + page.getByRole("heading", { |
| 89 | + level: 1, |
| 90 | + name: new RegExp(`^${vulnerabilityID}\\s*$`), |
| 91 | + }) |
| 92 | + ).toBeVisible(); |
| 93 | + } |
| 94 | +); |
| 95 | + |
0 commit comments