Skip to content

Commit 6d3bd14

Browse files
authored
Merge pull request #236 from KoolTheba/feature/replace-minus-one-score
Feature: replace minus one score
2 parents 2dc3238 + 61bb8a3 commit 6d3bd14

File tree

8 files changed

+142
-63
lines changed

8 files changed

+142
-63
lines changed

cypress/e2e/comparator.cy.ts

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe("Comparator", () => {
104104
"Please check if the org/repository/commit has been analysed by the Scorecard.",
105105
);
106106
});
107-
it("should compare data from each commit as expected", () => {
107+
it.only("should compare data from each commit as expected", () => {
108108
cy.intercept(
109109
"GET",
110110
"https://api.securityscorecards.dev/projects/github.com/nodejs/node/?commit=2ac5e9889aba461f5a54d320973d2574980d206b",
@@ -177,31 +177,28 @@ describe("Comparator", () => {
177177
"contain",
178178
"Binary-Artifacts",
179179
);
180-
cy.get('[data-testid="Binary-Artifacts"] > div > span')
180+
cy.get('[data-testid="Binary-Artifacts-score"] > span')
181181
.should("contain", "Unchanged")
182182
.and("have.css", "background-color")
183183
.and("eq", "rgb(108, 117, 125)");
184-
cy.get('[data-testid="Binary-Artifacts"] > span').should("contain", "0/10");
184+
185+
cy.get('[data-testid="Binary-Artifacts-score"] > span').should("contain", "0/10");
185186

186187
cy.get('[data-testid="Branch-Protection"]').should(
187188
"contain",
188189
"Branch-Protection",
189190
);
190-
cy.get('[data-testid="Branch-Protection"] > div > span')
191-
.should("contain", "Unchanged")
192-
.and("have.css", "background-color")
193-
.and("eq", "rgb(108, 117, 125)");
194-
cy.get('[data-testid="Branch-Protection"] > span').should(
191+
cy.get('[data-testid="Branch-Protection-score"] > abbr > span').should(
195192
"contain",
196-
"-1/10",
193+
"?",
197194
);
198195

199196
cy.get('[data-testid="CI-Tests"]').should("contain", "CI-Tests");
200-
cy.get('[data-testid="CI-Tests"] > div > span')
197+
cy.get('[data-testid="CI-Tests-score"] > span')
201198
.should("contain", "Decreased -1")
202199
.and("have.css", "background-color")
203200
.and("eq", "rgb(220, 53, 69)");
204-
cy.get('[data-testid="CI-Tests"] > span').and("contain", "9/10");
201+
cy.get('[data-testid="CI-Tests-score"] > span').and("contain", "9/10");
205202
cy.get('[data-testid="CI-Tests"] ~ h4').should(
206203
"contain",
207204
"Additional details / variations",
@@ -211,42 +208,42 @@ describe("Comparator", () => {
211208
"contain",
212209
"CII-Best-Practices",
213210
);
214-
cy.get('[data-testid="CII-Best-Practices"] > div > span')
211+
cy.get('[data-testid="CII-Best-Practices-score"] > span')
215212
.should("contain", "Unchanged")
216213
.and("have.css", "background-color")
217214
.and("eq", "rgb(108, 117, 125)");
218-
cy.get('[data-testid="CII-Best-Practices"] > span').should(
215+
cy.get('[data-testid="CII-Best-Practices-score"] > span').should(
219216
"contain",
220217
"5/10",
221218
);
222219

223220
cy.get('[data-testid="Code-Review"]').should("contain", "Code-Review");
224-
cy.get('[data-testid="Code-Review"] > div > span')
221+
cy.get('[data-testid="Code-Review-score"] > span')
225222
.should("contain", "Unchanged")
226223
.and("have.css", "background-color")
227224
.and("eq", "rgb(108, 117, 125)");
228-
cy.get('[data-testid="Code-Review"] > span').should("contain", "0/10");
225+
cy.get('[data-testid="Code-Review-score"] > span').should("contain", "0/10");
229226
cy.get('[data-testid="Code-Review"] ~ h4').should(
230227
"contain",
231228
"Additional details / variations",
232229
);
233230

234231
cy.get('[data-testid="Contributors"]').should("contain", "Contributors");
235-
cy.get('[data-testid="Contributors"] > div > span')
232+
cy.get('[data-testid="Contributors-score"] > span')
236233
.should("contain", "Unchanged")
237234
.and("have.css", "background-color")
238235
.and("eq", "rgb(108, 117, 125)");
239-
cy.get('[data-testid="Contributors"] > span').should("contain", "10/10");
236+
cy.get('[data-testid="Contributors-score"] > span').should("contain", "10/10");
240237

241238
cy.get('[data-testid="Dangerous-Workflow"]').should(
242239
"contain",
243240
"Dangerous-Workflow",
244241
);
245-
cy.get('[data-testid="Dangerous-Workflow"] > div > span')
242+
cy.get('[data-testid="Dangerous-Workflow-score"] > span')
246243
.should("contain", "Unchanged")
247244
.and("have.css", "background-color")
248245
.and("eq", "rgb(108, 117, 125)");
249-
cy.get('[data-testid="Dangerous-Workflow"] > span').should(
246+
cy.get('[data-testid="Dangerous-Workflow-score"] > span').should(
250247
"contain",
251248
"10/10",
252249
);
@@ -255,56 +252,52 @@ describe("Comparator", () => {
255252
"contain",
256253
"Dependency-Update-Tool",
257254
);
258-
cy.get('[data-testid="Dependency-Update-Tool"] > div > span')
255+
cy.get('[data-testid="Dependency-Update-Tool-score"] > span')
259256
.should("contain", "Unchanged")
260257
.and("have.css", "background-color")
261258
.and("eq", "rgb(108, 117, 125)");
262-
cy.get('[data-testid="Dependency-Update-Tool"] > span').should(
259+
cy.get('[data-testid="Dependency-Update-Tool-score"] > span').should(
263260
"contain",
264261
"10/10",
265262
);
266263

267264
cy.get('[data-testid="Fuzzing"]').should("contain", "Fuzzing");
268-
cy.get('[data-testid="Fuzzing"] > div > span')
265+
cy.get('[data-testid="Fuzzing-score"] > span')
269266
.should("contain", "Unchanged")
270267
.and("have.css", "background-color")
271268
.and("eq", "rgb(108, 117, 125)");
272-
cy.get('[data-testid="Fuzzing"] > span').should("contain", "10/10");
269+
cy.get('[data-testid="Fuzzing-score"] > span').should("contain", "10/10");
273270

274271
cy.get('[data-testid="License"]').should("contain", "License");
275-
cy.get('[data-testid="License"] > div > span')
272+
cy.get('[data-testid="License-score"] > span')
276273
.should("contain", "Unchanged")
277274
.and("have.css", "background-color")
278275
.and("eq", "rgb(108, 117, 125)");
279-
cy.get('[data-testid="License"] > span').should("contain", "9/10");
276+
cy.get('[data-testid="License-score"] > span').should("contain", "9/10");
280277

281278
cy.get('[data-testid="Maintained"]').should("contain", "Maintained");
282-
cy.get('[data-testid="Maintained"] > div > span')
279+
cy.get('[data-testid="Maintained-score"] > span')
283280
.should("contain", "Unchanged")
284281
.and("have.css", "background-color")
285282
.and("eq", "rgb(108, 117, 125)");
286-
cy.get('[data-testid="Maintained"] > span').should("contain", "10/10");
283+
cy.get('[data-testid="Maintained-score"] > span').should("contain", "10/10");
287284
cy.get('[data-testid="Maintained"] ~ h4').should(
288285
"contain",
289286
"Additional details / variations",
290287
);
291288

292289
cy.get('[data-testid="Packaging"]').should("contain", "Packaging");
293-
cy.get('[data-testid="Packaging"] > div > span')
294-
.should("contain", "Unchanged")
295-
.and("have.css", "background-color")
296-
.and("eq", "rgb(108, 117, 125)");
297-
cy.get('[data-testid="Packaging"] > span').should("contain", "-1/10");
290+
cy.get('[data-testid="Packaging-score"] > abbr > span').should("contain", "?");
298291

299292
cy.get('[data-testid="Pinned-Dependencies"]').should(
300293
"contain",
301294
"Pinned-Dependencies",
302295
);
303-
cy.get('[data-testid="Pinned-Dependencies"] > div > span')
296+
cy.get('[data-testid="Pinned-Dependencies-score"] > span')
304297
.should("contain", "Unchanged")
305298
.and("have.css", "background-color")
306299
.and("eq", "rgb(108, 117, 125)");
307-
cy.get('[data-testid="Pinned-Dependencies"] > span').should(
300+
cy.get('[data-testid="Pinned-Dependencies-score"] > span').should(
308301
"contain",
309302
"7/10",
310303
);
@@ -314,41 +307,37 @@ describe("Comparator", () => {
314307
);
315308

316309
cy.get('[data-testid="SAST"]').should("contain", "SAST");
317-
cy.get('[data-testid="SAST"] > div > span')
310+
cy.get('[data-testid="SAST-score"] > span')
318311
.should("contain", "Unchanged")
319312
.and("have.css", "background-color")
320313
.and("eq", "rgb(108, 117, 125)");
321-
cy.get('[data-testid="SAST"] > span').should("contain", "0/10");
314+
cy.get('[data-testid="SAST-score"] > span').should("contain", "0/10");
322315

323316
cy.get('[data-testid="Security-Policy"]').should(
324317
"contain",
325318
"Security-Policy",
326319
);
327-
cy.get('[data-testid="Security-Policy"] > div > span')
320+
cy.get('[data-testid="Security-Policy-score"] > span')
328321
.should("contain", "Unchanged")
329322
.and("have.css", "background-color")
330323
.and("eq", "rgb(108, 117, 125)");
331-
cy.get('[data-testid="Security-Policy"] > span').should("contain", "10/10");
324+
cy.get('[data-testid="Security-Policy-score"] > span').should("contain", "10/10");
332325

333326
cy.get('[data-testid="Signed-Releases"]').should(
334327
"contain",
335328
"Signed-Releases",
336329
);
337-
cy.get('[data-testid="Signed-Releases"] > div > span')
338-
.should("contain", "Unchanged")
339-
.and("have.css", "background-color")
340-
.and("eq", "rgb(108, 117, 125)");
341-
cy.get('[data-testid="Signed-Releases"] > span').should("contain", "-1/10");
330+
cy.get('[data-testid="Signed-Releases-score"] > abbr > span').should("contain", "?");
342331

343332
cy.get('[data-testid="Token-Permissions"]').should(
344333
"contain",
345334
"Token-Permissions",
346335
);
347-
cy.get('[data-testid="Token-Permissions"] > div > span')
336+
cy.get('[data-testid="Token-Permissions-score"] > span')
348337
.should("contain", "Unchanged")
349338
.and("have.css", "background-color")
350339
.and("eq", "rgb(108, 117, 125)");
351-
cy.get('[data-testid="Token-Permissions"] > span').should(
340+
cy.get('[data-testid="Token-Permissions-score"] > span').should(
352341
"contain",
353342
"10/10",
354343
);
@@ -361,11 +350,11 @@ describe("Comparator", () => {
361350
"contain",
362351
"Vulnerabilities",
363352
);
364-
cy.get('[data-testid="Vulnerabilities"] > div > span')
353+
cy.get('[data-testid="Vulnerabilities-score"] > span')
365354
.should("contain", "Increased 2.7")
366355
.and("have.css", "background-color")
367356
.and("eq", "rgb(24, 135, 84)");
368-
cy.get('[data-testid="Vulnerabilities"] > span').should("contain", "10/10");
357+
cy.get('[data-testid="Vulnerabilities-score"] > span').should("contain", "10/10");
369358
cy.get('[data-testid="Vulnerabilities"] ~ h4').should(
370359
"contain",
371360
"Additional details / variations",

cypress/e2e/visualizer.cy.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe("Visualizer", () => {
119119
.and("contain", "0/10");
120120
cy.get('[data-testid="Branch-Protection"]')
121121
.should("contain", "Branch-Protection")
122-
.and("contain", "-1/10");
122+
.and("contain", "?");
123123
cy.get('[data-testid="CI-Tests"]')
124124
.should("contain", "CI-Tests")
125125
.and("contain", "9/10");
@@ -149,7 +149,7 @@ describe("Visualizer", () => {
149149
.and("contain", "10/10");
150150
cy.get('[data-testid="Packaging"]')
151151
.should("contain", "Packaging")
152-
.and("contain", "-1/10");
152+
.and("contain", "?");
153153
cy.get('[data-testid="Pinned-Dependencies"]')
154154
.should("contain", "Pinned-Dependencies")
155155
.and("contain", "7/10");
@@ -161,7 +161,7 @@ describe("Visualizer", () => {
161161
.and("contain", "10/10");
162162
cy.get('[data-testid="Signed-Releases"]')
163163
.should("contain", "Signed-Releases")
164-
.and("contain", "-1/10");
164+
.and("contain", "?");
165165
cy.get('[data-testid="Token-Permissions"]')
166166
.should("contain", "Token-Permissions")
167167
.and("contain", "10/10");
@@ -239,7 +239,7 @@ describe("Visualizer", () => {
239239
.and("contain", "0/10");
240240
cy.get('[data-testid="Branch-Protection"]')
241241
.should("contain", "Branch-Protection")
242-
.and("contain", "-1/10");
242+
.and("contain", "?");
243243
cy.get('[data-testid="CI-Tests"]')
244244
.should("contain", "CI-Tests")
245245
.and("contain", "9/10");
@@ -269,7 +269,7 @@ describe("Visualizer", () => {
269269
.and("contain", "10/10");
270270
cy.get('[data-testid="Packaging"]')
271271
.should("contain", "Packaging")
272-
.and("contain", "-1/10");
272+
.and("contain", "?");
273273
cy.get('[data-testid="Pinned-Dependencies"]')
274274
.should("contain", "Pinned-Dependencies")
275275
.and("contain", "7/10");
@@ -281,7 +281,7 @@ describe("Visualizer", () => {
281281
.and("contain", "10/10");
282282
cy.get('[data-testid="Signed-Releases"]')
283283
.should("contain", "Signed-Releases")
284-
.and("contain", "-1/10");
284+
.and("contain", "?");
285285
cy.get('[data-testid="Token-Permissions"]')
286286
.should("contain", "Token-Permissions")
287287
.and("contain", "10/10");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import "../styles/NoAvailableDataMark.css";
2+
3+
export default function NoAvailableDataMark() {
4+
return (
5+
<abbr className="tooltip tooltip--top" data-tooltip="Data not available">
6+
<span className="not-available-data">?</span>
7+
</abbr>
8+
);
9+
}

src/components/ProjectComparator.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { scoreChecker } from "../utils/comparator/scoreChecker";
77
import CommonError from "./CommonError";
88
import Collapsible from "./Collapsable";
99
import Loading from "./Loading";
10+
import NoAvailableDataMark from "./NoAvailableDataMark";
1011
import { ComparatorDiff } from "./ComparatorDiff";
1112
import { ScoreElement, ConsolidatedScoreElement } from "../types";
1213
import { getRefinedChecks } from "../utils/comparator/getRefinedChecks";
@@ -100,10 +101,7 @@ function ProjectComparator() {
100101
return (
101102
<>
102103
<h1>OpenSSF Scorecard comparator for {`${org}/${repo}`}</h1>
103-
<div
104-
data-testid="current-score-and-badge"
105-
className="info-badge__wrapper"
106-
>
104+
<div data-testid="current-score-and-badge" className="score-wrapper">
107105
<h2>{`Current Score: ${currentData.score}/10`} </h2>
108106
{scoreChecker(currentData.score, previousData.score)}
109107
</div>
@@ -156,10 +154,19 @@ function ProjectComparator() {
156154
<div data-testid={element.name} className="heading__wrapper">
157155
<div className="info-badge__wrapper">
158156
<h3>{element.name}</h3>
159-
{scoreChecker(element.score, element.prevScore)}
157+
<div data-testid={`${element.name}-score`} className="info-score__wrapper">
158+
{element.score >= 0 ? (
159+
<>
160+
{scoreChecker(element.score, element.prevScore)}
161+
<span>{element.score}/10</span>
162+
</>
163+
) : (
164+
<NoAvailableDataMark />
165+
)}
166+
</div>
160167
</div>
161-
<span>{element.score}/10</span>
162168
</div>
169+
163170
<p>
164171
Description: {element.short.toLocaleLowerCase()}{" "}
165172
<a href={`${element.url}`} target="_blank" rel="noreferrer">

src/components/ProjectDetails.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { formatDate } from "../utils/formatDate";
66
import CommonError from "./CommonError";
77
import Collapsible from "./Collapsable";
88
import Loading from "./Loading";
9-
9+
import NoAvailableDataMark from "./NoAvailableDataMark";
1010
import { ScoreElement } from "../types";
1111
import { GITHUB } from "../constants/platforms";
1212

@@ -93,7 +93,11 @@ function ProjectDetails() {
9393
<div key={element.name} className="card__wrapper">
9494
<div className="heading__wrapper" data-testid={element.name}>
9595
<h3>{element.name}</h3>
96-
<span>{element.score}/10</span>
96+
{element.score !== -1 ? (
97+
<span>{element.score}/10</span>
98+
) : (
99+
<NoAvailableDataMark />
100+
)}
97101
</div>
98102
<p>
99103
Description: {element.documentation.short.toLocaleLowerCase()}{" "}

src/styles/Badge.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
.badge {
22
width: auto;
33
padding: 0.4rem;
4+
margin-right: 1rem;
45
color: white;
56
background-color: #6c757d;
67
border-radius: 5px;
7-
font-size: 1rem;
8+
font-size: 14px;
89
display: inline-block;
910
font-weight: 600;
1011
}

0 commit comments

Comments
 (0)