-
-
Notifications
You must be signed in to change notification settings - Fork 374
/
biblio-spec.js
120 lines (114 loc) · 3.38 KB
/
biblio-spec.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
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
"use strict";
describe("W3C — Bibliographic References", () => {
const config = {
editors: [
{
name: "Robin Berjon",
},
],
edDraftURI: "https://foo",
shortName: "Foo",
specStatus: "WD",
prevVersion: "FPWD",
previousMaturity: "WD",
previousPublishDate: "2013-12-17",
localBiblio: {
Zzz: {
title: "Last Reference",
},
aaa: {
title: "First Reference",
},
TestRef1: {
title: "Test ref title",
href: "http://test.com",
authors: ["William Shakespeare"],
publisher: "Publishers Inc.",
},
TestRef2: {
title: "Second test",
href: "http://test.com",
authors: ["Another author"],
publisher: "Testing 123",
},
TestRef3: {
title: "Third test",
href: "http://test.com",
publisher: "Publisher Here",
},
FOOBARGLOP: {
aliasOf: "BARBAR",
},
BARBAR: {
title: "The BARBAR Spec",
},
},
};
const body = `
<section id='sotd'>
<p>foo [[!TestRef1]] [[TestRef2]] [[!TestRef3]]</p>
</section>
<section id='sample'>
<h2>Privacy</h2>
<p>foo [[!FOOBARGLOP]] bar</p>
</section>
<section>
<h2>Sorted</h2>
<p>From [[!Zzz]] to [[!aaa]]</p>
</secton>
`;
afterAll(flushIframes);
const bibRefsURL = new URL("https://specref.herokuapp.com/bibrefs");
const specRefPing = fetch(bibRefsURL, { method: "HEAD" });
let doc;
beforeAll(async () => {
doc = await makeRSDoc({ config, body });
});
it("pings biblio service to see if it's running", async () => {
const res = await specRefPing;
expect(res.ok).toBeTruthy();
});
it("includes a dns-prefetch to bibref server", () => {
const host = bibRefsURL.host;
const link = doc.querySelector(`link[rel='dns-prefetch'][href*='${host}']`);
expect(link).toBeTruthy();
expect(link.classList.contains("removeOnSave")).toBeTruthy();
});
it("displays the publisher when present", () => {
// Make sure the reference is added.
let ref = doc.querySelector("#bib-TestRef1 + dd");
expect(ref).toBeTruthy();
// This prevents Jasmine from taking down the whole test suite if SpecRef is down.
if (!(await specRefPing).ok) {
throw new Error(
"SpecRef seems to be down. Can't proceed with this spec."
);
}
expect(ref.textContent).toMatch(/Publishers Inc\.\s/);
ref = null;
// Make sure the ". " is automatically added to publisher.
ref = doc.querySelector("#bib-TestRef2 + dd");
expect(ref).toBeTruthy();
expect(ref.textContent).toMatch(/Testing 123\.\s/);
ref = null;
// Make sure publisher is shown even when there is no author
ref = doc.querySelector("#bib-TestRef3 + dd");
expect(ref).toBeTruthy();
expect(ref.textContent).toMatch(/Publisher Here\.\s/);
});
it("resolves a localy-aliased spec", () => {
const ref = doc.querySelector("#bib-FOOBARGLOP + dd");
expect(ref).toBeTruthy();
expect(ref.textContent).toMatch(/BARBAR/);
});
it("sorts references as if they were lowercase", () => {
const { textContent: first } = doc.querySelector(
"#normative-references dt:first-of-type"
);
const { textContent: last } = doc.querySelector(
"#normative-references dt:last-of-type"
);
expect(first).toMatch("[a]");
expect(last).toMatch("[Zzz]");
});
});