-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathno-default-alt-text.test.js
94 lines (79 loc) · 3.52 KB
/
no-default-alt-text.test.js
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
const altTextRule = require("../no-default-alt-text");
const runTest = require("./utils/run-test").runTest;
describe("GH001: No Default Alt Text", () => {
describe("successes", () => {
test("inline", async () => {
const strings = [
"",
];
const results = await runTest(strings, altTextRule);
for (const result of results) {
expect(result).not.toBeDefined();
}
});
test("html image", async () => {
const strings = [
'<img alt="A helpful description" src="https://user-images.githubusercontent.com/abcdef.png">',
];
const results = await runTest(strings, altTextRule);
for (const result of results) {
expect(result).not.toBeDefined();
}
});
});
describe("failures", () => {
test("markdown example", async () => {
const strings = [
"",
"",
"",
"",
];
const results = await runTest(strings, altTextRule);
const failedRules = results
.map((result) => result.ruleNames)
.flat()
.filter((name) => !name.includes("GH"));
expect(failedRules).toHaveLength(4);
for (const rule of failedRules) {
expect(rule).toBe("no-default-alt-text");
}
});
test("HTML example", async () => {
const strings = [
'<img alt="Screen Shot 2022-06-26 at 7 41 30 PM" src="https://user-images.githubusercontent.com/abcdef.png">',
'<img alt="ScreenShot 2022-06-26 at 7 41 30 PM" src="https://user-images.githubusercontent.com/abcdef.png">',
'<img alt="Screen shot 2022-06-26 at 7 41 30 PM" src="https://user-images.githubusercontent.com/abcdef.png">',
'<img alt="Screenshot 2022-06-26 at 7 41 30 PM" src="https://user-images.githubusercontent.com/abcdef.png">',
];
const results = await runTest(strings, altTextRule);
const failedRules = results
.map((result) => result.ruleNames)
.flat()
.filter((name) => !name.includes("GH"));
expect(failedRules).toHaveLength(4);
for (const rule of failedRules) {
expect(rule).toBe("no-default-alt-text");
}
});
test("error message", async () => {
const strings = [
"",
'<img alt="Screen Shot 2022-06-26 at 7 41 30 PM" src="https://user-images.githubusercontent.com/abcdef.png">',
];
const results = await runTest(strings, altTextRule);
expect(results[0].ruleDescription).toMatch(
/Images should not use the MacOS default screenshot filename as alternate text/
);
expect(results[0].errorDetail).toBe(
"For image: Screen Shot 2022-06-26 at 7 41 30 PM"
);
expect(results[1].ruleDescription).toMatch(
/Images should not use the MacOS default screenshot filename as alternate text/
);
expect(results[1].errorDetail).toBe(
'For image: <img alt="Screen Shot 2022-06-26 at 7 41 30 PM" src="https://user-images.githubusercontent.com/abcdef.png">'
);
});
});
});