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
/
link-to-dfn-spec.js
50 lines (50 loc) · 1.72 KB
/
link-to-dfn-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
"use strict";
describe("Core — Link to definitions", function() {
afterAll(function(done) {
flushIframes();
done();
});
it("URL-encodes fragment components", done => {
const bodyText = `
<section">
<h2>Test section</h2>
<p><dfn>[[\\test]]</dfn><a id="testAnchor">[[\\test]]</a>
</section>`;
const ops = {
config: makeBasicConfig(),
body: makeDefaultBody() + bodyText,
};
makeRSDoc(ops, doc => {
const a = doc.body.querySelector("#testAnchor");
expect(a).toBeTruthy();
expect(a.hash).toEqual("#dfn-x%5B%5Btest%5D%5D");
const decodedHash = decodeURIComponent(a.hash);
expect(doc.getElementById(decodedHash.slice(1))).toBeTruthy();
}).then(done);
});
it("links to IDL definitions and wraps in code if needed", function(done) {
const bodyText = `
<section data-link-for="Request">
<h2><dfn>Request</dfn> interface</h2>
<pre class="idl">
interface Request {};
</pre>
<p id="codeWrap">A <a>Request</a> object.</p>
<p id="noCodeWrap">An instance of <a lt="Request">the request interface</a>.</p>
</section>`;
var ops = {
config: makeBasicConfig(),
body: makeDefaultBody() + bodyText,
};
makeRSDoc(ops, doc => {
const hasCode = doc.body.querySelector("#codeWrap a");
expect(hasCode).toBeTruthy();
expect(hasCode.firstElementChild.localName).toEqual("code");
expect(hasCode.textContent).toEqual("Request");
const noCodeWrap = doc.body.querySelector("#noCodeWrap a");
expect(noCodeWrap).toBeTruthy();
expect(noCodeWrap.querySelector("code")).toBeFalsy();
expect(noCodeWrap.textContent).toEqual("the request interface");
}).then(done);
});
});