|
1 |
| -varexpect=require('chai').expect; |
2 |
| -varpage=require('../lib/build/parser/page').page; |
3 |
| -vartask=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 |
| -varresult=function(){ |
8 |
| -return{ |
9 |
| -chapters:[{ |
10 |
| -pages:[] |
11 |
| -}] |
12 |
| -}; |
13 |
| -}; |
14 |
| -varindex=function(){ |
15 |
| -return{ |
16 |
| -chapter:0, |
17 |
| -page:-1, |
18 |
| -task:-1 |
19 |
| -}; |
20 |
| -}; |
| 7 | +constresult=()=>({ |
| 8 | +pages:[] |
| 9 | +}); |
21 | 10 |
|
22 |
| -varresultTask=function(){ |
23 |
| -return{ |
24 |
| -chapters:[{ |
25 |
| -pages:[{ |
26 |
| -title:'', |
27 |
| -description:'', |
28 |
| -tasks:[] |
29 |
| -}] |
30 |
| -}] |
31 |
| -}; |
32 |
| -}; |
| 11 | +constindex=()=>({ |
| 12 | +page:-1, |
| 13 | +task:-1 |
| 14 | +}); |
33 | 15 |
|
34 |
| -varindexTask=function(){ |
35 |
| -return{ |
36 |
| -chapter:0, |
37 |
| -page:0, |
38 |
| -task:-1 |
39 |
| -}; |
40 |
| -}; |
| 16 | +constresultTask=()=>({ |
| 17 | +pages:[{ |
| 18 | +title:'', |
| 19 | +description:'', |
| 20 | +tasks:[] |
| 21 | +}] |
| 22 | +}); |
41 | 23 |
|
42 |
| -it('should add @onPageComplete string to the page',function(){ |
43 |
| -varlines=['### Page One','page description','more page description','@onPageComplete("next page")']; |
44 |
| -varnext=page(result(),lines,index()); |
45 |
| -varnextPage=next.chapters[0].pages[0]; |
| 24 | +constindexTask=()=>({ |
| 25 | +page:0, |
| 26 | +task:-1 |
| 27 | +}); |
| 28 | + |
| 29 | +it('should add @onPageComplete string to the page',()=>{ |
| 30 | +constlines=['## Page One','page description','more page description','@onPageComplete("next page")']; |
| 31 | +constnext=page({result:result(), lines,index:index()}); |
| 32 | +constnextPage=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 |
| -varlines=['### Page One','page description','more page description', |
| 40 | +it('should handle multi-line codeblocks',()=>{ |
| 41 | +constlines=['## Page One','page description','more page description', |
55 | 42 | '@onPageComplete("next page','```','var a = 42;','```','")'
|
56 | 43 | ];
|
57 |
| -varnext=page(result(),lines,index()); |
58 |
| -varnextPage=next.chapters[0].pages[0]; |
| 44 | +constnext=page({result:result(), lines,index:index()}); |
| 45 | +constnextPage=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 |
| -varlines=['### Page One','page description','more page description', |
| 53 | +it('should handle string literals',()=>{ |
| 54 | +constlines=['## Page One','page description','more page description', |
68 | 55 | '@onPageComplete("next page','`var a = 42;`','")'
|
69 | 56 | ];
|
70 |
| -varnext=page(result(),lines,index()); |
71 |
| -varnextPage=next.chapters[0].pages[0]; |
| 57 | +constnext=page({result:result(), lines,index:index()}); |
| 58 | +constnextPage=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 |
| -varlines=['+ Task One','with more on the next','line']; |
81 |
| -varnext=task(resultTask(),lines,indexTask()); |
82 |
| -varnextTask=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 | });
|