kibana/x-pack/plugins/lens/public/datatable_visualization/expression.test.tsx
Marco Liberati 3c6b85469b
[Lens] Move Lens functions to common (#105455)
* 🚚 First move batch to common

* 🚚 Second batch of move

* 🏷️ Import types only

* 🚚 Third batch

* 🚚 Fourth batch move

* 🚚 Another module moved

* 🚚 More function moved

* 🚚 Last bit of move

*  Reduce page load bundle size

* 🐛 Fix import issue

* 🐛 More import fix

*  Registered functions on the server

* 🐛 Expose datatable_column as well

*  Add server side expression test

* 🚚 Moved back render functions to public

*  Add a timezone arg to time_scale

* 🔥 Remove timezone arg

* 🔥 Remove server side code for now

* 👌 Integrated feedback

* 🚚 Move back datatable render function

* 🏷️ Fix imports

* 🏷️ Fix missing export

* 🚚 Move render functions back!

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-07-26 15:26:29 +02:00

102 lines
2.6 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 { DatatableProps } from '../../common/expressions';
import type { LensMultiTable } from '../../common';
import { createMockExecutionContext } from '../../../../../src/plugins/expressions/common/mocks';
import { IFieldFormat } from '../../../../../src/plugins/data/public';
import { getDatatable } from './expression';
function sampleArgs() {
const indexPatternId = 'indexPatternId';
const data: LensMultiTable = {
type: 'lens_multitable',
tables: {
l1: {
type: 'datatable',
columns: [
{
id: 'a',
name: 'a',
meta: {
type: 'string',
source: 'esaggs',
field: 'a',
sourceParams: { type: 'terms', indexPatternId },
},
},
{
id: 'b',
name: 'b',
meta: {
type: 'date',
field: 'b',
source: 'esaggs',
sourceParams: {
type: 'date_histogram',
indexPatternId,
},
},
},
{
id: 'c',
name: 'c',
meta: {
type: 'number',
source: 'esaggs',
field: 'c',
sourceParams: { indexPatternId, type: 'count' },
},
},
],
rows: [{ a: 'shoes', b: 1588024800000, c: 3 }],
},
},
};
const args: DatatableProps['args'] = {
title: 'My fanci metric chart',
columns: [
{
columnId: 'a',
type: 'lens_datatable_column',
},
{
columnId: 'b',
type: 'lens_datatable_column',
},
{
columnId: 'c',
type: 'lens_datatable_column',
},
],
sortingColumnId: undefined,
sortingDirection: 'none',
};
return { data, args };
}
describe('datatable_expression', () => {
describe('datatable renders', () => {
test('it renders with the specified data and args', () => {
const { data, args } = sampleArgs();
const result = getDatatable({ formatFactory: (x) => x as IFieldFormat }).fn(
data,
args,
createMockExecutionContext()
);
expect(result).toEqual({
type: 'render',
as: 'lens_datatable_renderer',
value: { data, args },
});
});
});
});