@@ -20,22 +20,30 @@ let testCasesCustomRaw = fs.readFileSync(
20
20
'utf8' ,
21
21
) ;
22
22
23
- let testCases = testCasesRaw . slice ( 1 ) . trim ( ) . split ( SEP ) . map ( ( text ) => {
24
- let lines = text . split ( '\n' ) ;
25
- let description = lines . shift ( ) . trim ( ) ;
26
- let state = JSON . parse ( lines . shift ( ) ) ;
27
- let html = lines . join ( '\n' ) ;
28
- return { description, state, html} ;
29
- } ) ;
23
+ let testCases = testCasesRaw
24
+ . slice ( 1 )
25
+ . trim ( )
26
+ . split ( SEP )
27
+ . map ( ( text ) => {
28
+ let lines = text . split ( '\n' ) ;
29
+ let description = lines . shift ( ) . trim ( ) ;
30
+ let state = JSON . parse ( lines . shift ( ) ) ;
31
+ let html = lines . join ( '\n' ) ;
32
+ return { description, state, html} ;
33
+ } ) ;
30
34
31
- let testCasesCustom = testCasesCustomRaw . slice ( 1 ) . trim ( ) . split ( SEP ) . map ( ( text ) => {
32
- let lines = text . split ( '\n' ) ;
33
- let description = lines . shift ( ) . trim ( ) ;
34
- let options = JSON . parse ( lines . shift ( ) ) ;
35
- let state = JSON . parse ( lines . shift ( ) ) ;
36
- let html = lines . join ( '\n' ) ;
37
- return { description, options, state, html} ;
38
- } ) ;
35
+ let testCasesCustom = testCasesCustomRaw
36
+ . slice ( 1 )
37
+ . trim ( )
38
+ . split ( SEP )
39
+ . map ( ( text ) => {
40
+ let lines = text . split ( '\n' ) ;
41
+ let description = lines . shift ( ) . trim ( ) ;
42
+ let options = JSON . parse ( lines . shift ( ) ) ;
43
+ let state = JSON . parse ( lines . shift ( ) ) ;
44
+ let html = lines . join ( '\n' ) ;
45
+ return { description, options, state, html} ;
46
+ } ) ;
39
47
40
48
describe ( 'stateToHTML' , ( ) => {
41
49
testCases . forEach ( ( testCase ) => {
@@ -64,17 +72,41 @@ describe('stateToHTML', () => {
64
72
} ;
65
73
let contentState = convertFromRaw (
66
74
// <pre><code>Hello <em>world</em>.</code></pre>
67
- { "entityMap" :{ } , "blocks" :[ { "key" :"dn025" , "text" :"Hello world." , "type" :"code-block" , "depth" :0 , "inlineStyleRanges" :[ { "offset" :6 , "length" :5 , "style" :"ITALIC" } ] , "entityRanges" :[ ] } ] } // eslint-disable-line
75
+ {
76
+ entityMap : { } ,
77
+ blocks : [
78
+ {
79
+ key : 'dn025' ,
80
+ text : 'Hello world.' ,
81
+ type : 'code-block' ,
82
+ depth : 0 ,
83
+ inlineStyleRanges : [ { offset : 6 , length : 5 , style : 'ITALIC' } ] ,
84
+ entityRanges : [ ] ,
85
+ } ,
86
+ ] ,
87
+ } , // eslint-disable-line
68
88
) ;
69
89
expect ( stateToHTML ( contentState , options ) ) . toBe (
70
- '<div class="code">Hello world.</div>'
90
+ '<div class="code">Hello world.</div>' ,
71
91
) ;
72
92
let contentState2 = convertFromRaw (
73
93
// <h1>Hello <em>world</em>.</h1>
74
- { "entityMap" :{ } , "blocks" :[ { "key" :"dn025" , "text" :"Hello world." , "type" :"header-one" , "depth" :0 , "inlineStyleRanges" :[ { "offset" :6 , "length" :5 , "style" :"ITALIC" } ] , "entityRanges" :[ ] } ] } // eslint-disable-line
94
+ {
95
+ entityMap : { } ,
96
+ blocks : [
97
+ {
98
+ key : 'dn025' ,
99
+ text : 'Hello world.' ,
100
+ type : 'header-one' ,
101
+ depth : 0 ,
102
+ inlineStyleRanges : [ { offset : 6 , length : 5 , style : 'ITALIC' } ] ,
103
+ entityRanges : [ ] ,
104
+ } ,
105
+ ] ,
106
+ } , // eslint-disable-line
75
107
) ;
76
108
expect ( stateToHTML ( contentState2 , options ) ) . toBe (
77
- '<h1>Hello <em>world</em>.</h1>'
109
+ '<h1>Hello <em>world</em>.</h1>' ,
78
110
) ;
79
111
} ) ;
80
112
@@ -93,21 +125,46 @@ describe('stateToHTML', () => {
93
125
} ;
94
126
let contentState1 = convertFromRaw (
95
127
// <h1 style="text-align: left;">Hello <em>world</em>.</h1>
96
- { "entityMap" :{ } , "blocks" :[ { "data" :{ "alignment" :"left" } , "key" :"dn025" , "text" :"Hello world." , "type" :"header-one" , "depth" :0 , "inlineStyleRanges" :[ { "offset" :6 , "length" :5 , "style" :"ITALIC" } ] , "entityRanges" :[ ] } ] } // eslint-disable-line
128
+ {
129
+ entityMap : { } ,
130
+ blocks : [
131
+ {
132
+ data : { alignment : 'left' } ,
133
+ key : 'dn025' ,
134
+ text : 'Hello world.' ,
135
+ type : 'header-one' ,
136
+ depth : 0 ,
137
+ inlineStyleRanges : [ { offset : 6 , length : 5 , style : 'ITALIC' } ] ,
138
+ entityRanges : [ ] ,
139
+ } ,
140
+ ] ,
141
+ } , // eslint-disable-line
97
142
) ;
98
143
if ( contentState1 . getFirstBlock ( ) . getData == null ) {
99
144
// Older DraftJS does not support block.getData()
100
145
return ;
101
146
}
102
147
expect ( stateToHTML ( contentState1 , options ) ) . toBe (
103
- '<h1 style="text-align: left">Hello <em>world</em>.</h1>'
148
+ '<h1 style="text-align: left">Hello <em>world</em>.</h1>' ,
104
149
) ;
105
150
let contentState2 = convertFromRaw (
106
151
// <h1>Hello <em>world</em>.</h1>
107
- { "entityMap" :{ } , "blocks" :[ { "key" :"dn025" , "text" :"Hello world." , "type" :"header-one" , "depth" :0 , "inlineStyleRanges" :[ { "offset" :6 , "length" :5 , "style" :"ITALIC" } ] , "entityRanges" :[ ] } ] } // eslint-disable-line
152
+ {
153
+ entityMap : { } ,
154
+ blocks : [
155
+ {
156
+ key : 'dn025' ,
157
+ text : 'Hello world.' ,
158
+ type : 'header-one' ,
159
+ depth : 0 ,
160
+ inlineStyleRanges : [ { offset : 6 , length : 5 , style : 'ITALIC' } ] ,
161
+ entityRanges : [ ] ,
162
+ } ,
163
+ ] ,
164
+ } , // eslint-disable-line
108
165
) ;
109
166
expect ( stateToHTML ( contentState2 , options ) ) . toBe (
110
- '<h1>Hello <em>world</em>.</h1>'
167
+ '<h1>Hello <em>world</em>.</h1>' ,
111
168
) ;
112
169
} ) ;
113
170
@@ -128,14 +185,32 @@ describe('stateToHTML', () => {
128
185
} ;
129
186
let contentState1 = convertFromRaw (
130
187
// <p><em>a</em></p>
131
- { "entityMap" :{ "0" :{ "type" :"MENTION" , "mutability" :"MUTABLE" , "data" :{ "userId" :"mikaelwaltersson" } } } , "blocks" :[ { "key" :"8r91j" , "text" :"a" , "type" :"unstyled" , "depth" :0 , "inlineStyleRanges" :[ { "offset" :0 , "length" :1 , "style" :"ITALIC" } ] , "entityRanges" :[ { "offset" :0 , "length" :1 , "key" :0 } ] } ] } // eslint-disable-line
188
+ {
189
+ entityMap : {
190
+ [ 0 ] : {
191
+ type : 'MENTION' ,
192
+ mutability : 'MUTABLE' ,
193
+ data : { userId : 'mikaelwaltersson' } ,
194
+ } ,
195
+ } ,
196
+ blocks : [
197
+ {
198
+ key : '8r91j' ,
199
+ text : 'a' ,
200
+ type : 'unstyled' ,
201
+ depth : 0 ,
202
+ inlineStyleRanges : [ { offset : 0 , length : 1 , style : 'ITALIC' } ] ,
203
+ entityRanges : [ { offset : 0 , length : 1 , key : 0 } ] ,
204
+ } ,
205
+ ] ,
206
+ } , // eslint-disable-line
132
207
) ;
133
208
if ( contentState1 . getFirstBlock ( ) . getData == null ) {
134
209
// Older DraftJS does not support block.getData()
135
210
return ;
136
211
}
137
212
expect ( stateToHTML ( contentState1 , options ) ) . toBe (
138
- '<p><a href="/users/mikaelwaltersson" class="mention"><em>a</em></a></p>'
213
+ '<p><a href="/users/mikaelwaltersson" class="mention"><em>a</em></a></p>' ,
139
214
) ;
140
215
} ) ;
141
216
} ) ;
0 commit comments