-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathgithub-happy-path.spec.ts
More file actions
234 lines (194 loc) · 9.04 KB
/
Copy pathgithub-happy-path.spec.ts
File metadata and controls
234 lines (194 loc) · 9.04 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import { test, expect, Page, BrowserContext } from "@support/coverage/test";
import { BackstageShowcase, CatalogImport } from "../support/pages/catalog-import";
import { RESOURCES } from "../support/test-data/resources";
import { TEMPLATES } from "../support/test-data/templates";
import { Common, setupBrowser, teardownBrowser } from "../utils/common";
import { UIhelper } from "../utils/ui-helper";
type GithubPullRequest = { title: string; number: string };
function parseGithubPullRequests(data: unknown): GithubPullRequest[] {
if (!Array.isArray(data)) {
throw new TypeError(`Expected GitHub PR array, got ${typeof data}`);
}
return data.map((entry, index) => {
if (typeof entry !== "object" || entry === null) {
throw new TypeError(`Invalid PR entry at index ${index}`);
}
const title: unknown = Reflect.get(entry, "title");
const numberValue: unknown = Reflect.get(entry, "number");
if (typeof title !== "string") {
throw new TypeError(`PR at index ${index} is missing a string title`);
}
const number =
typeof numberValue === "string"
? numberValue
: typeof numberValue === "number"
? String(numberValue)
: "";
return { title, number };
});
}
async function getShowcasePullRequests(
state: "open" | "closed" | "all",
paginated = false,
): Promise<GithubPullRequest[]> {
const data: unknown = await BackstageShowcase.getShowcasePRs(state, paginated);
return parseGithubPullRequests(data);
}
let page: Page;
let browserContext: BrowserContext;
// Blocked by https://issues.redhat.com/browse/RHDHBUGS-2099
test.describe.fixme("GitHub Happy path", () => {
let common: Common;
let uiHelper: UIhelper;
let catalogImport: CatalogImport;
let backstageShowcase: BackstageShowcase;
const component = "https://github.com/redhat-developer/rhdh/blob/main/catalog-entities/all.yaml";
test.beforeAll(async ({ browser }, testInfo) => {
test.info().annotations.push({
type: "component",
description: "core",
});
({ page, context: browserContext } = await setupBrowser(browser, testInfo));
uiHelper = new UIhelper(page);
common = new Common(page);
catalogImport = new CatalogImport(page);
backstageShowcase = new BackstageShowcase(page);
test.info().setTimeout(600 * 1000);
});
test("Login as a Github user from Settings page.", async () => {
await common.loginAsKeycloakUser(process.env.GH_USER2_ID, process.env.GH_USER2_PASS);
const ghLogin = await common.githubLoginFromSettingsPage(
process.env.GH_USER2_ID!,
process.env.GH_USER2_PASS!,
process.env.GH_USER2_2FA_SECRET!,
);
expect(ghLogin).toBe("Login successful");
});
test("Verify Profile is Github Account Name in the Settings page", async () => {
await uiHelper.goToSettingsPage();
await uiHelper.verifyHeading(process.env.GH_USER2_ID!);
await uiHelper.verifyHeading(`User Entity: ${process.env.GH_USER2_ID!}`);
});
test("Import an existing Git repository", async () => {
await uiHelper.openSidebar("Catalog");
await uiHelper.selectMuiBox("Kind", "Component");
await uiHelper.clickButton("Self-service");
await uiHelper.clickButton("Import an existing Git repository");
await catalogImport.registerExistingComponent(component);
});
test("Verify that the following components were ingested into the Catalog", async () => {
await uiHelper.openSidebar("Catalog");
await uiHelper.selectMuiBox("Kind", "Group");
await uiHelper.verifyComponentInCatalog("Group", ["Janus-IDP Authors"]);
await uiHelper.verifyComponentInCatalog("API", ["Petstore"]);
await uiHelper.verifyComponentInCatalog("Component", ["Red Hat Developer Hub"]);
await uiHelper.selectMuiBox("Kind", "Resource");
await uiHelper.verifyRowsInTable([
"ArgoCD",
"GitHub Showcase repository",
"KeyCloak",
"PostgreSQL cluster",
"S3 Object bucket storage",
]);
await uiHelper.openSidebar("Catalog");
await uiHelper.selectMuiBox("Kind", "User");
await uiHelper.searchInputPlaceholder("rhdh");
await uiHelper.verifyRowsInTable(["rhdh-qe rhdh-qe"]);
});
test("Verify all 12 Software Templates appear in the Create page", async () => {
await uiHelper.goToSelfServicePage();
await uiHelper.verifyHeading("Templates");
for (const template of TEMPLATES) {
await uiHelper.waitForTitle(template, 4);
await uiHelper.verifyHeading(template);
}
});
test("Click login on the login popup and verify that Overview tab renders", async () => {
await uiHelper.openCatalogSidebar("Component");
await uiHelper.clickLink("Red Hat Developer Hub");
const expectedPath = "/catalog/default/component/red-hat-developer-hub";
// Wait for the expected path in the URL
// Wait until the DOM is loaded
await page.waitForURL(`**${expectedPath}`, {
waitUntil: "domcontentloaded",
timeout: 20000,
});
// Optionally, verify that the current URL contains the expected path
expect(page.url()).toContain(expectedPath);
await common.clickOnGHloginPopup();
await uiHelper.verifyLink("About RHDH", { exact: false });
// Workaround for RHDHBUGS-2091: Change the size to 10 to avoid information not being displayed
await page.getByRole("button", { name: "20" }).click();
await page.getByRole("option", { name: "10", exact: true }).click();
await backstageShowcase.verifyPRStatisticsRendered();
await backstageShowcase.verifyAboutCardIsDisplayed();
});
test("Verify that the Pull/Merge Requests tab renders the 5 most recently updated Open Pull Requests", async () => {
await uiHelper.clickTab("Pull/Merge Requests");
const openPRs = await getShowcasePullRequests("open");
await backstageShowcase.verifyPRRows(openPRs, 0, 5);
});
test("Click on the CLOSED filter and verify that the 5 most recently updated Closed PRs are rendered (same with ALL)", async () => {
// Use semantic selector and wait for button to be ready (no force needed)
const closedButton = page.getByRole("button", { name: "CLOSED" });
await expect(closedButton).toBeVisible();
await expect(closedButton).toBeEnabled();
await closedButton.click();
const closedPRs = await getShowcasePullRequests("closed");
await common.waitForLoad();
await backstageShowcase.verifyPRRows(closedPRs, 0, 5);
});
test("Click on the arrows to verify that the next/previous/first/last pages of PRs are loaded", async () => {
console.log("Fetching all PRs from GitHub");
const allPRs = await getShowcasePullRequests("all", true);
console.log("Clicking on ALL button");
// Use semantic selector and wait for button to be ready (no force needed)
const allButton = page.getByRole("button", { name: "ALL" });
await expect(allButton).toBeVisible();
await expect(allButton).toBeEnabled();
await allButton.click();
await backstageShowcase.verifyPRRows(allPRs, 0, 5);
console.log("Clicking on Next Page button");
await backstageShowcase.clickNextPage();
await backstageShowcase.verifyPRRows(allPRs, 5, 10);
// const lastPagePRs = Math.floor((allPRs.length - 1) / 5) * 5;
// redhat-developer/rhdh have more than 1000 PRs open/closed and by default the latest 1000 PR results are displayed.
const lastPagePRs = 996;
console.log("Clicking on Last Page button");
await backstageShowcase.clickLastPage();
await backstageShowcase.verifyPRRows(allPRs, lastPagePRs, 1000);
console.log("Clicking on Previous Page button");
await backstageShowcase.clickPreviousPage();
await common.waitForLoad();
await backstageShowcase.verifyPRRows(allPRs, lastPagePRs - 5, lastPagePRs - 1);
});
test("Verify that the 5, 10, 20 items per page option properly displays the correct number of PRs", async () => {
await uiHelper.openCatalogSidebar("Component");
await uiHelper.clickLink("Red Hat Developer Hub");
await common.clickOnGHloginPopup();
await uiHelper.clickTab("Pull/Merge Requests");
const allPRs = await getShowcasePullRequests("open");
await backstageShowcase.verifyPRRowsPerPage(5, allPRs);
await backstageShowcase.verifyPRRowsPerPage(10, allPRs);
await backstageShowcase.verifyPRRowsPerPage(20, allPRs);
});
// Blocked by https://issues.redhat.com/browse/RHDHBUGS-2099
test.fixme("Click on the Dependencies tab and verify that all the relations have been listed and displayed", async () => {
await uiHelper.clickTab("Dependencies");
for (const resource of RESOURCES) {
const resourceElement = page.locator(`#workspace:has-text("${resource}")`);
await resourceElement.scrollIntoViewIfNeeded();
await expect(resourceElement).toBeVisible();
}
});
// Blocked by https://issues.redhat.com/browse/RHDHBUGS-2099
test.fixme("Sign out and verify that you return back to the Sign in page", async () => {
await uiHelper.goToSettingsPage();
await common.signOut();
await browserContext.clearCookies();
await expect(page.getByRole("button", { name: "Sign In" })).toBeVisible();
});
test.afterAll(async ({}, testInfo) => {
await teardownBrowser(page, testInfo);
});
});