Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Jul 26, 2021
1 parent 70f068f commit 209db32
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/plugins/vis_type_pie/public/__snapshots__/pie_fn.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/plugins/vis_type_pie/public/pie_fn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { functionWrapper } from '../../expressions/common/expression_functions/specs/tests/utils';
import { createPieVisFn } from './pie_fn';
import { Datatable } from '../../expressions/common/expression_types/specs';

describe('interpreter/functions#pie', () => {
const fn = functionWrapper(createPieVisFn());
Expand Down Expand Up @@ -50,4 +51,20 @@ describe('interpreter/functions#pie', () => {
const actual = await fn(context, visConfig);
expect(actual).toMatchSnapshot();
});

it('logs correct datatable to inspector', async () => {
let loggedTable: Datatable;
const handlers = {
inspectorAdapters: {
tables: {
logDatatable: (name: string, datatable: Datatable) => {
loggedTable = datatable;
},
},
},
};
await fn(context, visConfig, handlers as any);
// @ts-ignore
expect(loggedTable).toMatchSnapshot();
});
});
74 changes: 74 additions & 0 deletions src/plugins/visualizations/common/prepare_log_table.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { prepareLogTable } from './prepare_log_table';

describe('prepareLogTable', () => {
test('returns first matching dimension name', () => {
const datatable = {
columns: [
{
meta: {},
},
{
meta: {},
},
{
meta: {},
},
],
};
const logTable = prepareLogTable(datatable as any, [
[[{ accessor: 0 } as any], 'dimension1'],
[[{ accessor: 2 } as any], 'dimension3'],
[[{ accessor: 1 } as any], 'dimension2'],
]);
expect(logTable).toMatchInlineSnapshot(
{
columns: [
{
meta: {
dimensionName: 'dimension1',
},
},
{
meta: {
dimensionName: 'dimension2',
},
},
{
meta: {
dimensionName: 'dimension3',
},
},
],
},
`
Object {
"columns": Array [
Object {
"meta": Object {
"dimensionName": "dimension1",
},
},
Object {
"meta": Object {
"dimensionName": "dimension2",
},
},
Object {
"meta": Object {
"dimensionName": "dimension3",
},
},
],
}
`
);
});
});

0 comments on commit 209db32

Please sign in to comment.