Skip to content

Commit 5317a7c

Browse files
committed
Add data formatter test for "json result"
1 parent e8cd4c6 commit 5317a7c

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Add tests for elasticsearch query results, both for table- and timeseries-data
66
- Interpolate datapoint field values with `__field_` prefix into transformation
77
data, now also for elasticsearch queries.
8+
- Add data formatter test for "json result"
89

910

1011
## v0.9.0

src/data_formatter.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,47 @@ describe('DataFormatter', () => {
423423
});
424424
});
425425

426+
describe('when data is coming from "json result" (regular)', () => {
427+
const data: any[] = [];
428+
beforeEach(() => {
429+
const ctrl = {
430+
panel: {
431+
locationData: 'json result',
432+
},
433+
series: [
434+
{ key: 'IE', name: 'Ireland', latitude: 1, longitude: 1, value: 3.3 },
435+
{ key: 'SE', name: 'Sweden', latitude: 2, longitude: 2, value: 5.5 },
436+
],
437+
};
438+
dataFormatter = new DataFormatter(ctrl);
439+
dataFormatter.setJsonValues(data);
440+
});
441+
442+
it('the fields should be available within transformed data', () => {
443+
expect(data[0].key).toEqual('IE');
444+
expect(data[0].locationName).toEqual('Ireland');
445+
expect(data[0].locationLatitude).toEqual(1);
446+
expect(data[0].locationLongitude).toEqual(1);
447+
expect(data[0].value).toEqual(3.3);
448+
expect(data[0].valueRounded).toEqual(3);
449+
450+
expect(data[1].key).toEqual('SE');
451+
expect(data[1].locationName).toEqual('Sweden');
452+
expect(data[1].locationLatitude).toEqual(2);
453+
expect(data[1].locationLongitude).toEqual(2);
454+
expect(data[1].value).toEqual(5.5);
455+
expect(data[1].valueRounded).toEqual(6);
456+
457+
expect(data.highestValue).toEqual(5.5);
458+
expect(data.lowestValue).toEqual(3.3);
459+
expect(data.valueRange).toEqual(2.2);
460+
461+
});
462+
463+
});
464+
426465
afterEach(() => {
427466
formattedData = [];
428467
});
468+
429469
});

0 commit comments

Comments
 (0)