summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-asciidoc/test/summary.js
blob: 7197df6090d7bd170c7ae15a79d41662eb669d57 (plain)
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
const fs = require('fs');
const path = require('path');
const expect = require('expect');

const summary = require('../src').summary;

describe('Summary parsing', () => {
    let LEXED, PART;

    before(() => {
        const CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SUMMARY.adoc'), 'utf8');
        LEXED = summary(CONTENT);
        PART = LEXED.parts[0];
        // todo: add support for parts in asciidoc
    });

    it('should detect parts', () => {
        expect(LEXED.parts.length).toBe(1);
    });

    it('should detect articles', () => {
        expect(PART.articles.length).toBe(5);
    });

    it('should support articles', () => {
        expect(PART.articles[0].articles.length).toBe(2);
        expect(PART.articles[1].articles.length).toBe(0);
        expect(PART.articles[2].articles.length).toBe(0);
    });

    it('should detect paths and titles', () => {
        expect(PART.articles[0].ref).toExist();
        expect(PART.articles[1].ref).toExist();
        expect(PART.articles[2].ref).toExist();
        expect(PART.articles[3].ref).toExist();
        expect(PART.articles[4].ref).toNotExist();

        expect(PART.articles[0].title).toExist();
        expect(PART.articles[1].title).toExist();
        expect(PART.articles[2].title).toExist();
        expect(PART.articles[3].title).toExist();
        expect(PART.articles[4].title).toExist();
    });

    it('should normalize paths from .md', () => {
        expect(PART.articles[0].ref).toBe('chapter-1/README.adoc');
        expect(PART.articles[1].ref).toBe('chapter-2/README.adoc');
        expect(PART.articles[2].ref).toBe('chapter-3/README.adoc');
    });

    it('should correctly convert it to text', () => {
        const text = summary.toText(LEXED);
        const parsed = summary(text);
        expect(parsed).toEqual(LEXED);
    });
});