This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
forked from speced/respec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-cite-spec.js
294 lines (294 loc) · 9.27 KB
/
data-cite-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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
"use strict";
describe("Core — data-cite attribute", () => {
afterAll(done => {
flushIframes();
done();
});
it(`walks up the tree to find the right reference to cite`, done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section data-cite="dahut">
<h2>test</h2>
<p>
<a id="t1" data-cite="#test">a</a>
<dfn id="t2" data-cite="#test">a</dfn>
</p>
<p data-cite="URL">
<a id="t3" data-cite="#urlspec">a</a>
</p>
<section data-cite="URL">
<div data-cite="#fail">
<p data-cite="#fail">
<a id="t4" data-cite="#urlspec">a</a>
<a id="t5" data-cite="CONSOLE#test5">a</a>
</p>
</div>
</section>
</section>
`,
};
ops.config.shortName = "fail";
makeRSDoc(ops).then(doc => {
const t1 = doc.getElementById("t1");
const t2 = doc.getElementById("t2").querySelector("a");
const t3 = doc.getElementById("t3");
const t4 = doc.getElementById("t4");
const t5 = doc.getElementById("t5");
const location = new URL("#test", "http://berjon.com/").href;
expect(t1.href).toEqual(location);
expect(t2.href).toEqual(location);
const urlSpecHref = new URL("#urlspec", "https://url.spec.whatwg.org/").href;
expect(t3.href).toEqual(urlSpecHref);
expect(t4.href).toEqual(urlSpecHref);
const fooBarHref = new URL("#test5", "https://console.spec.whatwg.org/").href;
expect(t5.href).toEqual(fooBarHref);
done();
});
});
it(`treats data-cite="#foo" as self citing when there is no parent data-cite`, done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section>
<h2>test</h2>
<p>
<a id="t1" data-cite="#test">a</a>
<dfn id="t2" data-cite="#test">a</dfn>
</p>
</section>
`,
};
ops.config.shortName = "dahut";
makeRSDoc(ops).then(doc => {
const t1 = doc.getElementById("t1");
const t2 = doc.getElementById("t2").querySelector("a");
const location = new URL("#test", doc.location).href;
expect(t1.href).toEqual(location);
expect(t2.href).toEqual(location);
done();
});
});
it("links data-cite attributes as normative/informative reference when parent is citing", done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section data-cite="FETCH">
<p><a data-cite="#fetch-thing">informative reference</a></p>
</section>
<section data-cite="!URL">
<p><a data-cite="#url-thing">normative reference</a></p>
</section>
`,
};
makeRSDoc(ops)
.then(doc => {
expect(
doc.querySelector("#bib-URL").closest("section").id
).toEqual("normative-references");
expect(
doc.querySelector("#bib-FETCH").closest("section").id
).toEqual("informative-references");
})
.then(done);
});
it("links directly to externally defined references", done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section>
<p id="t1"><a>inline link</a></p>
<p id="t2"><dfn data-cite="!WHATWG-HTML#test">inline link</dfn></p>
</section>
`,
};
makeRSDoc(ops)
.then(doc => {
const a = doc.querySelector("#t1 > a");
expect(a.textContent).toEqual("inline link");
expect(a.href).toEqual("https://html.spec.whatwg.org/multipage/#test");
expect(a.hasAttribute("data-cite")).toEqual(false);
expect(
doc.querySelector("#bib-WHATWG-HTML").closest("section").id,
).toEqual("normative-references");
// Definition part
const dfn = doc.querySelector("#t2 > dfn");
expect(dfn).toBeTruthy();
const dfnA = doc.querySelector("#t2 > dfn > a");
expect(dfnA.textContent).toEqual("inline link");
expect(dfnA.href).toEqual(
"https://html.spec.whatwg.org/multipage/#test",
);
expect(dfnA.hasAttribute("data-cite")).toEqual(false);
expect(
doc.querySelector("#bib-WHATWG-HTML").closest("section").id,
).toEqual("normative-references");
})
.then(done);
});
it("links data-cite attributes as normative reference", done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section>
<p id="t1"><a data-cite="!WHATWG-HTML">inline link</a></p>
</section>
`,
};
makeRSDoc(ops)
.then(doc => {
const a = doc.querySelector("#t1 > a");
expect(a.textContent).toEqual("inline link");
expect(a.href).toEqual("https://html.spec.whatwg.org/multipage/");
expect(a.hasAttribute("data-cite")).toEqual(false);
expect(
doc.querySelector("#bib-WHATWG-HTML").closest("section").id,
).toEqual("normative-references");
})
.then(done);
});
it("links data-cite attributes as informative reference", done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section>
<p id="t1"><a data-cite="WHATWG-DOM">inline link</a></p>
</section>
`,
};
makeRSDoc(ops)
.then(doc => {
const a = doc.querySelector("#t1 > a");
expect(a.textContent).toEqual("inline link");
expect(a.href).toEqual("https://dom.spec.whatwg.org/");
expect(a.hasAttribute("data-cite")).toEqual(false);
expect(
doc.querySelector("#bib-WHATWG-DOM").closest("section").id,
).toEqual("informative-references");
})
.then(done);
});
it("handles bogus data-cite values", done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section>
<p id="t1"><a data-cite="no-exist-inf">link 1</a></p>
<p id="t2"><a data-cite="!no-exist-norm">link 2</a></p>
</section>
`,
};
makeRSDoc(ops)
.then(doc => {
const a1 = doc.querySelector("#t1 > a");
const a2 = doc.querySelector("#t2 > a");
expect(a1.textContent).toEqual("link 1");
expect(a2.textContent).toEqual("link 2");
expect(a1.href).toEqual("");
expect(a2.href).toEqual("");
expect(a1.hasAttribute("data-cite")).toEqual(false);
expect(a2.hasAttribute("data-cite")).toEqual(false);
expect(
doc.querySelector("#bib-no-exist-inf").closest("section").id,
).toEqual("informative-references");
expect(
doc.querySelector("#bib-no-exist-norm").closest("section").id,
).toEqual("normative-references");
})
.then(done);
});
it("adds the fragment identifier to the link", done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section>
<p id="t1"><a
data-cite="!WHATWG-HTML#test">inline link</a></p>
</section>
`,
};
makeRSDoc(ops)
.then(doc => {
const a = doc.querySelector("#t1 > a");
expect(a.textContent).toEqual("inline link");
expect(a.href).toEqual("https://html.spec.whatwg.org/multipage/#test");
expect(a.hasAttribute("data-cite")).toEqual(false);
expect(
doc.querySelector("#bib-WHATWG-HTML").closest("section").id,
).toEqual("normative-references");
})
.then(done);
});
describe("data-cite-frag", () => {
it("adds the fragment identifier to the link", done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section>
<p id="t1"><a
data-cite="WHATWG-HTML"
data-cite-frag="pass">inline link</a></p>
</section>
`,
};
makeRSDoc(ops)
.then(doc => {
const a = doc.querySelector("#t1 > a");
expect(a.textContent).toEqual("inline link");
expect(a.href).toEqual(
"https://html.spec.whatwg.org/multipage/#pass",
);
expect(a.hasAttribute("data-cite")).toEqual(false);
expect(
doc.querySelector("#bib-WHATWG-HTML").closest("section").id,
).toEqual("informative-references");
})
.then(done);
});
it("cited fragments are overridden by cite-frag", done => {
const ops = {
config: makeBasicConfig(),
body:
makeDefaultBody() +
`
<section>
<p id="t1"><a
data-cite="!WHATWG-HTML#fail"
data-cite-frag="pass">inline link</a></p>
</section>
`,
};
makeRSDoc(ops)
.then(doc => {
const a = doc.querySelector("#t1 > a");
expect(a.textContent).toEqual("inline link");
expect(a.href).toEqual(
"https://html.spec.whatwg.org/multipage/#pass",
);
expect(a.hasAttribute("data-cite")).toEqual(false);
expect(
doc.querySelector("#bib-WHATWG-HTML").closest("section").id,
).toEqual("normative-references");
})
.then(done);
});
});
});