Commit 77b7f4b3 by Alexander Zobnin

heatmap: add unit tests for convertToCards()

parent c7e8b98d
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
import _ from 'lodash'; import _ from 'lodash';
import { describe, beforeEach, it, sinon, expect, angularMocks } from '../../../../../test/lib/common'; import { describe, beforeEach, it, sinon, expect, angularMocks } from '../../../../../test/lib/common';
import TimeSeries from 'app/core/time_series2'; import TimeSeries from 'app/core/time_series2';
import { convertToHeatMap, elasticHistogramToHeatmap, calculateBucketSize, isHeatmapDataEqual } from '../heatmap_data_converter'; import {convertToHeatMap, convertToCards, elasticHistogramToHeatmap,
calculateBucketSize, isHeatmapDataEqual} from '../heatmap_data_converter';
describe('isHeatmapDataEqual', () => { describe('isHeatmapDataEqual', () => {
let ctx: any = {}; let ctx: any = {};
...@@ -244,6 +245,47 @@ describe('ES Histogram converter', () => { ...@@ -244,6 +245,47 @@ describe('ES Histogram converter', () => {
}); });
}); });
describe('convertToCards', () => {
let buckets = {};
beforeEach(() => {
buckets = {
'1422774000000': {
x: 1422774000000,
buckets: {
'1': { y: 1, values: [1], count: 1, bounds: {} },
'2': { y: 2, values: [2], count: 1, bounds: {} }
}
},
'1422774060000': {
x: 1422774060000,
buckets: {
'2': { y: 2, values: [2, 3], count: 2, bounds: {} }
}
},
};
});
it('should build proper cards data', () => {
let expectedCards = [
{x: 1422774000000, y: 1, count: 1, values: [1], yBounds: {}},
{x: 1422774000000, y: 2, count: 1, values: [2], yBounds: {}},
{x: 1422774060000, y: 2, count: 2, values: [2, 3], yBounds: {}}
];
let {cards, cardStats} = convertToCards(buckets);
expect(cards).to.eql(expectedCards);
});
it('should build proper cards stats', () => {
let expectedStats = {
min: 1,
max: 2
};
let {cards, cardStats} = convertToCards(buckets);
expect(cardStats).to.eql(expectedStats);
});
});
/** /**
* Compare two numbers with given precision. Suitable for compare float numbers after conversions with precision loss. * Compare two numbers with given precision. Suitable for compare float numbers after conversions with precision loss.
* @param a * @param a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment