1
1
import DataFormatter from './data_formatter' ;
2
+ import { ErrorManager } from "./errors" ;
3
+ import * as jQuery from "jquery" ;
2
4
3
5
describe ( 'DataFormatter' , ( ) => {
6
+ let ctrl ;
4
7
let dataFormatter ;
5
8
let formattedData : any [ ] = [ ] ;
6
9
10
+ beforeEach ( ( ) => {
11
+ const errors = new ErrorManager ( ) ;
12
+ errors . registerDomains ( 'data' , 'location' ) ;
13
+ ctrl = {
14
+ errors : errors
15
+ } ;
16
+ } ) ;
17
+
7
18
describe ( 'when latitude and longitude are given in table data and query type is coordinates' , ( ) => {
8
19
beforeEach ( ( ) => {
9
- const ctrl = {
20
+ jQuery . extend ( ctrl , {
10
21
panel : {
11
22
tableQueryOptions : {
12
23
queryType : 'coordinates' ,
13
24
latitudeField : 'latitude' ,
14
25
longitudeField : 'longitude'
15
26
}
16
27
}
17
- } ;
28
+ } ) ;
18
29
dataFormatter = new DataFormatter ( ctrl ) ;
19
30
} ) ;
20
31
@@ -121,7 +132,7 @@ describe('DataFormatter', () => {
121
132
dataFormatter = new DataFormatter ( ctrl ) ;
122
133
} ) ;
123
134
124
- it ( 'should use the value from table\'s labelField as a key to lookup the designated locationName from the JSON/JSONP result' , ( ) => {
135
+ it ( 'should use the value from table\'s labelLocationKeyField as a key to lookup the designated locationName from the JSON/JSONP result' , ( ) => {
125
136
// Main Location Data is coming from table data.
126
137
// However, the humanized string is resolved by mapping e.g.
127
138
// "station_id == 28" to "key == 28", in turn yielding the
@@ -144,17 +155,17 @@ describe('DataFormatter', () => {
144
155
145
156
expect ( data [ 0 ] . locationLatitude ) . toBeCloseTo ( 48.7779 ) ;
146
157
expect ( data [ 0 ] . locationLongitude ) . toBeCloseTo ( 9.23600 ) ;
147
- expect ( data [ 0 ] . locationName ) . toEqual ( 'Ulmer Straße, Wangen, Stuttgart, Baden-Württemberg, DE (28) ' ) ;
158
+ expect ( data [ 0 ] . locationName ) . toEqual ( 'Ulmer Straße, Wangen, Stuttgart, Baden-Württemberg, DE' ) ;
148
159
149
160
expect ( data [ 1 ] . locationLatitude ) . toBeCloseTo ( 52.544 ) ;
150
161
expect ( data [ 1 ] . locationLongitude ) . toBeCloseTo ( 13.374 ) ;
151
- expect ( data [ 1 ] . locationName ) . toEqual ( 'Gerichtstraße, Gesundbrunnen, Mitte, Berlin, DE (1071) ' ) ;
162
+ expect ( data [ 1 ] . locationName ) . toEqual ( 'Gerichtstraße, Gesundbrunnen, Mitte, Berlin, DE' ) ;
152
163
} ) ;
153
164
} ) ;
154
165
155
166
describe ( 'when the time series data matches the location' , ( ) => {
156
167
beforeEach ( ( ) => {
157
- const ctrl = {
168
+ jQuery . extend ( ctrl , {
158
169
panel : {
159
170
valueName : 'total'
160
171
} ,
@@ -166,9 +177,9 @@ describe('DataFormatter', () => {
166
177
{ alias : 'IE' , datapoints : [ 1 , 2 ] , stats : { total : 3 } } ,
167
178
{ alias : 'SE' , datapoints : [ 2 , 3 ] , stats : { total : 5 } } ,
168
179
]
169
- } ;
180
+ } ) ;
170
181
dataFormatter = new DataFormatter ( ctrl ) ;
171
- dataFormatter . setTimeseriesValues ( formattedData ) ;
182
+ dataFormatter . setTimeseriesValues ( ctrl . series , formattedData ) ;
172
183
} ) ;
173
184
174
185
it ( 'should format the data and match the serie to a location' , ( ) => {
@@ -188,7 +199,7 @@ describe('DataFormatter', () => {
188
199
189
200
describe ( 'when the time series data has lowercase country codes' , ( ) => {
190
201
beforeEach ( ( ) => {
191
- const ctrl = {
202
+ jQuery . extend ( ctrl , {
192
203
panel : {
193
204
valueName : 'total'
194
205
} ,
@@ -200,9 +211,9 @@ describe('DataFormatter', () => {
200
211
{ alias : 'ie' , datapoints : [ 1 , 2 ] , stats : { total : 3 } } ,
201
212
{ alias : 'se' , datapoints : [ 2 , 3 ] , stats : { total : 5 } } ,
202
213
]
203
- } ;
214
+ } ) ;
204
215
dataFormatter = new DataFormatter ( ctrl ) ;
205
- dataFormatter . setTimeseriesValues ( formattedData ) ;
216
+ dataFormatter . setTimeseriesValues ( ctrl . series , formattedData ) ;
206
217
} ) ;
207
218
208
219
it ( 'should format the data and match the serie to a location' , ( ) => {
@@ -222,7 +233,7 @@ describe('DataFormatter', () => {
222
233
223
234
describe ( 'when the time series data does not match any location' , ( ) => {
224
235
beforeEach ( ( ) => {
225
- const ctrl = {
236
+ jQuery . extend ( ctrl , {
226
237
panel : {
227
238
valueName : 'total'
228
239
} ,
@@ -231,9 +242,9 @@ describe('DataFormatter', () => {
231
242
{ alias : 'SX' , datapoints : [ 1 , 2 ] , stats : { total : 3 } } ,
232
243
{ alias : 'IE' , datapoints : [ 1 , 2 ] , stats : { total : 3 } }
233
244
]
234
- } ;
245
+ } ) ;
235
246
dataFormatter = new DataFormatter ( ctrl ) ;
236
- dataFormatter . setTimeseriesValues ( formattedData ) ;
247
+ dataFormatter . setTimeseriesValues ( ctrl . series , formattedData ) ;
237
248
} ) ;
238
249
239
250
it ( 'should ignore the serie' , ( ) => {
@@ -244,7 +255,7 @@ describe('DataFormatter', () => {
244
255
describe ( 'when the time series data has decimals' , ( ) => {
245
256
describe ( 'and decimals are specified as an integer' , ( ) => {
246
257
beforeEach ( ( ) => {
247
- const ctrl = {
258
+ jQuery . extend ( ctrl , {
248
259
panel : {
249
260
valueName : 'total' ,
250
261
decimals : 2
@@ -257,9 +268,9 @@ describe('DataFormatter', () => {
257
268
{ alias : 'IE' , datapoints : [ 1.11 , 2.22 ] , stats : { total : 3.33 } } ,
258
269
{ alias : 'SE' , datapoints : [ 2.221 , 3.331 ] , stats : { total : 5.552 } } ,
259
270
]
260
- } ;
271
+ } ) ;
261
272
dataFormatter = new DataFormatter ( ctrl ) ;
262
- dataFormatter . setTimeseriesValues ( formattedData ) ;
273
+ dataFormatter . setTimeseriesValues ( ctrl . series , formattedData ) ;
263
274
} ) ;
264
275
265
276
it ( 'should format the value with 2 decimals' , ( ) => {
@@ -269,7 +280,7 @@ describe('DataFormatter', () => {
269
280
270
281
describe ( 'and decimals are specified as a string' , ( ) => {
271
282
beforeEach ( ( ) => {
272
- const ctrl = {
283
+ jQuery . extend ( ctrl , {
273
284
panel : {
274
285
valueName : 'total' ,
275
286
decimals : '2'
@@ -282,9 +293,9 @@ describe('DataFormatter', () => {
282
293
{ alias : 'IE' , datapoints : [ 1.11 , 2.22 ] , stats : { total : 3.33 } } ,
283
294
{ alias : 'SE' , datapoints : [ 2.221 , 3.331 ] , stats : { total : 5.552 } } ,
284
295
]
285
- } ;
296
+ } ) ;
286
297
dataFormatter = new DataFormatter ( ctrl ) ;
287
- dataFormatter . setTimeseriesValues ( formattedData ) ;
298
+ dataFormatter . setTimeseriesValues ( ctrl . series , formattedData ) ;
288
299
} ) ;
289
300
290
301
it ( 'should format the value with 2 decimals' , ( ) => {
0 commit comments