1
- var expect = require ( 'chai' ) . expect ;
2
- var page = require ( '../lib/build/parser/page' ) . page ;
1
+ const { expect} = require ( 'chai' ) ;
2
+ const { page} = require ( '../lib/build/parser/page' ) ;
3
3
4
- describe ( 'page' , function ( ) {
4
+ describe ( 'page' , ( ) => {
5
5
6
- var result = function ( ) {
7
- return {
8
- chapters :[ {
9
- pages :[ ]
10
- } ]
11
- } ;
12
- } ;
13
- var index = function ( ) {
14
- return {
15
- chapter :0 ,
16
- page :- 1 ,
17
- task :- 1
18
- } ;
19
- } ;
20
-
21
-
22
- it ( 'should return a trimmed page title' , function ( ) {
23
- var lines = [ '### Page One' ] ;
24
- var next = page ( result ( ) , lines , index ( ) ) ;
25
- var nextPage = next . chapters [ 0 ] . pages [ 0 ] ;
6
+ const result = ( ) => ( {
7
+ pages :[ ]
8
+ } ) ;
9
+
10
+ const index = ( ) => ( {
11
+ page :- 1 ,
12
+ task :- 1 ,
13
+ } ) ;
14
+
15
+ it ( 'should return a trimmed page title' , ( ) => {
16
+ const lines = [ '## Page One' ] ;
17
+ const next = page ( { result :result ( ) , lines, index :index ( ) } ) ;
18
+ const nextPage = next . pages [ 0 ] ;
26
19
expect ( nextPage . title ) . to . equal ( 'Page One' ) ;
27
20
} ) ;
28
21
29
- it ( 'should return a page description' , function ( ) {
30
- var lines = [ '# ## Page One' , 'page description' ] ;
31
- var next = page ( result ( ) , lines , index ( ) ) ;
32
- var nextPage = next . chapters [ 0 ] . pages [ 0 ] ;
22
+ it ( 'should return a page description' , ( ) => {
23
+ const lines = [ '## Page One' , 'page description' ] ;
24
+ const next = page ( { result : result ( ) , lines, index : index ( ) } ) ;
25
+ const nextPage = next . pages [ 0 ] ;
33
26
expect ( nextPage ) . to . deep . equal ( {
34
27
title :'Page One' ,
35
28
description :'page description'
36
29
} ) ;
37
30
} ) ;
38
31
39
- it ( 'should return a multi-line page description' , function ( ) {
40
- var lines = [ '# ## Page One' , 'page description' , 'more page description' ] ;
41
- var next = page ( result ( ) , lines , index ( ) ) ;
42
- var nextPage = next . chapters [ 0 ] . pages [ 0 ] ;
32
+ it ( 'should return a multi-line page description' , ( ) => {
33
+ const lines = [ '## Page One' , 'page description' , 'more page description' ] ;
34
+ const next = page ( { result : result ( ) , lines, index : index ( ) } ) ;
35
+ const nextPage = next . pages [ 0 ] ;
43
36
expect ( nextPage ) . to . deep . equal ( {
44
37
title :'Page One' ,
45
38
description :'page description\nmore page description'
46
39
} ) ;
47
40
} ) ;
48
41
49
- it ( 'should allow code blocks in the page description' , function ( ) {
50
- var lines = [ '### Page One' , 'page description' , '`var a = 42;`' ] ;
51
- var next = page ( result ( ) , lines , index ( ) ) ;
52
- var nextPage = next . chapters [ 0 ] . pages [ 0 ] ;
42
+ it ( 'should allow code blocks in the page description' , ( ) => {
43
+ const lines = [ '## Page One' , 'page description' , '`const a = 42;`' ] ;
44
+ const next = page ( { result : result ( ) , lines, index : index ( ) } ) ;
45
+ const nextPage = next . pages [ 0 ] ;
53
46
expect ( nextPage ) . to . deep . equal ( {
54
47
title :'Page One' ,
55
- description :'page description\n`var a = 42;`'
48
+ description :'page description\n`const a = 42;`'
56
49
} ) ;
57
50
} ) ;
58
51
59
52
60
- it ( 'should allow code blocks in the page description' , function ( ) {
61
- var lines = [ '### Page One' , 'page description' , '```' , 'var a = 12;' , '```' ] ;
62
- var next = page ( result ( ) , lines , index ( ) ) ;
63
- var nextPage = next . chapters [ 0 ] . pages [ 0 ] ;
53
+ it ( 'should allow code blocks in the page description' , ( ) => {
54
+ const lines = [ '## Page One' , 'page description' , '```' , 'const a = 12;' , '```' ] ;
55
+ const next = page ( { result : result ( ) , lines, index : index ( ) } ) ;
56
+ const nextPage = next . pages [ 0 ] ;
64
57
expect ( nextPage ) . to . deep . equal ( {
65
58
title :'Page One' ,
66
- description :'page description\n```\nvar a = 12;\n```'
59
+ description :'page description\n```\nconst a = 12;\n```'
67
60
} ) ;
68
61
} ) ;
69
62
70
- it ( 'should add codeblock languages' , function ( ) {
71
- var lines = [ '### Page Title' , 'code block' , '```js' , 'var a = 42;' , '```' , 'end code block' ] ;
72
- var next = page ( result ( ) , lines , index ( ) ) ;
73
- var nextPage = next . chapters [ 0 ] . pages [ 0 ] ;
74
- expect ( nextPage . description ) . to . equal ( 'code block\n```js\nvar a = 42;\n```\nend code block' ) ;
63
+ it ( 'should add codeblock languages' , ( ) => {
64
+ const lines = [ '## Page Title' , 'code block' , '```js' , 'const a = 42;' , '```' , 'end code block' ] ;
65
+ const next = page ( { result : result ( ) , lines, index : index ( ) } ) ;
66
+ const nextPage = next . pages [ 0 ] ;
67
+ expect ( nextPage . description ) . to . equal ( 'code block\n```js\nconst a = 42;\n```\nend code block' ) ;
75
68
} ) ;
76
69
77
- it ( 'should add single line codeblocks' , function ( ) {
78
- var lines = [ '### Page Title' , 'code block' , '```var a = 42;```' , 'end code block' ] ;
79
- var next = page ( result ( ) , lines , index ( ) ) ;
80
- var nextPage = next . chapters [ 0 ] . pages [ 0 ] ;
81
- expect ( nextPage . description ) . to . equal ( 'code block\n```var a = 42;```\nend code block' ) ;
70
+ it ( 'should add single line codeblocks' , ( ) => {
71
+ const lines = [ '## Page Title' , 'code block' , '```const a = 42;```' , 'end code block' ] ;
72
+ const next = page ( { result : result ( ) , lines, index : index ( ) } ) ;
73
+ const nextPage = next . pages [ 0 ] ;
74
+ expect ( nextPage . description ) . to . equal ( 'code block\n```const a = 42;```\nend code block' ) ;
82
75
} ) ;
83
76
84
- it ( 'should handle strangely formatted codeblocks' , function ( ) {
85
- var lines = [ '### Page Title' , 'code block' , '```var a = 42;' , '```' , 'end code block' ] ;
86
- var next = page ( result ( ) , lines , index ( ) ) ;
87
- var nextPage = next . chapters [ 0 ] . pages [ 0 ] ;
88
- expect ( nextPage . description ) . to . equal ( 'code block\n```var a = 42;\n```\nend code block' ) ;
77
+ it ( 'should handle strangely formatted codeblocks' , ( ) => {
78
+ const lines = [ '## Page Title' , 'code block' , '```const a = 42;' , '```' , 'end code block' ] ;
79
+ const next = page ( { result : result ( ) , lines, index : index ( ) } ) ;
80
+ const nextPage = next . pages [ 0 ] ;
81
+ expect ( nextPage . description ) . to . equal ( 'code block\n```const a = 42;\n```\nend code block' ) ;
89
82
} ) ;
90
83
91
- it ( 'should exit on a new chapter' , function ( ) {
92
- var lines = [ '# ## Page One' , 'page description' , '## Chapter Two' ] ;
93
- var next = page ( result ( ) , lines , index ( ) ) ;
94
- var nextPage = next . chapters [ 0 ] . pages [ 0 ] ;
84
+ it ( 'should exit on a new chapter' , ( ) => {
85
+ const lines = [ '## Page One' , 'page description' , '## Chapter Two' ] ;
86
+ const next = page ( { result : result ( ) , lines, index : index ( ) } ) ;
87
+ const nextPage = next . pages [ 0 ] ;
95
88
expect ( nextPage ) . to . deep . equal ( {
96
89
title :'Page One' ,
97
90
description :'page description'
98
91
} ) ;
99
92
} ) ;
100
93
101
- it ( 'should exit on a new page' , function ( ) {
102
- var lines = [ '### Page One' , 'page description' , '# ## Page Two' ] ;
103
- var next = page ( result ( ) , lines , index ( ) ) ;
104
- var nextPage = next . chapters [ 0 ] . pages [ 0 ] ;
94
+ it ( 'should exit on a new page' , ( ) => {
95
+ const lines = [ '## Page One' , 'page description' , '## Page Two' ] ;
96
+ const next = page ( { result : result ( ) , lines, index : index ( ) } ) ;
97
+ const nextPage = next . pages [ 0 ] ;
105
98
expect ( nextPage ) . to . deep . equal ( {
106
99
title :'Page One' ,
107
100
description :'page description'
108
101
} ) ;
109
102
} ) ;
110
103
111
- it ( 'should exit on a task' , function ( ) {
112
- var lines = [ '# ## Page One' , 'page description' , '+ Task One' ] ;
113
- var next = page ( result ( ) , lines , index ( ) ) ;
114
- var nextPage = next . chapters [ 0 ] . pages [ 0 ] ;
104
+ it ( 'should exit on a task' , ( ) => {
105
+ const lines = [ '## Page One' , 'page description' , '+ Task One' ] ;
106
+ const next = page ( { result : result ( ) , lines, index : index ( ) } ) ;
107
+ const nextPage = next . pages [ 0 ] ;
115
108
expect ( nextPage ) . to . deep . equal ( {
116
109
title :'Page One' ,
117
110
description :'page description' ,
@@ -121,20 +114,20 @@ describe('page', function() {
121
114
} ) ;
122
115
} ) ;
123
116
124
- it ( 'should import lines in page' , function ( ) {
125
- var lines = [ '# ## Page Title' , 'page description' , '' , "@import('./test/imports/chapter-sample')" ]
126
- var next = page ( result ( ) , lines , index ( ) ) ;
127
- var nextChapter = next . chapters [ 1 ] ;
128
- expect ( nextChapter . title ) . to . equal ( 'Chapter Sample' ) ;
129
- } ) ;
130
-
131
- it ( 'should accept multiple import lines in page' , function ( ) {
132
- var lines = [ '### Page Title' , 'page description' , '' ,
133
- "@import('./test/imports/chapter-sample')" , "@import('./test/imports/chapter-sample')"
134
- ]
135
- var next = page ( result ( ) , lines , index ( ) ) ;
136
- var nextChapter = next . chapters [ 2 ] ;
137
- expect ( nextChapter . title ) . to . equal ( 'Chapter Sample' ) ;
138
- } ) ;
117
+ // it('should import lines in page',() => {
118
+ // const lines = ['## Page Title', 'page description', '', "@import('./test/imports/chapter-sample')"]
119
+ // const next = page({ result: result (), lines, index: index() } );
120
+ // const nextChapter = next.chapters[1];
121
+ // expect(nextChapter.title).to.equal('Chapter Sample');
122
+ // });
123
+ //
124
+ // it('should accept multiple import lines in page',() => {
125
+ // const lines = ['### Page Title', 'page description', '',
126
+ // "@import('./test/imports/chapter-sample')", "@import('./test/imports/chapter-sample')"
127
+ // ]
128
+ // const next = page({ result: result (), lines, index: index() } );
129
+ // const nextChapter = next.chapters[2];
130
+ // expect(nextChapter.title).to.equal('Chapter Sample');
131
+ // });
139
132
140
133
} ) ; // page