summaryrefslogtreecommitdiffstats
path: root/packages/gitbook/src/modifiers/summary/__tests__/editPartTitle.js
blob: aa14a3418cb4250f30d0b2641407ad132440d150 (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
const Summary = require('../../../models/summary');
const File = require('../../../models/file');

describe('editPartTitle', function() {
    const editPartTitle = require('../editPartTitle');
    const summary = Summary.createFromParts(File(), [
        {
            articles: [
                {
                    title: 'My First Article',
                    path: 'README.md'
                },
                {
                    title: 'My Second Article',
                    path: 'article.md'
                }
            ]
        },
        {
            title: 'Test'
        }
    ]);

    it('should correctly set title of first part', function() {
        const newSummary = editPartTitle(summary, 0, 'Hello World');
        const part = newSummary.getPart(0);

        expect(part.getTitle()).toBe('Hello World');
    });

    it('should correctly set title of second part', function() {
        const newSummary = editPartTitle(summary, 1, 'Hello');
        const part = newSummary.getPart(1);

        expect(part.getTitle()).toBe('Hello');
    });

    it('should not fail if part doesn\'t exist', function() {
        const newSummary = editPartTitle(summary, 3, 'Hello');
        expect(newSummary.getParts().size).toBe(2);
    });
});