1616
1717import { test , expect } from "@playwright/test" ;
1818import { Common } from "../../../utils/common" ;
19- import { mockScorecardResponse } from "../../../utils/scorecard-utils" ;
2019import { ComponentImportPage } from "../../../support/page-objects/scorecard/component-import-page" ;
2120import { Catalog } from "../../../support/pages/catalog" ;
2221import { 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
3023test . 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 } ) ;
0 commit comments