Skip to content

Commit 3b86a49

Browse files
committed
Adjust software tests
1 parent 6fe1a1a commit 3b86a49

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

src/data_formatter.test.ts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
import DataFormatter from './data_formatter';
2+
import {ErrorManager} from "./errors";
3+
import * as jQuery from "jquery";
24

35
describe('DataFormatter', () => {
6+
let ctrl;
47
let dataFormatter;
58
let formattedData: any[] = [];
69

10+
beforeEach(() => {
11+
const errors = new ErrorManager();
12+
errors.registerDomains('data', 'location');
13+
ctrl = {
14+
errors: errors
15+
};
16+
});
17+
718
describe('when latitude and longitude are given in table data and query type is coordinates', () => {
819
beforeEach(() => {
9-
const ctrl = {
20+
jQuery.extend(ctrl, {
1021
panel: {
1122
tableQueryOptions: {
1223
queryType: 'coordinates',
1324
latitudeField: 'latitude',
1425
longitudeField: 'longitude'
1526
}
1627
}
17-
};
28+
});
1829
dataFormatter = new DataFormatter(ctrl);
1930
});
2031

@@ -121,7 +132,7 @@ describe('DataFormatter', () => {
121132
dataFormatter = new DataFormatter(ctrl);
122133
});
123134

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', () => {
125136
// Main Location Data is coming from table data.
126137
// However, the humanized string is resolved by mapping e.g.
127138
// "station_id == 28" to "key == 28", in turn yielding the
@@ -144,17 +155,17 @@ describe('DataFormatter', () => {
144155

145156
expect(data[0].locationLatitude).toBeCloseTo(48.7779);
146157
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');
148159

149160
expect(data[1].locationLatitude).toBeCloseTo(52.544);
150161
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');
152163
});
153164
});
154165

155166
describe('when the time series data matches the location', () => {
156167
beforeEach(() => {
157-
const ctrl = {
168+
jQuery.extend(ctrl, {
158169
panel: {
159170
valueName: 'total'
160171
},
@@ -166,9 +177,9 @@ describe('DataFormatter', () => {
166177
{alias: 'IE', datapoints: [1, 2], stats: {total: 3}},
167178
{alias: 'SE', datapoints: [2, 3], stats: {total: 5}},
168179
]
169-
};
180+
});
170181
dataFormatter = new DataFormatter(ctrl);
171-
dataFormatter.setTimeseriesValues(formattedData);
182+
dataFormatter.setTimeseriesValues(ctrl.series, formattedData);
172183
});
173184

174185
it('should format the data and match the serie to a location', () => {
@@ -188,7 +199,7 @@ describe('DataFormatter', () => {
188199

189200
describe('when the time series data has lowercase country codes', () => {
190201
beforeEach(() => {
191-
const ctrl = {
202+
jQuery.extend(ctrl, {
192203
panel: {
193204
valueName: 'total'
194205
},
@@ -200,9 +211,9 @@ describe('DataFormatter', () => {
200211
{alias: 'ie', datapoints: [1, 2], stats: {total: 3}},
201212
{alias: 'se', datapoints: [2, 3], stats: {total: 5}},
202213
]
203-
};
214+
});
204215
dataFormatter = new DataFormatter(ctrl);
205-
dataFormatter.setTimeseriesValues(formattedData);
216+
dataFormatter.setTimeseriesValues(ctrl.series, formattedData);
206217
});
207218

208219
it('should format the data and match the serie to a location', () => {
@@ -222,7 +233,7 @@ describe('DataFormatter', () => {
222233

223234
describe('when the time series data does not match any location', () => {
224235
beforeEach(() => {
225-
const ctrl = {
236+
jQuery.extend(ctrl, {
226237
panel: {
227238
valueName: 'total'
228239
},
@@ -231,9 +242,9 @@ describe('DataFormatter', () => {
231242
{alias: 'SX', datapoints: [1, 2], stats: {total: 3}},
232243
{alias: 'IE', datapoints: [1, 2], stats: {total: 3}}
233244
]
234-
};
245+
});
235246
dataFormatter = new DataFormatter(ctrl);
236-
dataFormatter.setTimeseriesValues(formattedData);
247+
dataFormatter.setTimeseriesValues(ctrl.series, formattedData);
237248
});
238249

239250
it('should ignore the serie', () => {
@@ -244,7 +255,7 @@ describe('DataFormatter', () => {
244255
describe('when the time series data has decimals', () => {
245256
describe('and decimals are specified as an integer', () => {
246257
beforeEach(() => {
247-
const ctrl = {
258+
jQuery.extend(ctrl, {
248259
panel: {
249260
valueName: 'total',
250261
decimals: 2
@@ -257,9 +268,9 @@ describe('DataFormatter', () => {
257268
{alias: 'IE', datapoints: [1.11, 2.22], stats: {total: 3.33}},
258269
{alias: 'SE', datapoints: [2.221, 3.331], stats: {total: 5.552}},
259270
]
260-
};
271+
});
261272
dataFormatter = new DataFormatter(ctrl);
262-
dataFormatter.setTimeseriesValues(formattedData);
273+
dataFormatter.setTimeseriesValues(ctrl.series, formattedData);
263274
});
264275

265276
it('should format the value with 2 decimals', () => {
@@ -269,7 +280,7 @@ describe('DataFormatter', () => {
269280

270281
describe('and decimals are specified as a string', () => {
271282
beforeEach(() => {
272-
const ctrl = {
283+
jQuery.extend(ctrl, {
273284
panel: {
274285
valueName: 'total',
275286
decimals: '2'
@@ -282,9 +293,9 @@ describe('DataFormatter', () => {
282293
{alias: 'IE', datapoints: [1.11, 2.22], stats: {total: 3.33}},
283294
{alias: 'SE', datapoints: [2.221, 3.331], stats: {total: 5.552}},
284295
]
285-
};
296+
});
286297
dataFormatter = new DataFormatter(ctrl);
287-
dataFormatter.setTimeseriesValues(formattedData);
298+
dataFormatter.setTimeseriesValues(ctrl.series, formattedData);
288299
});
289300

290301
it('should format the value with 2 decimals', () => {

src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class ErrorManager {
4747
const domain = args.domain || 'default';
4848

4949
const item = this.makeItem(message, level);
50-
console.exception(JSON.stringify(item));
50+
console.error(JSON.stringify(item));
5151

5252
if (!this.storage[domain]) {
5353
throw new Error(`Error domain "${domain}" not registered`);

0 commit comments

Comments
 (0)