-
-
Notifications
You must be signed in to change notification settings - Fork 374
/
biblio-spec.js
98 lines (93 loc) · 2.97 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
"use strict";
describe("W3C — Bibliographic References", function() {
var isSpecRefAvailable = true;
var bibRefsURL = new URL("https://specref.herokuapp.com/bibrefs");
afterAll(function(done) {
flushIframes();
done();
});
// Ping biblio service to see if it's running
it("should reach biblio service", function(done) {
var fetchOps = {
method: "HEAD"
};
fetch(bibRefsURL, fetchOps)
.then(function(res) {
isSpecRefAvailable = res.ok;
expect(res.ok).toBeTruthy();
done();
})
.catch(function(err) {
fail("Error", err);
done();
});
});
var customConfig = {
editors: [{
name: "Robin Berjon"
}],
shortName: "Foo",
specStatus: "WD",
prevVersion: "FPWD",
previousMaturity: "WD",
previousPublishDate: "2013-12-17",
localBiblio: {
"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"
},
}
};
it("includes a dns-prefetch to bibref server", function(done) {
var ops = {
config: customConfig,
body: "<section id='sotd'><p>foo [[!TestRef1]] [[TestRef2]] [[!TestRef3]]</p></section>",
};
makeRSDoc(ops, function(doc) {
var host = bibRefsURL.host;
var link = doc.querySelector("link[rel='dns-prefetch'][href*='" + host + "']");
expect(link).toBeTruthy();
expect(link.classList.contains("removeOnSave")).toBeTruthy();
}).then(done).catch(done);
});
it("should display the publisher when present", function(done) {
var ops = {
config: customConfig,
body: "<section id='sotd'><p>foo [[!TestRef1]] [[TestRef2]] [[!TestRef3]]</p></section>",
};
makeRSDoc(ops, function(doc) {
// Make sure the reference is added.
var ref = doc.querySelector("#bib-TestRef1 + dd");
expect(ref).toBeTruthy();
// This prevents Jasmine from taking down the whole test suite if SpecRef is down.
if (!isSpecRefAvailable) {
var err = new Error("SpecRef seems to be down. Can't proceed with this spec.");
return Promise.reject(err);
}
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/);
}).then(done).catch(done);
});
});