-
Notifications
You must be signed in to change notification settings - Fork 14
/
rule.spec.tsx
63 lines (52 loc) · 1.73 KB
/
rule.spec.tsx
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
import { jsx } from "@siteimprove/alfa-dom/jsx";
import { test } from "@siteimprove/alfa-test";
import { Document, Element } from "@siteimprove/alfa-dom";
import { Option } from "@siteimprove/alfa-option";
import R1, { Outcomes } from "../../src/sia-r1/rule";
import { evaluate } from "../common/evaluate";
import { passed, failed, inapplicable } from "../common/outcome";
test("evaluate() passes a document that that a non-empty <title> element", async (t) => {
const document = Document.of((self) => [
Element.fromElement(
<html>
<head>
<title>Hello world</title>
</head>
</html>,
Option.of(self)
),
]);
t.deepEqual(await evaluate(R1, { document }), [
passed(R1, document, {
1: Outcomes.HasTitle,
2: Outcomes.HasNonEmptyTitle,
}),
]);
});
test("evaluate() fails a document that has no <title> element", async (t) => {
const document = Document.of((self) => [
Element.fromElement(<html></html>, Option.of(self)),
]);
t.deepEqual(await evaluate(R1, { document }), [
failed(R1, document, { 1: Outcomes.HasNoTitle, 2: Outcomes.HasEmptyTitle }),
]);
});
test("evaluate() fails a document that has an empty <title> element", async (t) => {
const document = Document.of((self) => [
Element.fromElement(
<html>
<head>
<title></title>
</head>
</html>,
Option.of(self)
),
]);
t.deepEqual(await evaluate(R1, { document }), [
failed(R1, document, { 1: Outcomes.HasTitle, 2: Outcomes.HasEmptyTitle }),
]);
});
test("evaluate() is inapplicable when a document is not an HTML document", async (t) => {
const document = Document.empty();
t.deepEqual(await evaluate(R1, { document }), [inapplicable(R1)]);
});