UNPKG

2.01 kBtext/coffeescriptView Raw
1require './setup'
2
3describe 'Sectionize', ->
4 {sectionize} = require('../lib/filters')
5 pre = (s) -> s
6
7 describe 'sectionize filter, simple', ->
8 beforeEach ->
9 @$ = Cheerio.load '''
10 <p>0</p>
11 <h2 id='first-section'>First section</h2>
12 <p>1a <b>bold</b></p>
13 <p>1b</p>
14 <p>1c</p>
15 <p>1d</p>
16 <h2 id='second-section'>Second section</h2>
17 <p>2a</p>
18 <p>2b</p>
19 ''', normalizeWhitespace: true
20 sectionize(@$, 'h2', pre, class: 's2')
21
22 it 'left the <p> alone', ->
23 expect(@$('p:root')).have.length 1
24
25 it 'correct section 1', ->
26 expect(@$('section')).have.length 2
27 expect(@$('section.s2')).have.length 2
28 expect(@$('section.section-first-section')).have.length 1
29
30 it 'section 1 contents', ->
31 expect(@$('section.section-first-section').text()).eql 'First section1a bold1b1c1d'
32 expect(@$('section.section-first-section > h2')).have.length 1
33 expect(@$('section.section-first-section > p')).have.length 4
34
35 it 'section 2 contents', ->
36 expect(@$('section.section-second-section').text()).eql 'Second section2a2b'
37 expect(@$('section.section-second-section > h2')).have.length 1
38 expect(@$('section.section-second-section > p')).have.length 2
39
40 describe 'sectionize filter, mixed headings', ->
41 beforeEach ->
42 @$ = Cheerio.load '''
43 <p>0</p>
44 <h3 id='first-section'>First section</h3>
45 <p>1a</p>
46 <p>1b</p>
47 <h2 id='second-section'>Second section</h2>
48 <p>2a</p>
49 ''', normalizeWhitespace: true
50 sectionize(@$, 'h3', pre, class: 's3')
51
52 it 'left the <p> alone', ->
53 expect(@$('p:root')).have.length 2
54
55 it 'correct section 1', ->
56 expect(@$('section')).have.length 1
57 expect(@$('section.s3')).have.length 1
58 expect(@$('section.section-first-section')).have.length 1
59
60 it 'section 1 contents', ->
61 expect(@$('section.section-first-section').text()).eql 'First section1a1b'