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
/
structure-spec.js
100 lines (97 loc) · 4.47 KB
/
structure-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
describe("Core - Structure", function () {
var MAXOUT = 5000
, basicConfig = {
editors: [{ name: "Robin Berjon" }]
, specStatus: "WD"
// , doRDFa: false
}
, body = "<section class='introductory'><h2>INTRO</h2></section>" +
"<section><h2>ONE</h2><section><h2>TWO</h2><section><h2>THREE</h2><section><h2>FOUR</h2>" +
"<section><h2>FIVE</h2><section><h2>SIX</h2></section></section></section></section></section></section>" +
"<section class='notoc'><h2>Not in TOC</h2></section>" +
"<section class='appendix'><h2>ONE</h2><section><h2>TWO</h2><section><h2>THREE</h2><section>" +
"<h2>FOUR</h2><section><h2>FIVE</h2><section><h2>SIX</h2><p>[[DAHUT]]</p><p>[[!HTML5]]</p></section></section></section>" +
"</section></section></section>"
;
it("should build a ToC with default values", function () {
var doc;
runs(function () {
makeRSDoc({ config: basicConfig, body: body }, function (rsdoc) { doc = rsdoc; });
});
waitsFor(function () { return doc; }, MAXOUT);
// test default values
runs(function () {
var $toc = $("#toc", doc)
;
expect($toc.find("h2").text()).toEqual("Table of Contents");
expect($toc.find("h2 span").attr('resource')).toEqual('xhv:heading');
expect($toc.find("h2 span").attr('property')).toEqual('xhv:role');
expect($toc.find("ul:first").attr('role')).toEqual('navigation');
expect($toc.find("> ul > li").length).toEqual(3);
expect($toc.find("li").length).toEqual(15);
expect($toc.find("> ul > li a").first().text()).toEqual("1. ONE");
expect($toc.find("a[href='#six']").text()).toEqual("1.1.1.1.1.1 SIX");
expect($toc.find("> ul > li").first().next().find("> a").text()).toEqual("A. ONE");
expect($toc.find("a[href='#six-1']").text()).toEqual("A.1.1.1.1.1 SIX");
flushIframes();
});
});
it("should not build a ToC with noTOC", function () {
// test with noTOC
var doc;
runs(function () {
basicConfig.noTOC = true;
makeRSDoc({ config: basicConfig, body: body }, function (rsdoc) { doc = rsdoc; });
});
waitsFor(function () { return doc; }, MAXOUT);
runs(function () {
var $toc = $("#toc", doc)
;
expect($toc.length).toEqual(0);
flushIframes();
delete basicConfig.noTOC;
});
});
it("should include introductory sections in ToC with tocIntroductory", function () {
// test with tocIntroductory
var doc;
runs(function () {
basicConfig.tocIntroductory = true;
makeRSDoc({ config: basicConfig, body: body }, function (rsdoc) { doc = rsdoc; });
});
waitsFor(function () { return doc; }, MAXOUT);
runs(function () {
var $toc = $("#toc", doc)
;
expect($toc.find("h2").text()).toEqual("Table of Contents");
expect($toc.find("> ul > li").length).toEqual(6);
expect($toc.find("li").length).toEqual(18);
expect($toc.find("> ul > li a").first().text()).toEqual("Abstract");
expect($toc.find("> ul > li a[href='#intro']").length).toEqual(1);
flushIframes();
delete basicConfig.tocIntroductory;
});
});
it("should limit ToC depth with maxTocLevel", function () {
// test with maxTocLevel
var doc;
runs(function () {
basicConfig.maxTocLevel = 4;
makeRSDoc({ config: basicConfig, body: body }, function (rsdoc) { doc = rsdoc; });
});
waitsFor(function () { return doc; }, MAXOUT);
runs(function () {
var $toc = $("#toc", doc)
;
expect($toc.find("h2").text()).toEqual("Table of Contents");
expect($toc.find("> ul > li").length).toEqual(3);
expect($toc.find("li").length).toEqual(11);
expect($toc.find("> ul > li a").first().text()).toEqual("1. ONE");
expect($toc.find("a[href='#four']").text()).toEqual("1.1.1.1 FOUR");
expect($toc.find("> ul > li").first().next().find("> a").text()).toEqual("A. ONE");
expect($toc.find("a[href='#four-1']").text()).toEqual("A.1.1.1 FOUR");
flushIframes();
delete basicConfig.maxTocLevel;
});
});
});