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
|
var should = require('should');
var mock = require('./mock');
function mockSummary(files, summary) {
return mock.setupDefaultBook(files, summary)
.then(function(book) {
return book.readme.load()
.then(function() {
return book.summary.load();
})
.thenResolve(book);
});
}
describe('Summary / Table of contents', function() {
describe('Empty summary list', function() {
var book;
before(function() {
return mockSummary({})
.then(function(_book) {
book = _book;
});
});
it('should add README as first entry', function() {
should(book.summary.getArticle('README.md')).be.ok();
});
it('should correctly count articles', function() {
book.summary.count().should.equal(1);
});
});
describe('Non-empty summary list', function() {
var book;
before(function() {
return mockSummary({
'SUMMARY.md': '# Summary\n\n'
+ '* [Hello](./hello.md)\n'
+ '* [World](./world.md)\n\n'
})
.then(function(_book) {
book = _book;
});
});
it('should correctly count articles', function() {
book.summary.count().should.equal(3);
});
});
describe('Levels', function() {
var book;
before(function() {
return mockSummary({
'SUMMARY.md': '# Summary\n\n'
+ '* [Hello](./hello.md)\n'
+ ' * [Hello 2](./hello2.md)\n'
+ '* [World](./world.md)\n\n'
+ '## Part 2\n\n'
+ '* [Hello 3](./hello.md)\n'
+ ' * [Hello 4](./hello2.md)\n'
})
.then(function(_book) {
book = _book;
});
});
it('should correctly index levels', function() {
book.summary.getArticleByLevel('0').title.should.equal('Introduction');
book.summary.getArticleByLevel('1.1').title.should.equal('Hello');
book.summary.getArticleByLevel('1.1.1').title.should.equal('Hello 2');
book.summary.getArticleByLevel('1.2').title.should.equal('World');
book.summary.getArticleByLevel('2.1').title.should.equal('Hello 3');
book.summary.getArticleByLevel('2.1.1').title.should.equal('Hello 4');
});
});
describe('External', function() {
var book;
before(function() {
return mockSummary({}, [
{
title: 'Google',
path: 'https://www.google.fr'
}
])
.then(function(_book) {
book = _book;
});
});
it('should correctly count articles', function() {
book.summary.count().should.equal(2);
});
it('should correctly signal it as external', function() {
var article = book.summary.getArticleByLevel('1');
should(article).be.ok();
should(article.path).not.be.ok();
article.title.should.equal('Google');
article.ref.should.equal('https://www.google.fr');
article.isExternal().should.be.ok;
});
});
describe('Next / Previous', function() {
var book;
before(function() {
return mockSummary({
'SUMMARY.md': '# Summary\n\n' +
'* [Hello](hello.md)\n' +
'* [Hello 2](hello2.md)\n' +
' * [Hello 3](hello3.md)\n' +
' * [Hello 4](hello4.md)\n' +
' * [Hello 5](hello5.md)\n' +
'* [Hello 6](hello6.md)\n'
})
.then(function(_book) {
book = _book;
});
});
it('should only return a next for the readme', function() {
var article = book.summary.getArticle('README.md');
var prev = article.prev();
var next = article.next();
should(prev).equal(null);
should(next).be.ok();
next.path.should.equal('hello.md');
});
it('should return next/prev for a first level page', function() {
var article = book.summary.getArticle('hello.md');
var prev = article.prev();
var next = article.next();
should(prev).be.ok();
should(next).be.ok();
prev.path.should.equal('README.md');
next.path.should.equal('hello2.md');
});
it('should return next/prev for a joint -> child', function() {
var article = book.summary.getArticle('hello2.md');
var prev = article.prev();
var next = article.next();
should(prev).be.ok();
should(next).be.ok();
prev.path.should.equal('hello.md');
next.path.should.equal('hello3.md');
});
it('should return next/prev for a joint <- child', function() {
var article = book.summary.getArticle('hello3.md');
var prev = article.prev();
var next = article.next();
should(prev).be.ok();
should(next).be.ok();
prev.path.should.equal('hello2.md');
next.path.should.equal('hello4.md');
});
it('should return next/prev for a children', function() {
var article = book.summary.getArticle('hello4.md');
var prev = article.prev();
var next = article.next();
should(prev).be.ok();
should(next).be.ok();
prev.path.should.equal('hello3.md');
next.path.should.equal('hello5.md');
});
it('should return next/prev for a joint -> parent', function() {
var article = book.summary.getArticle('hello5.md');
var prev = article.prev();
var next = article.next();
should(prev).be.ok();
should(next).be.ok();
prev.path.should.equal('hello4.md');
next.path.should.equal('hello6.md');
});
it('should return prev for last', function() {
var article = book.summary.getArticle('hello6.md');
var prev = article.prev();
var next = article.next();
should(prev).be.ok();
should(next).be.not.ok();
prev.path.should.equal('hello5.md');
});
});
});
|