|
1 |
| -var expect = require('chai').expect; |
2 |
| -var page = require('../lib/build/parser/page').page; |
3 |
| -var task = require('../lib/build/parser/task').task; |
| 1 | +const { expect } = require('chai'); |
| 2 | +const { page } = require('../lib/build/parser/page'); |
| 3 | +const { task } = require('../lib/build/parser/task'); |
4 | 4 |
|
5 |
| -describe('@onPageComplete', function() { |
| 5 | +describe('@onPageComplete', () => { |
6 | 6 |
|
7 |
| - var result = function() { |
8 |
| - return { |
9 |
| - chapters: [{ |
10 |
| - pages: [] |
11 |
| - }] |
12 |
| - }; |
13 |
| - }; |
14 |
| - var index = function() { |
15 |
| - return { |
16 |
| - chapter: 0, |
17 |
| - page: -1, |
18 |
| - task: -1 |
19 |
| - }; |
20 |
| - }; |
| 7 | + const result = () => ({ |
| 8 | + pages: [] |
| 9 | + }); |
21 | 10 |
|
22 |
| - var resultTask = function() { |
23 |
| - return { |
24 |
| - chapters: [{ |
25 |
| - pages: [{ |
26 |
| - title: '', |
27 |
| - description: '', |
28 |
| - tasks: [] |
29 |
| - }] |
30 |
| - }] |
31 |
| - }; |
32 |
| - }; |
| 11 | + const index = () => ({ |
| 12 | + page: -1, |
| 13 | + task: -1 |
| 14 | + }); |
33 | 15 |
|
34 |
| - var indexTask = function() { |
35 |
| - return { |
36 |
| - chapter: 0, |
37 |
| - page: 0, |
38 |
| - task: -1 |
39 |
| - }; |
40 |
| - }; |
| 16 | + const resultTask = () => ({ |
| 17 | + pages: [{ |
| 18 | + title: '', |
| 19 | + description: '', |
| 20 | + tasks: [] |
| 21 | + }] |
| 22 | + }); |
41 | 23 |
|
42 |
| - it('should add @onPageComplete string to the page', function() { |
43 |
| - var lines = ['### Page One', 'page description', 'more page description', '@onPageComplete("next page")']; |
44 |
| - var next = page(result(), lines, index()); |
45 |
| - var nextPage = next.chapters[0].pages[0]; |
| 24 | + const indexTask = () => ({ |
| 25 | + page: 0, |
| 26 | + task: -1 |
| 27 | + }); |
| 28 | + |
| 29 | + it('should add @onPageComplete string to the page', () => { |
| 30 | + const lines = ['## Page One', 'page description', 'more page description', '@onPageComplete("next page")']; |
| 31 | + const next = page({ result: result(), lines, index: index() }); |
| 32 | + const nextPage = next.pages[0]; |
46 | 33 | expect(nextPage).to.deep.equal({
|
47 | 34 | title: 'Page One',
|
48 | 35 | description: 'page description\nmore page description',
|
49 | 36 | onPageComplete: 'next page'
|
50 | 37 | });
|
51 | 38 | });
|
52 | 39 |
|
53 |
| - it('should handle multi-line codeblocks', function() { |
54 |
| - var lines = ['### Page One', 'page description', 'more page description', |
| 40 | + it('should handle multi-line codeblocks', () => { |
| 41 | + const lines = ['## Page One', 'page description', 'more page description', |
55 | 42 | '@onPageComplete("next page', '```', 'var a = 42;', '```', '")'
|
56 | 43 | ];
|
57 |
| - var next = page(result(), lines, index()); |
58 |
| - var nextPage = next.chapters[0].pages[0]; |
| 44 | + const next = page({ result: result(), lines, index: index() }); |
| 45 | + const nextPage = next.pages[0]; |
59 | 46 | expect(nextPage).to.deep.equal({
|
60 | 47 | title: 'Page One',
|
61 | 48 | description: 'page description\nmore page description',
|
62 | 49 | onPageComplete: 'next page\n```\nvar a = 42;\n```'
|
63 | 50 | });
|
64 | 51 | });
|
65 | 52 |
|
66 |
| - it('should handle string literals', function() { |
67 |
| - var lines = ['### Page One', 'page description', 'more page description', |
| 53 | + it('should handle string literals', () => { |
| 54 | + const lines = ['## Page One', 'page description', 'more page description', |
68 | 55 | '@onPageComplete("next page', '`var a = 42;`', '")'
|
69 | 56 | ];
|
70 |
| - var next = page(result(), lines, index()); |
71 |
| - var nextPage = next.chapters[0].pages[0]; |
| 57 | + const next = page({ result: result(), lines, index: index() }); |
| 58 | + const nextPage = next.pages[0]; |
72 | 59 | expect(nextPage).to.deep.equal({
|
73 | 60 | title: 'Page One',
|
74 | 61 | description: 'page description\nmore page description',
|
75 | 62 | onPageComplete: 'next page\n`var a = 42;`'
|
76 | 63 | });
|
77 | 64 | });
|
78 | 65 |
|
79 |
| - it('shouldn\'t add to tasks', function() { |
80 |
| - var lines = ['+ Task One', 'with more on the next', 'line']; |
81 |
| - var next = task(resultTask(), lines, indexTask()); |
82 |
| - var nextTask = next.chapters[0].pages[0].tasks[0]; |
83 |
| - expect(nextTask.description).to.equal('Task One\nwith more on the next\nline'); |
84 |
| - }); |
85 |
| - |
86 | 66 | });
|
0 commit comments