@@ -4,16 +4,16 @@ var arrayData = require('./arrayData.json');
4
4
var objectData = require ( './objectData.json' ) ;
5
5
var weirdData = require ( './weirdData' ) ;
6
6
7
- describe ( 'prepare' , function ( ) {
7
+ describe ( 'prepare' , function ( ) {
8
8
9
- beforeEach ( function ( ) {
9
+ beforeEach ( function ( ) {
10
10
this . addMatchers ( {
11
- toEqualFields : function ( ) {
11
+ toEqualFields : function ( ) {
12
12
return {
13
- compare : function ( actual , expected ) {
13
+ compare : function ( actual , expected ) {
14
14
var res ;
15
- var res = expected && expected . all && expected . all ( function ( item , i ) {
16
- return actual [ i ] && Object . keys ( item ) . all ( function ( field ) {
15
+ var res = expected && expected . all && expected . all ( function ( item , i ) {
16
+ return actual [ i ] && Object . keys ( item ) . all ( function ( field ) {
17
17
return actual [ i ] [ field ] === item [ field ] ;
18
18
} ) ;
19
19
} )
@@ -23,68 +23,68 @@ describe('prepare',function() {
23
23
}
24
24
}
25
25
}
26
- } )
27
- } )
26
+ } ) ;
27
+ } ) ;
28
28
29
- describe ( 'handling illegal xml characters' , function ( ) {
30
- it ( 'should remove vertical tabs' , function ( ) {
29
+ describe ( 'handling illegal xml characters' , function ( ) {
30
+ it ( 'should remove vertical tabs' , function ( ) {
31
31
var res = prep ( weirdData ) ;
32
32
expect ( res . rows [ 0 ] [ 1 ] ) . toEqual ( ' foo bar ' ) ;
33
33
} ) ;
34
34
} ) ;
35
35
36
- describe ( 'when the data is an empty array' , function ( ) {
37
- it ( 'should create an empty config' , function ( ) {
36
+ describe ( 'when the data is an empty array' , function ( ) {
37
+ it ( 'should create an empty config' , function ( ) {
38
38
var res = prep ( [ ] ) ;
39
39
expect ( res . cols ) . toEqual ( [ ] ) ;
40
40
expect ( res . rows ) . toEqual ( [ ] ) ;
41
41
} ) ;
42
42
} ) ;
43
43
44
- describe ( 'when the data is an empty object' , function ( ) {
45
- it ( 'should create a config with one empty row' , function ( ) {
44
+ describe ( 'when the data is an empty object' , function ( ) {
45
+ it ( 'should create a config with one empty row' , function ( ) {
46
46
var res = prep ( { } ) ;
47
47
expect ( res . cols ) . toEqual ( [ ] ) ;
48
48
expect ( res . rows ) . toEqual ( [ [ ] ] ) ;
49
49
} ) ;
50
50
} ) ;
51
51
52
- describe ( 'when the data is an array' , function ( ) {
53
-
54
- describe ( 'cols' , function ( ) {
55
- it ( 'should create a cols part' , function ( ) {
52
+ describe ( 'when the data is an array' , function ( ) {
53
+
54
+ describe ( 'cols' , function ( ) {
55
+ it ( 'should create a cols part' , function ( ) {
56
56
var res = prep ( arrayData ) ;
57
57
expect ( res . cols ) . toBeDefined ( ) ;
58
58
} ) ;
59
- it ( 'should create the correct cols' , function ( ) {
59
+ it ( 'should create the correct cols' , function ( ) {
60
60
var res = prep ( arrayData ) ;
61
61
expect ( res . cols ) . toEqualFields ( [ {
62
62
caption : 'name' ,
63
63
type : 'string'
64
- } , {
64
+ } , {
65
65
caption : 'date' ,
66
66
type : 'string'
67
- } , {
67
+ } , {
68
68
caption : 'number' ,
69
69
type : 'number'
70
70
} ] ) ;
71
71
} ) ;
72
72
73
- it ( 'should create the correct cols when fields are given as array' , function ( ) {
74
- var res = prep ( arrayData , {
75
- fields : [ 'date' , 'name' ]
73
+ it ( 'should create the correct cols when fields are given as array' , function ( ) {
74
+ var res = prep ( arrayData , {
75
+ fields : [ 'date' , 'name' ]
76
76
} ) ;
77
77
expect ( res . cols ) . toEqualFields ( [ {
78
78
caption : 'date' ,
79
79
type : 'string'
80
- } , {
80
+ } , {
81
81
caption : 'name' ,
82
82
type : 'string'
83
83
} ] ) ;
84
84
} ) ;
85
85
86
- it ( 'should create the correct cols when fields are given as object' , function ( ) {
87
- var res = prep ( arrayData , {
86
+ it ( 'should create the correct cols when fields are given as object' , function ( ) {
87
+ var res = prep ( arrayData , {
88
88
fields : {
89
89
number : 'string' ,
90
90
name : 'string'
@@ -93,36 +93,36 @@ describe('prepare',function() {
93
93
expect ( res . cols ) . toEqualFields ( [ {
94
94
caption : 'number' ,
95
95
type : 'string'
96
- } , {
96
+ } , {
97
97
caption : 'name' ,
98
98
type : 'string'
99
99
} ] ) ;
100
100
} ) ;
101
101
102
- it ( 'should create caption and type field' , function ( ) {
102
+ it ( 'should create caption and type field' , function ( ) {
103
103
var cols = prep ( arrayData ) . cols ;
104
104
expect ( cols [ 0 ] . caption ) . toBeDefined ( ) ;
105
105
expect ( cols [ 0 ] . type ) . toBeDefined ( ) ;
106
106
} ) ;
107
107
} ) ;
108
108
109
- describe ( 'rows' , function ( ) {
110
- it ( 'should create a rows part' , function ( ) {
109
+ describe ( 'rows' , function ( ) {
110
+ it ( 'should create a rows part' , function ( ) {
111
111
var res = prep ( arrayData ) ;
112
112
expect ( res . rows ) . toBeDefined ( ) ;
113
113
} ) ;
114
- it ( 'should create rows with data in the correct order' , function ( ) {
114
+ it ( 'should create rows with data in the correct order' , function ( ) {
115
115
var res = prep ( arrayData ) ;
116
- expect ( res . rows [ 0 ] ) . toEqual ( [ 'Ivy Dickson' , '2013-05-27T11:04:15-07:00' , 10 ] ) ;
117
- expect ( res . rows [ 1 ] ) . toEqual ( [ 'Walker Lynch' , '2014-02-07T22:09:58-08:00' , 2 ] ) ;
118
- expect ( res . rows [ 2 ] ) . toEqual ( [ 'Maxwell U. Holden' , '2013-06-16T05:29:13-07:00' , 5 ] ) ;
116
+ expect ( res . rows [ 0 ] ) . toEqual ( [ 'Ivy Dickson' , '2013-05-27T11:04:15-07:00' , 10 ] ) ;
117
+ expect ( res . rows [ 1 ] ) . toEqual ( [ 'Walker Lynch' , '2014-02-07T22:09:58-08:00' , 2 ] ) ;
118
+ expect ( res . rows [ 2 ] ) . toEqual ( [ 'Maxwell U. Holden' , '2013-06-16T05:29:13-07:00' , 5 ] ) ;
119
119
} ) ;
120
120
} ) ;
121
121
122
- describe ( 'style' , function ( ) {
123
- it ( 'should have the provided style xml file' , function ( ) {
122
+ describe ( 'style' , function ( ) {
123
+ it ( 'should have the provided style xml file' , function ( ) {
124
124
var fn = 'test.xml' ;
125
- var res = prep ( arrayData , {
125
+ var res = prep ( arrayData , {
126
126
style : fn
127
127
} ) ;
128
128
expect ( res . stylesXmlFile ) . toBe ( fn ) ;
@@ -131,46 +131,46 @@ describe('prepare',function() {
131
131
132
132
} ) ;
133
133
134
- describe ( 'when the data is an object' , function ( ) {
135
- describe ( 'cols' , function ( ) {
136
- it ( 'should create a cols part' , function ( ) {
134
+ describe ( 'when the data is an object' , function ( ) {
135
+ describe ( 'cols' , function ( ) {
136
+ it ( 'should create a cols part' , function ( ) {
137
137
var res = prep ( objectData ) ;
138
138
expect ( res . cols ) . toBeDefined ( ) ;
139
139
} ) ;
140
- it ( 'should create caption and type field' , function ( ) {
140
+ it ( 'should create caption and type field' , function ( ) {
141
141
var cols = prep ( objectData ) . cols ;
142
142
expect ( cols [ 0 ] . caption ) . toBeDefined ( ) ;
143
143
expect ( cols [ 0 ] . type ) . toBeDefined ( ) ;
144
144
} ) ;
145
145
} ) ;
146
146
147
- describe ( 'rows' , function ( ) {
148
- it ( 'should create a rows part' , function ( ) {
147
+ describe ( 'rows' , function ( ) {
148
+ it ( 'should create a rows part' , function ( ) {
149
149
var res = prep ( objectData ) ;
150
150
expect ( res . rows ) . toBeDefined ( ) ;
151
151
} ) ;
152
152
} ) ;
153
153
154
- describe ( 'style' , function ( ) {
155
- it ( 'should have the provided style xml file' , function ( ) {
154
+ describe ( 'style' , function ( ) {
155
+ it ( 'should have the provided style xml file' , function ( ) {
156
156
var fn = 'test.xml' ;
157
- var res = prep ( objectData , {
157
+ var res = prep ( objectData , {
158
158
style : fn
159
159
} ) ;
160
160
expect ( res . stylesXmlFile ) . toBe ( fn ) ;
161
161
} ) ;
162
162
} ) ;
163
163
164
- describe ( 'display of nested fields' , function ( ) {
165
- it ( 'should write nested fields as json' , function ( ) {
164
+ describe ( 'display of nested fields' , function ( ) {
165
+ it ( 'should write nested fields as json' , function ( ) {
166
166
var res = prep ( objectData ) ;
167
167
expect ( res . rows [ 0 ] [ 3 ] ) . toEqual ( '{"field":"foo"}' ) ;
168
168
} ) ;
169
169
} ) ;
170
170
} ) ;
171
171
172
- describe ( 'working with missing fields' , function ( ) {
173
- it ( 'should leave missing fields blank' , function ( ) {
172
+ describe ( 'working with missing fields' , function ( ) {
173
+ it ( 'should leave missing fields blank' , function ( ) {
174
174
var res = prep ( [
175
175
{
176
176
"firma" : "transportabel" ,
@@ -197,13 +197,43 @@ describe('prepare',function() {
197
197
}
198
198
] ) ;
199
199
expect ( res . rows [ 2 ] [ 1 ] ) . toEqual ( null ) ;
200
- } )
201
- } )
200
+ } ) ;
201
+ } ) ;
202
+
203
+ describe ( 'handling empty value in first row' , function ( ) {
204
+ it ( 'should leave missing fields blank' , function ( ) {
205
+ var res = prep ( [
206
+ {
207
+ "internet" : "http://www.transportabel.de" ,
208
+ "Branche" : "Möbel" ,
209
+ "STRASSE" : "Messingweg 49" ,
210
+ "ort" : "Münster-Sprakel" ,
211
+ "TEL_ZENTRALE" : "(0251) 29 79 46"
212
+ } ,
213
+ {
214
+ "firma" : "Soziale Möbelbörse & mehr e.V." ,
215
+ "internet" : "http://www.gersch-ms.de" ,
216
+ "Branche" : "Möbel" ,
217
+ "STRASSE" : "Nienkamp 80" ,
218
+ "ort" : "Münster-Wienburg" ,
219
+ "TEL_ZENTRALE" : "(0251) 53 40 76"
220
+ } ,
221
+ {
222
+ "firma" : "Bald Eckhart e.K." ,
223
+ "Branche" : "Möbel" ,
224
+ "STRASSE" : "Weseler Str. 628" ,
225
+ "ort" : "Münster-Mecklenbeck" ,
226
+ "TEL_ZENTRALE" : "(0251) 53 40 76"
227
+ }
228
+ ] ) ;
229
+ expect ( res . rows [ 1 ] [ 0 ] ) . toEqual ( 'Soziale Möbelbörse & mehr e.V.' ) ;
230
+ } ) ;
231
+ } ) ;
202
232
203
- describe ( 'prepping with config' , function ( ) {
204
- it ( 'should get a nested field' , function ( ) {
205
- var res = prep ( objectData , {
206
- fields :[ 'nested.field' ]
233
+ describe ( 'prepping with config' , function ( ) {
234
+ it ( 'should get a nested field' , function ( ) {
235
+ var res = prep ( objectData , {
236
+ fields : [ 'nested.field' ]
207
237
} ) ;
208
238
expect ( res . rows [ 0 ] ) . toEqual ( [ 'foo' ] ) ;
209
239
} )
0 commit comments