kibana/x-pack/plugins/lens/public/pie_visualization/render_helpers.test.ts
renovate[bot] 57d9dd1419
Update dependency @elastic/charts to v24.5.1 (#89822)
Updates @elastic/charts to 24.5.1 with some Kibana related fixes:
- align tooltip z-index to EUI tooltip z-index
- external tooltip legend extra value sync
- legend: hierarchical legend order should follow the tree paths


fix #84307

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-02-11 09:18:48 +01:00

159 lines
3.9 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { Datatable } from 'src/plugins/expressions/public';
import { getSliceValue, getFilterContext } from './render_helpers';
describe('render helpers', () => {
describe('#getSliceValue', () => {
it('returns the metric when positive number', () => {
expect(
getSliceValue(
{ a: 'Cat', b: 'Home', c: 5 },
{
id: 'c',
name: 'C',
meta: { type: 'number' },
}
)
).toEqual(5);
});
it('returns the metric when negative number', () => {
expect(
getSliceValue(
{ a: 'Cat', b: 'Home', c: -100 },
{
id: 'c',
name: 'C',
meta: { type: 'number' },
}
)
).toEqual(-100);
});
it('returns epsilon when metric is 0 without fallback', () => {
expect(
getSliceValue(
{ a: 'Cat', b: 'Home', c: 0 },
{
id: 'c',
name: 'C',
meta: { type: 'number' },
}
)
).toEqual(Number.EPSILON);
});
});
describe('#getFilterContext', () => {
it('handles single slice click for single ring', () => {
const table: Datatable = {
type: 'datatable',
columns: [
{ id: 'a', name: 'A', meta: { type: 'string' } },
{ id: 'b', name: 'B', meta: { type: 'number' } },
],
rows: [
{ a: 'Hi', b: 2 },
{ a: 'Test', b: 4 },
{ a: 'Foo', b: 6 },
],
};
expect(
getFilterContext(
[{ groupByRollup: 'Test', value: 100, depth: 1, path: [], sortIndex: 1 }],
['a'],
table
)
).toEqual({
data: [
{
row: 1,
column: 0,
value: 'Test',
table,
},
],
});
});
it('handles single slice click with 2 rings', () => {
const table: Datatable = {
type: 'datatable',
columns: [
{ id: 'a', name: 'A', meta: { type: 'string' } },
{ id: 'b', name: 'B', meta: { type: 'string' } },
{ id: 'c', name: 'C', meta: { type: 'number' } },
],
rows: [
{ a: 'Hi', b: 'Two', c: 2 },
{ a: 'Test', b: 'Two', c: 5 },
{ a: 'Foo', b: 'Three', c: 6 },
],
};
expect(
getFilterContext(
[{ groupByRollup: 'Test', value: 100, depth: 1, path: [], sortIndex: 1 }],
['a', 'b'],
table
)
).toEqual({
data: [
{
row: 1,
column: 0,
value: 'Test',
table,
},
],
});
});
it('finds right row for multi slice click', () => {
const table: Datatable = {
type: 'datatable',
columns: [
{ id: 'a', name: 'A', meta: { type: 'string' } },
{ id: 'b', name: 'B', meta: { type: 'string' } },
{ id: 'c', name: 'C', meta: { type: 'number' } },
],
rows: [
{ a: 'Hi', b: 'Two', c: 2 },
{ a: 'Test', b: 'Two', c: 5 },
{ a: 'Foo', b: 'Three', c: 6 },
],
};
expect(
getFilterContext(
[
{ groupByRollup: 'Test', value: 100, depth: 1, path: [], sortIndex: 1 },
{ groupByRollup: 'Two', value: 5, depth: 1, path: [], sortIndex: 1 },
],
['a', 'b'],
table
)
).toEqual({
data: [
{
row: 1,
column: 0,
value: 'Test',
table,
},
{
row: 1,
column: 1,
value: 'Two',
table,
},
],
});
});
});
});