-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction_test.js
More file actions
376 lines (281 loc) · 10.6 KB
/
Copy pathaction_test.js
File metadata and controls
376 lines (281 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// SPDX-License-Identifier: PMPL-1.0-or-later
// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
//
// Accessibility Everywhere - GitHub Action Tests
// Tests GitHub Actions input validation, output format, and integration.
import {
assertEquals,
assertExists,
assertStringIncludes,
} from "https://deno.land/std@0.208.0/assert/mod.ts";
// Mock GitHub Action input/output
class MockGitHubAction {
inputs = {};
outputs = {};
setInput(name , value ) {
this.inputs[name ] = value;
}
getInput(name , required = false) {
const value = this.inputs[name ];
if (required && !value) {
throw new Error(`Input required and not supplied: ${name}`);
}
return value;
}
setOutput(name , value ) {
this.outputs[name ] = value ;
}
getOutputs() {
return this.outputs;
}
validateInputs()
{
const errors = [];
// Check required input: url
if (!this.getInput("url")) {
errors.push("url is required");
}
// Validate URL format if provided
const url = this.getInput("url");
if (url) {
try {
new URL(url);
} catch {
errors.push(`Invalid URL format: ${url}`);
}
}
// Validate wcag-level
const wcagLevel = this.getInput("wcag-level");
if (wcagLevel && !["A", "AA", "AAA"].includes(wcagLevel)) {
errors.push(`Invalid WCAG level: ${wcagLevel}. Must be A, AA, or AAA`);
}
// Validate min-score
const minScore = this.getInput("min-score");
if (minScore) {
const score = parseInt(minScore);
if (isNaN(score) || score < 0 || score > 100) {
errors.push(`Invalid min-score: ${minScore}. Must be 0-100`);
}
}
return {
valid: errors.length === 0,
errors,
};
}
generateSummary(result
) {
const grade =
result.score >= 90
? "A"
: result.score >= 80
? "B"
: result.score >= 70
? "C"
: "F";
let markdown = `# Accessibility Report\n\n`;
markdown += `**Score:** ${result.score}/100 (Grade ${grade})\n`;
markdown += `**Violations:** ${Array.isArray(result.violations) ? result.violations.length : 0}\n`;
markdown += `**Passes:** ${Array.isArray(result.passes) ? result.passes.length : 0}\n`;
return markdown;
}
}
// Test suite
Deno.test("GitHub Action - URL input required", () => {
const action = new MockGitHubAction();
const validation = action.validateInputs();
assertEquals(validation.valid, false);
assertStringIncludes(validation.errors.join(","), "url is required");
});
Deno.test("GitHub Action - Missing required input produces clear error", () => {
const action = new MockGitHubAction();
action.setInput("wcag-level", "AA");
const validation = action.validateInputs();
assertEquals(validation.valid, false);
assertEquals(validation.errors.length > 0, true);
});
Deno.test("GitHub Action - URL input validated", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
const validation = action.validateInputs();
assertEquals(validation.valid, true);
});
Deno.test("GitHub Action - Invalid URL returns error", () => {
const action = new MockGitHubAction();
action.setInput("url", "not-a-valid-url");
const validation = action.validateInputs();
assertEquals(validation.valid, false);
assertStringIncludes(validation.errors.join(","), "Invalid URL");
});
Deno.test("GitHub Action - WCAG level validated (A)", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
action.setInput("wcag-level", "A");
const validation = action.validateInputs();
assertEquals(validation.valid, true);
});
Deno.test("GitHub Action - WCAG level validated (AA)", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
action.setInput("wcag-level", "AA");
const validation = action.validateInputs();
assertEquals(validation.valid, true);
});
Deno.test("GitHub Action - WCAG level validated (AAA)", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
action.setInput("wcag-level", "AAA");
const validation = action.validateInputs();
assertEquals(validation.valid, true);
});
Deno.test("GitHub Action - Invalid WCAG level rejected", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
action.setInput("wcag-level", "INVALID");
const validation = action.validateInputs();
assertEquals(validation.valid, false);
assertStringIncludes(validation.errors.join(","), "Invalid WCAG level");
});
Deno.test("GitHub Action - Min score validated (0)", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
action.setInput("min-score", "0");
const validation = action.validateInputs();
assertEquals(validation.valid, true);
});
Deno.test("GitHub Action - Min score validated (100)", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
action.setInput("min-score", "100");
const validation = action.validateInputs();
assertEquals(validation.valid, true);
});
Deno.test("GitHub Action - Min score out of range rejected", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
action.setInput("min-score", "150");
const validation = action.validateInputs();
assertEquals(validation.valid, false);
assertStringIncludes(validation.errors.join(","), "Invalid min-score");
});
Deno.test("GitHub Action - Non-numeric min-score rejected", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
action.setInput("min-score", "not-a-number");
const validation = action.validateInputs();
assertEquals(validation.valid, false);
});
Deno.test("GitHub Action - Output score set correctly", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
action.setOutput("score", 85);
const outputs = action.getOutputs();
assertEquals(outputs.score, 85);
});
Deno.test("GitHub Action - Output violations count set", () => {
const action = new MockGitHubAction();
action.setOutput("violations", 3);
const outputs = action.getOutputs();
assertEquals(outputs.violations, 3);
});
Deno.test("GitHub Action - Output passes count set", () => {
const action = new MockGitHubAction();
action.setOutput("passes", 42);
const outputs = action.getOutputs();
assertEquals(outputs.passes, 42);
});
Deno.test("GitHub Action - Output report-url set", () => {
const action = new MockGitHubAction();
action.setOutput(
"report-url",
"https://accessibility-everywhere.org/report?url=..."
);
const outputs = action.getOutputs();
assertExists(outputs["report-url"]);
assertStringIncludes(outputs["report-url"] || "", "accessibility-everywhere");
});
Deno.test("GitHub Action - All required outputs present", () => {
const action = new MockGitHubAction();
action.setOutput("score", 85);
action.setOutput("violations", 3);
action.setOutput("passes", 42);
action.setOutput("report-url", "https://example.org/report");
const outputs = action.getOutputs();
assertExists(outputs.score);
assertExists(outputs.violations);
assertExists(outputs.passes);
assertExists(outputs["report-url"]);
});
Deno.test("GitHub Action - Summary generated with correct format", () => {
const action = new MockGitHubAction();
const summary = action.generateSummary({
score: 85,
violations: [{ id: "v1" }, { id: "v2" }, { id: "v3" }],
passes: Array(42).fill(null),
});
assertStringIncludes(summary, "Accessibility Report");
assertStringIncludes(summary, "85");
assertStringIncludes(summary, "Grade B");
assertStringIncludes(summary, "**Violations:** 3");
assertStringIncludes(summary, "**Passes:** 42");
});
Deno.test("GitHub Action - Summary grading accurate (A grade)", () => {
const action = new MockGitHubAction();
const summary = action.generateSummary({
score: 95,
violations: [],
passes: Array(50).fill(null),
});
assertStringIncludes(summary, "Grade A");
});
Deno.test("GitHub Action - Summary grading accurate (B grade)", () => {
const action = new MockGitHubAction();
const summary = action.generateSummary({
score: 85,
violations: [1, 2, 3],
passes: Array(40).fill(null),
});
assertStringIncludes(summary, "Grade B");
});
Deno.test("GitHub Action - Summary grading accurate (C grade)", () => {
const action = new MockGitHubAction();
const summary = action.generateSummary({
score: 75,
violations: Array(10).fill(null),
passes: Array(30).fill(null),
});
assertStringIncludes(summary, "Grade C");
});
Deno.test("GitHub Action - Summary grading accurate (F grade)", () => {
const action = new MockGitHubAction();
const summary = action.generateSummary({
score: 55,
violations: Array(20).fill(null),
passes: Array(20).fill(null),
});
assertStringIncludes(summary, "Grade F");
});
Deno.test("GitHub Action - Multiple inputs processed together", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
action.setInput("wcag-level", "AA");
action.setInput("min-score", "75");
action.setInput("fail-on-violations", "true");
action.setInput("comment-pr", "true");
const validation = action.validateInputs();
assertEquals(validation.valid, true);
assertEquals(validation.errors.length, 0);
});
Deno.test("GitHub Action - Input defaults applied", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
// Unset inputs should return undefined, not throw
const wcagLevel = action.getInput("wcag-level");
assertEquals(wcagLevel, undefined);
});
Deno.test("GitHub Action - Boolean inputs parsed", () => {
const action = new MockGitHubAction();
action.setInput("url", "https://example.com");
action.setInput("fail-on-violations", "true");
const failOnViolations = action.getInput("fail-on-violations");
assertEquals(failOnViolations, "true");
});