2020-05-05 21:59:32 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
2021-02-04 03:12:39 +01:00
|
|
|
* 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.
|
2020-05-05 21:59:32 +02:00
|
|
|
*/
|
|
|
|
|
2020-10-16 18:46:51 +02:00
|
|
|
import { Datatable } from 'src/plugins/expressions/public';
|
2020-10-29 15:48:49 +01:00
|
|
|
import { getSliceValue, getFilterContext } from './render_helpers';
|
2020-05-05 21:59:32 +02:00
|
|
|
|
|
|
|
describe('render helpers', () => {
|
2020-10-29 15:48:49 +01:00
|
|
|
describe('#getSliceValue', () => {
|
|
|
|
it('returns the metric when positive number', () => {
|
|
|
|
expect(
|
|
|
|
getSliceValue(
|
|
|
|
{ a: 'Cat', b: 'Home', c: 5 },
|
|
|
|
{
|
2020-05-05 21:59:32 +02:00
|
|
|
id: 'c',
|
|
|
|
name: 'C',
|
2020-10-16 18:46:51 +02:00
|
|
|
meta: { type: 'number' },
|
2020-10-29 15:48:49 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).toEqual(5);
|
|
|
|
});
|
2020-05-05 21:59:32 +02:00
|
|
|
|
2020-10-29 15:48:49 +01:00
|
|
|
it('returns the metric when negative number', () => {
|
|
|
|
expect(
|
|
|
|
getSliceValue(
|
|
|
|
{ a: 'Cat', b: 'Home', c: -100 },
|
|
|
|
{
|
2020-05-05 21:59:32 +02:00
|
|
|
id: 'c',
|
|
|
|
name: 'C',
|
2020-10-16 18:46:51 +02:00
|
|
|
meta: { type: 'number' },
|
2020-10-29 15:48:49 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).toEqual(-100);
|
|
|
|
});
|
2020-05-05 21:59:32 +02:00
|
|
|
|
2020-10-29 15:48:49 +01:00
|
|
|
it('returns epsilon when metric is 0 without fallback', () => {
|
|
|
|
expect(
|
|
|
|
getSliceValue(
|
|
|
|
{ a: 'Cat', b: 'Home', c: 0 },
|
|
|
|
{
|
2020-05-05 21:59:32 +02:00
|
|
|
id: 'c',
|
|
|
|
name: 'C',
|
2020-10-16 18:46:51 +02:00
|
|
|
meta: { type: 'number' },
|
2020-10-29 15:48:49 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
).toEqual(Number.EPSILON);
|
2020-05-05 21:59:32 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getFilterContext', () => {
|
|
|
|
it('handles single slice click for single ring', () => {
|
2020-10-16 18:46:51 +02:00
|
|
|
const table: Datatable = {
|
|
|
|
type: 'datatable',
|
2020-05-05 21:59:32 +02:00
|
|
|
columns: [
|
2020-10-16 18:46:51 +02:00
|
|
|
{ id: 'a', name: 'A', meta: { type: 'string' } },
|
|
|
|
{ id: 'b', name: 'B', meta: { type: 'number' } },
|
2020-05-05 21:59:32 +02:00
|
|
|
],
|
|
|
|
rows: [
|
|
|
|
{ a: 'Hi', b: 2 },
|
|
|
|
{ a: 'Test', b: 4 },
|
|
|
|
{ a: 'Foo', b: 6 },
|
|
|
|
],
|
|
|
|
};
|
2021-02-11 09:18:48 +01:00
|
|
|
expect(
|
|
|
|
getFilterContext(
|
|
|
|
[{ groupByRollup: 'Test', value: 100, depth: 1, path: [], sortIndex: 1 }],
|
|
|
|
['a'],
|
|
|
|
table
|
|
|
|
)
|
|
|
|
).toEqual({
|
2020-05-15 12:01:27 +02:00
|
|
|
data: [
|
|
|
|
{
|
|
|
|
row: 1,
|
|
|
|
column: 0,
|
|
|
|
value: 'Test',
|
|
|
|
table,
|
|
|
|
},
|
|
|
|
],
|
2020-05-05 21:59:32 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles single slice click with 2 rings', () => {
|
2020-10-16 18:46:51 +02:00
|
|
|
const table: Datatable = {
|
|
|
|
type: 'datatable',
|
2020-05-05 21:59:32 +02:00
|
|
|
columns: [
|
2020-10-16 18:46:51 +02:00
|
|
|
{ id: 'a', name: 'A', meta: { type: 'string' } },
|
|
|
|
{ id: 'b', name: 'B', meta: { type: 'string' } },
|
|
|
|
{ id: 'c', name: 'C', meta: { type: 'number' } },
|
2020-05-05 21:59:32 +02:00
|
|
|
],
|
|
|
|
rows: [
|
|
|
|
{ a: 'Hi', b: 'Two', c: 2 },
|
|
|
|
{ a: 'Test', b: 'Two', c: 5 },
|
|
|
|
{ a: 'Foo', b: 'Three', c: 6 },
|
|
|
|
],
|
|
|
|
};
|
2021-02-11 09:18:48 +01:00
|
|
|
expect(
|
|
|
|
getFilterContext(
|
|
|
|
[{ groupByRollup: 'Test', value: 100, depth: 1, path: [], sortIndex: 1 }],
|
|
|
|
['a', 'b'],
|
|
|
|
table
|
|
|
|
)
|
|
|
|
).toEqual({
|
2020-05-15 12:01:27 +02:00
|
|
|
data: [
|
|
|
|
{
|
|
|
|
row: 1,
|
|
|
|
column: 0,
|
|
|
|
value: 'Test',
|
|
|
|
table,
|
|
|
|
},
|
|
|
|
],
|
2020-05-05 21:59:32 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('finds right row for multi slice click', () => {
|
2020-10-16 18:46:51 +02:00
|
|
|
const table: Datatable = {
|
|
|
|
type: 'datatable',
|
2020-05-05 21:59:32 +02:00
|
|
|
columns: [
|
2020-10-16 18:46:51 +02:00
|
|
|
{ id: 'a', name: 'A', meta: { type: 'string' } },
|
|
|
|
{ id: 'b', name: 'B', meta: { type: 'string' } },
|
|
|
|
{ id: 'c', name: 'C', meta: { type: 'number' } },
|
2020-05-05 21:59:32 +02:00
|
|
|
],
|
|
|
|
rows: [
|
|
|
|
{ a: 'Hi', b: 'Two', c: 2 },
|
|
|
|
{ a: 'Test', b: 'Two', c: 5 },
|
|
|
|
{ a: 'Foo', b: 'Three', c: 6 },
|
|
|
|
],
|
|
|
|
};
|
|
|
|
expect(
|
|
|
|
getFilterContext(
|
|
|
|
[
|
2021-02-11 09:18:48 +01:00
|
|
|
{ groupByRollup: 'Test', value: 100, depth: 1, path: [], sortIndex: 1 },
|
|
|
|
{ groupByRollup: 'Two', value: 5, depth: 1, path: [], sortIndex: 1 },
|
2020-05-05 21:59:32 +02:00
|
|
|
],
|
|
|
|
['a', 'b'],
|
|
|
|
table
|
|
|
|
)
|
|
|
|
).toEqual({
|
2020-05-15 12:01:27 +02:00
|
|
|
data: [
|
|
|
|
{
|
|
|
|
row: 1,
|
|
|
|
column: 0,
|
|
|
|
value: 'Test',
|
|
|
|
table,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
row: 1,
|
|
|
|
column: 1,
|
|
|
|
value: 'Two',
|
|
|
|
table,
|
|
|
|
},
|
|
|
|
],
|
2020-05-05 21:59:32 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|