summaryrefslogtreecommitdiffstats
path: root/lib/models/__tests__/summary.js
blob: 29c9330ac7f5a9274b5a469a882f8e6a339e1ef6 (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
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

describe('Summary', function() {
    var File = require('../file');
    var Summary = require('../summary');

    var summary = Summary.createFromParts(File(), [
        {
            articles: [
                {
                    title: 'My First Article',
                    ref: 'README.md'
                },
                {
                    title: 'My Second Article',
                    ref: 'article.md'
                },
                {
                    title: 'Article without ref'
                },
                {
                    title: 'Article with absolute ref',
                    ref: 'https://google.fr'
                }
            ]
        },
        {
            title: 'Test'
        }
    ]);

    describe('createFromEntries', function() {
        it('must add all parts', function() {
            var parts = summary.getParts();
            expect(parts.size).toBe(2);
        });
    });

    describe('getByLevel', function() {
        it('can return a Part', function() {
            var part = summary.getByLevel('1');

            expect(part).toBeDefined();
            expect(part.getArticles().size).toBe(4);
        });

        it('can return a Part (2)', function() {
            var part = summary.getByLevel('2');

            expect(part).toBeDefined();
            expect(part.getTitle()).toBe('Test');
            expect(part.getArticles().size).toBe(0);
        });

        it('can return an Article', function() {
            var article = summary.getByLevel('1.1');

            expect(article).toBeDefined();
            expect(article.getTitle()).toBe('My First Article');
        });
    });

    describe('getByPath', function() {
        it('return correct article', function() {
            var article = summary.getByPath('README.md');

            expect(article).toBeDefined();
            expect(article.getTitle()).toBe('My First Article');
        });

        it('return correct article', function() {
            var article = summary.getByPath('article.md');

            expect(article).toBeDefined();
            expect(article.getTitle()).toBe('My Second Article');
        });

        it('return undefined if not found', function() {
            var article = summary.getByPath('NOT_EXISTING.md');

            expect(article).toBeFalsy();
        });
    });

    describe('toText', function() {
        it('return as markdown', function() {
            return summary.toText('.md')
            .then(function(text) {
                expect(text).toContain('# Summary');
            });
        });
    });
});