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 ;
@@ -62,38 +55,33 @@ test.describe.serial("Scorecard Plugin Tests", () => {
6255 } ) ;
6356
6457 test ( "Import component and validate scorecard tabs for GitHub PRs and Jira tickets" , async ( ) => {
65- await mockScorecardResponse ( page , CUSTOM_SCORECARD_RESPONSE ) ;
66-
67- await catalog . go ( ) ;
68- await catalog . goToByName ( "rhdh-app" ) ;
69- await scorecardPage . openTab ( ) ;
70-
71- await scorecardPage . verifyScorecardValues ( {
72- "GitHub open PRs" : "9" ,
73- "Jira open blocking tickets" : "8" ,
74- } ) ;
58+ await importPage . importAndOpenScorecard (
59+ "https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/all-scorecards.yaml" ,
60+ catalog ,
61+ scorecardPage ,
62+ ) ;
7563
7664 for ( const metric of scorecardPage . scorecardMetrics ) {
7765 await scorecardPage . validateScorecardAriaFor ( metric ) ;
7866 }
7967 } ) ;
8068
81- test ( "Display empty state when scorecard API returns no metrics " , async ( ) => {
82- await mockScorecardResponse ( page , EMPTY_SCORECARD_RESPONSE ) ;
83-
84- await catalog . go ( ) ;
85- await catalog . goToByName ( "rhdh-app" ) ;
86- await scorecardPage . openTab ( ) ;
69+ test ( "Validate empty scorecard state " , async ( ) => {
70+ await importPage . importAndOpenScorecard (
71+ "https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/no-scorecards.yaml" ,
72+ catalog ,
73+ scorecardPage ,
74+ ) ;
8775
8876 await scorecardPage . expectEmptyState ( ) ;
8977 } ) ;
9078
9179 test ( "Displays error state for unavailable data while rendering metrics" , async ( ) => {
92- await mockScorecardResponse ( page , UNAVAILABLE_METRIC_RESPONSE ) ;
93-
94- await catalog . go ( ) ;
95- await catalog . goToByName ( "rhdh-app" ) ;
96- await scorecardPage . openTab ( ) ;
80+ await importPage . importAndOpenScorecard (
81+ "https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/metrics-unavailable.yaml" ,
82+ catalog ,
83+ scorecardPage ,
84+ ) ;
9785
9886 const jiraMetric = scorecardPage . scorecardMetrics [ 1 ] ;
9987 const githubMetric = scorecardPage . scorecardMetrics [ 0 ] ;
@@ -114,22 +102,19 @@ test.describe.serial("Scorecard Plugin Tests", () => {
114102 await expect ( errorLocator ) . toBeVisible ( ) ;
115103
116104 await errorLocator . hover ( ) ;
117- const errorTooltip = UNAVAILABLE_METRIC_RESPONSE . find (
118- ( metric ) => metric . id === "github.open-prs" ,
119- ) ?. error ;
120-
121- expect ( errorTooltip ) . toBeTruthy ( ) ;
122- await expect ( page . getByText ( errorTooltip ! ) ) . toBeVisible ( ) ;
105+ const errorTooltip =
106+ "GraphqlResponseError: Request failed due to following response errors: - Could not resolve to a Repository with the name 'dzemanov/react-app-t1'." ;
107+ await expect ( page . getByText ( errorTooltip ) ) . toBeVisible ( ) ;
123108
124109 await scorecardPage . validateScorecardAriaFor ( jiraMetric ) ;
125110 } ) ;
126111
127112 test ( "Display error state for invalid threshold config while rendering metrics" , async ( ) => {
128- await mockScorecardResponse ( page , INVALID_THRESHOLD_RESPONSE ) ;
129-
130- await catalog . go ( ) ;
131- await catalog . goToByName ( "rhdh-app" ) ;
132- await scorecardPage . openTab ( ) ;
113+ await importPage . importAndOpenScorecard (
114+ "https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/invalid-threshold.yaml" ,
115+ catalog ,
116+ scorecardPage ,
117+ ) ;
133118
134119 const githubMetric = scorecardPage . scorecardMetrics [ 0 ] ;
135120 const jiraMetric = scorecardPage . scorecardMetrics [ 1 ] ;
@@ -150,12 +135,55 @@ test.describe.serial("Scorecard Plugin Tests", () => {
150135 await expect ( errorLocator ) . toBeVisible ( ) ;
151136
152137 await errorLocator . hover ( ) ;
153- const errorTooltip = INVALID_THRESHOLD_RESPONSE . find (
154- ( metric ) => metric . id === "github.open-prs" ,
155- ) ?. result ?. thresholdResult ?. error ;
138+ const errorTooltip =
139+ "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\"" ;
140+ await expect ( page . getByText ( errorTooltip ) ) . toBeVisible ( ) ;
141+
142+ await scorecardPage . validateScorecardAriaFor ( jiraMetric ) ;
143+ } ) ;
156144
157- expect ( errorTooltip ) . toBeTruthy ( ) ;
158- await expect ( page . getByText ( errorTooltip ! ) ) . toBeVisible ( ) ;
145+ test ( "Validate only GitHub scorecard is displayed" , async ( ) => {
146+ await importPage . importAndOpenScorecard (
147+ "https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/github-scorecard-only.yaml" ,
148+ catalog ,
149+ scorecardPage ,
150+ ) ;
151+
152+ const githubMetric = scorecardPage . scorecardMetrics [ 0 ] ;
153+ const jiraMetric = scorecardPage . scorecardMetrics [ 1 ] ;
154+
155+ const isGithubVisible = await scorecardPage . isScorecardVisible (
156+ githubMetric . title ,
157+ ) ;
158+ expect ( isGithubVisible ) . toBe ( true ) ;
159+
160+ const isJiraVisible = await scorecardPage . isScorecardVisible (
161+ jiraMetric . title ,
162+ ) ;
163+ expect ( isJiraVisible ) . toBe ( false ) ;
164+
165+ await scorecardPage . validateScorecardAriaFor ( githubMetric ) ;
166+ } ) ;
167+
168+ test ( "Validate only Jira scorecard is displayed" , async ( ) => {
169+ await importPage . importAndOpenScorecard (
170+ "https://github.com/rhdh-pai-qe/RHDH-scorecard-plugin-test/blob/main/jira-scorecard-only.yaml" ,
171+ catalog ,
172+ scorecardPage ,
173+ ) ;
174+
175+ const githubMetric = scorecardPage . scorecardMetrics [ 0 ] ;
176+ const jiraMetric = scorecardPage . scorecardMetrics [ 1 ] ;
177+
178+ const isGithubVisible = await scorecardPage . isScorecardVisible (
179+ githubMetric . title ,
180+ ) ;
181+ expect ( isGithubVisible ) . toBe ( false ) ;
182+
183+ const isJiraVisible = await scorecardPage . isScorecardVisible (
184+ jiraMetric . title ,
185+ ) ;
186+ expect ( isJiraVisible ) . toBe ( true ) ;
159187
160188 await scorecardPage . validateScorecardAriaFor ( jiraMetric ) ;
161189 } ) ;
0 commit comments