Skip to content

Commit 3f77d55

Browse files
committed
Improve "json result" tests
1 parent 1986198 commit 3f77d55

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Interpolate datapoint field values with `__field_` prefix into transformation
77
data, now also for elasticsearch queries.
88
- Add data formatter test for "json result"
9+
- Add handling for data coming from datasources using dataframes. Thanks, @sarahleon!
910

1011

1112
## v0.9.0

src/data_formatter.test.ts

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -429,34 +429,75 @@ describe('DataFormatter', () => {
429429
const ctrl = {
430430
panel: {
431431
locationData: 'json result',
432+
decimals: 2,
432433
},
433434
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 },
435+
{ key: 'IE', name: 'Ireland', latitude: 1, longitude: 1, value: 3.333 },
436+
{ key: 'SE', name: 'Sweden', latitude: 2, longitude: 2, value: 5.555 },
436437
],
437438
};
438439
dataFormatter = new DataFormatter(ctrl);
439-
dataFormatter.setJsonValues(data);
440+
dataFormatter.setJsonValues(ctrl.series, data);
440441
});
441442

442443
it('the fields should be available within transformed data', () => {
443444
expect(data[0].key).toEqual('IE');
444445
expect(data[0].locationName).toEqual('Ireland');
445446
expect(data[0].locationLatitude).toEqual(1);
446447
expect(data[0].locationLongitude).toEqual(1);
447-
expect(data[0].value).toEqual(3.3);
448-
expect(data[0].valueRounded).toEqual(3);
448+
expect(data[0].value).toEqual(3.333);
449+
expect(data[0].valueRounded).toEqual(3.33);
449450

450451
expect(data[1].key).toEqual('SE');
451452
expect(data[1].locationName).toEqual('Sweden');
452453
expect(data[1].locationLatitude).toEqual(2);
453454
expect(data[1].locationLongitude).toEqual(2);
454-
expect(data[1].value).toEqual(5.5);
455-
expect(data[1].valueRounded).toEqual(6);
455+
expect(data[1].value).toEqual(5.555);
456+
expect(data[1].valueRounded).toEqual(5.56);
456457

457-
expect(data.highestValue).toEqual(5.5);
458-
expect(data.lowestValue).toEqual(3.3);
459-
expect(data.valueRange).toEqual(2.2);
458+
expect(data.highestValue).toEqual(5.555);
459+
expect(data.lowestValue).toEqual(3.333);
460+
expect(data.valueRange).toEqual(2.2219999999999995);
461+
462+
});
463+
464+
});
465+
466+
describe('when data is coming from "json result" (dataframe)', () => {
467+
const data: any[] = [];
468+
beforeEach(() => {
469+
const ctrl = {
470+
panel: {
471+
locationData: 'json result',
472+
decimals: 2,
473+
},
474+
series: [
475+
{datapoints: [{ key: 'IE', name: 'Ireland', latitude: 1, longitude: 1, value: 3.333 }]},
476+
{datapoints: [{ key: 'SE', name: 'Sweden', latitude: 2, longitude: 2, value: 5.555 }]},
477+
],
478+
};
479+
dataFormatter = new DataFormatter(ctrl);
480+
dataFormatter.setJsonValues(ctrl.series, data);
481+
});
482+
483+
it('the fields should be available within transformed data', () => {
484+
expect(data[0].key).toEqual('IE');
485+
expect(data[0].locationName).toEqual('Ireland');
486+
expect(data[0].locationLatitude).toEqual(1);
487+
expect(data[0].locationLongitude).toEqual(1);
488+
expect(data[0].value).toEqual(3.333);
489+
expect(data[0].valueRounded).toEqual(3.33);
490+
491+
expect(data[1].key).toEqual('SE');
492+
expect(data[1].locationName).toEqual('Sweden');
493+
expect(data[1].locationLatitude).toEqual(2);
494+
expect(data[1].locationLongitude).toEqual(2);
495+
expect(data[1].value).toEqual(5.555);
496+
expect(data[1].valueRounded).toEqual(5.56);
497+
498+
expect(data.highestValue).toEqual(5.555);
499+
expect(data.lowestValue).toEqual(3.333);
500+
expect(data.valueRange).toEqual(2.2219999999999995);
460501

461502
});
462503

0 commit comments

Comments
 (0)