summaryrefslogtreecommitdiffstats
path: root/test/init.js
blob: e1e8a4ae06fee3e51e58900d486a56be96e1ee66 (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
var Book = require('../lib/book');
var mock = require('./mock');

describe('Init', function() {

    it('should create file according to summary', function() {
        return mock.setupFS({
            'SUMMARY.md': '# Summary\n\n'
                + '* [Hello](hello.md)\n'
                + '* [Hello 2](hello 2.md)\n'
        })
        .then(function(rootFolder) {
            return Book.init(mock.fs, rootFolder, {
                log: function() {}
            })
            .then(function() {
                rootFolder.should.have.file('SUMMARY.md');
                rootFolder.should.have.file('README.md');
                rootFolder.should.have.file('hello.md');
                rootFolder.should.have.file('hello 2.md');
            });
        })
    });

    it('should create file subfolder', function() {
        return mock.setupFS({
            'SUMMARY.md': '# Summary\n\n'
                + '* [Hello](test/hello.md)\n'
                + '* [Hello 2](test/test2/world.md)\n'
        })
        .then(function(rootFolder) {
            return Book.init(mock.fs, rootFolder, {
                log: function() {}
            })
            .then(function() {
                rootFolder.should.have.file('README.md');
                rootFolder.should.have.file('SUMMARY.md');
                rootFolder.should.have.file('test/hello.md');
                rootFolder.should.have.file('test/test2/world.md');
            });
        })
    });

    it('should create SUMMARY if non-existant', function() {
        return mock.setupFS({})
        .then(function(rootFolder) {
            return Book.init(mock.fs, rootFolder, {
                log: function() {}
            })
            .then(function() {
                rootFolder.should.have.file('SUMMARY.md');
                rootFolder.should.have.file('README.md');
            });
        })
    });

});