-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathvalidate-openacr-chapters.test.ts
152 lines (146 loc) · 4.04 KB
/
validate-openacr-chapters.test.ts
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
import { expect } from "chai";
import { validateOpenACR } from "../src/validateOpenACR";
describe("Validate OpenACR chapters", () => {
const validSchema = "openacr-0.1.0.json";
const validJSON1 = {
title: "Lorem Ipsum Accessibility Conformance Report",
product: {
name: "Lorem Ipsum",
},
author: {
email: "[email protected]",
},
chapters: {
success_criteria_level_a: {
criteria: [
{
num: "1.1.1",
components: [
{
name: "web",
adherence: {
level: "supports",
notes:
"Cras ultrices, diam in laoreet condimentum, purus leo tempor erat, eu facilisis erat tortor at purus.",
},
},
],
},
],
},
hardware: {
notes:
"Lorem Ipsum is a web application. Hardware accessibility criteria is not applicable.",
},
},
};
const validJSON2 = {
title: "Lorem Ipsum Accessibility Conformance Report",
product: {
name: "Lorem Ipsum",
},
author: {
email: "[email protected]",
},
chapters: {
success_criteria_level_a: {
disabled: false,
},
success_criteria_level_aa: {
disabled: false,
},
success_criteria_level_aaa: {
disabled: false,
},
functional_performance_criteria: {
disable: false,
},
hardware: {
disable: true,
},
software: {
disable: true,
},
support_documentation_and_services: {
disable: false,
},
},
};
const invalidJSON1 = {
title: "Lorem Ipsum Accessibility Conformance Report",
product: {
name: "Lorem Ipsum",
},
author: {
email: "[email protected]",
},
chapters: {
success_criteria_level_a: 3,
hardware: 4,
},
};
const invalidJSON2 = {
title: "Lorem Ipsum Accessibility Conformance Report",
product: {
name: "Lorem Ipsum",
},
author: {
email: "[email protected]",
},
chapters: {
success_criteria_level_a: {
criteria: ["1.1.1", "1.4.1"],
},
},
};
const invalidJSON3 = {
title: "Lorem Ipsum Accessibility Conformance Report",
product: {
name: "Lorem Ipsum",
},
author: {
email: "[email protected]",
},
chapters: {
software: {
disabled: "Yes",
notes:
"Lorem Ipsum is a web application. Hardware accessibility criteria is not applicable.",
},
},
};
let result = null;
it("pass some valid chapters JSON should return valid message", () => {
result = validateOpenACR(validJSON1, validSchema);
expect(result.result).to.equal(true);
expect(result.message).to.equal("Valid!");
});
it("pass all valid chapters JSON should return valid message", () => {
result = validateOpenACR(validJSON2, validSchema);
expect(result.result).to.equal(true);
expect(result.message).to.equal("Valid!");
});
it("pass invalid chapters JSON should return invalid JSON message", () => {
result = validateOpenACR(invalidJSON1, validSchema);
expect(result.result).to.equal(false);
expect(result.message).to.equal(
"Invalid: data/chapters/success_criteria_level_a must be object, " +
"data/chapters/hardware must be object"
);
});
it("pass invalid criteria JSON should return invalid JSON message", () => {
result = validateOpenACR(invalidJSON2, validSchema);
expect(result.result).to.equal(false);
expect(result.message).to.equal(
"Invalid: data/chapters/success_criteria_level_a/criteria/0 must be object, " +
"data/chapters/success_criteria_level_a/criteria/1 must be object"
);
});
it("pass invalid disabled JSON should return invalid JSON message", () => {
result = validateOpenACR(invalidJSON3, validSchema);
expect(result.result).to.equal(false);
expect(result.message).to.equal(
"Invalid: data/chapters/software/disabled must be boolean"
);
});
});