forked from guacsec/trustify-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvisory-explorer.step.ts
More file actions
211 lines (184 loc) · 6.38 KB
/
advisory-explorer.step.ts
File metadata and controls
211 lines (184 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import { createBdd } from "playwright-bdd";
import { expect } from "../../assertions";
import { ToolbarTable } from "../../helpers/ToolbarTable";
import { SearchPage } from "../../helpers/SearchPage";
import { AdvisoryListPage } from "../../pages/advisory-list/AdvisoryListPage";
import { test } from "../../fixtures";
import { DeletionConfirmDialog } from "../../pages/ConfirmDialog";
import { DetailsPage } from "../../helpers/DetailsPage";
export const { Given, When, Then } = createBdd(test);
const VULN_TABLE_NAME = "vulnerability table";
Given(
"User visits Advisory details Page of {string}",
async ({ page }, advisoryID) => {
const searchPage = new SearchPage(page, "Advisories");
await searchPage.dedicatedSearch(advisoryID);
await page.getByRole("link", { name: advisoryID, exact: true }).click();
},
);
Given(
"User visits Advisory details Page of {string} with type {string}",
async ({ page }, advisoryName, advisoryType) => {
const searchPage = new SearchPage(page, "Advisories");
await searchPage.dedicatedSearch(advisoryName);
const advisory = `xpath=//tr[contains(.,'${advisoryName}') and contains(.,'${advisoryType}')]/td/a`;
await page.locator(advisory).click();
},
);
// Advisory Search
When(
"User searches for an advisory named {string} in the general search bar",
async ({ page }, item) => {
const searchPage = new SearchPage(page, "Dashboard");
await searchPage.generalSearch("Advisories", item);
},
);
When(
"User searches for {string} in the dedicated search bar",
async ({ page }, advisoryID) => {
const searchPage = new SearchPage(page, "Advisories");
await searchPage.dedicatedSearch(advisoryID);
},
);
Then(
"The advisory {string} shows in the results",
async ({ page }, advisoryID) => {
await expect(
page.getByRole("gridcell").filter({ hasText: advisoryID }),
).toBeVisible();
},
);
// Advisory Explorer
Then(
"The vulnerabilities table is sorted by {string}",
async ({ page }, columnName) => {
const toolbarTable = new ToolbarTable(page, VULN_TABLE_NAME);
await toolbarTable.verifyTableIsSortedBy(columnName);
},
);
Then(
"The vulnerabilities table total results is {int}",
async ({ page }, totalResults) => {
const toolbarTable = new ToolbarTable(page, VULN_TABLE_NAME);
await toolbarTable.verifyPaginationHasTotalResults(totalResults);
},
);
Then(
"The {string} column of the vulnerability table contains {string}",
async ({ page }, columnName, expectedValue) => {
const toolbarTable = new ToolbarTable(page, VULN_TABLE_NAME);
await toolbarTable.verifyColumnContainsText(columnName, expectedValue);
},
);
// Advisory Explorer / Vulenrabilities
Then(
"User navigates to the Vulnerabilities tab on the Advisory Overview page",
async ({ page }) => {
await page.getByRole("tab", { name: "Vulnerabilities" }).click();
},
);
Then(
"A list of all active vulnerabilites tied to the advisory should display",
async ({ page }) => {
const totalItemsLocator = page
.locator(
"#vulnerability-table-pagination-top .pf-v6-c-pagination__page-menu",
)
.first();
await expect(totalItemsLocator).toBeVisible();
const totalText = await totalItemsLocator.textContent();
const match = totalText?.match(/of\s+(\d+)/);
expect(match, "unable to parse pagination total").not.toBeNull();
// biome-ignore lint/style/noNonNullAssertion: allowed
const total = Number(match![1]);
expect(total).toBeGreaterThan(0);
},
);
Then(
"The {string} information should be visible for each vulnerability",
async ({ page }, headers: string) => {
const headersArr = headers
.split(`,`)
.map((column: string) => column.trim());
for (const label of headersArr) {
const header = page.getByRole("columnheader", { name: label });
if (await header.count()) {
await expect(header).toBeVisible();
} else {
await expect(page.getByRole("button", { name: label })).toBeVisible();
}
}
},
);
Then(
"The vulnerabilities should be sorted by ID by default",
async ({ page }) => {
const toolbarTable = new ToolbarTable(page, VULN_TABLE_NAME);
await toolbarTable.verifyTableIsSortedBy("ID");
},
);
Then(
"User visits Vulnerability details Page of {string} by clicking it",
async ({ page }, vulnerabilityID) => {
const link = page.getByRole("link", { name: vulnerabilityID });
await Promise.all([
page.waitForURL(new RegExp(`/vulnerabilities/${vulnerabilityID}$`)),
link.click(),
]);
await expect(
page.getByRole("heading", {
level: 1,
name: new RegExp(`^${vulnerabilityID}\\s*$`),
}),
).toBeVisible();
},
);
When(
"User Deletes {string} using the toggle option from Advisory List Page",
async ({ page }, advisoryID) => {
const listPage = await AdvisoryListPage.build(page);
const toolbar = await listPage.getToolbar();
await toolbar.applyFilter({ "Filter text": advisoryID });
const table = await listPage.getTable();
const rowToDelete = 0;
await table.clickAction("Delete", rowToDelete);
},
);
When(
"User Clicks on Actions button and Selects Delete option from the drop down",
async ({ page }) => {
const details = new DetailsPage(page);
await details.clickOnPageAction("Delete");
},
);
When(
"User select Delete button from the Permanently delete Advisory model window",
async ({ page }) => {
const dialog = await DeletionConfirmDialog.build(page, "Confirm dialog");
await expect(dialog).toHaveTitle(
"Warning alert:Permanently delete Advisory?",
);
await dialog.clickConfirm();
},
);
Then(
"The {string} should not be present on Advisory list page as it is deleted",
async ({ page }, advisoryID: string) => {
const list = await AdvisoryListPage.build(page);
const toolbar = await list.getToolbar();
const table = await list.getTable();
await toolbar.applyFilter({ "Filter text": advisoryID });
await expect(table).toHaveEmptyState();
},
);
Then("Application Navigates to Advisory list page", async ({ page }) => {
await expect(
page.getByRole("heading", { level: 1, name: "Advisories" }),
).toBeVisible();
});
Then("The Advisory deleted message is displayed", async ({ page }) => {
const alertHeading = page.getByRole("heading", { level: 4 }).filter({
hasText: /The Advisory .+ was deleted/,
});
await expect(alertHeading).toBeVisible({ timeout: 10000 });
});