Skip to content

Commit 0d9065e

Browse files
author
HusneShabbir
committed
update scorecard e2e
1 parent e5aa1a3 commit 0d9065e

File tree

5 files changed

+96
-316
lines changed

5 files changed

+96
-316
lines changed

e2e-tests/playwright/e2e/plugins/scorecard/scorecard.spec.ts

Lines changed: 71 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,9 @@
1616

1717
import { test, expect } from "@playwright/test";
1818
import { Common } from "../../../utils/common";
19-
import { mockScorecardResponse } from "../../../utils/scorecard-utils";
2019
import { ComponentImportPage } from "../../../support/page-objects/scorecard/component-import-page";
2120
import { Catalog } from "../../../support/pages/catalog";
2221
import { ScorecardPage } from "../../../support/page-objects/scorecard/scorecard-page";
23-
import {
24-
CUSTOM_SCORECARD_RESPONSE,
25-
EMPTY_SCORECARD_RESPONSE,
26-
UNAVAILABLE_METRIC_RESPONSE,
27-
INVALID_THRESHOLD_RESPONSE,
28-
} from "../../../utils/scorecard-response-utils";
2922

3023
test.describe.serial("Scorecard Plugin Tests", () => {
3124
let context;
@@ -53,42 +46,33 @@ test.describe.serial("Scorecard Plugin Tests", () => {
5346
});
5447

5548
test("Import component and validate scorecard tabs for GitHub PRs and Jira tickets", async () => {
56-
await mockScorecardResponse(page, CUSTOM_SCORECARD_RESPONSE);
57-
58-
await catalog.go();
59-
await importPage.startComponentImport();
60-
await importPage.analyzeComponent(
61-
"https://github.com/rhdh-pai-qe/backstage-catalog/blob/main/catalog-info.yaml",
49+
await importPage.importAndOpenScorecard(
50+
"https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/all-scorecards.yaml",
51+
catalog,
52+
scorecardPage,
6253
);
63-
await importPage.viewImportedComponent();
64-
await scorecardPage.openTab();
65-
66-
await scorecardPage.verifyScorecardValues({
67-
"GitHub open PRs": "9",
68-
"Jira open blocking tickets": "8",
69-
});
7054

7155
for (const metric of scorecardPage.scorecardMetrics) {
7256
await scorecardPage.validateScorecardAriaFor(metric);
7357
}
7458
});
7559

76-
test("Display empty state when scorecard API returns no metrics", async () => {
77-
await mockScorecardResponse(page, EMPTY_SCORECARD_RESPONSE);
78-
79-
await catalog.go();
80-
await catalog.goToByName("rhdh-app");
81-
await scorecardPage.openTab();
60+
test("Validate empty scorecard state", async () => {
61+
await importPage.importAndOpenScorecard(
62+
"https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/no-scorecards.yaml",
63+
catalog,
64+
scorecardPage,
65+
);
8266

8367
await scorecardPage.expectEmptyState();
8468
});
8569

8670
test("Displays error state for unavailable data while rendering metrics", async () => {
87-
await mockScorecardResponse(page, UNAVAILABLE_METRIC_RESPONSE);
88-
89-
await catalog.go();
90-
await catalog.goToByName("rhdh-app");
91-
await scorecardPage.openTab();
71+
await importPage.importAndOpenScorecard(
72+
"https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/metrics-unavailable.yaml",
73+
catalog,
74+
scorecardPage,
75+
);
9276

9377
const jiraMetric = scorecardPage.scorecardMetrics[1];
9478
const githubMetric = scorecardPage.scorecardMetrics[0];
@@ -109,22 +93,19 @@ test.describe.serial("Scorecard Plugin Tests", () => {
10993
await expect(errorLocator).toBeVisible();
11094

11195
await errorLocator.hover();
112-
const errorTooltip = UNAVAILABLE_METRIC_RESPONSE.find(
113-
(metric) => metric.id === "github.open-prs",
114-
)?.error;
115-
116-
expect(errorTooltip).toBeTruthy();
117-
await expect(page.getByText(errorTooltip!)).toBeVisible();
96+
const errorTooltip =
97+
"GraphqlResponseError: Request failed due to following response errors: - Could not resolve to a Repository with the name 'dzemanov/react-app-t1'.";
98+
await expect(page.getByText(errorTooltip)).toBeVisible();
11899

119100
await scorecardPage.validateScorecardAriaFor(jiraMetric);
120101
});
121102

122103
test("Display error state for invalid threshold config while rendering metrics", async () => {
123-
await mockScorecardResponse(page, INVALID_THRESHOLD_RESPONSE);
124-
125-
await catalog.go();
126-
await catalog.goToByName("rhdh-app");
127-
await scorecardPage.openTab();
104+
await importPage.importAndOpenScorecard(
105+
"https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/invalid-threshold.yaml",
106+
catalog,
107+
scorecardPage,
108+
);
128109

129110
const githubMetric = scorecardPage.scorecardMetrics[0];
130111
const jiraMetric = scorecardPage.scorecardMetrics[1];
@@ -145,12 +126,55 @@ test.describe.serial("Scorecard Plugin Tests", () => {
145126
await expect(errorLocator).toBeVisible();
146127

147128
await errorLocator.hover();
148-
const errorTooltip = INVALID_THRESHOLD_RESPONSE.find(
149-
(metric) => metric.id === "github.open-prs",
150-
)?.result?.thresholdResult?.error;
129+
const errorTooltip =
130+
"ThresholdConfigFormatError: Invalid threshold annotation 'scorecard.io/github.open_prs.thresholds.rules.error: >50d' in entity 'component:default/invalid-threshold': Cannot parse \"50d\" as number from expression: \">50d\"";
131+
await expect(page.getByText(errorTooltip)).toBeVisible();
132+
133+
await scorecardPage.validateScorecardAriaFor(jiraMetric);
134+
});
135+
136+
test("Validate only GitHub scorecard is displayed", async () => {
137+
await importPage.importAndOpenScorecard(
138+
"https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/github-scorecard-only.yaml",
139+
catalog,
140+
scorecardPage,
141+
);
142+
143+
const githubMetric = scorecardPage.scorecardMetrics[0];
144+
const jiraMetric = scorecardPage.scorecardMetrics[1];
145+
146+
const isGithubVisible = await scorecardPage.isScorecardVisible(
147+
githubMetric.title,
148+
);
149+
expect(isGithubVisible).toBe(true);
150+
151+
const isJiraVisible = await scorecardPage.isScorecardVisible(
152+
jiraMetric.title,
153+
);
154+
expect(isJiraVisible).toBe(false);
151155

152-
expect(errorTooltip).toBeTruthy();
153-
await expect(page.getByText(errorTooltip!)).toBeVisible();
156+
await scorecardPage.validateScorecardAriaFor(githubMetric);
157+
});
158+
159+
test("Validate only Jira scorecard is displayed", async () => {
160+
await importPage.importAndOpenScorecard(
161+
"https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/jira-scorecard-only.yaml",
162+
catalog,
163+
scorecardPage,
164+
);
165+
166+
const githubMetric = scorecardPage.scorecardMetrics[0];
167+
const jiraMetric = scorecardPage.scorecardMetrics[1];
168+
169+
const isGithubVisible = await scorecardPage.isScorecardVisible(
170+
githubMetric.title,
171+
);
172+
expect(isGithubVisible).toBe(false);
173+
174+
const isJiraVisible = await scorecardPage.isScorecardVisible(
175+
jiraMetric.title,
176+
);
177+
expect(isJiraVisible).toBe(true);
154178

155179
await scorecardPage.validateScorecardAriaFor(jiraMetric);
156180
});

e2e-tests/playwright/support/page-objects/scorecard/component-import-page.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
import { Page } from "@playwright/test";
1717
import { UIhelper } from "../../../utils/ui-helper";
18+
import { Catalog } from "../../../support/pages/catalog";
19+
import { ScorecardPage } from "./scorecard-page";
1820

1921
export class ComponentImportPage {
2022
readonly page: Page;
@@ -34,12 +36,29 @@ export class ComponentImportPage {
3436
await this.uiHelper.fillTextInputByLabel("URL", url);
3537
await this.uiHelper.clickButton("Analyze");
3638
await this.uiHelper.clickButton("Import");
37-
//wait for few seconds
3839
await this.page.waitForTimeout(5000);
3940
}
4041

4142
async viewImportedComponent() {
4243
await this.uiHelper.clickButton("View Component");
44+
const entityNotFoundLocator = this.page.getByRole("button", {
45+
name: "Warning: Entity not found",
46+
});
47+
if (await entityNotFoundLocator.isVisible({ timeout: 10000 })) {
48+
await this.page.reload();
49+
}
4350
await this.uiHelper.verifyText("Overview");
4451
}
52+
53+
async importAndOpenScorecard(
54+
url: string,
55+
catalog: Catalog,
56+
scorecardPage: ScorecardPage,
57+
) {
58+
await catalog.go();
59+
await this.startComponentImport();
60+
await this.analyzeComponent(url);
61+
await this.viewImportedComponent();
62+
await scorecardPage.openTab();
63+
}
4564
}

e2e-tests/playwright/support/page-objects/scorecard/scorecard-page.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import { Page, expect } from "@playwright/test";
18-
import { waitUntilApiCallSucceeds } from "../../../utils/scorecard-utils";
1918

2019
export class ScorecardPage {
2120
readonly page: Page;
@@ -34,25 +33,15 @@ export class ScorecardPage {
3433
{
3534
title: "Jira open blocking tickets",
3635
description:
37-
"Highlights the number of critical, blocking issues that are currently open in Jira.",
36+
"Highlights the number of issues that are currently open in Jira.",
3837
},
3938
];
4039
}
4140

4241
async openTab() {
43-
const scorecardTab = this.page.getByText("Scorecard");
42+
const scorecardTab = this.page.getByText("Scorecard", { exact: true });
4443
await expect(scorecardTab).toBeVisible();
45-
await Promise.all([
46-
waitUntilApiCallSucceeds(this.page),
47-
scorecardTab.click(),
48-
]);
49-
}
50-
51-
async verifyScorecardValues(expectedValues: { [key: string]: string }) {
52-
for (const [metric, value] of Object.entries(expectedValues)) {
53-
await expect(this.page.getByText(metric)).toBeVisible();
54-
await expect(this.page.getByText(value)).toBeVisible();
55-
}
44+
await scorecardTab.click();
5645
}
5746

5847
async expectEmptyState() {
@@ -79,9 +68,9 @@ export class ScorecardPage {
7968
- article:
8069
- text: ${title}
8170
- paragraph: ${description}
82-
- paragraph: /Error/
83-
- paragraph: /Warning/
8471
- paragraph: /Success/
72+
- paragraph: /Warning/
73+
- paragraph: /Error/
8574
`);
8675
}
8776

0 commit comments

Comments
 (0)