mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
* Convert function tests to jest * Fix some bad merge conflict resolutions * Exclude Server tests from being included in mocha run * Remove code leftover from testing * Fix rebase * Fix paths for running Jest tests * do not run function server tests as part of test:server * Move Jest tests to be alongside files
This commit is contained in:
parent
8c2dbd5f99
commit
44983ce504
78 changed files with 1361 additions and 1423 deletions
|
@ -4,31 +4,29 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { markdown } from '../markdown';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from '../../common/__tests__/fixtures/test_tables';
|
||||
import { fontStyle } from '../../common/__tests__/fixtures/test_styles';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from '../common/__tests__/fixtures/test_tables';
|
||||
import { fontStyle } from '../common/__tests__/fixtures/test_styles';
|
||||
import { markdown } from './markdown';
|
||||
|
||||
describe('markdown', () => {
|
||||
const fn = functionWrapper(markdown);
|
||||
|
||||
it('returns a render as markdown', () => {
|
||||
const result = fn(null, { expression: [''], font: fontStyle });
|
||||
expect(result)
|
||||
.to.have.property('type', 'render')
|
||||
.and.to.have.property('as', 'markdown');
|
||||
const result = fn(null, { content: [''], font: fontStyle });
|
||||
expect(result).toHaveProperty('type', 'render');
|
||||
expect(result).toHaveProperty('as', 'markdown');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('expression', () => {
|
||||
it('sets the content to all strings in expression concatenated', () => {
|
||||
const result = fn(null, {
|
||||
expression: ['# this ', 'is ', 'some ', 'markdown'],
|
||||
content: ['# this ', 'is ', 'some ', 'markdown'],
|
||||
font: fontStyle,
|
||||
});
|
||||
|
||||
expect(result.value).to.have.property('content', '# this is some markdown');
|
||||
expect(result.value).toHaveProperty('content', '# this is some markdown');
|
||||
});
|
||||
|
||||
it('compiles and concatenates handlebars expressions using context', () => {
|
||||
|
@ -36,27 +34,21 @@ describe('markdown', () => {
|
|||
testTable.columns.map(col => (expectedContent += ` ${col.name}`));
|
||||
|
||||
const result = fn(testTable, {
|
||||
expression: ['Columns:', '{{#each columns}} {{name}}{{/each}}'],
|
||||
content: ['Columns:', '{{#each columns}} {{name}}{{/each}}'],
|
||||
});
|
||||
|
||||
expect(result.value).to.have.property('content', expectedContent);
|
||||
expect(result.value).toHaveProperty('content', expectedContent);
|
||||
});
|
||||
|
||||
// it('returns a markdown object with no content', () => {
|
||||
// const result = fn(null, { font: fontStyle });
|
||||
|
||||
// expect(result.value).to.have.property('content', '');
|
||||
// });
|
||||
});
|
||||
|
||||
describe('font', () => {
|
||||
it('sets the font style for the markdown', () => {
|
||||
const result = fn(null, {
|
||||
expression: ['some ', 'markdown'],
|
||||
content: ['some ', 'markdown'],
|
||||
font: fontStyle,
|
||||
});
|
||||
|
||||
expect(result.value).to.have.property('font', fontStyle);
|
||||
expect(result.value).toHaveProperty('font', fontStyle);
|
||||
});
|
||||
|
||||
// TODO: write test when using an instance of the interpreter
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { all } from '../all';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
|
||||
describe('all', () => {
|
||||
const fn = functionWrapper(all);
|
||||
|
||||
it('should return true with no conditions', () => {
|
||||
expect(fn(null, {})).to.be(true);
|
||||
expect(fn(null, { condition: [] })).to.be(true);
|
||||
});
|
||||
|
||||
it('should return true when all conditions are true', () => {
|
||||
expect(fn(null, { condition: [true] })).to.be(true);
|
||||
expect(fn(null, { condition: [true, true, true] })).to.be(true);
|
||||
});
|
||||
|
||||
it('should return true when all conditions are truthy', () => {
|
||||
expect(fn(null, { condition: [true, 1, 'hooray', {}] })).to.be(true);
|
||||
});
|
||||
|
||||
it('should return false when at least one condition is false', () => {
|
||||
expect(fn(null, { condition: [false, true, true] })).to.be(false);
|
||||
expect(fn(null, { condition: [false, false, true] })).to.be(false);
|
||||
expect(fn(null, { condition: [false, false, false] })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return false when at least one condition is falsy', () => {
|
||||
expect(fn(null, { condition: [true, 0, 'hooray', {}] })).to.be(false);
|
||||
expect(fn(null, { condition: [true, 1, 'hooray', null] })).to.be(false);
|
||||
expect(fn(null, { condition: [true, 1, '', {}] })).to.be(false);
|
||||
});
|
||||
});
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { any } from '../any';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
|
||||
describe('any', () => {
|
||||
const fn = functionWrapper(any);
|
||||
|
||||
it('should return false with no conditions', () => {
|
||||
expect(fn(null, {})).to.be(false);
|
||||
expect(fn(null, { condition: [] })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return false when no conditions are true', () => {
|
||||
expect(fn(null, null, { condition: [false] })).to.be(false);
|
||||
expect(fn(null, { condition: [false, false, false] })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return false when all conditions are falsy', () => {
|
||||
expect(fn(null, { condition: [false, 0, '', null] })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return true when at least one condition is true', () => {
|
||||
expect(fn(null, { condition: [false, false, true] })).to.be(true);
|
||||
expect(fn(null, { condition: [false, true, true] })).to.be(true);
|
||||
expect(fn(null, { condition: [true, true, true] })).to.be(true);
|
||||
});
|
||||
|
||||
it('should return true when at least one condition is truthy', () => {
|
||||
expect(fn(null, { condition: [false, 0, '', null, 1] })).to.be(true);
|
||||
expect(fn(null, { condition: [false, 0, 'hooray', null] })).to.be(true);
|
||||
expect(fn(null, { condition: [false, 0, {}, null] })).to.be(true);
|
||||
});
|
||||
});
|
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { columns } from '../columns';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { emptyTable, testTable } from './fixtures/test_tables';
|
||||
|
||||
describe('columns', () => {
|
||||
const fn = functionWrapper(columns);
|
||||
|
||||
it('returns a datatable', () => {
|
||||
expect(fn(testTable, { include: 'name' }).type).to.be('datatable');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
it('returns a datatable with included columns and without excluded columns', () => {
|
||||
const arbitraryRowIndex = 7;
|
||||
const result = fn(testTable, {
|
||||
include: 'name, price, quantity, foo, bar',
|
||||
exclude: 'price, quantity, fizz, buzz',
|
||||
});
|
||||
|
||||
expect(result.columns[0]).to.have.property('name', 'name');
|
||||
expect(result.rows[arbitraryRowIndex])
|
||||
.to.have.property('name', testTable.rows[arbitraryRowIndex].name)
|
||||
.and.to.not.have.property('price')
|
||||
.and.to.not.have.property('quantity')
|
||||
.and.to.not.have.property('foo')
|
||||
.and.to.not.have.property('bar')
|
||||
.and.to.not.have.property('fizz')
|
||||
.and.to.not.have.property('buzz');
|
||||
});
|
||||
|
||||
it('returns original context if args are not provided', () => {
|
||||
expect(fn(testTable)).to.eql(testTable);
|
||||
});
|
||||
|
||||
it('returns an empty datatable if include and exclude both reference the same column(s)', () => {
|
||||
expect(fn(testTable, { include: 'price', exclude: 'price' })).to.eql(emptyTable);
|
||||
|
||||
expect(
|
||||
fn(testTable, {
|
||||
include: 'price, quantity, in_stock',
|
||||
exclude: 'price, quantity, in_stock',
|
||||
})
|
||||
).to.eql(emptyTable);
|
||||
});
|
||||
|
||||
describe('include', () => {
|
||||
it('returns a datatable with included columns only', () => {
|
||||
const arbitraryRowIndex = 3;
|
||||
const result = fn(testTable, {
|
||||
include: 'name, time, in_stock',
|
||||
});
|
||||
|
||||
expect(result.columns).to.have.length(3);
|
||||
expect(Object.keys(result.rows[0])).to.have.length(3);
|
||||
|
||||
expect(result.columns[0]).to.have.property('name', 'name');
|
||||
expect(result.columns[1]).to.have.property('name', 'time');
|
||||
expect(result.columns[2]).to.have.property('name', 'in_stock');
|
||||
expect(result.rows[arbitraryRowIndex])
|
||||
.to.have.property('name', testTable.rows[arbitraryRowIndex].name)
|
||||
.and.to.have.property('time', testTable.rows[arbitraryRowIndex].time)
|
||||
.and.to.have.property('in_stock', testTable.rows[arbitraryRowIndex].in_stock);
|
||||
});
|
||||
|
||||
it('ignores invalid columns', () => {
|
||||
const arbitraryRowIndex = 6;
|
||||
const result = fn(testTable, {
|
||||
include: 'name, foo, bar',
|
||||
});
|
||||
|
||||
expect(result.columns[0]).to.have.property('name', 'name');
|
||||
expect(result.rows[arbitraryRowIndex])
|
||||
.to.have.property('name', testTable.rows[arbitraryRowIndex].name)
|
||||
.and.to.not.have.property('foo')
|
||||
.and.to.not.have.property('bar');
|
||||
});
|
||||
|
||||
it('returns an empty datable if include only has invalid columns', () => {
|
||||
expect(fn(testTable, { include: 'foo, bar' })).to.eql(emptyTable);
|
||||
});
|
||||
});
|
||||
|
||||
describe('exclude', () => {
|
||||
it('returns a datatable without excluded columns', () => {
|
||||
const arbitraryRowIndex = 5;
|
||||
const result = fn(testTable, { exclude: 'price, quantity, foo, bar' });
|
||||
|
||||
expect(result.columns.length).to.equal(testTable.columns.length - 2);
|
||||
expect(Object.keys(result.rows[0])).to.have.length(testTable.columns.length - 2);
|
||||
expect(result.rows[arbitraryRowIndex])
|
||||
.to.not.have.property('price')
|
||||
.and.to.not.have.property('quantity')
|
||||
.and.to.not.have.property('foo')
|
||||
.and.to.not.have.property('bar');
|
||||
});
|
||||
|
||||
it('ignores invalid columns', () => {
|
||||
const arbitraryRowIndex = 1;
|
||||
const result = fn(testTable, { exclude: 'time, foo, bar' });
|
||||
|
||||
expect(result.columns.length).to.equal(testTable.columns.length - 1);
|
||||
expect(result.rows[arbitraryRowIndex])
|
||||
.to.not.have.property('time')
|
||||
.and.to.not.have.property('foo')
|
||||
.and.to.not.have.property('bar');
|
||||
});
|
||||
|
||||
it('returns original context if exclude only references invalid column name(s)', () => {
|
||||
expect(fn(testTable, { exclude: 'foo, bar, fizz, buzz' })).to.eql(testTable);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { context } from '../context';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable, emptyTable } from './fixtures/test_tables';
|
||||
|
||||
describe('context', () => {
|
||||
const fn = functionWrapper(context);
|
||||
|
||||
it('returns whatever context you pass into', () => {
|
||||
expect(fn(null)).to.be(null);
|
||||
expect(fn(true)).to.be(true);
|
||||
expect(fn(1)).to.be(1);
|
||||
expect(fn('foo')).to.be('foo');
|
||||
expect(fn({})).to.eql({});
|
||||
expect(fn(emptyTable)).to.eql(emptyTable);
|
||||
expect(fn(testTable)).to.eql(testTable);
|
||||
});
|
||||
});
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { eq } from '../eq';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
|
||||
describe('eq', () => {
|
||||
const fn = functionWrapper(eq);
|
||||
|
||||
it('should return false when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).to.be(false);
|
||||
expect(fn(true, { value: 'true' })).to.be(false);
|
||||
expect(fn(null, { value: 'null' })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return false when the values are different', () => {
|
||||
expect(fn(1, { value: 2 })).to.be(false);
|
||||
expect(fn('foo', { value: 'bar' })).to.be(false);
|
||||
expect(fn(true, { value: false })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return true when the values are the same', () => {
|
||||
expect(fn(1, { value: 1 })).to.be(true);
|
||||
expect(fn('foo', { value: 'foo' })).to.be(true);
|
||||
expect(fn(true, { value: true })).to.be(true);
|
||||
expect(fn(null, { value: null })).to.be(true);
|
||||
});
|
||||
});
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { gt } from '../gt';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
|
||||
describe('gt', () => {
|
||||
const fn = functionWrapper(gt);
|
||||
|
||||
it('should return false when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).to.be(false);
|
||||
expect(fn('3', { value: 3 })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return true when greater than', () => {
|
||||
expect(fn(2, { value: 1 })).to.be(true);
|
||||
expect(fn('b', { value: 'a' })).to.be(true);
|
||||
expect(fn('foo', { value: 'bar' })).to.be(true);
|
||||
});
|
||||
|
||||
it('should return false when less than or equal to', () => {
|
||||
expect(fn(1, { value: 2 })).to.be(false);
|
||||
expect(fn(2, { value: 2 })).to.be(false);
|
||||
expect(fn('a', { value: 'b' })).to.be(false);
|
||||
expect(fn('bar', { value: 'foo' })).to.be(false);
|
||||
expect(fn('foo', { value: 'foo' })).to.be(false);
|
||||
});
|
||||
});
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { gte } from '../gte';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
|
||||
describe('gte', () => {
|
||||
const fn = functionWrapper(gte);
|
||||
|
||||
it('should return false when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).to.be(false);
|
||||
expect(fn(3, { value: '3' })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return true when greater than or equal to', () => {
|
||||
expect(fn(2, { value: 1 })).to.be(true);
|
||||
expect(fn(2, { value: 2 })).to.be(true);
|
||||
expect(fn('b', { value: 'a' })).to.be(true);
|
||||
expect(fn('b', { value: 'b' })).to.be(true);
|
||||
expect(fn('foo', { value: 'bar' })).to.be(true);
|
||||
expect(fn('foo', { value: 'foo' })).to.be(true);
|
||||
});
|
||||
|
||||
it('should return false when less than', () => {
|
||||
expect(fn(1, { value: 2 })).to.be(false);
|
||||
expect(fn('a', { value: 'b' })).to.be(false);
|
||||
expect(fn('bar', { value: 'foo' })).to.be(false);
|
||||
});
|
||||
});
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { head } from '../head';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { emptyTable, testTable } from './fixtures/test_tables';
|
||||
|
||||
describe('head', () => {
|
||||
const fn = functionWrapper(head);
|
||||
|
||||
it('returns a datatable with the first N rows of the context', () => {
|
||||
const result = fn(testTable, { count: 2 });
|
||||
|
||||
expect(result.type).to.be('datatable');
|
||||
expect(result.columns).to.eql(testTable.columns);
|
||||
expect(result.rows).to.have.length(2);
|
||||
expect(result.rows[0]).to.eql(testTable.rows[0]);
|
||||
expect(result.rows[1]).to.eql(testTable.rows[1]);
|
||||
});
|
||||
|
||||
it('returns the original context if N >= context.rows.length', () => {
|
||||
expect(fn(testTable, { count: testTable.rows.length + 5 })).to.eql(testTable);
|
||||
expect(fn(testTable, { count: testTable.rows.length })).to.eql(testTable);
|
||||
expect(fn(emptyTable)).to.eql(emptyTable);
|
||||
});
|
||||
|
||||
it('returns the first row if N is not specified', () => {
|
||||
const result = fn(testTable);
|
||||
|
||||
expect(result.rows).to.have.length(1);
|
||||
expect(result.rows[0]).to.eql(testTable.rows[0]);
|
||||
});
|
||||
});
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { lt } from '../lt';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
|
||||
describe('lt', () => {
|
||||
const fn = functionWrapper(lt);
|
||||
|
||||
it('should return false when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).to.be(false);
|
||||
expect(fn('3', { value: 3 })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return false when greater than or equal to', () => {
|
||||
expect(fn(2, { value: 1 })).to.be(false);
|
||||
expect(fn(2, { value: 2 })).to.be(false);
|
||||
expect(fn('b', { value: 'a' })).to.be(false);
|
||||
expect(fn('b', { value: 'b' })).to.be(false);
|
||||
expect(fn('foo', { value: 'bar' })).to.be(false);
|
||||
expect(fn('foo', { value: 'foo' })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return true when less than', () => {
|
||||
expect(fn(1, { value: 2 })).to.be(true);
|
||||
expect(fn('a', { value: 'b' })).to.be(true);
|
||||
expect(fn('bar', { value: 'foo' })).to.be(true);
|
||||
});
|
||||
});
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { lte } from '../lte';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
|
||||
describe('lte', () => {
|
||||
const fn = functionWrapper(lte);
|
||||
|
||||
it('should return false when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).to.be(false);
|
||||
expect(fn('3', { value: 3 })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return false when greater than', () => {
|
||||
expect(fn(2, { value: 1 })).to.be(false);
|
||||
expect(fn('b', { value: 'a' })).to.be(false);
|
||||
expect(fn('foo', { value: 'bar' })).to.be(false);
|
||||
});
|
||||
|
||||
it('should return true when less than or equal to', () => {
|
||||
expect(fn(1, { value: 2 })).to.be(true);
|
||||
expect(fn(2, { value: 2 })).to.be(true);
|
||||
expect(fn('a', { value: 'b' })).to.be(true);
|
||||
expect(fn('a', { value: 'a' })).to.be(true);
|
||||
expect(fn('bar', { value: 'foo' })).to.be(true);
|
||||
expect(fn('foo', { value: 'foo' })).to.be(true);
|
||||
});
|
||||
});
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { math } from '../math';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../../strings';
|
||||
import { emptyTable, testTable } from './fixtures/test_tables';
|
||||
|
||||
const errors = getFunctionErrors().math;
|
||||
|
||||
describe('math', () => {
|
||||
const fn = functionWrapper(math);
|
||||
|
||||
it('evaluates math expressions without reference to context', () => {
|
||||
expect(fn(null, { expression: '10.5345' })).to.be(10.5345);
|
||||
expect(fn(null, { expression: '123 + 456' })).to.be(579);
|
||||
expect(fn(null, { expression: '100 - 46' })).to.be(54);
|
||||
expect(fn(1, { expression: '100 / 5' })).to.be(20);
|
||||
expect(fn('foo', { expression: '100 / 5' })).to.be(20);
|
||||
expect(fn(true, { expression: '100 / 5' })).to.be(20);
|
||||
expect(fn(testTable, { expression: '100 * 5' })).to.be(500);
|
||||
expect(fn(emptyTable, { expression: '100 * 5' })).to.be(500);
|
||||
});
|
||||
|
||||
it('evaluates math expressions with reference to the value of the context, must be a number', () => {
|
||||
expect(fn(-103, { expression: 'abs(value)' })).to.be(103);
|
||||
});
|
||||
|
||||
it('evaluates math expressions with references to columns in a datatable', () => {
|
||||
expect(fn(testTable, { expression: 'unique(in_stock)' })).to.be(2);
|
||||
expect(fn(testTable, { expression: 'sum(quantity)' })).to.be(2508);
|
||||
expect(fn(testTable, { expression: 'mean(price)' })).to.be(320);
|
||||
expect(fn(testTable, { expression: 'min(price)' })).to.be(67);
|
||||
expect(fn(testTable, { expression: 'median(quantity)' })).to.be(256);
|
||||
expect(fn(testTable, { expression: 'max(price)' })).to.be(605);
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('expression', () => {
|
||||
it('sets the math expression to be evaluted', () => {
|
||||
expect(fn(null, { expression: '10' })).to.be(10);
|
||||
expect(fn(23.23, { expression: 'floor(value)' })).to.be(23);
|
||||
expect(fn(testTable, { expression: 'count(price)' })).to.be(9);
|
||||
expect(fn(testTable, { expression: 'count(name)' })).to.be(9);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid expressions', () => {
|
||||
it('throws when expression evaluates to an array', () => {
|
||||
expect(fn)
|
||||
.withArgs(testTable, { expression: 'multiply(price, 2)' })
|
||||
.to.throwException(new RegExp(errors.tooManyResults().message.replace(/[()]/g, '\\$&')));
|
||||
});
|
||||
|
||||
it('throws when using an unknown context variable', () => {
|
||||
expect(fn)
|
||||
.withArgs(testTable, { expression: 'sum(foo)' })
|
||||
.to.throwException(e => {
|
||||
expect(e.message).to.be('Unknown variable: foo');
|
||||
});
|
||||
});
|
||||
|
||||
it('throws when using non-numeric data', () => {
|
||||
expect(fn)
|
||||
.withArgs(testTable, { expression: 'mean(name)' })
|
||||
.to.throwException(new RegExp(errors.executionFailed().message));
|
||||
expect(fn)
|
||||
.withArgs(testTable, { expression: 'mean(in_stock)' })
|
||||
.to.throwException(new RegExp(errors.executionFailed().message));
|
||||
});
|
||||
|
||||
it('throws when missing expression', () => {
|
||||
expect(fn)
|
||||
.withArgs(testTable)
|
||||
.to.throwException(new RegExp(errors.emptyExpression().message));
|
||||
expect(fn)
|
||||
.withArgs(testTable, { expression: '' })
|
||||
.to.throwException(new RegExp(errors.emptyExpression().message));
|
||||
expect(fn)
|
||||
.withArgs(testTable, { expression: ' ' })
|
||||
.to.throwException(new RegExp(errors.emptyExpression().message));
|
||||
});
|
||||
|
||||
it('throws when passing a context variable from an empty datatable', () => {
|
||||
expect(fn)
|
||||
.withArgs(emptyTable, { expression: 'mean(foo)' })
|
||||
.to.throwException(new RegExp(errors.emptyDatatable().message));
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { neq } from '../neq';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
|
||||
describe('neq', () => {
|
||||
const fn = functionWrapper(neq);
|
||||
|
||||
it('should return true when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).to.be(true);
|
||||
expect(fn(true, { value: 'true' })).to.be(true);
|
||||
expect(fn(null, { value: 'null' })).to.be(true);
|
||||
});
|
||||
|
||||
it('should return true when the values are different', () => {
|
||||
expect(fn(1, { value: 2 })).to.be(true);
|
||||
expect(fn('foo', { value: 'bar' })).to.be(true);
|
||||
expect(fn(true, { value: false })).to.be(true);
|
||||
});
|
||||
|
||||
it('should return false when the values are the same', () => {
|
||||
expect(fn(1, { value: 1 })).to.be(false);
|
||||
expect(fn('foo', { value: 'foo' })).to.be(false);
|
||||
expect(fn(true, { value: true })).to.be(false);
|
||||
expect(fn(null, { value: null })).to.be(false);
|
||||
});
|
||||
});
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { tail } from '../tail';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { emptyTable, testTable } from './fixtures/test_tables';
|
||||
|
||||
describe('tail', () => {
|
||||
const fn = functionWrapper(tail);
|
||||
const lastIndex = testTable.rows.length - 1;
|
||||
|
||||
it('returns a datatable with the last N rows of the context', () => {
|
||||
const result = fn(testTable, { count: 2 });
|
||||
|
||||
expect(result.type).to.be('datatable');
|
||||
expect(result.columns).to.eql(testTable.columns);
|
||||
expect(result.rows).to.have.length(2);
|
||||
expect(result.rows[0]).to.eql(testTable.rows[lastIndex - 1]);
|
||||
expect(result.rows[1]).to.eql(testTable.rows[lastIndex]);
|
||||
});
|
||||
|
||||
it('returns the original context if N >= context.rows.length', () => {
|
||||
expect(fn(testTable, { count: testTable.rows.length + 5 })).to.eql(testTable);
|
||||
expect(fn(testTable, { count: testTable.rows.length })).to.eql(testTable);
|
||||
expect(fn(emptyTable)).to.eql(emptyTable);
|
||||
});
|
||||
|
||||
it('returns the last row if N is not specified', () => {
|
||||
const result = fn(testTable);
|
||||
|
||||
expect(result.rows).to.have.length(1);
|
||||
expect(result.rows[0]).to.eql(testTable.rows[lastIndex]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { all } from './all';
|
||||
|
||||
describe('all', () => {
|
||||
const fn = functionWrapper(all);
|
||||
|
||||
it('should return true with no conditions', () => {
|
||||
expect(fn(null, {})).toBe(true);
|
||||
expect(fn(null, { condition: [] })).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true when all conditions are true', () => {
|
||||
expect(fn(null, { condition: [true] })).toBe(true);
|
||||
expect(fn(null, { condition: [true, true, true] })).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true when all conditions are truthy', () => {
|
||||
expect(fn(null, { condition: [true, 1, 'hooray', {}] })).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when at least one condition is false', () => {
|
||||
expect(fn(null, { condition: [false, true, true] })).toBe(false);
|
||||
expect(fn(null, { condition: [false, false, true] })).toBe(false);
|
||||
expect(fn(null, { condition: [false, false, false] })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when at least one condition is falsy', () => {
|
||||
expect(fn(null, { condition: [true, 0, 'hooray', {}] })).toBe(false);
|
||||
expect(fn(null, { condition: [true, 1, 'hooray', null] })).toBe(false);
|
||||
expect(fn(null, { condition: [true, 1, '', {}] })).toBe(false);
|
||||
});
|
||||
});
|
|
@ -4,11 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { alterColumn } from '../alterColumn';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../../strings';
|
||||
import { emptyTable, testTable } from './fixtures/test_tables';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../strings';
|
||||
import { emptyTable, testTable } from './__tests__/fixtures/test_tables';
|
||||
import { alterColumn } from './alterColumn';
|
||||
|
||||
const errors = getFunctionErrors().alterColumn;
|
||||
|
||||
|
@ -22,12 +21,12 @@ describe('alterColumn', () => {
|
|||
it('returns a datatable', () => {
|
||||
const alteredTable = fn(testTable, { column: 'price', type: 'string', name: 'priceString' });
|
||||
|
||||
expect(alteredTable.type).to.be('datatable');
|
||||
expect(alteredTable.type).toBe('datatable');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
it('returns original context if no args are provided', () => {
|
||||
expect(fn(testTable)).to.eql(testTable);
|
||||
expect(fn(testTable)).toEqual(testTable);
|
||||
});
|
||||
|
||||
describe('column', () => {
|
||||
|
@ -38,20 +37,20 @@ describe('alterColumn', () => {
|
|||
const newColumn = dateToString.columns[timeColumnIndex];
|
||||
const arbitraryRowIndex = 6;
|
||||
|
||||
expect(newColumn.name).to.not.be(originalColumn.name);
|
||||
expect(newColumn.type).to.not.be(originalColumn.type);
|
||||
expect(dateToString.rows[arbitraryRowIndex].timeISO).to.be.a('string');
|
||||
expect(new Date(dateToString.rows[arbitraryRowIndex].timeISO)).to.eql(
|
||||
expect(newColumn.name).not.toBe(originalColumn.name);
|
||||
expect(newColumn.type).not.toBe(originalColumn.type);
|
||||
expect(typeof dateToString.rows[arbitraryRowIndex].timeISO).toBe('string');
|
||||
expect(new Date(dateToString.rows[arbitraryRowIndex].timeISO)).toEqual(
|
||||
new Date(testTable.rows[arbitraryRowIndex].time)
|
||||
);
|
||||
});
|
||||
|
||||
it('returns original context if column is not specified', () => {
|
||||
expect(fn(testTable, { type: 'date', name: 'timeISO' })).to.eql(testTable);
|
||||
expect(fn(testTable, { type: 'date', name: 'timeISO' })).toBe(testTable);
|
||||
});
|
||||
|
||||
it('throws if column does not exists', () => {
|
||||
expect(() => fn(emptyTable, { column: 'foo', type: 'number' })).to.throwException(
|
||||
expect(() => fn(emptyTable, { column: 'foo', type: 'number' })).toThrow(
|
||||
new RegExp(errors.columnNotFound('foo').message)
|
||||
);
|
||||
});
|
||||
|
@ -61,9 +60,9 @@ describe('alterColumn', () => {
|
|||
it('converts the column to the specified type', () => {
|
||||
const dateToString = fn(testTable, { column: 'time', type: 'string', name: 'timeISO' });
|
||||
|
||||
expect(dateToString.columns[timeColumnIndex].type).to.be('string');
|
||||
expect(dateToString.rows[timeColumnIndex].timeISO).to.be.a('string');
|
||||
expect(new Date(dateToString.rows[timeColumnIndex].timeISO)).to.eql(
|
||||
expect(typeof dateToString.columns[timeColumnIndex].type).toBe('string');
|
||||
expect(typeof dateToString.rows[timeColumnIndex].timeISO).toBe('string');
|
||||
expect(new Date(dateToString.rows[timeColumnIndex].timeISO)).toEqual(
|
||||
new Date(testTable.rows[timeColumnIndex].time)
|
||||
);
|
||||
});
|
||||
|
@ -73,15 +72,12 @@ describe('alterColumn', () => {
|
|||
const originalType = testTable.columns[priceColumnIndex].type;
|
||||
const arbitraryRowIndex = 2;
|
||||
|
||||
expect(unconvertedColumn.columns[priceColumnIndex].type).to.be(originalType);
|
||||
expect(unconvertedColumn.rows[arbitraryRowIndex].foo).to.be.a(
|
||||
originalType,
|
||||
testTable.rows[arbitraryRowIndex].price
|
||||
);
|
||||
expect(unconvertedColumn.columns[priceColumnIndex].type).toBe(originalType);
|
||||
expect(typeof unconvertedColumn.rows[arbitraryRowIndex].foo).toBe(originalType);
|
||||
});
|
||||
|
||||
it('throws when converting to an invalid type', () => {
|
||||
expect(() => fn(testTable, { column: 'name', type: 'foo' })).to.throwException(
|
||||
expect(() => fn(testTable, { column: 'name', type: 'foo' })).toThrow(
|
||||
new RegExp(errors.cannotConvertType('foo').message)
|
||||
);
|
||||
});
|
||||
|
@ -92,8 +88,8 @@ describe('alterColumn', () => {
|
|||
const dateToString = fn(testTable, { column: 'time', type: 'date', name: 'timeISO' });
|
||||
const arbitraryRowIndex = 8;
|
||||
|
||||
expect(dateToString.columns[timeColumnIndex].name).to.be('timeISO');
|
||||
expect(dateToString.rows[arbitraryRowIndex]).to.have.property('timeISO');
|
||||
expect(dateToString.columns[timeColumnIndex].name).toBe('timeISO');
|
||||
expect(dateToString.rows[arbitraryRowIndex]).toHaveProperty('timeISO');
|
||||
});
|
||||
|
||||
it('overwrites existing column if provided an existing column name', () => {
|
||||
|
@ -102,10 +98,10 @@ describe('alterColumn', () => {
|
|||
const newColumn = overwriteName.columns[nameColumnIndex];
|
||||
const arbitraryRowIndex = 5;
|
||||
|
||||
expect(newColumn.name).to.not.be(originalColumn.name);
|
||||
expect(newColumn.type).to.not.be(originalColumn.type);
|
||||
expect(overwriteName.rows[arbitraryRowIndex].name).to.be.a('string');
|
||||
expect(new Date(overwriteName.rows[arbitraryRowIndex].name)).to.eql(
|
||||
expect(newColumn.name).not.toBe(originalColumn.name);
|
||||
expect(newColumn.type).not.toBe(originalColumn.type);
|
||||
expect(typeof overwriteName.rows[arbitraryRowIndex].name).toBe('string');
|
||||
expect(new Date(overwriteName.rows[arbitraryRowIndex].name)).toEqual(
|
||||
new Date(testTable.rows[arbitraryRowIndex].time)
|
||||
);
|
||||
});
|
||||
|
@ -113,7 +109,7 @@ describe('alterColumn', () => {
|
|||
it('retains original column name if name is not provided', () => {
|
||||
const unchangedName = fn(testTable, { column: 'price', type: 'string' });
|
||||
|
||||
expect(unchangedName.columns[priceColumnIndex].name).to.be(
|
||||
expect(unchangedName.columns[priceColumnIndex].name).toBe(
|
||||
testTable.columns[priceColumnIndex].name
|
||||
);
|
||||
});
|
||||
|
@ -125,95 +121,104 @@ describe('alterColumn', () => {
|
|||
const arbitraryRowIndex = 4;
|
||||
const numberToString = fn(testTable, { column: 'price', type: 'string' });
|
||||
|
||||
expect(numberToString.columns[priceColumnIndex])
|
||||
.to.have.property('name', 'price')
|
||||
.and.to.have.property('type', 'string');
|
||||
expect(numberToString.rows[arbitraryRowIndex].price)
|
||||
.to.be.a('string')
|
||||
.and.to.eql(testTable.rows[arbitraryRowIndex].price);
|
||||
expect(numberToString.columns[priceColumnIndex]).toHaveProperty('name', 'price');
|
||||
expect(numberToString.columns[priceColumnIndex]).toHaveProperty('type', 'string');
|
||||
|
||||
expect(typeof numberToString.rows[arbitraryRowIndex].price).toBe('string');
|
||||
expect(numberToString.rows[arbitraryRowIndex].price).toBe(
|
||||
`${testTable.rows[arbitraryRowIndex].price}`
|
||||
);
|
||||
|
||||
const stringToNumber = fn(numberToString, { column: 'price', type: 'number' });
|
||||
|
||||
expect(stringToNumber.columns[priceColumnIndex])
|
||||
.to.have.property('name', 'price')
|
||||
.and.to.have.property('type', 'number');
|
||||
expect(stringToNumber.rows[arbitraryRowIndex].price)
|
||||
.to.be.a('number')
|
||||
.and.to.eql(numberToString.rows[arbitraryRowIndex].price);
|
||||
expect(stringToNumber.columns[priceColumnIndex]).toHaveProperty('name', 'price');
|
||||
expect(stringToNumber.columns[priceColumnIndex]).toHaveProperty('type', 'number');
|
||||
|
||||
expect(typeof stringToNumber.rows[arbitraryRowIndex].price).toBe('number');
|
||||
|
||||
expect(stringToNumber.rows[arbitraryRowIndex].price).toEqual(
|
||||
parseFloat(numberToString.rows[arbitraryRowIndex].price)
|
||||
);
|
||||
});
|
||||
|
||||
it('converts date <-> string', () => {
|
||||
const arbitraryRowIndex = 4;
|
||||
const dateToString = fn(testTable, { column: 'time', type: 'string' });
|
||||
|
||||
expect(dateToString.columns[timeColumnIndex])
|
||||
.to.have.property('name', 'time')
|
||||
.and.to.have.property('type', 'string');
|
||||
expect(dateToString.rows[arbitraryRowIndex].time).to.be.a('string');
|
||||
expect(new Date(dateToString.rows[arbitraryRowIndex].time)).to.eql(
|
||||
expect(dateToString.columns[timeColumnIndex]).toHaveProperty('name', 'time');
|
||||
expect(dateToString.columns[timeColumnIndex]).toHaveProperty('type', 'string');
|
||||
|
||||
expect(typeof dateToString.rows[arbitraryRowIndex].time).toBe('string');
|
||||
expect(new Date(dateToString.rows[arbitraryRowIndex].time)).toEqual(
|
||||
new Date(testTable.rows[arbitraryRowIndex].time)
|
||||
);
|
||||
|
||||
const stringToDate = fn(dateToString, { column: 'time', type: 'date' });
|
||||
|
||||
expect(stringToDate.columns[timeColumnIndex])
|
||||
.to.have.property('name', 'time')
|
||||
.and.to.have.property('type', 'date');
|
||||
expect(new Date(stringToDate.rows[timeColumnIndex].time))
|
||||
.to.be.a(Date)
|
||||
.and.to.eql(new Date(dateToString.rows[timeColumnIndex].time));
|
||||
expect(stringToDate.columns[timeColumnIndex]).toHaveProperty('name', 'time');
|
||||
expect(stringToDate.columns[timeColumnIndex]).toHaveProperty('type', 'date');
|
||||
expect(new Date(stringToDate.rows[timeColumnIndex].time)).toBeInstanceOf(Date);
|
||||
|
||||
expect(new Date(stringToDate.rows[timeColumnIndex].time)).toEqual(
|
||||
new Date(dateToString.rows[timeColumnIndex].time)
|
||||
);
|
||||
});
|
||||
|
||||
it('converts date <-> number', () => {
|
||||
const dateToNumber = fn(testTable, { column: 'time', type: 'number' });
|
||||
const arbitraryRowIndex = 1;
|
||||
|
||||
expect(dateToNumber.columns[timeColumnIndex])
|
||||
.to.have.property('name', 'time')
|
||||
.and.to.have.property('type', 'number');
|
||||
expect(dateToNumber.rows[arbitraryRowIndex].time)
|
||||
.to.be.a('number')
|
||||
.and.to.eql(testTable.rows[arbitraryRowIndex].time);
|
||||
expect(dateToNumber.columns[timeColumnIndex]).toHaveProperty('name', 'time');
|
||||
expect(dateToNumber.columns[timeColumnIndex]).toHaveProperty('type', 'number');
|
||||
|
||||
expect(typeof dateToNumber.rows[arbitraryRowIndex].time).toBe('number');
|
||||
expect(dateToNumber.rows[arbitraryRowIndex].time).toEqual(
|
||||
testTable.rows[arbitraryRowIndex].time
|
||||
);
|
||||
|
||||
const numberToDate = fn(dateToNumber, { column: 'time', type: 'date' });
|
||||
|
||||
expect(numberToDate.columns[timeColumnIndex])
|
||||
.to.have.property('name', 'time')
|
||||
.and.to.have.property('type', 'date');
|
||||
expect(new Date(numberToDate.rows[arbitraryRowIndex].time))
|
||||
.to.be.a(Date)
|
||||
.and.to.eql(testTable.rows[arbitraryRowIndex].time);
|
||||
expect(numberToDate.columns[timeColumnIndex]).toHaveProperty('name', 'time');
|
||||
expect(numberToDate.columns[timeColumnIndex]).toHaveProperty('type', 'date');
|
||||
|
||||
expect(new Date(numberToDate.rows[arbitraryRowIndex].time)).toBeInstanceOf(Date);
|
||||
expect(new Date(numberToDate.rows[arbitraryRowIndex].time)).toEqual(
|
||||
new Date(testTable.rows[arbitraryRowIndex].time)
|
||||
);
|
||||
});
|
||||
|
||||
it('converts bool <-> number', () => {
|
||||
const booleanToNumber = fn(testTable, { column: 'in_stock', type: 'number' });
|
||||
const arbitraryRowIndex = 7;
|
||||
|
||||
expect(booleanToNumber.columns[inStockColumnIndex])
|
||||
.to.have.property('name', 'in_stock')
|
||||
.and.to.have.property('type', 'number');
|
||||
expect(booleanToNumber.rows[arbitraryRowIndex].in_stock)
|
||||
.to.be.a('number')
|
||||
.and.to.eql(booleanToNumber.rows[arbitraryRowIndex].in_stock);
|
||||
expect(booleanToNumber.columns[inStockColumnIndex]).toHaveProperty('name', 'in_stock');
|
||||
expect(booleanToNumber.columns[inStockColumnIndex]).toHaveProperty('type', 'number');
|
||||
|
||||
expect(typeof booleanToNumber.rows[arbitraryRowIndex].in_stock).toBe('number');
|
||||
expect(booleanToNumber.rows[arbitraryRowIndex].in_stock).toEqual(
|
||||
booleanToNumber.rows[arbitraryRowIndex].in_stock
|
||||
);
|
||||
|
||||
const numberToBoolean = fn(booleanToNumber, { column: 'in_stock', type: 'boolean' });
|
||||
|
||||
expect(numberToBoolean.columns[inStockColumnIndex])
|
||||
.to.have.property('name', 'in_stock')
|
||||
.and.to.have.property('type', 'boolean');
|
||||
expect(numberToBoolean.rows[arbitraryRowIndex].in_stock)
|
||||
.to.be.a('boolean')
|
||||
.and.to.eql(numberToBoolean.rows[arbitraryRowIndex].in_stock);
|
||||
expect(numberToBoolean.columns[inStockColumnIndex]).toHaveProperty('name', 'in_stock');
|
||||
expect(numberToBoolean.columns[inStockColumnIndex]).toHaveProperty('type', 'boolean');
|
||||
|
||||
expect(typeof numberToBoolean.rows[arbitraryRowIndex].in_stock).toBe('boolean');
|
||||
expect(numberToBoolean.rows[arbitraryRowIndex].in_stock).toEqual(
|
||||
numberToBoolean.rows[arbitraryRowIndex].in_stock
|
||||
);
|
||||
});
|
||||
|
||||
it('converts any type -> null', () => {
|
||||
const stringToNull = fn(testTable, { column: 'name', type: 'null' });
|
||||
const arbitraryRowIndex = 0;
|
||||
|
||||
expect(stringToNull.columns[nameColumnIndex])
|
||||
.to.have.property('name', 'name')
|
||||
.and.to.have.property('type', 'null');
|
||||
expect(stringToNull.rows[arbitraryRowIndex].name).to.be(null);
|
||||
expect(stringToNull.columns[nameColumnIndex]).toHaveProperty('name', 'name');
|
||||
|
||||
expect(stringToNull.columns[nameColumnIndex]).toHaveProperty('type', 'null');
|
||||
|
||||
expect(stringToNull.rows[arbitraryRowIndex].name).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { any } from './any';
|
||||
|
||||
describe('any', () => {
|
||||
const fn = functionWrapper(any);
|
||||
|
||||
it('should return false with no conditions', () => {
|
||||
expect(fn(null, {})).toBe(false);
|
||||
expect(fn(null, { condition: [] })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when no conditions are true', () => {
|
||||
expect(fn(null, null, { condition: [false] })).toBe(false);
|
||||
expect(fn(null, { condition: [false, false, false] })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when all conditions are falsy', () => {
|
||||
expect(fn(null, { condition: [false, 0, '', null] })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when at least one condition is true', () => {
|
||||
expect(fn(null, { condition: [false, false, true] })).toBe(true);
|
||||
expect(fn(null, { condition: [false, true, true] })).toBe(true);
|
||||
expect(fn(null, { condition: [true, true, true] })).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true when at least one condition is truthy', () => {
|
||||
expect(fn(null, { condition: [false, 0, '', null, 1] })).toBe(true);
|
||||
expect(fn(null, { condition: [false, 0, 'hooray', null] })).toBe(true);
|
||||
expect(fn(null, { condition: [false, 0, {}, null] })).toBe(true);
|
||||
});
|
||||
});
|
|
@ -4,27 +4,26 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { asFn } from '../as';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { asFn } from './as';
|
||||
|
||||
describe('as', () => {
|
||||
const fn = functionWrapper(asFn);
|
||||
|
||||
it('returns a datatable with a single column and single row', () => {
|
||||
expect(fn('foo', { name: 'bar' })).to.eql({
|
||||
expect(fn('foo', { name: 'bar' })).toEqual({
|
||||
type: 'datatable',
|
||||
columns: [{ name: 'bar', type: 'string' }],
|
||||
rows: [{ bar: 'foo' }],
|
||||
});
|
||||
|
||||
expect(fn(2, { name: 'num' })).to.eql({
|
||||
expect(fn(2, { name: 'num' })).toEqual({
|
||||
type: 'datatable',
|
||||
columns: [{ name: 'num', type: 'number' }],
|
||||
rows: [{ num: 2 }],
|
||||
});
|
||||
|
||||
expect(fn(true, { name: 'bool' })).to.eql({
|
||||
expect(fn(true, { name: 'bool' })).toEqual({
|
||||
type: 'datatable',
|
||||
columns: [{ name: 'bool', type: 'boolean' }],
|
||||
rows: [{ bool: true }],
|
||||
|
@ -34,11 +33,11 @@ describe('as', () => {
|
|||
describe('args', () => {
|
||||
describe('name', () => {
|
||||
it('sets the column name of the resulting datatable', () => {
|
||||
expect(fn(null, { name: 'foo' }).columns[0].name).to.eql('foo');
|
||||
expect(fn(null, { name: 'foo' }).columns[0].name).toEqual('foo');
|
||||
});
|
||||
|
||||
it("returns a datatable with the column name 'value'", () => {
|
||||
expect(fn(null).columns[0].name).to.eql('value');
|
||||
expect(fn(null).columns[0].name).toEqual('value');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,11 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { axisConfig } from '../axisConfig';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../../strings';
|
||||
import { testTable } from './fixtures/test_tables';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../strings';
|
||||
import { testTable } from './__tests__/fixtures/test_tables';
|
||||
import { axisConfig } from './axisConfig';
|
||||
|
||||
const errors = getFunctionErrors().axisConfig;
|
||||
|
||||
|
@ -17,100 +16,100 @@ describe('axisConfig', () => {
|
|||
|
||||
it('returns an axisConfig', () => {
|
||||
const result = fn(testTable, { show: true, position: 'right' });
|
||||
expect(result).to.have.property('type', 'axisConfig');
|
||||
expect(result).toHaveProperty('type', 'axisConfig');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('show', () => {
|
||||
it('hides labels', () => {
|
||||
const result = fn(testTable, { show: false });
|
||||
expect(result).to.have.property('show', false);
|
||||
expect(result).toHaveProperty('show', false);
|
||||
});
|
||||
|
||||
it('shows labels', () => {
|
||||
const result = fn(testTable, { show: true });
|
||||
expect(result).to.have.property('show', true);
|
||||
expect(result).toHaveProperty('show', true);
|
||||
});
|
||||
|
||||
it('defaults to true', () => {
|
||||
const result = fn(testTable);
|
||||
expect(result).to.have.property('show', true);
|
||||
expect(result).toHaveProperty('show', true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('position', () => {
|
||||
it('sets the position of the axis labels', () => {
|
||||
let result = fn(testTable, { position: 'left' });
|
||||
expect(result).to.have.property('position', 'left');
|
||||
expect(result).toHaveProperty('position', 'left');
|
||||
|
||||
result = fn(testTable, { position: 'top' });
|
||||
expect(result).to.have.property('position', 'top');
|
||||
expect(result).toHaveProperty('position', 'top');
|
||||
|
||||
result = fn(testTable, { position: 'right' });
|
||||
expect(result).to.have.property('position', 'right');
|
||||
expect(result).toHaveProperty('position', 'right');
|
||||
|
||||
result = fn(testTable, { position: 'bottom' });
|
||||
expect(result).to.have.property('position', 'bottom');
|
||||
expect(result).toHaveProperty('position', 'bottom');
|
||||
});
|
||||
|
||||
it('defaults to "left" if not provided', () => {
|
||||
const result = fn(testTable);
|
||||
expect(result).to.have.property('position', 'left');
|
||||
expect(result).toHaveProperty('position', 'left');
|
||||
});
|
||||
|
||||
it('throws when given an invalid position', () => {
|
||||
expect(fn)
|
||||
.withArgs(testTable, { position: 'foo' })
|
||||
.to.throwException(new RegExp(errors.invalidPosition('foo').message));
|
||||
expect(() => {
|
||||
fn(testTable, { position: 'foo' });
|
||||
}).toThrow(new RegExp(errors.invalidPosition('foo').message));
|
||||
});
|
||||
});
|
||||
|
||||
describe('min', () => {
|
||||
it('sets the minimum value shown of the axis', () => {
|
||||
let result = fn(testTable, { min: -100 });
|
||||
expect(result).to.have.property('min', -100);
|
||||
expect(result).toHaveProperty('min', -100);
|
||||
result = fn(testTable, { min: 1010101010101 });
|
||||
expect(result).to.have.property('min', 1010101010101);
|
||||
expect(result).toHaveProperty('min', 1010101010101);
|
||||
result = fn(testTable, { min: '2017-09-01T00:00:00Z' });
|
||||
expect(result).to.have.property('min', 1504224000000);
|
||||
expect(result).toHaveProperty('min', 1504224000000);
|
||||
result = fn(testTable, { min: '2017-09-01' });
|
||||
expect(result).to.have.property('min', 1504224000000);
|
||||
expect(result).toHaveProperty('min', 1504224000000);
|
||||
result = fn(testTable, { min: '1 Sep 2017' });
|
||||
expect(result).to.have.property('min', 1504224000000);
|
||||
expect(result).toHaveProperty('min', 1504224000000);
|
||||
});
|
||||
|
||||
it('throws when given an invalid date string', () => {
|
||||
expect(fn)
|
||||
.withArgs(testTable, { min: 'foo' })
|
||||
.to.throwException(new RegExp(errors.invalidMinDateString('foo').message));
|
||||
expect(() => {
|
||||
fn(testTable, { min: 'foo' });
|
||||
}).toThrow(new RegExp(errors.invalidMinDateString('foo').message));
|
||||
});
|
||||
});
|
||||
|
||||
describe('max', () => {
|
||||
it('sets the maximum value shown of the axis', () => {
|
||||
let result = fn(testTable, { max: 2000 });
|
||||
expect(result).to.have.property('max', 2000);
|
||||
expect(result).toHaveProperty('max', 2000);
|
||||
result = fn(testTable, { max: 1234567000000 });
|
||||
expect(result).to.have.property('max', 1234567000000);
|
||||
expect(result).toHaveProperty('max', 1234567000000);
|
||||
result = fn(testTable, { max: '2018-10-06T00:00:00Z' });
|
||||
expect(result).to.have.property('max', 1538784000000);
|
||||
expect(result).toHaveProperty('max', 1538784000000);
|
||||
result = fn(testTable, { max: '10/06/2018' });
|
||||
expect(result).to.have.property('max', 1538784000000);
|
||||
expect(result).toHaveProperty('max', 1538784000000);
|
||||
result = fn(testTable, { max: 'October 6 2018' });
|
||||
expect(result).to.have.property('max', 1538784000000);
|
||||
expect(result).toHaveProperty('max', 1538784000000);
|
||||
});
|
||||
|
||||
it('throws when given an invalid date string', () => {
|
||||
expect(fn)
|
||||
.withArgs(testTable, { max: '20/02/17' })
|
||||
.to.throwException(new RegExp(errors.invalidMaxDateString('20/02/17').message));
|
||||
expect(() => {
|
||||
fn(testTable, { max: '20/02/17' });
|
||||
}).toThrow(new RegExp(errors.invalidMaxDateString('20/02/17').message));
|
||||
});
|
||||
});
|
||||
|
||||
describe('tickSize ', () => {
|
||||
it('sets the increment size between ticks of the axis', () => {
|
||||
const result = fn(testTable, { tickSize: 100 });
|
||||
expect(result).to.have.property('tickSize', 100);
|
||||
expect(result).toHaveProperty('tickSize', 100);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,16 +4,15 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { caseFn } from '../case';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { caseFn } from './case';
|
||||
|
||||
describe('case', () => {
|
||||
const fn = functionWrapper(caseFn);
|
||||
|
||||
describe('spec', () => {
|
||||
it('is a function', () => {
|
||||
expect(fn).to.be.a('function');
|
||||
expect(typeof fn).toBe('function');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -22,7 +21,7 @@ describe('case', () => {
|
|||
it('should return a case object that matches with the result as the context', async () => {
|
||||
const context = null;
|
||||
const args = {};
|
||||
expect(await fn(context, args)).to.eql({
|
||||
expect(await fn(context, args)).toEqual({
|
||||
type: 'case',
|
||||
matches: true,
|
||||
result: context,
|
||||
|
@ -36,7 +35,7 @@ describe('case', () => {
|
|||
const args = {
|
||||
then: () => 'foo',
|
||||
};
|
||||
expect(await fn(context, args)).to.eql({
|
||||
expect(await fn(context, args)).toEqual({
|
||||
type: 'case',
|
||||
matches: true,
|
||||
result: args.then(),
|
||||
|
@ -48,7 +47,7 @@ describe('case', () => {
|
|||
it('should return as the matches prop', async () => {
|
||||
const context = null;
|
||||
const args = { if: false };
|
||||
expect(await fn(context, args)).to.eql({
|
||||
expect(await fn(context, args)).toEqual({
|
||||
type: 'case',
|
||||
matches: args.if,
|
||||
result: context,
|
||||
|
@ -62,12 +61,12 @@ describe('case', () => {
|
|||
when: () => 'foo',
|
||||
then: () => 'bar',
|
||||
};
|
||||
expect(await fn('foo', args)).to.eql({
|
||||
expect(await fn('foo', args)).toEqual({
|
||||
type: 'case',
|
||||
matches: true,
|
||||
result: args.then(),
|
||||
});
|
||||
expect(await fn('bar', args)).to.eql({
|
||||
expect(await fn('bar', args)).toEqual({
|
||||
type: 'case',
|
||||
matches: false,
|
||||
result: null,
|
||||
|
@ -82,7 +81,7 @@ describe('case', () => {
|
|||
when: () => 'foo',
|
||||
if: true,
|
||||
};
|
||||
expect(await fn(context, args)).to.eql({
|
||||
expect(await fn(context, args)).toEqual({
|
||||
type: 'case',
|
||||
matches: args.if,
|
||||
result: context,
|
|
@ -4,18 +4,17 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { clear } from '../clear';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './fixtures/test_tables';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './__tests__/fixtures/test_tables';
|
||||
import { clear } from './clear';
|
||||
|
||||
describe('clear', () => {
|
||||
const fn = functionWrapper(clear);
|
||||
|
||||
it('returns null for any context', () => {
|
||||
expect(fn()).to.be(null);
|
||||
expect(fn('foo')).to.be(null);
|
||||
expect(fn(2)).to.be(null);
|
||||
expect(fn(testTable)).to.be(null);
|
||||
expect(fn()).toBe(null);
|
||||
expect(fn('foo')).toBe(null);
|
||||
expect(fn(2)).toBe(null);
|
||||
expect(fn(testTable)).toBe(null);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { emptyTable, testTable } from './__tests__/fixtures/test_tables';
|
||||
import { columns } from './columns';
|
||||
|
||||
describe('columns', () => {
|
||||
const fn = functionWrapper(columns);
|
||||
|
||||
it('returns a datatable', () => {
|
||||
expect(fn(testTable, { include: 'name' }).type).toBe('datatable');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
it('returns a datatable with included columns and without excluded columns', () => {
|
||||
const arbitraryRowIndex = 7;
|
||||
const result = fn(testTable, {
|
||||
include: 'name, price, quantity, foo, bar',
|
||||
exclude: 'price, quantity, fizz, buzz',
|
||||
});
|
||||
|
||||
expect(result.columns[0]).toHaveProperty('name', 'name');
|
||||
expect(result.rows[arbitraryRowIndex]).toHaveProperty(
|
||||
'name',
|
||||
testTable.rows[arbitraryRowIndex].name
|
||||
);
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('price');
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('quantity');
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('foo');
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('bar');
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('fizz');
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('buzz');
|
||||
});
|
||||
|
||||
it('returns original context if args are not provided', () => {
|
||||
expect(fn(testTable)).toEqual(testTable);
|
||||
});
|
||||
|
||||
it('returns an empty datatable if include and exclude both reference the same column(s)', () => {
|
||||
expect(fn(testTable, { include: 'price', exclude: 'price' })).toEqual(emptyTable);
|
||||
|
||||
expect(
|
||||
fn(testTable, {
|
||||
include: 'price, quantity, in_stock',
|
||||
exclude: 'price, quantity, in_stock',
|
||||
})
|
||||
).toEqual(emptyTable);
|
||||
});
|
||||
|
||||
describe('include', () => {
|
||||
it('returns a datatable with included columns only', () => {
|
||||
const arbitraryRowIndex = 3;
|
||||
const result = fn(testTable, {
|
||||
include: 'name, time, in_stock',
|
||||
});
|
||||
|
||||
expect(result.columns).toHaveLength(3);
|
||||
expect(Object.keys(result.rows[0])).toHaveLength(3);
|
||||
|
||||
expect(result.columns[0]).toHaveProperty('name', 'name');
|
||||
expect(result.columns[1]).toHaveProperty('name', 'time');
|
||||
expect(result.columns[2]).toHaveProperty('name', 'in_stock');
|
||||
expect(result.rows[arbitraryRowIndex]).toHaveProperty(
|
||||
'name',
|
||||
testTable.rows[arbitraryRowIndex].name
|
||||
);
|
||||
expect(result.rows[arbitraryRowIndex]).toHaveProperty(
|
||||
'time',
|
||||
testTable.rows[arbitraryRowIndex].time
|
||||
);
|
||||
expect(result.rows[arbitraryRowIndex]).toHaveProperty(
|
||||
'in_stock',
|
||||
testTable.rows[arbitraryRowIndex].in_stock
|
||||
);
|
||||
});
|
||||
|
||||
it('ignores invalid columns', () => {
|
||||
const arbitraryRowIndex = 6;
|
||||
const result = fn(testTable, {
|
||||
include: 'name, foo, bar',
|
||||
});
|
||||
|
||||
expect(result.columns[0]).toHaveProperty('name', 'name');
|
||||
expect(result.rows[arbitraryRowIndex]).toHaveProperty(
|
||||
'name',
|
||||
testTable.rows[arbitraryRowIndex].name
|
||||
);
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('foo');
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('bar');
|
||||
});
|
||||
|
||||
it('returns an empty datable if include only has invalid columns', () => {
|
||||
expect(fn(testTable, { include: 'foo, bar' })).toEqual(emptyTable);
|
||||
});
|
||||
});
|
||||
|
||||
describe('exclude', () => {
|
||||
it('returns a datatable without excluded columns', () => {
|
||||
const arbitraryRowIndex = 5;
|
||||
const result = fn(testTable, { exclude: 'price, quantity, foo, bar' });
|
||||
|
||||
expect(result.columns.length).toEqual(testTable.columns.length - 2);
|
||||
expect(Object.keys(result.rows[0])).toHaveLength(testTable.columns.length - 2);
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('price');
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('quantity');
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('foo');
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('bar');
|
||||
});
|
||||
|
||||
it('ignores invalid columns', () => {
|
||||
const arbitraryRowIndex = 1;
|
||||
const result = fn(testTable, { exclude: 'time, foo, bar' });
|
||||
|
||||
expect(result.columns.length).toEqual(testTable.columns.length - 1);
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('time');
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('foo');
|
||||
expect(result.rows[arbitraryRowIndex]).not.toHaveProperty('bar');
|
||||
});
|
||||
|
||||
it('returns original context if exclude only references invalid column name(s)', () => {
|
||||
expect(fn(testTable, { exclude: 'foo, bar, fizz, buzz' })).toEqual(testTable);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,11 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { containerStyle } from '../containerStyle';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { elasticLogo } from '../../../lib/elastic_logo';
|
||||
import { getFunctionErrors } from '../../../strings';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { elasticLogo } from '../../lib/elastic_logo';
|
||||
import { getFunctionErrors } from '../../strings';
|
||||
import { containerStyle } from './containerStyle';
|
||||
|
||||
const errors = getFunctionErrors().containerStyle;
|
||||
|
||||
|
@ -19,12 +18,13 @@ describe('containerStyle', () => {
|
|||
const result = fn(null);
|
||||
|
||||
it('returns a containerStyle', () => {
|
||||
expect(result).to.have.property('type', 'containerStyle');
|
||||
expect(result).toHaveProperty('type', 'containerStyle');
|
||||
});
|
||||
|
||||
it('all style properties except `overflow` are omitted if args not provided', () => {
|
||||
expect(result).to.have.keys('type', 'overflow');
|
||||
expect(result).to.have.property('overflow', 'hidden');
|
||||
expect(Object.keys(result)).toHaveLength(2);
|
||||
expect(result).toHaveProperty('type');
|
||||
expect(result).toHaveProperty('overflow');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -32,109 +32,109 @@ describe('containerStyle', () => {
|
|||
describe('border', () => {
|
||||
it('sets border', () => {
|
||||
const result = fn(null, { border: '1px solid black' });
|
||||
expect(result).to.have.property('border', '1px solid black');
|
||||
expect(result).toHaveProperty('border', '1px solid black');
|
||||
});
|
||||
});
|
||||
|
||||
describe('borderRadius', () => {
|
||||
it('sets border-radius', () => {
|
||||
const result = fn(null, { borderRadius: '20px' });
|
||||
expect(result).to.have.property('borderRadius', '20px');
|
||||
expect(result).toHaveProperty('borderRadius', '20px');
|
||||
});
|
||||
});
|
||||
|
||||
describe('padding', () => {
|
||||
it('sets padding', () => {
|
||||
const result = fn(null, { padding: '10px' });
|
||||
expect(result).to.have.property('padding', '10px');
|
||||
expect(result).toHaveProperty('padding', '10px');
|
||||
});
|
||||
});
|
||||
|
||||
describe('backgroundColor', () => {
|
||||
it('sets backgroundColor', () => {
|
||||
const result = fn(null, { backgroundColor: '#3f9939' });
|
||||
expect(result).to.have.property('backgroundColor', '#3f9939');
|
||||
expect(result).toHaveProperty('backgroundColor', '#3f9939');
|
||||
});
|
||||
});
|
||||
|
||||
describe('backgroundImage', () => {
|
||||
it('sets backgroundImage', () => {
|
||||
let result = fn(null, { backgroundImage: elasticLogo });
|
||||
expect(result).to.have.property('backgroundImage', `url(${elasticLogo})`);
|
||||
expect(result).toHaveProperty('backgroundImage', `url(${elasticLogo})`);
|
||||
|
||||
const imageURL = 'https://www.elastic.co/assets/blt45b0886c90beceee/logo-elastic.svg';
|
||||
result = fn(null, {
|
||||
backgroundImage: imageURL,
|
||||
});
|
||||
expect(result).to.have.property('backgroundImage', `url(${imageURL})`);
|
||||
expect(result).toHaveProperty('backgroundImage', `url(${imageURL})`);
|
||||
});
|
||||
|
||||
it('omitted when provided a null value', () => {
|
||||
let result = fn(null, { backgroundImage: '' });
|
||||
expect(result).to.not.have.property('backgroundImage');
|
||||
expect(result).not.toHaveProperty('backgroundImage');
|
||||
|
||||
result = fn(null, { backgroundImage: null });
|
||||
expect(result).to.not.have.property('backgroundImage');
|
||||
expect(result).not.toHaveProperty('backgroundImage');
|
||||
});
|
||||
|
||||
it('throws when provided an invalid dataurl/url', () => {
|
||||
expect(fn)
|
||||
.withArgs(null, { backgroundImage: 'foo' })
|
||||
.to.throwException(new RegExp(errors.invalidBackgroundImage('foo').message));
|
||||
expect(() => {
|
||||
fn(null, { backgroundImage: 'foo' });
|
||||
}).toThrow(new RegExp(errors.invalidBackgroundImage('foo').message));
|
||||
});
|
||||
});
|
||||
|
||||
describe('backgroundSize', () => {
|
||||
it('sets backgroundSize when backgroundImage is provided', () => {
|
||||
const result = fn(null, { backgroundImage: elasticLogo, backgroundSize: 'cover' });
|
||||
expect(result).to.have.property('backgroundSize', 'cover');
|
||||
expect(result).toHaveProperty('backgroundSize', 'cover');
|
||||
});
|
||||
|
||||
it("defaults to 'contain' when backgroundImage is provided", () => {
|
||||
const result = fn(null, { backgroundImage: elasticLogo });
|
||||
expect(result).to.have.property('backgroundSize', 'contain');
|
||||
expect(result).toHaveProperty('backgroundSize', 'contain');
|
||||
});
|
||||
|
||||
it('omitted when backgroundImage is not provided', () => {
|
||||
const result = fn(null, { backgroundSize: 'cover' });
|
||||
expect(result).to.not.have.property('backgroundSize');
|
||||
expect(result).not.toHaveProperty('backgroundSize');
|
||||
});
|
||||
});
|
||||
|
||||
describe('backgroundRepeat', () => {
|
||||
it('sets backgroundRepeat when backgroundImage is provided', () => {
|
||||
const result = fn(null, { backgroundImage: elasticLogo, backgroundRepeat: 'repeat' });
|
||||
expect(result).to.have.property('backgroundRepeat', 'repeat');
|
||||
expect(result).toHaveProperty('backgroundRepeat', 'repeat');
|
||||
});
|
||||
|
||||
it("defaults to 'no-repeat'", () => {
|
||||
const result = fn(null, { backgroundImage: elasticLogo });
|
||||
expect(result).to.have.property('backgroundRepeat', 'no-repeat');
|
||||
expect(result).toHaveProperty('backgroundRepeat', 'no-repeat');
|
||||
});
|
||||
|
||||
it('omitted when backgroundImage is not provided', () => {
|
||||
const result = fn(null, { backgroundRepeat: 'repeat' });
|
||||
expect(result).to.not.have.property('backgroundRepeat');
|
||||
expect(result).not.toHaveProperty('backgroundRepeat');
|
||||
});
|
||||
});
|
||||
|
||||
describe('opacity', () => {
|
||||
it('sets opacity', () => {
|
||||
const result = fn(null, { opacity: 0.5 });
|
||||
expect(result).to.have.property('opacity', 0.5);
|
||||
expect(result).toHaveProperty('opacity', 0.5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('overflow', () => {
|
||||
it('sets overflow', () => {
|
||||
let result = fn(null, { overflow: 'visible' });
|
||||
expect(result).to.have.property('overflow', 'visible');
|
||||
expect(result).toHaveProperty('overflow', 'visible');
|
||||
result = fn(null, { overflow: 'hidden' });
|
||||
expect(result).to.have.property('overflow', 'hidden');
|
||||
expect(result).toHaveProperty('overflow', 'hidden');
|
||||
});
|
||||
it(`defaults to 'hidden'`, () => {
|
||||
const result = fn(null);
|
||||
expect(result).to.have.property('overflow', 'hidden');
|
||||
expect(result).toHaveProperty('overflow', 'hidden');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable, emptyTable } from './__tests__/fixtures/test_tables';
|
||||
import { context } from './context';
|
||||
|
||||
describe('context', () => {
|
||||
const fn = functionWrapper(context);
|
||||
|
||||
it('returns whatever context you pass into', () => {
|
||||
expect(fn(null)).toBe(null);
|
||||
expect(fn(true)).toBe(true);
|
||||
expect(fn(1)).toBe(1);
|
||||
expect(fn('foo')).toBe('foo');
|
||||
expect(fn({})).toEqual({});
|
||||
expect(fn(emptyTable)).toEqual(emptyTable);
|
||||
expect(fn(testTable)).toEqual(testTable);
|
||||
});
|
||||
});
|
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { csv } from '../csv';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../../strings';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../strings';
|
||||
import { csv } from './csv';
|
||||
|
||||
const errors = getFunctionErrors().csv;
|
||||
|
||||
|
@ -17,9 +16,9 @@ describe('csv', () => {
|
|||
type: 'datatable',
|
||||
columns: [{ name: 'name', type: 'string' }, { name: 'number', type: 'string' }],
|
||||
rows: [
|
||||
{ name: 'one', number: 1 },
|
||||
{ name: 'two', number: 2 },
|
||||
{ name: 'fourty two', number: 42 },
|
||||
{ name: 'one', number: '1' },
|
||||
{ name: 'two', number: '2' },
|
||||
{ name: 'fourty two', number: '42' },
|
||||
],
|
||||
};
|
||||
|
||||
|
@ -31,7 +30,7 @@ one,1
|
|||
two,2
|
||||
fourty two,42`,
|
||||
})
|
||||
).to.eql(expected);
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should allow custom delimiter', () => {
|
||||
|
@ -43,7 +42,7 @@ two\t2
|
|||
fourty two\t42`,
|
||||
delimiter: '\t',
|
||||
})
|
||||
).to.eql(expected);
|
||||
).toEqual(expected);
|
||||
|
||||
expect(
|
||||
fn(null, {
|
||||
|
@ -53,7 +52,7 @@ two%SPLIT%2
|
|||
fourty two%SPLIT%42`,
|
||||
delimiter: '%SPLIT%',
|
||||
})
|
||||
).to.eql(expected);
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should allow custom newline', () => {
|
||||
|
@ -62,7 +61,7 @@ fourty two%SPLIT%42`,
|
|||
data: `name,number\rone,1\rtwo,2\rfourty two,42`,
|
||||
newline: '\r',
|
||||
})
|
||||
).to.eql(expected);
|
||||
).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should trim column names', () => {
|
||||
|
@ -71,7 +70,7 @@ fourty two%SPLIT%42`,
|
|||
data: `foo," bar ", baz, " buz "
|
||||
1,2,3,4`,
|
||||
})
|
||||
).to.eql({
|
||||
).toEqual({
|
||||
type: 'datatable',
|
||||
columns: [
|
||||
{ name: 'foo', type: 'string' },
|
||||
|
@ -90,7 +89,7 @@ fourty two%SPLIT%42`,
|
|||
1," best ",3, " ok"
|
||||
" good", bad, better , " worst " `,
|
||||
})
|
||||
).to.eql({
|
||||
).toEqual({
|
||||
type: 'datatable',
|
||||
columns: [
|
||||
{ name: 'foo', type: 'string' },
|
||||
|
@ -106,13 +105,13 @@ fourty two%SPLIT%42`,
|
|||
});
|
||||
|
||||
it('throws when given invalid csv', () => {
|
||||
expect(fn)
|
||||
.withArgs(null, {
|
||||
expect(() => {
|
||||
fn(null, {
|
||||
data: `name,number
|
||||
one|1
|
||||
two.2
|
||||
fourty two,42`,
|
||||
})
|
||||
.to.throwException(new RegExp(errors.invalidInputCSV().message));
|
||||
});
|
||||
}).toThrow(new RegExp(errors.invalidInputCSV().message));
|
||||
});
|
||||
});
|
|
@ -4,11 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import sinon from 'sinon';
|
||||
import { date } from '../date';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../../strings';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../strings';
|
||||
import { date } from './date';
|
||||
|
||||
const errors = getFunctionErrors().date;
|
||||
|
||||
|
@ -26,31 +25,31 @@ describe('date', () => {
|
|||
});
|
||||
|
||||
it('returns a date in ms from a date string with the provided format', () => {
|
||||
expect(fn(null, { value: '20111031', format: 'YYYYMMDD' })).to.be(1320019200000);
|
||||
expect(fn(null, { value: '20111031', format: 'YYYYMMDD' })).toBe(1320019200000);
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('value', () => {
|
||||
it('sets the date string to convert into ms', () => {
|
||||
expect(fn(null, { value: '2011-10-05T14:48:00.000Z' })).to.be(1317826080000);
|
||||
expect(fn(null, { value: '2011-10-05T14:48:00.000Z' })).toBe(1317826080000);
|
||||
});
|
||||
|
||||
it('defaults to current date (ms)', () => {
|
||||
expect(fn(null)).to.be(new Date().valueOf());
|
||||
expect(fn(null)).toBe(new Date().valueOf());
|
||||
});
|
||||
});
|
||||
|
||||
describe('format', () => {
|
||||
it('sets the format to parse the date string', () => {
|
||||
expect(fn(null, { value: '20111031', format: 'YYYYMMDD' })).to.be(1320019200000);
|
||||
expect(fn(null, { value: '20111031', format: 'YYYYMMDD' })).toBe(1320019200000);
|
||||
});
|
||||
|
||||
it('defaults to ISO 8601 format', () => {
|
||||
expect(fn(null, { value: '2011-10-05T14:48:00.000Z' })).to.be(1317826080000);
|
||||
expect(fn(null, { value: '2011-10-05T14:48:00.000Z' })).toBe(1317826080000);
|
||||
});
|
||||
|
||||
it('throws when passing an invalid date string and format is not specified', () => {
|
||||
expect(() => fn(null, { value: '23/25/2014' })).to.throwException(
|
||||
expect(() => fn(null, { value: '23/25/2014' })).toThrow(
|
||||
new RegExp(errors.invalidDateInput('23/25/2014').message)
|
||||
);
|
||||
});
|
|
@ -4,17 +4,16 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { doFn } from '../do';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { doFn } from './do';
|
||||
|
||||
describe('do', () => {
|
||||
const fn = functionWrapper(doFn);
|
||||
|
||||
it('should only pass context', () => {
|
||||
expect(fn(1, { fn: '1' })).to.equal(1);
|
||||
expect(fn(true, {})).to.equal(true);
|
||||
expect(fn(null, {})).to.equal(null);
|
||||
expect(fn(null, { fn: 'not null' })).to.equal(null);
|
||||
expect(fn(1, { fn: '1' })).toEqual(1);
|
||||
expect(fn(true, {})).toEqual(true);
|
||||
expect(fn(null, {})).toEqual(null);
|
||||
expect(fn(null, { fn: 'not null' })).toEqual(null);
|
||||
});
|
||||
});
|
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { dropdownControl } from '../dropdownControl';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './fixtures/test_tables';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './__tests__/fixtures/test_tables';
|
||||
import { dropdownControl } from './dropdownControl';
|
||||
|
||||
describe('dropdownControl', () => {
|
||||
const fn = functionWrapper(dropdownControl);
|
||||
|
@ -17,39 +16,44 @@ describe('dropdownControl', () => {
|
|||
);
|
||||
|
||||
it('returns a render as dropdown_filter', () => {
|
||||
expect(fn(testTable, { filterColumn: 'name', valueColumn: 'name' }))
|
||||
.to.have.property('type', 'render')
|
||||
.and.to.have.property('as', 'dropdown_filter');
|
||||
expect(fn(testTable, { filterColumn: 'name', valueColumn: 'name' })).toHaveProperty(
|
||||
'type',
|
||||
'render'
|
||||
);
|
||||
expect(fn(testTable, { filterColumn: 'name', valueColumn: 'name' })).toHaveProperty(
|
||||
'as',
|
||||
'dropdown_filter'
|
||||
);
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('valueColumn', () => {
|
||||
it('populates dropdown choices with unique values in valueColumn', () => {
|
||||
expect(fn(testTable, { valueColumn: 'name' }).value.choices).to.eql(uniqueNames);
|
||||
expect(fn(testTable, { valueColumn: 'name' }).value.choices).toEqual(uniqueNames);
|
||||
});
|
||||
|
||||
it('returns an empty array when provided an invalid column', () => {
|
||||
expect(fn(testTable, { valueColumn: 'foo' }).value.choices).to.be.empty();
|
||||
expect(fn(testTable, { valueColumn: '' }).value.choices).to.be.empty();
|
||||
expect(fn(testTable, { valueColumn: 'foo' }).value.choices).toEqual([]);
|
||||
expect(fn(testTable, { valueColumn: '' }).value.choices).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterColumn', () => {
|
||||
it('sets which column the filter is applied to', () => {
|
||||
expect(fn(testTable, { filterColumn: 'name' }).value).to.have.property('column', 'name');
|
||||
expect(fn(testTable, { filterColumn: 'name', valueColumn: 'price' }).value).to.have.property(
|
||||
expect(fn(testTable, { filterColumn: 'name' }).value).toHaveProperty('column', 'name');
|
||||
expect(fn(testTable, { filterColumn: 'name', valueColumn: 'price' }).value).toHaveProperty(
|
||||
'column',
|
||||
'name'
|
||||
);
|
||||
});
|
||||
|
||||
it('defaults to valueColumn if not provided', () => {
|
||||
expect(fn(testTable, { valueColumn: 'price' }).value).to.have.property('column', 'price');
|
||||
expect(fn(testTable, { valueColumn: 'price' }).value).toHaveProperty('column', 'price');
|
||||
});
|
||||
|
||||
it('sets column to undefined if no args are provided', () => {
|
||||
expect(fn(testTable).value).to.have.property('column', undefined);
|
||||
expect(fn(testTable).value).toHaveProperty('column', undefined);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { eq } from './eq';
|
||||
|
||||
describe('eq', () => {
|
||||
const fn = functionWrapper(eq);
|
||||
|
||||
it('should return false when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).toBe(false);
|
||||
expect(fn(true, { value: 'true' })).toBe(false);
|
||||
expect(fn(null, { value: 'null' })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when the values are different', () => {
|
||||
expect(fn(1, { value: 2 })).toBe(false);
|
||||
expect(fn('foo', { value: 'bar' })).toBe(false);
|
||||
expect(fn(true, { value: false })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when the values are the same', () => {
|
||||
expect(fn(1, { value: 1 })).toBe(true);
|
||||
expect(fn('foo', { value: 'foo' })).toBe(true);
|
||||
expect(fn(true, { value: true })).toBe(true);
|
||||
expect(fn(null, { value: null })).toBe(true);
|
||||
});
|
||||
});
|
|
@ -4,36 +4,35 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { exactly } from '../exactly';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { emptyFilter } from './fixtures/test_filters';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { emptyFilter } from './__tests__/fixtures/test_filters';
|
||||
import { exactly } from './exactly';
|
||||
|
||||
describe('exactly', () => {
|
||||
const fn = functionWrapper(exactly);
|
||||
|
||||
it('returns a filter', () => {
|
||||
const args = { column: 'name', value: 'product2' };
|
||||
expect(fn(emptyFilter, args)).to.have.property('type', 'filter');
|
||||
expect(fn(emptyFilter, args)).toHaveProperty('type', 'filter');
|
||||
});
|
||||
|
||||
it("adds an exactly object to 'and'", () => {
|
||||
const result = fn(emptyFilter, { column: 'name', value: 'product2' });
|
||||
expect(result.and[0]).to.have.property('type', 'exactly');
|
||||
expect(result.and[0]).toHaveProperty('type', 'exactly');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('column', () => {
|
||||
it('sets the column to apply the filter to', () => {
|
||||
const result = fn(emptyFilter, { column: 'name' });
|
||||
expect(result.and[0]).to.have.property('column', 'name');
|
||||
expect(result.and[0]).toHaveProperty('column', 'name');
|
||||
});
|
||||
});
|
||||
|
||||
describe('value', () => {
|
||||
it('sets the exact value to filter on in a column', () => {
|
||||
const result = fn(emptyFilter, { value: 'product2' });
|
||||
expect(result.and[0]).to.have.property('value', 'product2');
|
||||
expect(result.and[0]).toHaveProperty('value', 'product2');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { filterrows } from '../filterrows';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './fixtures/test_tables';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './__tests__/fixtures/test_tables';
|
||||
import { filterrows } from './filterrows';
|
||||
|
||||
const inStock = datatable => datatable.rows[0].in_stock;
|
||||
const returnFalse = () => false;
|
||||
|
@ -17,7 +16,7 @@ describe('filterrows', () => {
|
|||
|
||||
it('returns a datable', () => {
|
||||
return fn(testTable, { fn: inStock }).then(result => {
|
||||
expect(result).to.have.property('type', 'datatable');
|
||||
expect(result).toHaveProperty('type', 'datatable');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -25,20 +24,18 @@ describe('filterrows', () => {
|
|||
const inStockRows = testTable.rows.filter(row => row.in_stock);
|
||||
|
||||
return fn(testTable, { fn: inStock }).then(result => {
|
||||
expect(result.columns).to.eql(testTable.columns);
|
||||
expect(result.rows).to.eql(inStockRows);
|
||||
expect(result.columns).toEqual(testTable.columns);
|
||||
expect(result.rows).toEqual(inStockRows);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns datatable with no rows when no rows meet function condition', () => {
|
||||
return fn(testTable, { fn: returnFalse }).then(result => {
|
||||
expect(result.rows).to.be.empty();
|
||||
expect(result.rows).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
it('throws when no function is provided', () => {
|
||||
expect(() => fn(testTable)).to.throwException(e => {
|
||||
expect(e.message).to.be('fn is not a function');
|
||||
});
|
||||
expect(() => fn(testTable)).toThrow('fn is not a function');
|
||||
});
|
||||
});
|
|
@ -4,31 +4,30 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { formatdate } from '../formatdate';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { formatdate } from './formatdate';
|
||||
|
||||
describe('formatdate', () => {
|
||||
const fn = functionWrapper(formatdate);
|
||||
|
||||
it('returns formatted date string from ms or ISO8601 string using the given format', () => {
|
||||
const testDate = new Date('2011-10-31T12:30:45Z').valueOf();
|
||||
expect(fn(testDate, { format: 'MM/DD/YYYY' })).to.be('10/31/2011');
|
||||
expect(fn(testDate, { format: 'MM/DD/YYYY' })).toBe('10/31/2011');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('format', () => {
|
||||
it('sets the format of the returned date string', () => {
|
||||
const testDate = new Date('2013-03-12T08:03:27Z').valueOf();
|
||||
expect(fn(testDate, { format: 'MMMM Do YYYY, h:mm:ss a' })).to.be(
|
||||
expect(fn(testDate, { format: 'MMMM Do YYYY, h:mm:ss a' })).toBe(
|
||||
'March 12th 2013, 8:03:27 am'
|
||||
);
|
||||
expect(fn(testDate, { format: 'MMM Do YY' })).to.be('Mar 12th 13');
|
||||
expect(fn(testDate, { format: 'MMM Do YY' })).toBe('Mar 12th 13');
|
||||
});
|
||||
|
||||
it('defaults to ISO 8601 format', () => {
|
||||
const testDate = new Date('2018-01-08T20:15:59Z').valueOf();
|
||||
expect(fn(testDate)).to.be('2018-01-08T20:15:59.000Z');
|
||||
expect(fn(testDate)).toBe('2018-01-08T20:15:59.000Z');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,25 +4,24 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { formatnumber } from '../formatnumber';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { formatnumber } from './formatnumber';
|
||||
|
||||
describe('formatnumber', () => {
|
||||
const fn = functionWrapper(formatnumber);
|
||||
|
||||
it('returns number as formatted string with given format', () => {
|
||||
expect(fn(140000, { format: '$0,0.00' })).to.be('$140,000.00');
|
||||
expect(fn(140000, { format: '$0,0.00' })).toBe('$140,000.00');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('format', () => {
|
||||
it('sets the format of the resulting number string', () => {
|
||||
expect(fn(0.68, { format: '0.000%' })).to.be('68.000%');
|
||||
expect(fn(0.68, { format: '0.000%' })).toBe('68.000%');
|
||||
});
|
||||
|
||||
it('casts number to a string if format is not specified', () => {
|
||||
expect(fn(140000.999999)).to.be('140000.999999');
|
||||
expect(fn(140000.999999)).toBe('140000.999999');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,11 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { getCell } from '../getCell';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../../strings';
|
||||
import { emptyTable, testTable } from './fixtures/test_tables';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../strings';
|
||||
import { emptyTable, testTable } from './__tests__/fixtures/test_tables';
|
||||
import { getCell } from './getCell';
|
||||
|
||||
const errors = getFunctionErrors().getCell;
|
||||
|
||||
|
@ -18,7 +17,7 @@ describe('getCell', () => {
|
|||
it('returns the value from the specified row and column', () => {
|
||||
const arbitraryRowIndex = 3;
|
||||
|
||||
expect(fn(testTable, { column: 'quantity', row: arbitraryRowIndex })).to.eql(
|
||||
expect(fn(testTable, { column: 'quantity', row: arbitraryRowIndex })).toEqual(
|
||||
testTable.rows[arbitraryRowIndex].quantity
|
||||
);
|
||||
});
|
||||
|
@ -27,26 +26,26 @@ describe('getCell', () => {
|
|||
const firstColumn = testTable.columns[0].name;
|
||||
|
||||
it('defaults to first column in first row if no args are provided', () => {
|
||||
expect(fn(testTable)).to.be(testTable.rows[0][firstColumn]);
|
||||
expect(fn(testTable)).toBe(testTable.rows[0][firstColumn]);
|
||||
});
|
||||
|
||||
describe('column', () => {
|
||||
const arbitraryRowIndex = 1;
|
||||
|
||||
it('sets which column to get the value from', () => {
|
||||
expect(fn(testTable, { column: 'price', row: arbitraryRowIndex })).to.be(
|
||||
expect(fn(testTable, { column: 'price', row: arbitraryRowIndex })).toBe(
|
||||
testTable.rows[arbitraryRowIndex].price
|
||||
);
|
||||
});
|
||||
|
||||
it('defaults to first column if not provided', () => {
|
||||
expect(fn(testTable, { row: arbitraryRowIndex })).to.be(
|
||||
expect(fn(testTable, { row: arbitraryRowIndex })).toBe(
|
||||
testTable.rows[arbitraryRowIndex][firstColumn]
|
||||
);
|
||||
});
|
||||
|
||||
it('throws when invalid column is provided', () => {
|
||||
expect(() => fn(testTable, { column: 'foo' })).to.throwException(
|
||||
expect(() => fn(testTable, { column: 'foo' })).toThrow(
|
||||
new RegExp(errors.columnNotFound('foo').message)
|
||||
);
|
||||
});
|
||||
|
@ -56,27 +55,27 @@ describe('getCell', () => {
|
|||
it('sets which row to get the value from', () => {
|
||||
const arbitraryRowIndex = 8;
|
||||
|
||||
expect(fn(testTable, { column: 'in_stock', row: arbitraryRowIndex })).to.eql(
|
||||
expect(fn(testTable, { column: 'in_stock', row: arbitraryRowIndex })).toEqual(
|
||||
testTable.rows[arbitraryRowIndex].in_stock
|
||||
);
|
||||
});
|
||||
|
||||
it('defaults to first row if not specified', () => {
|
||||
expect(fn(testTable, { column: 'name' })).to.eql(testTable.rows[0].name);
|
||||
expect(fn(testTable, { column: 'name' })).toEqual(testTable.rows[0].name);
|
||||
});
|
||||
|
||||
it('throws when row does not exist', () => {
|
||||
const invalidRow = testTable.rows.length;
|
||||
|
||||
expect(() => fn(testTable, { column: 'name', row: invalidRow })).to.throwException(
|
||||
expect(() => fn(testTable, { column: 'name', row: invalidRow })).toThrow(
|
||||
new RegExp(errors.rowNotFound(invalidRow).message)
|
||||
);
|
||||
|
||||
expect(() => fn(emptyTable, { column: 'foo' })).to.throwException(
|
||||
expect(() => fn(emptyTable, { column: 'foo' })).toThrow(
|
||||
new RegExp(errors.rowNotFound(0).message)
|
||||
);
|
||||
|
||||
expect(() => fn(emptyTable)).to.throwException(new RegExp(errors.rowNotFound(0).message));
|
||||
expect(() => fn(emptyTable)).toThrow(new RegExp(errors.rowNotFound(0).message));
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,9 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { getFlotAxisConfig } from '../plot/get_flot_axis_config';
|
||||
import { xAxisConfig, yAxisConfig, hideAxis } from './fixtures/test_styles';
|
||||
import { xAxisConfig, yAxisConfig, hideAxis } from './__tests__/fixtures/test_styles';
|
||||
import { getFlotAxisConfig } from './plot/get_flot_axis_config';
|
||||
|
||||
describe('getFlotAxisConfig', () => {
|
||||
const columns = {
|
||||
|
@ -21,41 +20,42 @@ describe('getFlotAxisConfig', () => {
|
|||
|
||||
describe('show', () => {
|
||||
it('hides the axis', () => {
|
||||
expect(getFlotAxisConfig('x', false, { columns, ticks }))
|
||||
.to.only.have.key('show')
|
||||
.and.to.have.property('show', false);
|
||||
expect(getFlotAxisConfig('y', false, { columns, ticks }))
|
||||
.to.only.have.key('show')
|
||||
.and.to.have.property('show', false);
|
||||
let config = getFlotAxisConfig('x', false, { columns, ticks });
|
||||
expect(Object.keys(config)).toHaveLength(1);
|
||||
expect(config).toHaveProperty('show', false);
|
||||
|
||||
config = getFlotAxisConfig('y', false, { columns, ticks });
|
||||
expect(Object.keys(config)).toHaveLength(1);
|
||||
expect(config).toHaveProperty('show', false);
|
||||
});
|
||||
|
||||
it('shows the axis', () => {
|
||||
expect(getFlotAxisConfig('x', true, { columns, ticks })).to.have.property('show', true);
|
||||
expect(getFlotAxisConfig('y', true, { columns, ticks })).to.have.property('show', true);
|
||||
expect(getFlotAxisConfig('x', true, { columns, ticks })).toHaveProperty('show', true);
|
||||
expect(getFlotAxisConfig('y', true, { columns, ticks })).toHaveProperty('show', true);
|
||||
});
|
||||
|
||||
it('sets show using an AxisConfig', () => {
|
||||
let result = getFlotAxisConfig('x', xAxisConfig, { columns, ticks });
|
||||
expect(result).to.have.property('show', xAxisConfig.show);
|
||||
expect(result).toHaveProperty('show', xAxisConfig.show);
|
||||
|
||||
result = getFlotAxisConfig('y', yAxisConfig, { columns, ticks });
|
||||
expect(result).to.have.property('show', yAxisConfig.show);
|
||||
expect(result).toHaveProperty('show', yAxisConfig.show);
|
||||
|
||||
result = getFlotAxisConfig('x', hideAxis, { columns, ticks });
|
||||
expect(result).to.have.property('show', hideAxis.show);
|
||||
expect(result).toHaveProperty('show', hideAxis.show);
|
||||
|
||||
result = getFlotAxisConfig('y', hideAxis, { columns, ticks });
|
||||
expect(result).to.have.property('show', hideAxis.show);
|
||||
expect(result).toHaveProperty('show', hideAxis.show);
|
||||
});
|
||||
});
|
||||
|
||||
describe('position', () => {
|
||||
it('sets the position of the axis when given an AxisConfig', () => {
|
||||
let result = getFlotAxisConfig('x', xAxisConfig, { columns, ticks });
|
||||
expect(result).to.have.property('position', xAxisConfig.position);
|
||||
expect(result).toHaveProperty('position', xAxisConfig.position);
|
||||
|
||||
result = getFlotAxisConfig('y', yAxisConfig, { columns, ticks });
|
||||
expect(result).to.have.property('position', yAxisConfig.position);
|
||||
expect(result).toHaveProperty('position', yAxisConfig.position);
|
||||
});
|
||||
|
||||
it("defaults position to 'bottom' for the x-axis", () => {
|
||||
|
@ -66,7 +66,7 @@ describe('getFlotAxisConfig', () => {
|
|||
};
|
||||
|
||||
const result = getFlotAxisConfig('x', invalidXPosition, { columns, ticks });
|
||||
expect(result).to.have.property('position', 'bottom');
|
||||
expect(result).toHaveProperty('position', 'bottom');
|
||||
});
|
||||
|
||||
it("defaults position to 'left' for the y-axis", () => {
|
||||
|
@ -77,27 +77,27 @@ describe('getFlotAxisConfig', () => {
|
|||
};
|
||||
|
||||
const result = getFlotAxisConfig('y', invalidYPosition, { columns, ticks });
|
||||
expect(result).to.have.property('position', 'left');
|
||||
expect(result).toHaveProperty('position', 'left');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ticks', () => {
|
||||
it('adds a tick mark mapping for string columns', () => {
|
||||
let result = getFlotAxisConfig('x', true, { columns, ticks });
|
||||
expect(result.ticks).to.eql([[2, 'product1'], [1, 'product2']]);
|
||||
expect(result.ticks).toEqual([[2, 'product1'], [1, 'product2']]);
|
||||
|
||||
result = getFlotAxisConfig('x', xAxisConfig, { columns, ticks });
|
||||
expect(result.ticks).to.eql([[2, 'product1'], [1, 'product2']]);
|
||||
expect(result.ticks).toEqual([[2, 'product1'], [1, 'product2']]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mode', () => {
|
||||
it('sets the mode to time for date columns', () => {
|
||||
let result = getFlotAxisConfig('y', true, { columns, ticks });
|
||||
expect(result).to.have.property('mode', 'time');
|
||||
expect(result).toHaveProperty('mode', 'time');
|
||||
|
||||
result = getFlotAxisConfig('y', yAxisConfig, { columns, ticks });
|
||||
expect(result).to.have.property('mode', 'time');
|
||||
expect(result).toHaveProperty('mode', 'time');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,20 +4,19 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { defaultSpec, getFontSpec } from '../plot/get_font_spec';
|
||||
import { fontStyle } from './fixtures/test_styles';
|
||||
import { fontStyle } from './__tests__/fixtures/test_styles';
|
||||
import { defaultSpec, getFontSpec } from './plot/get_font_spec';
|
||||
|
||||
describe('getFontSpec', () => {
|
||||
describe('default output', () => {
|
||||
it('returns the default spec object', () => {
|
||||
expect(getFontSpec()).to.eql(defaultSpec);
|
||||
expect(getFontSpec()).toEqual(defaultSpec);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convert from fontStyle object', () => {
|
||||
it('returns plot font spec', () => {
|
||||
expect(getFontSpec(fontStyle)).to.eql({
|
||||
expect(getFontSpec(fontStyle)).toEqual({
|
||||
size: 14,
|
||||
lHeight: 21,
|
||||
style: 'normal',
|
|
@ -4,8 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { getTickHash } from '../plot/get_tick_hash';
|
||||
import { getTickHash } from './plot/get_tick_hash';
|
||||
|
||||
describe('getTickHash', () => {
|
||||
it('creates a hash for tick marks for string columns only', () => {
|
||||
|
@ -20,7 +19,7 @@ describe('getTickHash', () => {
|
|||
{ x: 'product2', y: 'CA' },
|
||||
];
|
||||
|
||||
expect(getTickHash(columns, rows)).to.eql({
|
||||
expect(getTickHash(columns, rows)).toEqual({
|
||||
x: { hash: { product1: 2, product2: 1 }, counter: 3 },
|
||||
y: { hash: { CA: 1, AZ: 2 }, counter: 3 },
|
||||
});
|
||||
|
@ -33,7 +32,7 @@ describe('getTickHash', () => {
|
|||
};
|
||||
const rows = [{ x: 1, y: true }, { x: 2, y: true }, { x: 1, y: false }, { x: 2, y: false }];
|
||||
|
||||
expect(getTickHash(columns, rows)).to.eql({
|
||||
expect(getTickHash(columns, rows)).toEqual({
|
||||
x: { hash: {}, counter: 0 },
|
||||
y: { hash: {}, counter: 0 },
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { gt } from './gt';
|
||||
|
||||
describe('gt', () => {
|
||||
const fn = functionWrapper(gt);
|
||||
|
||||
it('should return false when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).toBe(false);
|
||||
expect(fn('3', { value: 3 })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when greater than', () => {
|
||||
expect(fn(2, { value: 1 })).toBe(true);
|
||||
expect(fn('b', { value: 'a' })).toBe(true);
|
||||
expect(fn('foo', { value: 'bar' })).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when less than or equal to', () => {
|
||||
expect(fn(1, { value: 2 })).toBe(false);
|
||||
expect(fn(2, { value: 2 })).toBe(false);
|
||||
expect(fn('a', { value: 'b' })).toBe(false);
|
||||
expect(fn('bar', { value: 'foo' })).toBe(false);
|
||||
expect(fn('foo', { value: 'foo' })).toBe(false);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { gte } from './gte';
|
||||
|
||||
describe('gte', () => {
|
||||
const fn = functionWrapper(gte);
|
||||
|
||||
it('should return false when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).toBe(false);
|
||||
expect(fn(3, { value: '3' })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when greater than or equal to', () => {
|
||||
expect(fn(2, { value: 1 })).toBe(true);
|
||||
expect(fn(2, { value: 2 })).toBe(true);
|
||||
expect(fn('b', { value: 'a' })).toBe(true);
|
||||
expect(fn('b', { value: 'b' })).toBe(true);
|
||||
expect(fn('foo', { value: 'bar' })).toBe(true);
|
||||
expect(fn('foo', { value: 'foo' })).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when less than', () => {
|
||||
expect(fn(1, { value: 2 })).toBe(false);
|
||||
expect(fn('a', { value: 'b' })).toBe(false);
|
||||
expect(fn('bar', { value: 'foo' })).toBe(false);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { emptyTable, testTable } from './__tests__/fixtures/test_tables';
|
||||
import { head } from './head';
|
||||
|
||||
describe('head', () => {
|
||||
const fn = functionWrapper(head);
|
||||
|
||||
it('returns a datatable with the first N rows of the context', () => {
|
||||
const result = fn(testTable, { count: 2 });
|
||||
|
||||
expect(result.type).toBe('datatable');
|
||||
expect(result.columns).toEqual(testTable.columns);
|
||||
expect(result.rows).toHaveLength(2);
|
||||
expect(result.rows[0]).toEqual(testTable.rows[0]);
|
||||
expect(result.rows[1]).toEqual(testTable.rows[1]);
|
||||
});
|
||||
|
||||
it('returns the original context if N >= context.rows.length', () => {
|
||||
expect(fn(testTable, { count: testTable.rows.length + 5 })).toEqual(testTable);
|
||||
expect(fn(testTable, { count: testTable.rows.length })).toEqual(testTable);
|
||||
expect(fn(emptyTable)).toEqual(emptyTable);
|
||||
});
|
||||
|
||||
it('returns the first row if N is not specified', () => {
|
||||
const result = fn(testTable);
|
||||
|
||||
expect(result.rows).toHaveLength(1);
|
||||
expect(result.rows[0]).toEqual(testTable.rows[0]);
|
||||
});
|
||||
});
|
|
@ -4,31 +4,30 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { ifFn } from '../if';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { ifFn } from './if';
|
||||
|
||||
describe('if', () => {
|
||||
const fn = functionWrapper(ifFn);
|
||||
|
||||
describe('spec', () => {
|
||||
it('is a function', () => {
|
||||
expect(fn).to.be.a('function');
|
||||
expect(typeof fn).toBe('function');
|
||||
});
|
||||
});
|
||||
|
||||
describe('function', () => {
|
||||
describe('condition passed', () => {
|
||||
it('with then', async () => {
|
||||
expect(await fn(null, { condition: true, then: () => 'foo' })).to.be('foo');
|
||||
expect(await fn(null, { condition: true, then: () => 'foo', else: () => 'bar' })).to.be(
|
||||
expect(await fn(null, { condition: true, then: () => 'foo' })).toBe('foo');
|
||||
expect(await fn(null, { condition: true, then: () => 'foo', else: () => 'bar' })).toBe(
|
||||
'foo'
|
||||
);
|
||||
});
|
||||
|
||||
it('without then', async () => {
|
||||
expect(await fn(null, { condition: true })).to.be(null);
|
||||
expect(await fn('some context', { condition: true })).to.be('some context');
|
||||
expect(await fn(null, { condition: true })).toBe(null);
|
||||
expect(await fn('some context', { condition: true })).toBe('some context');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -36,10 +35,10 @@ describe('if', () => {
|
|||
it('with else', async () =>
|
||||
expect(
|
||||
await fn('some context', { condition: false, then: () => 'foo', else: () => 'bar' })
|
||||
).to.be('bar'));
|
||||
).toBe('bar'));
|
||||
|
||||
it('without else', async () =>
|
||||
expect(await fn('some context', { condition: false, then: () => 'foo' })).to.be(
|
||||
expect(await fn('some context', { condition: false, then: () => 'foo' })).toBe(
|
||||
'some context'
|
||||
));
|
||||
});
|
||||
|
@ -47,24 +46,24 @@ describe('if', () => {
|
|||
describe('falsy values', () => {
|
||||
describe('for then', () => {
|
||||
it('with null', async () =>
|
||||
expect(await fn('some context', { condition: true, then: () => null })).to.be(null));
|
||||
expect(await fn('some context', { condition: true, then: () => null })).toBe(null));
|
||||
|
||||
it('with false', async () =>
|
||||
expect(await fn('some context', { condition: true, then: () => false })).to.be(false));
|
||||
expect(await fn('some context', { condition: true, then: () => false })).toBe(false));
|
||||
|
||||
it('with 0', async () =>
|
||||
expect(await fn('some context', { condition: true, then: () => 0 })).to.be(0));
|
||||
expect(await fn('some context', { condition: true, then: () => 0 })).toBe(0));
|
||||
});
|
||||
|
||||
describe('for else', () => {
|
||||
it('with null', async () =>
|
||||
expect(await fn('some context', { condition: false, else: () => null })).to.be(null));
|
||||
expect(await fn('some context', { condition: false, else: () => null })).toBe(null));
|
||||
|
||||
it('with false', async () =>
|
||||
expect(await fn('some context', { condition: false, else: () => false })).to.be(false));
|
||||
expect(await fn('some context', { condition: false, else: () => false })).toBe(false));
|
||||
|
||||
it('with 0', async () =>
|
||||
expect(await fn('some context', { condition: false, else: () => 0 })).to.be(0));
|
||||
expect(await fn('some context', { condition: false, else: () => 0 })).toBe(0));
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { lt } from './lt';
|
||||
|
||||
describe('lt', () => {
|
||||
const fn = functionWrapper(lt);
|
||||
|
||||
it('should return false when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).toBe(false);
|
||||
expect(fn('3', { value: 3 })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when greater than or equal to', () => {
|
||||
expect(fn(2, { value: 1 })).toBe(false);
|
||||
expect(fn(2, { value: 2 })).toBe(false);
|
||||
expect(fn('b', { value: 'a' })).toBe(false);
|
||||
expect(fn('b', { value: 'b' })).toBe(false);
|
||||
expect(fn('foo', { value: 'bar' })).toBe(false);
|
||||
expect(fn('foo', { value: 'foo' })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when less than', () => {
|
||||
expect(fn(1, { value: 2 })).toBe(true);
|
||||
expect(fn('a', { value: 'b' })).toBe(true);
|
||||
expect(fn('bar', { value: 'foo' })).toBe(true);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { lte } from './lte';
|
||||
|
||||
describe('lte', () => {
|
||||
const fn = functionWrapper(lte);
|
||||
|
||||
it('should return false when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).toBe(false);
|
||||
expect(fn('3', { value: 3 })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false when greater than', () => {
|
||||
expect(fn(2, { value: 1 })).toBe(false);
|
||||
expect(fn('b', { value: 'a' })).toBe(false);
|
||||
expect(fn('foo', { value: 'bar' })).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true when less than or equal to', () => {
|
||||
expect(fn(1, { value: 2 })).toBe(true);
|
||||
expect(fn(2, { value: 2 })).toBe(true);
|
||||
expect(fn('a', { value: 'b' })).toBe(true);
|
||||
expect(fn('a', { value: 'a' })).toBe(true);
|
||||
expect(fn('bar', { value: 'foo' })).toBe(true);
|
||||
expect(fn('foo', { value: 'foo' })).toBe(true);
|
||||
});
|
||||
});
|
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { mapColumn } from '../mapColumn';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable, emptyTable } from './fixtures/test_tables';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable, emptyTable } from './__tests__/fixtures/test_tables';
|
||||
import { mapColumn } from './mapColumn';
|
||||
|
||||
const pricePlusTwo = datatable => Promise.resolve(datatable.rows[0].price + 2);
|
||||
|
||||
|
@ -18,13 +17,13 @@ describe('mapColumn', () => {
|
|||
return fn(testTable, { name: 'pricePlusTwo', expression: pricePlusTwo }).then(result => {
|
||||
const arbitraryRowIndex = 2;
|
||||
|
||||
expect(result.type).to.be('datatable');
|
||||
expect(result.columns).to.eql([
|
||||
expect(result.type).toBe('datatable');
|
||||
expect(result.columns).toEqual([
|
||||
...testTable.columns,
|
||||
{ name: 'pricePlusTwo', type: 'number' },
|
||||
]);
|
||||
expect(result.columns[result.columns.length - 1]).to.have.property('name', 'pricePlusTwo');
|
||||
expect(result.rows[arbitraryRowIndex]).to.have.property('pricePlusTwo');
|
||||
expect(result.columns[result.columns.length - 1]).toHaveProperty('name', 'pricePlusTwo');
|
||||
expect(result.rows[arbitraryRowIndex]).toHaveProperty('pricePlusTwo');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -33,22 +32,20 @@ describe('mapColumn', () => {
|
|||
const nameColumnIndex = result.columns.findIndex(({ name }) => name === 'name');
|
||||
const arbitraryRowIndex = 4;
|
||||
|
||||
expect(result.type).to.be('datatable');
|
||||
expect(result.columns).to.have.length(testTable.columns.length);
|
||||
expect(result.columns[nameColumnIndex])
|
||||
.to.have.property('name', 'name')
|
||||
.and.to.have.property('type', 'number');
|
||||
expect(result.rows[arbitraryRowIndex]).to.have.property('name', 202);
|
||||
expect(result.type).toBe('datatable');
|
||||
expect(result.columns).toHaveLength(testTable.columns.length);
|
||||
expect(result.columns[nameColumnIndex]).toHaveProperty('name', 'name');
|
||||
expect(result.columns[nameColumnIndex]).toHaveProperty('type', 'number');
|
||||
expect(result.rows[arbitraryRowIndex]).toHaveProperty('name', 202);
|
||||
});
|
||||
});
|
||||
|
||||
it('adds a column to empty tables', () => {
|
||||
return fn(emptyTable, { name: 'name', expression: pricePlusTwo }).then(result => {
|
||||
expect(result.type).to.be('datatable');
|
||||
expect(result.columns).to.have.length(1);
|
||||
expect(result.columns[0])
|
||||
.to.have.property('name', 'name')
|
||||
.and.to.have.property('type', 'null');
|
||||
expect(result.type).toBe('datatable');
|
||||
expect(result.columns).toHaveLength(1);
|
||||
expect(result.columns[0]).toHaveProperty('name', 'name');
|
||||
expect(result.columns[0]).toHaveProperty('type', 'null');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -58,10 +55,9 @@ describe('mapColumn', () => {
|
|||
const emptyColumnIndex = result.columns.findIndex(({ name }) => name === 'empty');
|
||||
const arbitraryRowIndex = 8;
|
||||
|
||||
expect(result.columns[emptyColumnIndex])
|
||||
.to.have.property('name', 'empty')
|
||||
.and.to.have.property('type', 'null');
|
||||
expect(result.rows[arbitraryRowIndex]).to.have.property('empty', null);
|
||||
expect(result.columns[emptyColumnIndex]).toHaveProperty('name', 'empty');
|
||||
expect(result.columns[emptyColumnIndex]).toHaveProperty('type', 'null');
|
||||
expect(result.rows[arbitraryRowIndex]).toHaveProperty('empty', null);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../strings';
|
||||
import { emptyTable, testTable } from './__tests__/fixtures/test_tables';
|
||||
import { math } from './math';
|
||||
|
||||
const errors = getFunctionErrors().math;
|
||||
|
||||
describe('math', () => {
|
||||
const fn = functionWrapper(math);
|
||||
|
||||
it('evaluates math expressions without reference to context', () => {
|
||||
expect(fn(null, { expression: '10.5345' })).toBe(10.5345);
|
||||
expect(fn(null, { expression: '123 + 456' })).toBe(579);
|
||||
expect(fn(null, { expression: '100 - 46' })).toBe(54);
|
||||
expect(fn(1, { expression: '100 / 5' })).toBe(20);
|
||||
expect(fn('foo', { expression: '100 / 5' })).toBe(20);
|
||||
expect(fn(true, { expression: '100 / 5' })).toBe(20);
|
||||
expect(fn(testTable, { expression: '100 * 5' })).toBe(500);
|
||||
expect(fn(emptyTable, { expression: '100 * 5' })).toBe(500);
|
||||
});
|
||||
|
||||
it('evaluates math expressions with reference to the value of the context, must be a number', () => {
|
||||
expect(fn(-103, { expression: 'abs(value)' })).toBe(103);
|
||||
});
|
||||
|
||||
it('evaluates math expressions with references to columns in a datatable', () => {
|
||||
expect(fn(testTable, { expression: 'unique(in_stock)' })).toBe(2);
|
||||
expect(fn(testTable, { expression: 'sum(quantity)' })).toBe(2508);
|
||||
expect(fn(testTable, { expression: 'mean(price)' })).toBe(320);
|
||||
expect(fn(testTable, { expression: 'min(price)' })).toBe(67);
|
||||
expect(fn(testTable, { expression: 'median(quantity)' })).toBe(256);
|
||||
expect(fn(testTable, { expression: 'max(price)' })).toBe(605);
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('expression', () => {
|
||||
it('sets the math expression to be evaluted', () => {
|
||||
expect(fn(null, { expression: '10' })).toBe(10);
|
||||
expect(fn(23.23, { expression: 'floor(value)' })).toBe(23);
|
||||
expect(fn(testTable, { expression: 'count(price)' })).toBe(9);
|
||||
expect(fn(testTable, { expression: 'count(name)' })).toBe(9);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid expressions', () => {
|
||||
it('throws when expression evaluates to an array', () => {
|
||||
expect(() => fn(testTable, { expression: 'multiply(price, 2)' })).toThrow(
|
||||
new RegExp(errors.tooManyResults().message.replace(/[()]/g, '\\$&'))
|
||||
);
|
||||
});
|
||||
|
||||
it('throws when using an unknown context variable', () => {
|
||||
expect(() => fn(testTable, { expression: 'sum(foo)' })).toThrow('Unknown variable: foo');
|
||||
});
|
||||
|
||||
it('throws when using non-numeric data', () => {
|
||||
expect(() => fn(testTable, { expression: 'mean(name)' })).toThrow(
|
||||
new RegExp(errors.executionFailed().message)
|
||||
);
|
||||
|
||||
expect(() => fn(testTable, { expression: 'mean(in_stock)' })).toThrow(
|
||||
new RegExp(errors.executionFailed().message)
|
||||
);
|
||||
});
|
||||
|
||||
it('throws when missing expression', () => {
|
||||
expect(() => fn(testTable)).toThrow(new RegExp(errors.emptyExpression().message));
|
||||
|
||||
expect(() => fn(testTable, { expession: '' })).toThrow(
|
||||
new RegExp(errors.emptyExpression().message)
|
||||
);
|
||||
|
||||
expect(() => fn(testTable, { expession: ' ' })).toThrow(
|
||||
new RegExp(errors.emptyExpression().message)
|
||||
);
|
||||
});
|
||||
|
||||
it('throws when passing a context variable from an empty datatable', () => {
|
||||
expect(() => fn(emptyTable, { expression: 'mean(foo)' })).toThrow(
|
||||
new RegExp(errors.emptyDatatable().message)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,29 +4,27 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { metric } from '../metric';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { fontStyle } from './fixtures/test_styles';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { fontStyle } from './__tests__/fixtures/test_styles';
|
||||
import { metric } from './metric';
|
||||
|
||||
describe('metric', () => {
|
||||
const fn = functionWrapper(metric);
|
||||
|
||||
it('returns a render as metric', () => {
|
||||
const result = fn(null);
|
||||
expect(result)
|
||||
.to.have.property('type', 'render')
|
||||
.and.to.have.property('as', 'metric');
|
||||
expect(result).toHaveProperty('type', 'render');
|
||||
expect(result).toHaveProperty('as', 'metric');
|
||||
});
|
||||
|
||||
it('sets the metric to context', () => {
|
||||
const result = fn('2');
|
||||
expect(result.value).to.have.property('metric', '2');
|
||||
expect(result.value).toHaveProperty('metric', '2');
|
||||
});
|
||||
|
||||
it(`defaults metric to '?' when context is missing`, () => {
|
||||
const result = fn(null);
|
||||
expect(result.value).to.have.property('metric', '?');
|
||||
expect(result.value).toHaveProperty('metric', '?');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
|
@ -36,7 +34,7 @@ describe('metric', () => {
|
|||
label: 'My Label',
|
||||
});
|
||||
|
||||
expect(result.value).to.have.property('label', 'My Label');
|
||||
expect(result.value).toHaveProperty('label', 'My Label');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -46,7 +44,7 @@ describe('metric', () => {
|
|||
metricFont: fontStyle,
|
||||
});
|
||||
|
||||
expect(result.value).to.have.property('metricFont', fontStyle);
|
||||
expect(result.value).toHaveProperty('metricFont', fontStyle);
|
||||
});
|
||||
|
||||
// TODO: write test when using an instance of the interpreter
|
||||
|
@ -59,7 +57,7 @@ describe('metric', () => {
|
|||
labelFont: fontStyle,
|
||||
});
|
||||
|
||||
expect(result.value).to.have.property('labelFont', fontStyle);
|
||||
expect(result.value).toHaveProperty('labelFont', fontStyle);
|
||||
});
|
||||
|
||||
// TODO: write test when using an instance of the interpreter
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { neq } from './neq';
|
||||
|
||||
describe('neq', () => {
|
||||
const fn = functionWrapper(neq);
|
||||
|
||||
it('should return true when the types are different', () => {
|
||||
expect(fn(1, { value: '1' })).toBe(true);
|
||||
expect(fn(true, { value: 'true' })).toBe(true);
|
||||
expect(fn(null, { value: 'null' })).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true when the values are different', () => {
|
||||
expect(fn(1, { value: 2 })).toBe(true);
|
||||
expect(fn('foo', { value: 'bar' })).toBe(true);
|
||||
expect(fn(true, { value: false })).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false when the values are the same', () => {
|
||||
expect(fn(1, { value: 1 })).toBe(false);
|
||||
expect(fn('foo', { value: 'foo' })).toBe(false);
|
||||
expect(fn(true, { value: true })).toBe(false);
|
||||
expect(fn(null, { value: null })).toBe(false);
|
||||
});
|
||||
});
|
|
@ -4,61 +4,60 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { palette } from '../palette';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { palettes } from '../../../../common/lib/palettes';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { palettes } from '../../../common/lib/palettes';
|
||||
import { palette } from './palette';
|
||||
|
||||
describe('palette', () => {
|
||||
const fn = functionWrapper(palette);
|
||||
|
||||
it('results a palette', () => {
|
||||
const result = fn(null);
|
||||
expect(result).to.have.property('type', 'palette');
|
||||
expect(result).toHaveProperty('type', 'palette');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('color', () => {
|
||||
it('sets colors', () => {
|
||||
const result = fn(null, { color: ['red', 'green', 'blue'] });
|
||||
expect(result.colors).to.eql(['red', 'green', 'blue']);
|
||||
expect(result.colors).toEqual(['red', 'green', 'blue']);
|
||||
});
|
||||
|
||||
it('defaults to pault_tor_14 colors', () => {
|
||||
const result = fn(null);
|
||||
expect(result.colors).to.eql(palettes.paul_tor_14.colors);
|
||||
expect(result.colors).toEqual(palettes.paul_tor_14.colors);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gradient', () => {
|
||||
it('sets gradient', () => {
|
||||
let result = fn(null, { gradient: true });
|
||||
expect(result).to.have.property('gradient', true);
|
||||
expect(result).toHaveProperty('gradient', true);
|
||||
|
||||
result = fn(null, { gradient: false });
|
||||
expect(result).to.have.property('gradient', false);
|
||||
expect(result).toHaveProperty('gradient', false);
|
||||
});
|
||||
|
||||
it('defaults to false', () => {
|
||||
const result = fn(null);
|
||||
expect(result).to.have.property('gradient', false);
|
||||
expect(result).toHaveProperty('gradient', false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('reverse', () => {
|
||||
it('reverses order of the colors', () => {
|
||||
const result = fn(null, { reverse: true });
|
||||
expect(result.colors).to.eql(palettes.paul_tor_14.colors.reverse());
|
||||
expect(result.colors).toEqual(palettes.paul_tor_14.colors.reverse());
|
||||
});
|
||||
|
||||
it('keeps the original order of the colors', () => {
|
||||
const result = fn(null, { reverse: false });
|
||||
expect(result.colors).to.eql(palettes.paul_tor_14.colors);
|
||||
expect(result.colors).toEqual(palettes.paul_tor_14.colors);
|
||||
});
|
||||
|
||||
it(`defaults to 'false`, () => {
|
||||
const result = fn(null);
|
||||
expect(result.colors).to.eql(palettes.paul_tor_14.colors);
|
||||
expect(result.colors).toEqual(palettes.paul_tor_14.colors);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,20 +4,18 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { pie } from '../pie';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testPie } from './fixtures/test_pointseries';
|
||||
import { fontStyle, grayscalePalette, seriesStyle } from './fixtures/test_styles';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { testPie } from './__tests__/fixtures/test_pointseries';
|
||||
import { fontStyle, grayscalePalette, seriesStyle } from './__tests__/fixtures/test_styles';
|
||||
import { pie } from './pie';
|
||||
|
||||
describe('pie', () => {
|
||||
const fn = functionWrapper(pie);
|
||||
|
||||
it('returns a render as pie', () => {
|
||||
const result = fn(testPie);
|
||||
expect(result)
|
||||
.to.have.property('type', 'render')
|
||||
.and.to.have.property('as', 'pie');
|
||||
expect(result).toHaveProperty('type', 'render');
|
||||
expect(result).toHaveProperty('as', 'pie');
|
||||
});
|
||||
|
||||
describe('data', () => {
|
||||
|
@ -30,16 +28,16 @@ describe('pie', () => {
|
|||
[]
|
||||
);
|
||||
|
||||
expect(result).to.have.length(uniqueLabels.length);
|
||||
expect(result.every((series, i) => series.label === uniqueLabels[i])).to.be(true);
|
||||
expect(result).toHaveLength(uniqueLabels.length);
|
||||
expect(result.every((series, i) => series.label === uniqueLabels[i])).toBe(true);
|
||||
});
|
||||
|
||||
it('populates the data of the plot with points from the pointseries', () => {
|
||||
expect(result[0].data).to.eql([202]);
|
||||
expect(result[1].data).to.eql([67]);
|
||||
expect(result[2].data).to.eql([311]);
|
||||
expect(result[3].data).to.eql([536]);
|
||||
expect(result[4].data).to.eql([288]);
|
||||
expect(result[0].data).toEqual([202]);
|
||||
expect(result[1].data).toEqual([67]);
|
||||
expect(result[2].data).toEqual([311]);
|
||||
expect(result[3].data).toEqual([536]);
|
||||
expect(result[4].data).toEqual([288]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -47,8 +45,8 @@ describe('pie', () => {
|
|||
describe('palette', () => {
|
||||
it('sets the color palette', () => {
|
||||
const result = fn(testPie, { palette: grayscalePalette }).value.options;
|
||||
expect(result).to.have.property('colors');
|
||||
expect(result.colors).to.eql(grayscalePalette.colors);
|
||||
expect(result).toHaveProperty('colors');
|
||||
expect(result.colors).toEqual(grayscalePalette.colors);
|
||||
});
|
||||
|
||||
// TODO: write test when using an instance of the interpreter
|
||||
|
@ -61,74 +59,74 @@ describe('pie', () => {
|
|||
const seriesIndex = result.data.findIndex(series => series.label === seriesStyle.label);
|
||||
const resultSeries = result.data[seriesIndex];
|
||||
|
||||
expect(resultSeries).to.have.property('color', seriesStyle.color);
|
||||
expect(resultSeries).toHaveProperty('color', seriesStyle.color);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hole', () => {
|
||||
it('sets the innerRadius of the pie chart', () => {
|
||||
let result = fn(testPie, { hole: 0 }).value.options.series.pie;
|
||||
expect(result).to.have.property('innerRadius', 0);
|
||||
expect(result).toHaveProperty('innerRadius', 0);
|
||||
|
||||
result = fn(testPie, { hole: 50 }).value.options.series.pie;
|
||||
expect(result).to.have.property('innerRadius', 0.5);
|
||||
expect(result).toHaveProperty('innerRadius', 0.5);
|
||||
|
||||
result = fn(testPie, { hole: 100 }).value.options.series.pie;
|
||||
expect(result).to.have.property('innerRadius', 1);
|
||||
expect(result).toHaveProperty('innerRadius', 1);
|
||||
});
|
||||
|
||||
it('defaults to 0 when given an invalid radius', () => {
|
||||
let result = fn(testPie).value.options.series.pie;
|
||||
expect(result).to.have.property('innerRadius', 0);
|
||||
expect(result).toHaveProperty('innerRadius', 0);
|
||||
|
||||
result = fn(testPie, { hole: -100 }).value.options.series.pie;
|
||||
expect(result).to.have.property('innerRadius', 0);
|
||||
expect(result).toHaveProperty('innerRadius', 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('labels', () => {
|
||||
it('shows pie labels', () => {
|
||||
const result = fn(testPie, { labels: true }).value.options.series.pie.label;
|
||||
expect(result).to.have.property('show', true);
|
||||
expect(result).toHaveProperty('show', true);
|
||||
});
|
||||
|
||||
it('hides pie labels', () => {
|
||||
const result = fn(testPie, { labels: false }).value.options.series.pie.label;
|
||||
expect(result).to.have.property('show', false);
|
||||
expect(result).toHaveProperty('show', false);
|
||||
});
|
||||
|
||||
it('defaults to true', () => {
|
||||
const result = fn(testPie).value.options.series.pie.label;
|
||||
expect(result).to.have.property('show', true);
|
||||
expect(result).toHaveProperty('show', true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('labelRadius', () => {
|
||||
it('sets the radius of the label circle', () => {
|
||||
let result = fn(testPie, { labelRadius: 0 }).value.options.series.pie.label;
|
||||
expect(result).to.have.property('radius', 0);
|
||||
expect(result).toHaveProperty('radius', 0);
|
||||
|
||||
result = fn(testPie, { labelRadius: 50 }).value.options.series.pie.label;
|
||||
expect(result).to.have.property('radius', 0.5);
|
||||
expect(result).toHaveProperty('radius', 0.5);
|
||||
|
||||
result = fn(testPie, { labelRadius: 100 }).value.options.series.pie.label;
|
||||
expect(result).to.have.property('radius', 1);
|
||||
expect(result).toHaveProperty('radius', 1);
|
||||
});
|
||||
|
||||
it('defaults to 100% when given an invalid radius', () => {
|
||||
let result = fn(testPie).value.options.series.pie.label;
|
||||
expect(result).to.have.property('radius', 1);
|
||||
expect(result).toHaveProperty('radius', 1);
|
||||
|
||||
result = fn(testPie, { labelRadius: -100 }).value.options.series.pie.label;
|
||||
expect(result).to.have.property('radius', 1);
|
||||
expect(result).toHaveProperty('radius', 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('font', () => {
|
||||
it('sets the font style', () => {
|
||||
const result = fn(testPie, { font: fontStyle }).value;
|
||||
expect(result).to.have.property('font');
|
||||
expect(result.font).to.eql(fontStyle);
|
||||
expect(result).toHaveProperty('font');
|
||||
expect(result.font).toEqual(fontStyle);
|
||||
});
|
||||
|
||||
// TODO: write test when using an instance of the interpreter
|
|
@ -4,10 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { plot } from '../plot';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testPlot } from './fixtures/test_pointseries';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { testPlot } from './__tests__/fixtures/test_pointseries';
|
||||
import {
|
||||
fontStyle,
|
||||
grayscalePalette,
|
||||
|
@ -16,22 +14,22 @@ import {
|
|||
xAxisConfig,
|
||||
seriesStyle,
|
||||
defaultStyle,
|
||||
} from './fixtures/test_styles';
|
||||
} from './__tests__/fixtures/test_styles';
|
||||
import { plot } from './plot';
|
||||
|
||||
describe('plot', () => {
|
||||
const fn = functionWrapper(plot);
|
||||
|
||||
it('returns a render as plot', () => {
|
||||
const result = fn(testPlot);
|
||||
expect(result, () => {})
|
||||
.to.have.property('type', 'render')
|
||||
.and.to.have.property('as', 'plot');
|
||||
expect(result).toHaveProperty('type', 'render');
|
||||
expect(result).toHaveProperty('as', 'plot');
|
||||
});
|
||||
|
||||
describe('data', () => {
|
||||
const result = fn(testPlot).value.data;
|
||||
it('is sorted by the series labels', () => {
|
||||
expect(result.every((val, i) => (!!i ? val.label >= result[i - 1].label : true))).to.be(true);
|
||||
expect(result.every((val, i) => (!!i ? val.label >= result[i - 1].label : true))).toBe(true);
|
||||
});
|
||||
|
||||
it('has one series per unique label', () => {
|
||||
|
@ -43,24 +41,24 @@ describe('plot', () => {
|
|||
)
|
||||
.sort();
|
||||
|
||||
expect(result).to.have.length(uniqueLabels.length);
|
||||
expect(result.every((series, i) => series.label === uniqueLabels[i])).to.be(true);
|
||||
expect(result).toHaveLength(uniqueLabels.length);
|
||||
expect(result.every((series, i) => series.label === uniqueLabels[i])).toBe(true);
|
||||
});
|
||||
|
||||
it('populates the data of the plot with points from the pointseries', () => {
|
||||
expect(result[0].data).to.eql([
|
||||
expect(result[0].data).toEqual([
|
||||
[1517842800950, 605, { size: 100, text: 605 }],
|
||||
[1517929200950, 583, { size: 200, text: 583 }],
|
||||
]);
|
||||
|
||||
expect(result[1].data).to.eql([
|
||||
expect(result[1].data).toEqual([
|
||||
[1517842800950, 216, { size: 350, text: 216 }],
|
||||
[1517929200950, 200, { size: 256, text: 200 }],
|
||||
]);
|
||||
|
||||
expect(result[2].data).to.eql([[1517842800950, 67, { size: 240, text: 67 }]]);
|
||||
expect(result[2].data).toEqual([[1517842800950, 67, { size: 240, text: 67 }]]);
|
||||
|
||||
expect(result[3].data).to.eql([[1517842800950, 311, { size: 447, text: 311 }]]);
|
||||
expect(result[3].data).toEqual([[1517842800950, 311, { size: 447, text: 311 }]]);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -71,22 +69,19 @@ describe('plot', () => {
|
|||
const seriesIndex = result.data.findIndex(series => series.label === seriesStyle.label);
|
||||
const resultSeries = result.data[seriesIndex];
|
||||
|
||||
expect(resultSeries.lines)
|
||||
.to.have.property('lineWidth', seriesStyle.lines)
|
||||
.and.to.have.property('show', false)
|
||||
.and.to.have.property('fillColor', seriesStyle.color)
|
||||
.and.to.have.property('fill', seriesStyle.fill / 10);
|
||||
expect(resultSeries.lines).toHaveProperty('lineWidth', seriesStyle.lines);
|
||||
expect(resultSeries.lines).toHaveProperty('show', false);
|
||||
expect(resultSeries.lines).toHaveProperty('fillColor', seriesStyle.color);
|
||||
expect(resultSeries.lines).toHaveProperty('fill', seriesStyle.fill / 10);
|
||||
|
||||
expect(resultSeries.bars)
|
||||
.to.have.property('show', false)
|
||||
.and.to.have.property('barWidth', seriesStyle.bars)
|
||||
.and.to.have.property('horizontal', seriesStyle.horizontalBars);
|
||||
expect(resultSeries.bars).toHaveProperty('show', false);
|
||||
expect(resultSeries.bars).toHaveProperty('barWidth', seriesStyle.bars);
|
||||
expect(resultSeries.bars).toHaveProperty('horizontal', seriesStyle.horizontalBars);
|
||||
|
||||
expect(resultSeries.bubbles).to.have.property('fill', seriesStyle.fill);
|
||||
expect(resultSeries.bubbles).toHaveProperty('fill', seriesStyle.fill);
|
||||
|
||||
expect(resultSeries)
|
||||
.to.have.property('stack', seriesStyle.stack)
|
||||
.and.to.have.property('color', seriesStyle.color);
|
||||
expect(resultSeries).toHaveProperty('stack', seriesStyle.stack);
|
||||
expect(resultSeries).toHaveProperty('color', seriesStyle.color);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -95,22 +90,19 @@ describe('plot', () => {
|
|||
const results = fn(testPlot, { defaultStyle: defaultStyle });
|
||||
const defaultSeriesConfig = results.value.options.series;
|
||||
|
||||
expect(defaultSeriesConfig.lines)
|
||||
.to.have.property('lineWidth', defaultStyle.lines)
|
||||
.and.to.have.property('show', false)
|
||||
.and.to.have.property('fillColor', defaultStyle.color)
|
||||
.and.to.have.property('fill', defaultStyle.fill / 10);
|
||||
expect(defaultSeriesConfig.lines).toHaveProperty('lineWidth', defaultStyle.lines);
|
||||
expect(defaultSeriesConfig.lines).toHaveProperty('show', false);
|
||||
expect(defaultSeriesConfig.lines).toHaveProperty('fillColor', defaultStyle.color);
|
||||
expect(defaultSeriesConfig.lines).toHaveProperty('fill', defaultStyle.fill / 10);
|
||||
|
||||
expect(defaultSeriesConfig.bars)
|
||||
.to.have.property('show', false)
|
||||
.and.to.have.property('barWidth', defaultStyle.bars)
|
||||
.and.to.have.property('horizontal', defaultStyle.horizontalBars);
|
||||
expect(defaultSeriesConfig.bars).toHaveProperty('show', false);
|
||||
expect(defaultSeriesConfig.bars).toHaveProperty('barWidth', defaultStyle.bars);
|
||||
expect(defaultSeriesConfig.bars).toHaveProperty('horizontal', defaultStyle.horizontalBars);
|
||||
|
||||
expect(defaultSeriesConfig.bubbles).to.have.property('fill', defaultStyle.fill);
|
||||
expect(defaultSeriesConfig.bubbles).toHaveProperty('fill', defaultStyle.fill);
|
||||
|
||||
expect(defaultSeriesConfig)
|
||||
.to.not.have.property('stack')
|
||||
.and.to.not.have.property('color');
|
||||
expect(defaultSeriesConfig).not.toHaveProperty('stack');
|
||||
expect(defaultSeriesConfig).not.toHaveProperty('color');
|
||||
});
|
||||
|
||||
// TODO: write test when using an instance of the interpreter
|
||||
|
@ -120,14 +112,14 @@ describe('plot', () => {
|
|||
describe('palette', () => {
|
||||
it('sets the color palette', () => {
|
||||
const result = fn(testPlot, { palette: grayscalePalette }).value.options;
|
||||
expect(result).to.have.property('colors');
|
||||
expect(result.colors).to.eql(grayscalePalette.colors);
|
||||
expect(result).toHaveProperty('colors');
|
||||
expect(result.colors).toEqual(grayscalePalette.colors);
|
||||
});
|
||||
|
||||
it('creates a new set of colors from a color scale when gradient is true', () => {
|
||||
const result = fn(testPlot, { palette: gradientPalette }).value.options;
|
||||
expect(result).to.have.property('colors');
|
||||
expect(result.colors).to.eql(['#ffffff', '#aaaaaa', '#555555', '#000000']);
|
||||
expect(result).toHaveProperty('colors');
|
||||
expect(result.colors).toEqual(['#ffffff', '#aaaaaa', '#555555', '#000000']);
|
||||
});
|
||||
|
||||
// TODO: write test when using an instance of the interpreter
|
||||
|
@ -145,8 +137,8 @@ describe('plot', () => {
|
|||
family: 'Chalkboard, serif',
|
||||
color: 'pink',
|
||||
};
|
||||
expect(result.options.xaxis.font).to.eql(style);
|
||||
expect(result.options.yaxis.font).to.eql(style);
|
||||
expect(result.options.xaxis.font).toEqual(style);
|
||||
expect(result.options.yaxis.font).toEqual(style);
|
||||
});
|
||||
|
||||
// TODO: write test when using an instance of the interpreter
|
||||
|
@ -156,78 +148,75 @@ describe('plot', () => {
|
|||
describe('legend', () => {
|
||||
it('hides the legend', () => {
|
||||
const result = fn(testPlot, { legend: false }).value.options;
|
||||
expect(result.legend)
|
||||
.to.only.have.key('show')
|
||||
.and.to.have.property('show', false);
|
||||
expect(Object.keys(result.legend)).toHaveLength(1);
|
||||
expect(result.legend).toHaveProperty('show', false);
|
||||
});
|
||||
|
||||
it('sets the position of the legend', () => {
|
||||
let result = fn(testPlot, { legend: 'nw' }).value.options;
|
||||
expect(result.legend).to.have.property('position', 'nw');
|
||||
expect(result.legend).toHaveProperty('position', 'nw');
|
||||
|
||||
result = fn(testPlot, { legend: 'ne' }).value.options;
|
||||
expect(result.legend).to.have.property('position', 'ne');
|
||||
expect(result.legend).toHaveProperty('position', 'ne');
|
||||
|
||||
result = fn(testPlot, { legend: 'sw' }).value.options;
|
||||
expect(result.legend).to.have.property('position', 'sw');
|
||||
expect(result.legend).toHaveProperty('position', 'sw');
|
||||
|
||||
result = fn(testPlot, { legend: 'se' }).value.options;
|
||||
expect(result.legend).to.have.property('position', 'se');
|
||||
expect(result.legend).toHaveProperty('position', 'se');
|
||||
});
|
||||
|
||||
it("defaults to 'ne' if invalid position is provided", () => {
|
||||
let result = fn(testPlot).value.options;
|
||||
expect(result.legend).to.have.property('position', 'ne');
|
||||
expect(result.legend).toHaveProperty('position', 'ne');
|
||||
|
||||
result = fn(testPlot, { legend: true }).value.options;
|
||||
expect(result.legend).to.have.property('position', 'ne');
|
||||
expect(result.legend).toHaveProperty('position', 'ne');
|
||||
|
||||
result = fn(testPlot, { legend: 'foo' }).value.options;
|
||||
expect(result.legend).to.have.property('position', 'ne');
|
||||
expect(result.legend).toHaveProperty('position', 'ne');
|
||||
});
|
||||
});
|
||||
|
||||
describe('yaxis', () => {
|
||||
it('sets visibility of the y-axis labels', () => {
|
||||
let result = fn(testPlot, { yaxis: true }).value.options;
|
||||
expect(result.yaxis).to.have.property('show', true);
|
||||
expect(result.yaxis).toHaveProperty('show', true);
|
||||
|
||||
result = fn(testPlot, { yaxis: false }).value.options;
|
||||
expect(result.yaxis).to.have.property('show', false);
|
||||
expect(result.yaxis).toHaveProperty('show', false);
|
||||
});
|
||||
|
||||
it('configures the y-axis with an AxisConfig', () => {
|
||||
const result = fn(testPlot, { yaxis: yAxisConfig }).value.options;
|
||||
expect(result.yaxis)
|
||||
.to.have.property('show', true)
|
||||
.and.to.have.property('position', 'right');
|
||||
expect(result.yaxis).toHaveProperty('show', true);
|
||||
expect(result.yaxis).toHaveProperty('position', 'right');
|
||||
});
|
||||
|
||||
it("defaults to 'true' if not provided", () => {
|
||||
const result = fn(testPlot).value.options;
|
||||
expect(result.yaxis).to.have.property('show', true);
|
||||
expect(result.yaxis).toHaveProperty('show', true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('xaxis', () => {
|
||||
it('sets visibility of the x-axis labels', () => {
|
||||
let result = fn(testPlot, { xaxis: true }).value.options;
|
||||
expect(result.xaxis).to.have.property('show', true);
|
||||
expect(result.xaxis).toHaveProperty('show', true);
|
||||
|
||||
result = fn(testPlot, { xaxis: false }).value.options;
|
||||
expect(result.xaxis).to.have.property('show', false);
|
||||
expect(result.xaxis).toHaveProperty('show', false);
|
||||
});
|
||||
|
||||
it('configures the x-axis with an AxisConfig', () => {
|
||||
const result = fn(testPlot, { xaxis: xAxisConfig }).value.options;
|
||||
expect(result.xaxis)
|
||||
.to.have.property('show', true)
|
||||
.and.to.have.property('position', 'top');
|
||||
expect(result.xaxis).toHaveProperty('show', true);
|
||||
expect(result.xaxis).toHaveProperty('position', 'top');
|
||||
});
|
||||
|
||||
it("defaults to 'true' if not provided", () => {
|
||||
const result = fn(testPlot).value.options;
|
||||
expect(result.xaxis).to.have.property('show', true);
|
||||
expect(result.xaxis).toHaveProperty('show', true);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,11 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { ply } from '../ply';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../../strings';
|
||||
import { testTable } from './fixtures/test_tables';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../strings';
|
||||
import { testTable } from './__tests__/fixtures/test_tables';
|
||||
import { ply } from './ply';
|
||||
|
||||
const errors = getFunctionErrors().ply;
|
||||
|
||||
|
@ -52,29 +51,28 @@ describe('ply', () => {
|
|||
|
||||
return fn(testTable, { by: ['name', 'in_stock'], expression: [averagePrice, rowCount] }).then(
|
||||
result => {
|
||||
expect(result.type).to.be('datatable');
|
||||
expect(result.columns).to.eql([
|
||||
expect(result.type).toBe('datatable');
|
||||
expect(result.columns).toEqual([
|
||||
{ name: 'name', type: 'string' },
|
||||
{ name: 'in_stock', type: 'boolean' },
|
||||
{ name: 'average_price', type: 'number' },
|
||||
{ name: 'row_count', type: 'number' },
|
||||
]);
|
||||
expect(result.rows[arbitaryRowIndex])
|
||||
.to.have.property('average_price')
|
||||
.and.to.have.property('row_count');
|
||||
expect(result.rows[arbitaryRowIndex]).toHaveProperty('average_price');
|
||||
expect(result.rows[arbitaryRowIndex]).toHaveProperty('row_count');
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('missing args', () => {
|
||||
it('returns the original datatable if both args are missing', () => {
|
||||
return fn(testTable).then(result => expect(result).to.eql(testTable));
|
||||
return fn(testTable).then(result => expect(result).toEqual(testTable));
|
||||
});
|
||||
|
||||
describe('by', () => {
|
||||
it('passes the entire context into the expression when no columns are provided', () => {
|
||||
return fn(testTable, { expression: [rowCount] }).then(result =>
|
||||
expect(result).to.eql({
|
||||
expect(result).toEqual({
|
||||
type: 'datatable',
|
||||
rows: [{ row_count: testTable.rows.length }],
|
||||
columns: [{ name: 'row_count', type: 'number' }],
|
||||
|
@ -83,10 +81,11 @@ describe('ply', () => {
|
|||
});
|
||||
|
||||
it('throws when by is an invalid column', () => {
|
||||
expect(() => fn(testTable, { by: [''], expression: [averagePrice] })).to.throwException(
|
||||
expect(() => fn(testTable, { by: [''], expression: [averagePrice] })).toThrow(
|
||||
new RegExp(errors.columnNotFound('').message)
|
||||
);
|
||||
expect(() => fn(testTable, { by: ['foo'], expression: [averagePrice] })).to.throwException(
|
||||
|
||||
expect(() => fn(testTable, { by: ['foo'], expression: [averagePrice] })).toThrow(
|
||||
new RegExp(errors.columnNotFound('foo').message)
|
||||
);
|
||||
});
|
||||
|
@ -97,19 +96,17 @@ describe('ply', () => {
|
|||
const arbitaryRowIndex = 6;
|
||||
|
||||
return fn(testTable, { by: ['price', 'quantity'] }).then(result => {
|
||||
expect(result.columns[0]).to.have.property('name', 'price');
|
||||
expect(result.columns[1]).to.have.property('name', 'quantity');
|
||||
expect(result.rows[arbitaryRowIndex])
|
||||
.to.have.property('price')
|
||||
.and.to.have.property('quantity');
|
||||
expect(result.columns[0]).toHaveProperty('name', 'price');
|
||||
expect(result.columns[1]).toHaveProperty('name', 'quantity');
|
||||
expect(result.rows[arbitaryRowIndex]).toHaveProperty('price');
|
||||
expect(result.rows[arbitaryRowIndex]).toHaveProperty('quantity');
|
||||
});
|
||||
});
|
||||
|
||||
it('throws when row counts do not match across resulting datatables', () => {
|
||||
return fn(testTable, {
|
||||
by: ['name'],
|
||||
expression: [doublePrice, rowCount],
|
||||
}).catch(e => expect(e).to.eql(errors.rowCountMismatch()));
|
||||
return fn(testTable, { by: ['name'], expression: [doublePrice, rowCount] }).catch(e =>
|
||||
expect(e.message).toBe(errors.rowCountMismatch().message)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,12 +4,11 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { render } from '../render';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { DEFAULT_ELEMENT_CSS } from '../../../../common/lib/constants';
|
||||
import { testTable } from './fixtures/test_tables';
|
||||
import { fontStyle, containerStyle } from './fixtures/test_styles';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { DEFAULT_ELEMENT_CSS } from '../../../common/lib/constants';
|
||||
import { testTable } from './__tests__/fixtures/test_tables';
|
||||
import { fontStyle, containerStyle } from './__tests__/fixtures/test_styles';
|
||||
import { render } from './render';
|
||||
|
||||
const renderTable = {
|
||||
type: 'render',
|
||||
|
@ -32,19 +31,19 @@ describe('render', () => {
|
|||
containerStyle: containerStyle,
|
||||
});
|
||||
|
||||
expect(result).to.have.property('type', 'render');
|
||||
expect(result).toHaveProperty('type', 'render');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('as', () => {
|
||||
it('sets what the element will render as', () => {
|
||||
const result = fn(renderTable, { as: 'debug' });
|
||||
expect(result).to.have.property('as', 'debug');
|
||||
expect(result).toHaveProperty('as', 'debug');
|
||||
});
|
||||
|
||||
it('keep the original context.as if not specified', () => {
|
||||
const result = fn(renderTable);
|
||||
expect(result).to.have.property('as', renderTable.as);
|
||||
expect(result).toHaveProperty('as', renderTable.as);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -54,12 +53,12 @@ describe('render', () => {
|
|||
css: '".canvasRenderEl { background-color: red; }"',
|
||||
});
|
||||
|
||||
expect(result).to.have.property('css', '".canvasRenderEl { background-color: red; }"');
|
||||
expect(result).toHaveProperty('css', '".canvasRenderEl { background-color: red; }"');
|
||||
});
|
||||
|
||||
it(`defaults to '${DEFAULT_ELEMENT_CSS}'`, () => {
|
||||
const result = fn(renderTable);
|
||||
expect(result).to.have.property('css', `"${DEFAULT_ELEMENT_CSS}"`);
|
||||
expect(result).toHaveProperty('css', `"${DEFAULT_ELEMENT_CSS}"`);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -67,12 +66,12 @@ describe('render', () => {
|
|||
it('sets the containerStyler', () => {
|
||||
const result = fn(renderTable, { containerStyle: containerStyle });
|
||||
|
||||
expect(result).to.have.property('containerStyle', containerStyle);
|
||||
expect(result).toHaveProperty('containerStyle', containerStyle);
|
||||
});
|
||||
|
||||
it('returns a render object with containerStyle as undefined', () => {
|
||||
const result = fn(renderTable);
|
||||
expect(result).to.have.property('containerStyle', undefined);
|
||||
expect(result).toHaveProperty('containerStyle', '{containerStyle}');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,66 +4,64 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { repeatImage } from '../repeatImage';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { elasticOutline } from '../../../lib/elastic_outline';
|
||||
import { elasticLogo } from '../../../lib/elastic_logo';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { elasticOutline } from '../../lib/elastic_outline';
|
||||
import { elasticLogo } from '../../lib/elastic_logo';
|
||||
import { repeatImage } from './repeatImage';
|
||||
|
||||
describe('repeatImage', () => {
|
||||
const fn = functionWrapper(repeatImage);
|
||||
|
||||
it('returns a render as repeatImage', () => {
|
||||
const result = fn(10);
|
||||
expect(result)
|
||||
.to.have.property('type', 'render')
|
||||
.and.to.have.property('as', 'repeatImage');
|
||||
expect(result).toHaveProperty('type', 'render');
|
||||
expect(result).toHaveProperty('as', 'repeatImage');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('image', () => {
|
||||
it('sets the source of the repeated image', () => {
|
||||
const result = fn(10, { image: elasticLogo }).value;
|
||||
expect(result).to.have.property('image', elasticLogo);
|
||||
expect(result).toHaveProperty('image', elasticLogo);
|
||||
});
|
||||
|
||||
it('defaults to the Elastic outline logo', () => {
|
||||
const result = fn(100000).value;
|
||||
expect(result).to.have.property('image', elasticOutline);
|
||||
expect(result).toHaveProperty('image', elasticOutline);
|
||||
});
|
||||
});
|
||||
|
||||
describe('size', () => {
|
||||
it('sets the size of the image', () => {
|
||||
const result = fn(-5, { size: 200 }).value;
|
||||
expect(result).to.have.property('size', 200);
|
||||
expect(result).toHaveProperty('size', 200);
|
||||
});
|
||||
|
||||
it('defaults to 100', () => {
|
||||
const result = fn(-5).value;
|
||||
expect(result).to.have.property('size', 100);
|
||||
expect(result).toHaveProperty('size', 100);
|
||||
});
|
||||
});
|
||||
|
||||
describe('max', () => {
|
||||
it('sets the maximum number of a times the image is repeated', () => {
|
||||
const result = fn(100000, { max: 20 }).value;
|
||||
expect(result).to.have.property('max', 20);
|
||||
expect(result).toHaveProperty('max', 20);
|
||||
});
|
||||
it('defaults to 1000', () => {
|
||||
const result = fn(100000).value;
|
||||
expect(result).to.have.property('max', 1000);
|
||||
expect(result).toHaveProperty('max', 1000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('emptyImage', () => {
|
||||
it('returns repeatImage object with emptyImage as undefined', () => {
|
||||
const result = fn(100000, { emptyImage: elasticLogo }).value;
|
||||
expect(result).to.have.property('emptyImage', elasticLogo);
|
||||
expect(result).toHaveProperty('emptyImage', elasticLogo);
|
||||
});
|
||||
it('sets emptyImage to undefined', () => {
|
||||
it('sets emptyImage to null', () => {
|
||||
const result = fn(100000).value;
|
||||
expect(result).to.have.property('emptyImage', undefined);
|
||||
expect(result).toHaveProperty('emptyImage', null);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,9 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { replace } from '../replace';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { replace } from './replace';
|
||||
|
||||
describe('replace', () => {
|
||||
const fn = functionWrapper(replace);
|
||||
|
@ -18,11 +17,11 @@ describe('replace', () => {
|
|||
flags: 'gi',
|
||||
replacement: '*',
|
||||
})
|
||||
).to.be('* str*ng w*th v*w*ls');
|
||||
).toBe('* str*ng w*th v*w*ls');
|
||||
});
|
||||
|
||||
it('supports capture groups in the pattern', () => {
|
||||
expect(fn('abcABCabcABC', { pattern: '(a)(b)(c)', flags: 'ig', replacement: '$1-$2 ' })).to.be(
|
||||
expect(fn('abcABCabcABC', { pattern: '(a)(b)(c)', flags: 'ig', replacement: '$1-$2 ' })).toBe(
|
||||
'a-b A-B a-b A-B '
|
||||
);
|
||||
|
||||
|
@ -32,7 +31,7 @@ describe('replace', () => {
|
|||
flags: 'g',
|
||||
replacement: '($1)$2-$3',
|
||||
})
|
||||
).to.be('(500)948-0888, (589)786-3621, (887)486-5577, (123)456-7890');
|
||||
).toBe('(500)948-0888, (589)786-3621, (887)486-5577, (123)456-7890');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
|
@ -44,12 +43,12 @@ describe('replace', () => {
|
|||
flag: 'g',
|
||||
replacement: ',',
|
||||
})
|
||||
).to.be(',foo,bar,fizz,buzz,');
|
||||
).toBe(',foo,bar,fizz,buzz,');
|
||||
});
|
||||
|
||||
it('adds the replacement between every character if not specified (default behavior of String.replace)', () => {
|
||||
expect(fn('140000', { flags: 'g', replacement: 'X' })).to.be('X1X4X0X0X0X0X');
|
||||
expect(fn('140000', { flags: 'g', replacement: 'foo' })).to.be(
|
||||
expect(fn('140000', { flags: 'g', replacement: 'X' })).toBe('X1X4X0X0X0X0X');
|
||||
expect(fn('140000', { flags: 'g', replacement: 'foo' })).toBe(
|
||||
'foo1foo4foo0foo0foo0foo0foo'
|
||||
);
|
||||
});
|
||||
|
@ -57,23 +56,23 @@ describe('replace', () => {
|
|||
|
||||
describe('flags', () => {
|
||||
it('sets the flags for RegEx', () => {
|
||||
expect(fn('AaBbAaBb', { pattern: 'a', flags: 'ig', replacement: '_' })).to.be('__Bb__Bb');
|
||||
expect(fn('AaBbAaBb', { pattern: 'a', flags: 'i', replacement: '_' })).to.be('_aBbAaBb');
|
||||
expect(fn('AaBbAaBb', { pattern: 'a', flags: '', replacement: '_' })).to.be('A_BbAaBb');
|
||||
expect(fn('AaBbAaBb', { pattern: 'a', flags: 'ig', replacement: '_' })).toBe('__Bb__Bb');
|
||||
expect(fn('AaBbAaBb', { pattern: 'a', flags: 'i', replacement: '_' })).toBe('_aBbAaBb');
|
||||
expect(fn('AaBbAaBb', { pattern: 'a', flags: '', replacement: '_' })).toBe('A_BbAaBb');
|
||||
});
|
||||
|
||||
it("defaults to 'g' if flag is not provided", () => {
|
||||
expect(fn('This,is,a,test!', { pattern: ',', replacement: ' ' })).to.be('This is a test!');
|
||||
expect(fn('This,is,a,test!', { pattern: ',', replacement: ' ' })).toBe('This is a test!');
|
||||
});
|
||||
});
|
||||
|
||||
describe('replacement', () => {
|
||||
it('sets the replacement string for all RegEx matches', () => {
|
||||
expect(fn('140000', { pattern: '0', replacement: '1' })).to.be('141111');
|
||||
expect(fn('140000', { pattern: '0', replacement: '1' })).toBe('141111');
|
||||
});
|
||||
// TODO: put test back when using interpreter
|
||||
// it('removes matches to regex if replacement is not provided', () => {
|
||||
// expect(fn('140000', { pattern: '0' })).to.be('14');
|
||||
// expect(fn('140000', { pattern: '0' })).toBe('14');
|
||||
// });
|
||||
});
|
||||
});
|
|
@ -4,12 +4,11 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { revealImage } from '../revealImage';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { elasticOutline } from '../../../lib/elastic_outline';
|
||||
import { elasticLogo } from '../../../lib/elastic_logo';
|
||||
import { getFunctionErrors } from '../../../strings';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { elasticOutline } from '../../lib/elastic_outline';
|
||||
import { elasticLogo } from '../../lib/elastic_logo';
|
||||
import { getFunctionErrors } from '../../strings';
|
||||
import { revealImage } from './revealImage';
|
||||
|
||||
const errors = getFunctionErrors().revealImage;
|
||||
|
||||
|
@ -18,28 +17,27 @@ describe('revealImage', () => {
|
|||
|
||||
it('returns a render as revealImage', () => {
|
||||
const result = fn(0.5);
|
||||
expect(result)
|
||||
.to.have.property('type', 'render')
|
||||
.and.to.have.property('as', 'revealImage');
|
||||
expect(result).toHaveProperty('type', 'render');
|
||||
expect(result).toHaveProperty('as', 'revealImage');
|
||||
});
|
||||
|
||||
describe('context', () => {
|
||||
it('throws when context is not a number between 0 and 1', () => {
|
||||
expect(fn)
|
||||
.withArgs(10, {
|
||||
expect(() => {
|
||||
fn(10, {
|
||||
image: elasticLogo,
|
||||
emptyImage: elasticOutline,
|
||||
origin: 'top',
|
||||
})
|
||||
.to.throwException(new RegExp(errors.invalidPercent(10).message));
|
||||
});
|
||||
}).toThrow(new RegExp(errors.invalidPercent(10).message));
|
||||
|
||||
expect(fn)
|
||||
.withArgs(-0.1, {
|
||||
expect(() => {
|
||||
fn(-0.1, {
|
||||
image: elasticLogo,
|
||||
emptyImage: elasticOutline,
|
||||
origin: 'top',
|
||||
})
|
||||
.to.throwException(new RegExp(errors.invalidPercent(-0.1).message));
|
||||
});
|
||||
}).toThrow(new RegExp(errors.invalidPercent(-0.1).message));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -47,42 +45,42 @@ describe('revealImage', () => {
|
|||
describe('image', () => {
|
||||
it('sets the image', () => {
|
||||
const result = fn(0.89, { image: elasticLogo }).value;
|
||||
expect(result).to.have.property('image', elasticLogo);
|
||||
expect(result).toHaveProperty('image', elasticLogo);
|
||||
});
|
||||
|
||||
it('defaults to the Elastic outline logo', () => {
|
||||
const result = fn(0.89).value;
|
||||
expect(result).to.have.property('image', elasticOutline);
|
||||
expect(result).toHaveProperty('image', elasticOutline);
|
||||
});
|
||||
});
|
||||
|
||||
describe('emptyImage', () => {
|
||||
it('sets the background image', () => {
|
||||
const result = fn(0, { emptyImage: elasticLogo }).value;
|
||||
expect(result).to.have.property('emptyImage', elasticLogo);
|
||||
expect(result).toHaveProperty('emptyImage', elasticLogo);
|
||||
});
|
||||
|
||||
it('sets emptyImage to undefined', () => {
|
||||
it('sets emptyImage to null', () => {
|
||||
const result = fn(0).value;
|
||||
expect(result).to.have.property('emptyImage', undefined);
|
||||
expect(result).toHaveProperty('emptyImage', null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('origin', () => {
|
||||
it('sets which side to start the reveal from', () => {
|
||||
let result = fn(1, { origin: 'top' }).value;
|
||||
expect(result).to.have.property('origin', 'top');
|
||||
expect(result).toHaveProperty('origin', 'top');
|
||||
result = fn(1, { origin: 'left' }).value;
|
||||
expect(result).to.have.property('origin', 'left');
|
||||
expect(result).toHaveProperty('origin', 'left');
|
||||
result = fn(1, { origin: 'bottom' }).value;
|
||||
expect(result).to.have.property('origin', 'bottom');
|
||||
expect(result).toHaveProperty('origin', 'bottom');
|
||||
result = fn(1, { origin: 'right' }).value;
|
||||
expect(result).to.have.property('origin', 'right');
|
||||
expect(result).toHaveProperty('origin', 'right');
|
||||
});
|
||||
|
||||
it('defaults to bottom', () => {
|
||||
const result = fn(1).value;
|
||||
expect(result).to.have.property('origin', 'bottom');
|
||||
expect(result).toHaveProperty('origin', 'bottom');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,27 +4,26 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { rounddate } from '../rounddate';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { rounddate } from './rounddate';
|
||||
|
||||
describe('rounddate', () => {
|
||||
const fn = functionWrapper(rounddate);
|
||||
const date = new Date('2011-10-31T00:00:00.000Z').valueOf();
|
||||
|
||||
it('returns date in ms from date in ms or ISO8601 string', () => {
|
||||
expect(fn(date, { format: 'YYYY' })).to.be(1293840000000);
|
||||
expect(fn(date, { format: 'YYYY' })).toBe(1293840000000);
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('format', () => {
|
||||
it('sets the format for the rounded date', () => {
|
||||
expect(fn(date, { format: 'YYYY-MM' })).to.be(1317427200000);
|
||||
expect(fn(date, { format: 'YYYY-MM-DD-hh' })).to.be(1320062400000);
|
||||
expect(fn(date, { format: 'YYYY-MM' })).toBe(1317427200000);
|
||||
expect(fn(date, { format: 'YYYY-MM-DD-hh' })).toBe(1320062400000);
|
||||
});
|
||||
|
||||
it('returns original date if format is not provided', () => {
|
||||
expect(fn(date)).to.be(date);
|
||||
expect(fn(date)).toBe(date);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,16 +4,15 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { rowCount } from '../rowCount';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { emptyTable, testTable } from './fixtures/test_tables';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { emptyTable, testTable } from './__tests__/fixtures/test_tables';
|
||||
import { rowCount } from './rowCount';
|
||||
|
||||
describe('rowCount', () => {
|
||||
const fn = functionWrapper(rowCount);
|
||||
|
||||
it('returns the number of rows in the datatable', () => {
|
||||
expect(fn(testTable)).to.equal(testTable.rows.length);
|
||||
expect(fn(emptyTable)).to.equal(0);
|
||||
expect(fn(testTable)).toEqual(testTable.rows.length);
|
||||
expect(fn(emptyTable)).toEqual(0);
|
||||
});
|
||||
});
|
|
@ -4,79 +4,78 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { seriesStyle } from '../seriesStyle';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { seriesStyle } from './seriesStyle';
|
||||
|
||||
describe('seriesStyle', () => {
|
||||
const fn = functionWrapper(seriesStyle);
|
||||
|
||||
it('returns a seriesStyle', () => {
|
||||
const result = fn(null);
|
||||
expect(result).to.have.property('type', 'seriesStyle');
|
||||
expect(result).toHaveProperty('type', 'seriesStyle');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('label', () => {
|
||||
it('sets label to identify which series to style', () => {
|
||||
const result = fn(null, { label: 'kibana' });
|
||||
expect(result).to.have.property('label', 'kibana');
|
||||
expect(result).toHaveProperty('label', 'kibana');
|
||||
});
|
||||
});
|
||||
|
||||
describe('color', () => {
|
||||
it('sets color', () => {
|
||||
const result = fn(null, { color: 'purple' });
|
||||
expect(result).to.have.property('color', 'purple');
|
||||
expect(result).toHaveProperty('color', 'purple');
|
||||
});
|
||||
});
|
||||
|
||||
describe('lines', () => {
|
||||
it('sets line width', () => {
|
||||
const result = fn(null, { lines: 1 });
|
||||
expect(result).to.have.property('lines', 1);
|
||||
expect(result).toHaveProperty('lines', 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('bars', () => {
|
||||
it('sets bar width', () => {
|
||||
const result = fn(null, { bars: 3 });
|
||||
expect(result).to.have.property('bars', 3);
|
||||
expect(result).toHaveProperty('bars', 3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('points', () => {
|
||||
it('sets point size', () => {
|
||||
const result = fn(null, { points: 2 });
|
||||
expect(result).to.have.property('points', 2);
|
||||
expect(result).toHaveProperty('points', 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fill', () => {
|
||||
it('sets if series is filled', () => {
|
||||
let result = fn(null, { fill: true });
|
||||
expect(result).to.have.property('fill', true);
|
||||
expect(result).toHaveProperty('fill', true);
|
||||
|
||||
result = fn(null, { fill: false });
|
||||
expect(result).to.have.property('fill', false);
|
||||
expect(result).toHaveProperty('fill', false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('stack', () => {
|
||||
it('sets stack id to stack multiple series with a shared id', () => {
|
||||
const result = fn(null, { stack: 1 });
|
||||
expect(result).to.have.property('stack', 1);
|
||||
expect(result).toHaveProperty('stack', 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('horizontalBars', () => {
|
||||
it('sets orientation of the series to horizontal', () => {
|
||||
const result = fn(null, { horizontalBars: true });
|
||||
expect(result).to.have.property('horizontalBars', true);
|
||||
expect(result).toHaveProperty('horizontalBars', true);
|
||||
});
|
||||
it('sets orientation of the series to vertical', () => {
|
||||
const result = fn(null, { horizontalBars: false });
|
||||
expect(result).to.have.property('horizontalBars', false);
|
||||
expect(result).toHaveProperty('horizontalBars', false);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,12 +4,11 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { seriesStyleToFlot } from '../plot/series_style_to_flot';
|
||||
import { seriesStyleToFlot } from './plot/series_style_to_flot';
|
||||
|
||||
describe('seriesStyleToFlot', () => {
|
||||
it('returns an empty object if seriesStyle is not provided', () => {
|
||||
expect(seriesStyleToFlot(null)).to.be.empty();
|
||||
expect(seriesStyleToFlot(null)).toEqual({});
|
||||
});
|
||||
|
||||
const testSeriesStyle = {
|
||||
|
@ -29,11 +28,11 @@ describe('seriesStyleToFlot', () => {
|
|||
const seriesStyle = { ...testSeriesStyle, color: 'blue' };
|
||||
const result = seriesStyleToFlot(seriesStyle);
|
||||
it('sets fillColor for lines', () => {
|
||||
expect(result.lines).to.have.property('fillColor', 'blue');
|
||||
expect(result.lines).toHaveProperty('fillColor', 'blue');
|
||||
});
|
||||
|
||||
it('sets color', () => {
|
||||
expect(result).to.have.property('color', 'blue');
|
||||
expect(result).toHaveProperty('color', 'blue');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -41,12 +40,12 @@ describe('seriesStyleToFlot', () => {
|
|||
describe('sets show', () => {
|
||||
it('hides line graphs when line width <= 0', () => {
|
||||
const seriesStyle = { ...testSeriesStyle };
|
||||
expect(seriesStyleToFlot(seriesStyle).lines).to.have.property('show', false);
|
||||
expect(seriesStyleToFlot(seriesStyle).lines).toHaveProperty('show', false);
|
||||
});
|
||||
|
||||
it('shows line graphs when line width > 0', () => {
|
||||
const seriesStyle = { ...testSeriesStyle, lines: 1 };
|
||||
expect(seriesStyleToFlot(seriesStyle).lines).to.have.property('show', true);
|
||||
expect(seriesStyleToFlot(seriesStyle).lines).toHaveProperty('show', true);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -54,15 +53,15 @@ describe('seriesStyleToFlot', () => {
|
|||
it('sets the line width', () => {
|
||||
const seriesStyle = { ...testSeriesStyle };
|
||||
let result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.lines).to.have.property('lineWidth', 0);
|
||||
expect(result.lines).toHaveProperty('lineWidth', 0);
|
||||
|
||||
seriesStyle.lines = 1;
|
||||
result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.lines).to.have.property('lineWidth', 1);
|
||||
expect(result.lines).toHaveProperty('lineWidth', 1);
|
||||
|
||||
seriesStyle.lines = 10;
|
||||
result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.lines).to.have.property('lineWidth', 10);
|
||||
expect(result.lines).toHaveProperty('lineWidth', 10);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -71,12 +70,12 @@ describe('seriesStyleToFlot', () => {
|
|||
describe('sets show', () => {
|
||||
it('hides bar graphs when bar width <= 0', () => {
|
||||
const seriesStyle = { ...testSeriesStyle };
|
||||
expect(seriesStyleToFlot(seriesStyle).bars).to.have.property('show', false);
|
||||
expect(seriesStyleToFlot(seriesStyle).bars).toHaveProperty('show', false);
|
||||
});
|
||||
|
||||
it('shows bar graphs when bar width > 0', () => {
|
||||
const seriesStyle = { ...testSeriesStyle, bars: 1 };
|
||||
expect(seriesStyleToFlot(seriesStyle).bars).to.have.property('show', true);
|
||||
expect(seriesStyleToFlot(seriesStyle).bars).toHaveProperty('show', true);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -84,15 +83,15 @@ describe('seriesStyleToFlot', () => {
|
|||
it('sets the bar width', () => {
|
||||
const seriesStyle = { ...testSeriesStyle };
|
||||
let result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.bars).to.have.property('barWidth', 0);
|
||||
expect(result.bars).toHaveProperty('barWidth', 0);
|
||||
|
||||
seriesStyle.bars = 1;
|
||||
result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.bars).to.have.property('barWidth', 1);
|
||||
expect(result.bars).toHaveProperty('barWidth', 1);
|
||||
|
||||
seriesStyle.bars = 10;
|
||||
result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.bars).to.have.property('barWidth', 10);
|
||||
expect(result.bars).toHaveProperty('barWidth', 10);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -101,21 +100,21 @@ describe('seriesStyleToFlot', () => {
|
|||
it('sets opacity of fill for line graphs', () => {
|
||||
const seriesStyle = { ...testSeriesStyle, fill: 10 };
|
||||
let result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.lines).to.have.property('fill', 1);
|
||||
expect(result.lines).toHaveProperty('fill', 1);
|
||||
|
||||
seriesStyle.fill = 5;
|
||||
result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.lines).to.have.property('fill', 0.5);
|
||||
expect(result.lines).toHaveProperty('fill', 0.5);
|
||||
});
|
||||
|
||||
it('sets fill of bubbles', () => {
|
||||
const seriesStyle = { ...testSeriesStyle, fill: 10 };
|
||||
let result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.bubbles).to.have.property('fill', 10);
|
||||
expect(result.bubbles).toHaveProperty('fill', 10);
|
||||
|
||||
seriesStyle.fill = 5;
|
||||
result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.bubbles).to.have.property('fill', 5);
|
||||
expect(result.bubbles).toHaveProperty('fill', 5);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -123,11 +122,11 @@ describe('seriesStyleToFlot', () => {
|
|||
it('sets stack', () => {
|
||||
const seriesStyle = { ...testSeriesStyle, stack: 1 };
|
||||
let result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result).to.have.property('stack', 1);
|
||||
expect(result).toHaveProperty('stack', 1);
|
||||
|
||||
seriesStyle.stack = 5;
|
||||
result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result).to.have.property('stack', 5);
|
||||
expect(result).toHaveProperty('stack', 5);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -135,11 +134,11 @@ describe('seriesStyleToFlot', () => {
|
|||
it('sets the orientation of the bar graph', () => {
|
||||
const seriesStyle = { ...testSeriesStyle };
|
||||
let result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.bars).to.have.property('horizontal', false);
|
||||
expect(result.bars).toHaveProperty('horizontal', false);
|
||||
|
||||
seriesStyle.horizontalBars = true;
|
||||
result = seriesStyleToFlot(seriesStyle);
|
||||
expect(result.bars).to.have.property('horizontal', true);
|
||||
expect(result.bars).toHaveProperty('horizontal', true);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { sort } from '../sort';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './fixtures/test_tables';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './__tests__/fixtures/test_tables';
|
||||
import { sort } from './sort';
|
||||
|
||||
describe('sort', () => {
|
||||
const fn = functionWrapper(sort);
|
||||
|
@ -22,9 +21,9 @@ describe('sort', () => {
|
|||
it('returns a datatable sorted by a specified column in asc order', () => {
|
||||
const result = fn(testTable, { by: 'price', reverse: false });
|
||||
|
||||
expect(result.type).to.be('datatable');
|
||||
expect(result.columns).to.eql(testTable.columns);
|
||||
expect(isSorted(result.rows, 'price', false)).to.be(true);
|
||||
expect(result.type).toBe('datatable');
|
||||
expect(result.columns).toEqual(testTable.columns);
|
||||
expect(isSorted(result.rows, 'price', false)).toBe(true);
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
|
@ -32,17 +31,17 @@ describe('sort', () => {
|
|||
it('sorts on a specified column', () => {
|
||||
const result = fn(testTable, { by: 'quantity', reverse: true });
|
||||
|
||||
expect(isSorted(result.rows, 'quantity', true)).to.be(true);
|
||||
expect(isSorted(result.rows, 'quantity', true)).toBe(true);
|
||||
});
|
||||
|
||||
it('sorts on the first column if not specified', () => {
|
||||
const result = fn(testTable, { reverse: false });
|
||||
|
||||
expect(isSorted(result.rows, result.columns[0].name, false)).to.be(true);
|
||||
expect(isSorted(result.rows, result.columns[0].name, false)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns the original datatable if given an invalid column', () => {
|
||||
expect(fn(testTable, { by: 'foo' })).to.eql(testTable);
|
||||
expect(fn(testTable, { by: 'foo' })).toEqual(testTable);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -50,19 +49,19 @@ describe('sort', () => {
|
|||
it('sorts in asc order', () => {
|
||||
const result = fn(testTable, { by: 'in_stock', reverse: false });
|
||||
|
||||
expect(isSorted(result.rows, 'in_stock', false)).to.be(true);
|
||||
expect(isSorted(result.rows, 'in_stock', false)).toBe(true);
|
||||
});
|
||||
|
||||
it('sorts in desc order', () => {
|
||||
const result = fn(testTable, { by: 'price', reverse: true });
|
||||
|
||||
expect(isSorted(result.rows, 'price', true)).to.be(true);
|
||||
expect(isSorted(result.rows, 'price', true)).toBe(true);
|
||||
});
|
||||
|
||||
it('sorts in asc order by default', () => {
|
||||
const result = fn(testTable, { by: 'time' });
|
||||
|
||||
expect(isSorted(result.rows, 'time', false)).to.be(true);
|
||||
expect(isSorted(result.rows, 'time', false)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,10 +4,9 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { staticColumn } from '../staticColumn';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable, emptyTable } from './fixtures/test_tables';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable, emptyTable } from './__tests__/fixtures/test_tables';
|
||||
import { staticColumn } from './staticColumn';
|
||||
|
||||
describe('staticColumn', () => {
|
||||
const fn = functionWrapper(staticColumn);
|
||||
|
@ -15,34 +14,34 @@ describe('staticColumn', () => {
|
|||
it('adds a column to a datatable with a static value in every row', () => {
|
||||
const result = fn(testTable, { name: 'foo', value: 'bar' });
|
||||
|
||||
expect(result.type).to.be('datatable');
|
||||
expect(result.columns).to.eql([...testTable.columns, { name: 'foo', type: 'string' }]);
|
||||
expect(result.rows.every(row => typeof row.foo === 'string')).to.be(true);
|
||||
expect(result.rows.every(row => row.foo === 'bar')).to.be(true);
|
||||
expect(result.type).toBe('datatable');
|
||||
expect(result.columns).toEqual([...testTable.columns, { name: 'foo', type: 'string' }]);
|
||||
expect(result.rows.every(row => typeof row.foo === 'string')).toBe(true);
|
||||
expect(result.rows.every(row => row.foo === 'bar')).toBe(true);
|
||||
});
|
||||
|
||||
it('overwrites an existing column if provided an existing column name', () => {
|
||||
const result = fn(testTable, { name: 'name', value: 'John' });
|
||||
|
||||
expect(result.type).to.be('datatable');
|
||||
expect(result.columns).to.eql(testTable.columns);
|
||||
expect(result.rows.every(row => typeof row.name === 'string')).to.be(true);
|
||||
expect(result.rows.every(row => row.name === 'John')).to.be(true);
|
||||
expect(result.type).toBe('datatable');
|
||||
expect(result.columns).toEqual(testTable.columns);
|
||||
expect(result.rows.every(row => typeof row.name === 'string')).toBe(true);
|
||||
expect(result.rows.every(row => row.name === 'John')).toBe(true);
|
||||
});
|
||||
|
||||
it('adds a column with null values', () => {
|
||||
const result = fn(testTable, { name: 'empty' });
|
||||
|
||||
expect(result.type).to.be('datatable');
|
||||
expect(result.columns).to.eql([...testTable.columns, { name: 'empty', type: 'null' }]);
|
||||
expect(result.rows.every(row => row.empty === null)).to.be(true);
|
||||
expect(result.type).toBe('datatable');
|
||||
expect(result.columns).toEqual([...testTable.columns, { name: 'empty', type: 'null' }]);
|
||||
expect(result.rows.every(row => row.empty === null)).toBe(true);
|
||||
});
|
||||
|
||||
it('adds a column to empty tables', () => {
|
||||
const result = fn(emptyTable, { name: 'empty', value: 1 });
|
||||
|
||||
expect(result.type).to.be('datatable');
|
||||
expect(result.columns).to.eql([{ name: 'empty', type: 'number' }]);
|
||||
expect(result.rows.length).to.be(0);
|
||||
expect(result.type).toBe('datatable');
|
||||
expect(result.columns).toEqual([{ name: 'empty', type: 'number' }]);
|
||||
expect(result.rows.length).toBe(0);
|
||||
});
|
||||
});
|
|
@ -4,22 +4,21 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { string } from '../string';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { string } from './string';
|
||||
|
||||
describe('string', () => {
|
||||
const fn = functionWrapper(string);
|
||||
|
||||
it('casts primitive types to strings', () => {
|
||||
expect(fn(null, { value: [14000] })).to.be('14000');
|
||||
expect(fn(null, { value: ['foo'] })).to.be('foo');
|
||||
expect(fn(null, { value: [null] })).to.be('');
|
||||
expect(fn(null, { value: [true] })).to.be('true');
|
||||
expect(fn(null, { value: [14000] })).toBe('14000');
|
||||
expect(fn(null, { value: ['foo'] })).toBe('foo');
|
||||
expect(fn(null, { value: [null] })).toBe('');
|
||||
expect(fn(null, { value: [true] })).toBe('true');
|
||||
});
|
||||
|
||||
it('concatenates all args to one string', () => {
|
||||
expect(fn(null, { value: ['foo', 'bar', 'fizz', 'buzz'] })).to.be('foobarfizzbuzz');
|
||||
expect(fn(null, { value: ['foo', 1, true, null] })).to.be('foo1true');
|
||||
expect(fn(null, { value: ['foo', 'bar', 'fizz', 'buzz'] })).toBe('foobarfizzbuzz');
|
||||
expect(fn(null, { value: ['foo', 1, true, null] })).toBe('foo1true');
|
||||
});
|
||||
});
|
|
@ -4,9 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { switchFn } from '../switch';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { switchFn } from './switch';
|
||||
|
||||
describe('switch', () => {
|
||||
const fn = functionWrapper(switchFn);
|
||||
|
@ -42,7 +41,7 @@ describe('switch', () => {
|
|||
|
||||
describe('spec', () => {
|
||||
it('is a function', () => {
|
||||
expect(fn).to.be.a('function');
|
||||
expect(typeof fn).toBe('function');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -50,13 +49,13 @@ describe('switch', () => {
|
|||
describe('with no cases', () => {
|
||||
it('should return the context if no default is provided', async () => {
|
||||
const context = 'foo';
|
||||
expect(await fn(context, {})).to.be(context);
|
||||
expect(await fn(context, {})).toBe(context);
|
||||
});
|
||||
|
||||
it('should return the default if provided', async () => {
|
||||
const context = 'foo';
|
||||
const args = { default: () => 'bar' };
|
||||
expect(await fn(context, args)).to.be(args.default());
|
||||
expect(await fn(context, args)).toBe(args.default());
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -64,7 +63,7 @@ describe('switch', () => {
|
|||
it('should return the context if no default is provided', async () => {
|
||||
const context = 'foo';
|
||||
const args = { case: nonMatchingCases.map(getter) };
|
||||
expect(await fn(context, args)).to.be(context);
|
||||
expect(await fn(context, args)).toBe(context);
|
||||
});
|
||||
|
||||
it('should return the default if provided', async () => {
|
||||
|
@ -73,7 +72,7 @@ describe('switch', () => {
|
|||
case: nonMatchingCases.map(getter),
|
||||
default: () => 'bar',
|
||||
};
|
||||
expect(await fn(context, args)).to.be(args.default());
|
||||
expect(await fn(context, args)).toBe(args.default());
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -82,7 +81,7 @@ describe('switch', () => {
|
|||
const context = 'foo';
|
||||
const args = { case: mockCases.map(getter) };
|
||||
const firstMatch = mockCases.find(c => c.matches);
|
||||
expect(await fn(context, args)).to.be(firstMatch.result);
|
||||
expect(await fn(context, args)).toBe(firstMatch.result);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,11 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { table } from '../table';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './fixtures/test_tables';
|
||||
import { fontStyle } from './fixtures/test_styles';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './__tests__/fixtures/test_tables';
|
||||
import { fontStyle } from './__tests__/fixtures/test_styles';
|
||||
import { table } from './table';
|
||||
|
||||
describe('table', () => {
|
||||
const fn = functionWrapper(table);
|
||||
|
@ -19,15 +18,14 @@ describe('table', () => {
|
|||
paginate: false,
|
||||
perPage: 2,
|
||||
});
|
||||
expect(result)
|
||||
.to.have.property('type', 'render')
|
||||
.and.to.have.property('as', 'table');
|
||||
expect(result).toHaveProperty('type', 'render');
|
||||
expect(result).toHaveProperty('as', 'table');
|
||||
});
|
||||
|
||||
describe('context', () => {
|
||||
it('sets the context as the datatable', () => {
|
||||
const result = fn(testTable).value;
|
||||
expect(result).to.have.property('datatable', testTable);
|
||||
expect(result).toHaveProperty('datatable', testTable);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -35,51 +33,51 @@ describe('table', () => {
|
|||
describe('font', () => {
|
||||
it('sets the font style of the table', () => {
|
||||
const result = fn(testTable, { font: fontStyle }).value;
|
||||
expect(result).to.have.property('font', fontStyle);
|
||||
expect(result).toHaveProperty('font', fontStyle);
|
||||
});
|
||||
|
||||
it('defaults to a Canvas expression that calls the font function', () => {
|
||||
const result = fn(testTable).value;
|
||||
expect(result).to.have.property('font', '{font}'); // should evaluate to a font object and not a string
|
||||
expect(result).toHaveProperty('font', '{font}'); // should evaluate to a font object and not a string
|
||||
});
|
||||
});
|
||||
|
||||
describe('paginate', () => {
|
||||
it('sets whether or not to paginate the table', () => {
|
||||
let result = fn(testTable, { paginate: true }).value;
|
||||
expect(result).to.have.property('paginate', true);
|
||||
expect(result).toHaveProperty('paginate', true);
|
||||
|
||||
result = fn(testTable, { paginate: false }).value;
|
||||
expect(result).to.have.property('paginate', false);
|
||||
expect(result).toHaveProperty('paginate', false);
|
||||
});
|
||||
|
||||
it('defaults to true', () => {
|
||||
const result = fn(testTable).value;
|
||||
expect(result).to.have.property('paginate', true);
|
||||
expect(result).toHaveProperty('paginate', true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('perPage', () => {
|
||||
it('sets how many rows display per page', () => {
|
||||
const result = fn(testTable, { perPage: 30 }).value;
|
||||
expect(result).to.have.property('perPage', 30);
|
||||
expect(result).toHaveProperty('perPage', 30);
|
||||
});
|
||||
|
||||
it('defaults to 10', () => {
|
||||
const result = fn(testTable).value;
|
||||
expect(result).to.have.property('perPage', 10);
|
||||
expect(result).toHaveProperty('perPage', 10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('showHeader', () => {
|
||||
it('sets the showHeader property', () => {
|
||||
const result = fn(testTable, { showHeader: false }).value;
|
||||
expect(result).to.have.property('showHeader', false);
|
||||
expect(result).toHaveProperty('showHeader', false);
|
||||
});
|
||||
|
||||
it('defaults to true', () => {
|
||||
const result = fn(testTable).value;
|
||||
expect(result).to.have.property('showHeader', true);
|
||||
expect(result).toHaveProperty('showHeader', true);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { emptyTable, testTable } from './__tests__/fixtures/test_tables';
|
||||
import { tail } from './tail';
|
||||
|
||||
describe('tail', () => {
|
||||
const fn = functionWrapper(tail);
|
||||
const lastIndex = testTable.rows.length - 1;
|
||||
|
||||
it('returns a datatable with the last N rows of the context', () => {
|
||||
const result = fn(testTable, { count: 2 });
|
||||
|
||||
expect(result.type).toBe('datatable');
|
||||
expect(result.columns).toEqual(testTable.columns);
|
||||
expect(result.rows).toHaveLength(2);
|
||||
expect(result.rows[0]).toEqual(testTable.rows[lastIndex - 1]);
|
||||
expect(result.rows[1]).toEqual(testTable.rows[lastIndex]);
|
||||
});
|
||||
|
||||
it('returns the original context if N >= context.rows.length', () => {
|
||||
expect(fn(testTable, { count: testTable.rows.length + 5 })).toEqual(testTable);
|
||||
expect(fn(testTable, { count: testTable.rows.length })).toEqual(testTable);
|
||||
expect(fn(emptyTable)).toEqual(emptyTable);
|
||||
});
|
||||
|
||||
it('returns the last row if N is not specified', () => {
|
||||
const result = fn(testTable);
|
||||
|
||||
expect(result.rows).toHaveLength(1);
|
||||
expect(result.rows[0]).toEqual(testTable.rows[lastIndex]);
|
||||
});
|
||||
});
|
|
@ -4,12 +4,11 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import sinon from 'sinon';
|
||||
import { timefilter } from '../timefilter';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../../strings';
|
||||
import { emptyFilter } from './fixtures/test_filters';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { getFunctionErrors } from '../../strings';
|
||||
import { emptyFilter } from './__tests__/fixtures/test_filters';
|
||||
import { timefilter } from './timefilter';
|
||||
|
||||
const errors = getFunctionErrors().timefilter;
|
||||
|
||||
|
@ -35,7 +34,7 @@ describe('timefilter', () => {
|
|||
from: fromDate,
|
||||
to: toDate,
|
||||
})
|
||||
).to.have.property('type', 'filter');
|
||||
).toHaveProperty('type', 'filter');
|
||||
});
|
||||
|
||||
it("adds a time object to 'and'", () => {
|
||||
|
@ -45,35 +44,35 @@ describe('timefilter', () => {
|
|||
from: fromDate,
|
||||
to: toDate,
|
||||
}).and[0]
|
||||
).to.have.property('type', 'time');
|
||||
).toHaveProperty('type', 'time');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
it("returns the original context if neither 'from' nor 'to' is provided", () => {
|
||||
expect(fn(emptyFilter, { column: 'time' })).to.eql(emptyFilter);
|
||||
expect(fn(emptyFilter, { column: 'time' })).toEqual(emptyFilter);
|
||||
});
|
||||
|
||||
describe('column', () => {
|
||||
it('sets the column to apply the filter to', () => {
|
||||
expect(fn(emptyFilter, { column: 'time', from: 'now' }).and[0]).to.have.property(
|
||||
expect(fn(emptyFilter, { column: 'time', from: 'now' }).and[0]).toHaveProperty(
|
||||
'column',
|
||||
'time'
|
||||
);
|
||||
});
|
||||
|
||||
it("defaults column to '@timestamp'", () => {
|
||||
expect(fn(emptyFilter, { from: 'now' }).and[0]).to.have.property('column', '@timestamp');
|
||||
expect(fn(emptyFilter, { from: 'now' }).and[0]).toHaveProperty('column', '@timestamp');
|
||||
});
|
||||
});
|
||||
|
||||
describe('from', () => {
|
||||
it('sets the start date', () => {
|
||||
let result = fn(emptyFilter, { from: fromDate });
|
||||
expect(result.and[0]).to.have.property('from', fromDate);
|
||||
expect(result.and[0]).toHaveProperty('from', fromDate);
|
||||
|
||||
result = fn(emptyFilter, { from: 'now-5d' });
|
||||
const dateOffset = 24 * 60 * 60 * 1000 * 5; //5 days
|
||||
expect(result.and[0]).to.have.property(
|
||||
expect(result.and[0]).toHaveProperty(
|
||||
'from',
|
||||
new Date(new Date().getTime() - dateOffset).toISOString()
|
||||
);
|
||||
|
@ -83,14 +82,14 @@ describe('timefilter', () => {
|
|||
describe('to', () => {
|
||||
it('sets the end date', () => {
|
||||
let result = fn(emptyFilter, { to: toDate });
|
||||
expect(result.and[0]).to.have.property('to', toDate);
|
||||
expect(result.and[0]).toHaveProperty('to', toDate);
|
||||
|
||||
result = fn(emptyFilter, { to: 'now' });
|
||||
expect(result.and[0]).to.have.property('to', new Date().toISOString());
|
||||
expect(result.and[0]).toHaveProperty('to', new Date().toISOString());
|
||||
});
|
||||
|
||||
it('throws when provided an invalid date string', () => {
|
||||
expect(() => fn(emptyFilter, { from: '2018-13-42T15:00:00.950Z' })).to.throwException(
|
||||
expect(() => fn(emptyFilter, { from: '2018-13-42T15:00:00.950Z' })).toThrow(
|
||||
new RegExp(errors.invalidString('2018-13-42T15:00:00.950Z').message)
|
||||
);
|
||||
});
|
|
@ -4,33 +4,31 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { timefilterControl } from '../timefilterControl';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { timefilterControl } from './timefilterControl';
|
||||
|
||||
describe('timefilterControl', () => {
|
||||
const fn = functionWrapper(timefilterControl);
|
||||
|
||||
it('returns a render as time_filter', () => {
|
||||
expect(fn(null, { column: 'time', compact: false }))
|
||||
.to.have.property('type', 'render')
|
||||
.and.to.have.property('as', 'time_filter');
|
||||
expect(fn(null, { column: 'time', compact: false })).toHaveProperty('type', 'render');
|
||||
expect(fn(null, { column: 'time', compact: false })).toHaveProperty('as', 'time_filter');
|
||||
});
|
||||
|
||||
describe('args', () => {
|
||||
describe('column', () => {
|
||||
it('set the column the filter is applied to', () => {
|
||||
expect(fn(null, { column: 'time' }).value).to.have.property('column', 'time');
|
||||
expect(fn(null, { column: 'time' }).value).toHaveProperty('column', 'time');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('set if time filter displays in compact mode', () => {
|
||||
expect(fn(null, { compact: false }).value).to.have.property('compact', false);
|
||||
expect(fn(null, { compact: true }).value).to.have.property('compact', true);
|
||||
expect(fn(null, { compact: false }).value).toHaveProperty('compact', false);
|
||||
expect(fn(null, { compact: true }).value).toHaveProperty('compact', true);
|
||||
});
|
||||
|
||||
it('defaults time filter display to compact mode', () => {
|
||||
expect(fn(null).value).to.have.property('compact', true);
|
||||
expect(fn(null).value).toHaveProperty('compact', true);
|
||||
});
|
||||
});
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { demodata } from '../demodata';
|
||||
import { getFunctionErrors } from '../../../strings';
|
||||
|
||||
const errors = getFunctionErrors().demodata;
|
||||
|
||||
const nullFilter = {
|
||||
type: 'filter',
|
||||
meta: {},
|
||||
size: null,
|
||||
sort: [],
|
||||
and: [],
|
||||
};
|
||||
|
||||
const fn = demodata().fn;
|
||||
|
||||
describe('demodata', () => {
|
||||
it('ci, different object references', () => {
|
||||
const ci1 = fn(nullFilter, { type: 'ci' });
|
||||
const ci2 = fn(nullFilter, { type: 'ci' });
|
||||
expect(ci1).not.to.equal(ci2);
|
||||
expect(ci1.rows).not.to.equal(ci2.rows);
|
||||
expect(ci1.rows[0]).not.to.equal(ci2.rows[0]);
|
||||
});
|
||||
it('shirts, different object references', () => {
|
||||
const shirts1 = fn(nullFilter, { type: 'shirts' });
|
||||
const shirts2 = fn(nullFilter, { type: 'shirts' });
|
||||
expect(shirts1).not.to.be.equal(shirts2);
|
||||
expect(shirts1.rows).not.to.be.equal(shirts2.rows);
|
||||
expect(shirts1.rows[0]).not.to.be.equal(shirts2.rows[0]);
|
||||
});
|
||||
it('invalid set', () => {
|
||||
expect(fn)
|
||||
.withArgs(null, { type: 'foo' })
|
||||
.to.throwException(new RegExp(errors.invalidDataSet('foo').message));
|
||||
});
|
||||
});
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { getExpressionType } from '../pointseries/lib/get_expression_type';
|
||||
import { emptyTable, testTable } from '../../common/__tests__/fixtures/test_tables';
|
||||
|
||||
describe('getExpressionType', () => {
|
||||
it('returns the result type of an evaluated math expression', () => {
|
||||
expect(getExpressionType(testTable.columns, '2')).to.be.equal('number');
|
||||
expect(getExpressionType(testTable.colunns, '2 + 3')).to.be.equal('number');
|
||||
expect(getExpressionType(testTable.columns, 'name')).to.be.equal('string');
|
||||
expect(getExpressionType(testTable.columns, 'time')).to.be.equal('date');
|
||||
expect(getExpressionType(testTable.columns, 'price')).to.be.equal('number');
|
||||
expect(getExpressionType(testTable.columns, 'quantity')).to.be.equal('number');
|
||||
expect(getExpressionType(testTable.columns, 'in_stock')).to.be.equal('boolean');
|
||||
expect(getExpressionType(testTable.columns, 'mean(price)')).to.be.equal('number');
|
||||
expect(getExpressionType(testTable.columns, 'count(name)')).to.be.equal('string');
|
||||
expect(getExpressionType(testTable.columns, 'random()')).to.be.equal('number');
|
||||
expect(getExpressionType(testTable.columns, 'mean(multiply(price,quantity))')).to.be.eql(
|
||||
'number'
|
||||
);
|
||||
});
|
||||
it('returns date instead of number when referencing date column', () => {
|
||||
expect(getExpressionType(testTable.columns, 'mean(time)')).to.be.equal('date');
|
||||
});
|
||||
it(`returns 'null' if referenced field does not exist in datatable`, () => {
|
||||
expect(getExpressionType(testTable.columns, 'foo')).to.be.equal('null');
|
||||
expect(getExpressionType(emptyTable.columns, 'foo')).to.be.equal('null');
|
||||
expect(getExpressionType(emptyTable.columns, 'mean(foo)')).to.be.equal('string');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { demodata } from './demodata';
|
||||
|
||||
const nullFilter = {
|
||||
type: 'filter',
|
||||
meta: {},
|
||||
size: null,
|
||||
sort: [],
|
||||
and: [],
|
||||
};
|
||||
|
||||
const fn = demodata().fn;
|
||||
|
||||
describe('demodata', () => {
|
||||
it('ci, different object references', () => {
|
||||
const ci1 = fn(nullFilter, { type: 'ci' }, {});
|
||||
const ci2 = fn(nullFilter, { type: 'ci' }, {});
|
||||
expect(ci1).not.toBe(ci2);
|
||||
expect(ci1.rows).not.toBe(ci2.rows);
|
||||
expect(ci1.rows[0]).not.toBe(ci2.rows[0]);
|
||||
});
|
||||
it('shirts, different object references', () => {
|
||||
const shirts1 = fn(nullFilter, { type: 'shirts' }, {});
|
||||
const shirts2 = fn(nullFilter, { type: 'shirts' }, {});
|
||||
expect(shirts1).not.toBe(shirts2);
|
||||
expect(shirts1.rows).not.toBe(shirts2.rows);
|
||||
expect(shirts1.rows[0]).not.toBe(shirts2.rows[0]);
|
||||
});
|
||||
it('invalid set', () => {
|
||||
expect(() => {
|
||||
fn(nullFilter, { type: 'foo' }, {});
|
||||
}).toThrowError("Invalid data set: 'foo', use 'ci' or 'shirts'.");
|
||||
});
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { emptyTable, testTable } from '../common/__tests__/fixtures/test_tables';
|
||||
import { getExpressionType } from './pointseries/lib/get_expression_type';
|
||||
|
||||
describe('getExpressionType', () => {
|
||||
it('returns the result type of an evaluated math expression', () => {
|
||||
expect(getExpressionType(testTable.columns, '2')).toBe('number');
|
||||
expect(getExpressionType(testTable.colunns, '2 + 3')).toBe('number');
|
||||
expect(getExpressionType(testTable.columns, 'name')).toBe('string');
|
||||
expect(getExpressionType(testTable.columns, 'time')).toBe('date');
|
||||
expect(getExpressionType(testTable.columns, 'price')).toBe('number');
|
||||
expect(getExpressionType(testTable.columns, 'quantity')).toBe('number');
|
||||
expect(getExpressionType(testTable.columns, 'in_stock')).toBe('boolean');
|
||||
expect(getExpressionType(testTable.columns, 'mean(price)')).toBe('number');
|
||||
expect(getExpressionType(testTable.columns, 'count(name)')).toBe('string');
|
||||
expect(getExpressionType(testTable.columns, 'random()')).toBe('number');
|
||||
expect(getExpressionType(testTable.columns, 'mean(multiply(price,quantity))')).toBe('number');
|
||||
});
|
||||
it('returns date instead of number when referencing date column', () => {
|
||||
expect(getExpressionType(testTable.columns, 'mean(time)')).toBe('date');
|
||||
});
|
||||
it(`returns 'null' if referenced field does not exist in datatable`, () => {
|
||||
expect(getExpressionType(testTable.columns, 'foo')).toBe('null');
|
||||
expect(getExpressionType(emptyTable.columns, 'foo')).toBe('null');
|
||||
expect(getExpressionType(emptyTable.columns, 'mean(foo)')).toBe('string');
|
||||
});
|
||||
});
|
|
@ -4,18 +4,18 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
// @ts-ignore untyped library
|
||||
import { parse } from 'tinymath';
|
||||
import { getFieldNames } from '../pointseries/lib/get_field_names';
|
||||
import { getFieldNames } from './pointseries/lib/get_field_names';
|
||||
|
||||
describe('getFieldNames', () => {
|
||||
it('returns array of field names referenced in a parsed math object', () => {
|
||||
expect(getFieldNames([], parse('2+3'))).to.be.eql([]);
|
||||
expect(getFieldNames([], parse('mean(foo)'))).to.be.eql(['foo']);
|
||||
expect(getFieldNames([], parse('max(foo + bar)'))).to.be.eql(['foo', 'bar']);
|
||||
expect(getFieldNames([], parse('count(foo) + count(bar)'))).to.be.eql(['foo', 'bar']);
|
||||
expect(getFieldNames([], parse('2+3'))).toEqual([]);
|
||||
expect(getFieldNames([], parse('mean(foo)'))).toEqual(['foo']);
|
||||
expect(getFieldNames([], parse('max(foo + bar)'))).toEqual(['foo', 'bar']);
|
||||
expect(getFieldNames([], parse('count(foo) + count(bar)'))).toEqual(['foo', 'bar']);
|
||||
expect(
|
||||
getFieldNames([], parse('sum(count(foo),count(bar),count(fizz),count(buzz),2,3,4)'))
|
||||
).to.be.eql(['foo', 'bar', 'fizz', 'buzz']);
|
||||
).toEqual(['foo', 'bar', 'fizz', 'buzz']);
|
||||
});
|
||||
});
|
|
@ -4,16 +4,15 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { isColumnReference } from '../pointseries/lib/is_column_reference';
|
||||
import { isColumnReference } from './pointseries/lib/is_column_reference';
|
||||
|
||||
describe('isColumnReference', () => {
|
||||
it('get a string result after parsing math expression', () => {
|
||||
expect(isColumnReference('field')).to.be(true);
|
||||
expect(isColumnReference('field')).toBe(true);
|
||||
});
|
||||
it('non-string', () => {
|
||||
expect(isColumnReference('2')).to.be(false);
|
||||
expect(isColumnReference('mean(field)')).to.be(false);
|
||||
expect(isColumnReference('field * 3')).to.be(false);
|
||||
expect(isColumnReference('2')).toBe(false);
|
||||
expect(isColumnReference('mean(field)')).toBe(false);
|
||||
expect(isColumnReference('field * 3')).toBe(false);
|
||||
});
|
||||
});
|
|
@ -4,30 +4,29 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { pointseries } from '../pointseries';
|
||||
import { emptyTable, testTable } from '../../common/__tests__/fixtures/test_tables';
|
||||
import { emptyTable, testTable } from '../common/__tests__/fixtures/test_tables';
|
||||
import { pointseries } from './pointseries';
|
||||
|
||||
describe('pointseries', () => {
|
||||
const fn = pointseries().fn;
|
||||
|
||||
describe('function', () => {
|
||||
it('empty datatable, null args', () => {
|
||||
expect(fn(emptyTable, { x: null, y: null })).to.be.eql({
|
||||
expect(fn(emptyTable, { x: null, y: null })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {},
|
||||
rows: [],
|
||||
});
|
||||
});
|
||||
it('empty datatable, invalid args', () => {
|
||||
expect(fn(emptyTable, { x: 'name', y: 'price' })).to.be.eql({
|
||||
expect(fn(emptyTable, { x: 'name', y: 'price' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {},
|
||||
rows: [],
|
||||
});
|
||||
});
|
||||
it('args with constants only', () => {
|
||||
expect(fn(testTable, { x: '1', y: '2' })).to.be.eql({
|
||||
expect(fn(testTable, { x: '1', y: '2' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: { type: 'number', role: 'measure', expression: '1' },
|
||||
|
@ -37,7 +36,7 @@ describe('pointseries', () => {
|
|||
});
|
||||
});
|
||||
it('args with dimensions only', () => {
|
||||
expect(fn(testTable, { x: 'name', y: 'price', size: 'quantity' })).to.be.eql({
|
||||
expect(fn(testTable, { x: 'name', y: 'price', size: 'quantity' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: {
|
||||
|
@ -70,7 +69,7 @@ describe('pointseries', () => {
|
|||
});
|
||||
});
|
||||
it('args including measures', () => {
|
||||
expect(fn(testTable, { x: 'name', y: 'mean(price)', size: 'mean(quantity)' })).to.be.eql({
|
||||
expect(fn(testTable, { x: 'name', y: 'mean(price)', size: 'mean(quantity)' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: {
|
||||
|
@ -97,7 +96,7 @@ describe('pointseries', () => {
|
|||
{ x: 'product5', y: 288, size: 384 },
|
||||
],
|
||||
});
|
||||
expect(fn(testTable, { x: 'name', y: 'max(price * quantity + 2)' })).to.be.eql({
|
||||
expect(fn(testTable, { x: 'name', y: 'max(price * quantity + 2)' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: {
|
||||
|
@ -119,7 +118,7 @@ describe('pointseries', () => {
|
|||
{ x: 'product5', y: 110594 },
|
||||
],
|
||||
});
|
||||
expect(fn(testTable, { x: 'name', y: 'count(price)' })).to.be.eql({
|
||||
expect(fn(testTable, { x: 'name', y: 'count(price)' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: {
|
||||
|
@ -141,7 +140,7 @@ describe('pointseries', () => {
|
|||
{ x: 'product5', y: 1 },
|
||||
],
|
||||
});
|
||||
expect(fn(testTable, { x: 'unique(name)' })).to.be.eql({
|
||||
expect(fn(testTable, { x: 'unique(name)' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: {
|
||||
|
@ -155,8 +154,8 @@ describe('pointseries', () => {
|
|||
});
|
||||
it('args including random()', () => {
|
||||
const randomPointseries = fn(testTable, { x: 'time', y: 'random()' });
|
||||
expect(randomPointseries).to.have.property('type', 'pointseries');
|
||||
expect(randomPointseries.columns).to.be.eql({
|
||||
expect(randomPointseries).toHaveProperty('type', 'pointseries');
|
||||
expect(randomPointseries.columns).toEqual({
|
||||
x: { type: 'date', role: 'dimension', expression: 'time' },
|
||||
y: {
|
||||
type: 'number',
|
||||
|
@ -165,12 +164,13 @@ describe('pointseries', () => {
|
|||
},
|
||||
});
|
||||
randomPointseries.rows.map((row, i) => {
|
||||
expect(row.x).to.be(testTable.rows[i].time);
|
||||
expect(row.y).to.be.within(0, 1);
|
||||
expect(row.x).toBe(testTable.rows[i].time);
|
||||
expect(row.y).toBeGreaterThanOrEqual(0);
|
||||
expect(row.y).toBeLessThanOrEqual(1);
|
||||
});
|
||||
});
|
||||
it('empty string arg', () => {
|
||||
expect(fn(testTable, { x: 'name', y: 'max(time)', size: ' ', text: '' })).to.be.eql({
|
||||
expect(fn(testTable, { x: 'name', y: 'max(time)', size: ' ', text: '' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: {
|
||||
|
@ -194,7 +194,7 @@ describe('pointseries', () => {
|
|||
});
|
||||
});
|
||||
it('ignores missing columns', () => {
|
||||
expect(fn(testTable, { x: 'name', y: 'notInTheTable' })).to.be.eql({
|
||||
expect(fn(testTable, { x: 'name', y: 'notInTheTable' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: {
|
||||
|
@ -211,12 +211,12 @@ describe('pointseries', () => {
|
|||
{ x: 'product5' },
|
||||
],
|
||||
});
|
||||
expect(fn(testTable, { y: 'notInTheTable' })).to.be.eql({
|
||||
expect(fn(testTable, { y: 'notInTheTable' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {},
|
||||
rows: [{}],
|
||||
});
|
||||
expect(fn(testTable, { x: 'name', y: 'mean(notInTheTable)' })).to.be.eql({
|
||||
expect(fn(testTable, { x: 'name', y: 'mean(notInTheTable)' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: {
|
||||
|
@ -240,7 +240,7 @@ describe('pointseries', () => {
|
|||
});
|
||||
});
|
||||
it('invalid args', () => {
|
||||
expect(fn(testTable, { x: 'name', y: 'quantity * 3' })).to.be.eql({
|
||||
expect(fn(testTable, { x: 'name', y: 'quantity * 3' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: {
|
||||
|
@ -262,7 +262,7 @@ describe('pointseries', () => {
|
|||
{ x: 'product5', y: null },
|
||||
],
|
||||
});
|
||||
expect(fn(testTable, { x: 'time', y: 'sum(notInTheTable)' })).to.be.eql({
|
||||
expect(fn(testTable, { x: 'time', y: 'sum(notInTheTable)' })).toEqual({
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: { type: 'date', role: 'dimension', expression: 'time' },
|
|
@ -4,8 +4,16 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export function getFieldNames(names, arg) {
|
||||
if (arg.args != null) {
|
||||
type Arg =
|
||||
| string
|
||||
| number
|
||||
| {
|
||||
name: string;
|
||||
args: Arg[];
|
||||
};
|
||||
|
||||
export function getFieldNames(names: string[], arg: Arg): string[] {
|
||||
if (typeof arg === 'object' && arg.args !== undefined) {
|
||||
return names.concat(arg.args.reduce(getFieldNames, []));
|
||||
}
|
||||
|
|
@ -4,9 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
// @ts-ignore Untyped Library
|
||||
import { parse } from 'tinymath';
|
||||
|
||||
export function isColumnReference(mathExpression) {
|
||||
export function isColumnReference(mathExpression: string | null): boolean {
|
||||
if (mathExpression == null) {
|
||||
mathExpression = 'null';
|
||||
}
|
|
@ -4,4 +4,4 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
require('./_helpers').runXPackScript('jest', ['plugins/canvas']);
|
||||
require('./_helpers').runXPackScript('jest', ['legacy/plugins/canvas']);
|
||||
|
|
|
@ -16,6 +16,7 @@ function getPluginPaths(plugins, opts = {}) {
|
|||
|
||||
return plugins.reduce((paths, pluginName) => {
|
||||
const plugin = pluginName.trim();
|
||||
|
||||
const commonPath = `${plugin}/common`;
|
||||
const serverPath = `${plugin}/**/server`;
|
||||
const publicPath = `${plugin}/**/public`;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue