Skip to content

Commit 4a3ee20

Browse files
authored
chore(e2e): role based quick start e2e (#3484)
* quickstart rbac e2e * quickstart rbac e2e * removed quickstart config * enabled test for rbac * fixed button url check * fixed button url check * fixed button url check * fix * fixed learning-path button * fix
1 parent 0247a82 commit 4a3ee20

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

e2e-tests/playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export default defineConfig({
7676
"**/playwright/e2e/**/*-rbac.spec.ts",
7777
"**/playwright/e2e/verify-tls-config-with-external-postgres-db.spec.ts",
7878
"**/playwright/e2e/plugins/bulk-import.spec.ts",
79+
"**/playwright/e2e/plugins/quick-start.spec.ts",
7980
"**/playwright/e2e/plugins/scorecard/scorecard.spec.ts",
8081
],
8182
},

e2e-tests/playwright/e2e/plugins/quick-start.spec.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ test.describe("Test Quick Start plugin", () => {
1414

1515
test.beforeEach(async ({ page }) => {
1616
common = new Common(page);
17-
await common.loginAsKeycloakUser();
1817
uiHelper = new UIhelper(page);
1918
});
2019

2120
test("Access Quick start from Global Header", async ({ page }) => {
21+
await common.loginAsKeycloakUser();
2222
await page.waitForTimeout(1000);
2323
// eslint-disable-next-line playwright/no-conditional-in-test
2424
if (await page.getByRole("button", { name: "Hide" }).isHidden()) {
@@ -27,20 +27,32 @@ test.describe("Test Quick Start plugin", () => {
2727
console.log("Quick start button clicked");
2828
}
2929
await expect(page.getByRole("button", { name: "Hide" })).toBeVisible();
30+
});
31+
32+
test("Access Quick start as Guest or Admin", async ({ page }) => {
33+
// eslint-disable-next-line playwright/no-conditional-in-test
34+
if (test.info().project.name !== "showcase-rbac") {
35+
await common.loginAsGuest();
36+
} else {
37+
await common.loginAsKeycloakUser();
38+
}
39+
await page.waitForTimeout(1000);
3040
await uiHelper.verifyText("Let's get you started with Developer Hub");
3141
await uiHelper.verifyText("We'll guide you through a few quick steps");
3242
await uiHelper.verifyText("Not started");
3343
await uiHelper.clickButtonByText("Set up authentication");
3444
await uiHelper.verifyButtonURL(
3545
"Learn more",
3646
"https://docs.redhat.com/en/documentation/red_hat_developer_hub/latest/html/authentication_in_red_hat_developer_hub/",
47+
{ exact: false },
3748
);
3849
await uiHelper.clickButtonByText("Configure RBAC");
3950
await uiHelper.verifyButtonURL("Manage access", "/rbac");
4051
await uiHelper.clickButtonByText("Configure Git");
4152
await uiHelper.verifyButtonURL(
4253
"Learn more",
4354
"https://docs.redhat.com/en/documentation/red_hat_developer_hub/latest/html/integrating_red_hat_developer_hub_with_github/",
55+
{ exact: false },
4456
);
4557
await uiHelper.clickButtonByText("Manage plugins");
4658
await uiHelper.verifyButtonURL("Explore plugins", "/extensions");
@@ -51,4 +63,34 @@ test.describe("Test Quick Start plugin", () => {
5163
await uiHelper.clickButton("Hide");
5264
await expect(page.getByRole("button", { name: "Hide" })).toBeHidden();
5365
});
66+
67+
test("Access Quick start as User", async ({ page }) => {
68+
// eslint-disable-next-line playwright/no-conditional-in-test
69+
if (test.info().project.name !== "showcase-rbac") {
70+
test.skip();
71+
}
72+
await common.loginAsKeycloakUser(
73+
process.env.GH_USER2_ID,
74+
process.env.GH_USER2_PASS,
75+
);
76+
await page.waitForTimeout(1000);
77+
await uiHelper.verifyText("Let's get you started with Developer Hub");
78+
await uiHelper.verifyText("We'll guide you through a few quick steps");
79+
await uiHelper.clickButtonByText("Import application");
80+
await uiHelper.verifyButtonURL("Import", "/bulk-import");
81+
await uiHelper.clickButtonByText("Import");
82+
await uiHelper.clickButtonByText("Learn about the Catalog");
83+
await uiHelper.verifyButtonURL("View Catalog", "/catalog");
84+
await uiHelper.clickButtonByText("View Catalog");
85+
await uiHelper.verifyText(/All Components \((\d+)\)/);
86+
await uiHelper.clickButtonByText("Explore Self-service templates");
87+
await uiHelper.verifyButtonURL("Explore templates", "/create");
88+
await uiHelper.clickButtonByText("Explore templates");
89+
await uiHelper.verifyText("Self-service");
90+
await uiHelper.clickButtonByText("Find all Learning Paths");
91+
await uiHelper.verifyButtonURL("View Learning Paths", "/docs");
92+
await uiHelper.clickButtonByText("View Learning Paths");
93+
await uiHelper.verifyText("Documentation");
94+
await uiHelper.verifyText("100% progress");
95+
});
5496
});

e2e-tests/playwright/utils/ui-helper.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -527,21 +527,22 @@ export class UIhelper {
527527
async verifyButtonURL(
528528
label: string | RegExp,
529529
url: string | RegExp,
530-
options: { locator?: string } = {
530+
options: { locator?: string; exact?: boolean } = {
531531
locator: "",
532+
exact: true,
532533
},
533534
) {
534-
const buttonUrl =
535-
options.locator == ""
536-
? await this.page
537-
.getByRole("button", { name: label })
538-
.first()
539-
.getAttribute("href")
540-
: await this.page
541-
.locator(options.locator)
542-
.getByRole("button", { name: label })
543-
.first()
544-
.getAttribute("href");
535+
// To verify the button URL if it is in a specific locator
536+
const baseLocator =
537+
!options.locator || options.locator === ""
538+
? this.page
539+
: this.page.locator(options.locator);
540+
541+
const buttonUrl = await baseLocator
542+
.getByRole("button", { name: label, exact: options.exact })
543+
.first()
544+
.getAttribute("href");
545+
545546
expect(buttonUrl).toContain(url);
546547
}
547548

0 commit comments

Comments
 (0)