mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
This commit is contained in:
parent
a3574c281c
commit
f600edaf9c
4 changed files with 22 additions and 4 deletions
|
@ -7,7 +7,7 @@
|
|||
import expect from 'expect.js';
|
||||
import { mapColumn } from '../mapColumn';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './fixtures/test_tables';
|
||||
import { testTable, emptyTable } from './fixtures/test_tables';
|
||||
|
||||
const pricePlusTwo = datatable => Promise.resolve(datatable.rows[0].price + 2);
|
||||
|
||||
|
@ -42,6 +42,16 @@ describe('mapColumn', () => {
|
|||
});
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
describe('expression', () => {
|
||||
it('maps null values to the new column', () => {
|
||||
return fn(testTable, { name: 'empty' }).then(result => {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
import expect from 'expect.js';
|
||||
import { staticColumn } from '../staticColumn';
|
||||
import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper';
|
||||
import { testTable } from './fixtures/test_tables';
|
||||
import { testTable, emptyTable } from './fixtures/test_tables';
|
||||
|
||||
describe('staticColumn', () => {
|
||||
const fn = functionWrapper(staticColumn);
|
||||
|
@ -37,4 +37,12 @@ describe('staticColumn', () => {
|
|||
expect(result.columns).to.eql([...testTable.columns, { name: 'empty', type: 'null' }]);
|
||||
expect(result.rows.every(row => row.empty === null)).to.be(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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -47,7 +47,7 @@ export const mapColumn = () => ({
|
|||
|
||||
return Promise.all(rowPromises).then(rows => {
|
||||
const existingColumnIndex = columns.findIndex(({ name }) => name === args.name);
|
||||
const type = getType(rows[0][args.name]);
|
||||
const type = rows.length ? getType(rows[0][args.name]) : 'null';
|
||||
const newColumn = { name: args.name, type };
|
||||
if (existingColumnIndex === -1) {
|
||||
columns.push(newColumn);
|
||||
|
|
|
@ -29,7 +29,7 @@ export const staticColumn = () => ({
|
|||
},
|
||||
fn: (context, args) => {
|
||||
const rows = context.rows.map(row => ({ ...row, [args.name]: args.value }));
|
||||
const type = getType(rows[0][args.name]);
|
||||
const type = getType(args.value);
|
||||
const columns = [...context.columns];
|
||||
const existingColumnIndex = columns.findIndex(({ name }) => name === args.name);
|
||||
const newColumn = { name: args.name, type };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue