mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[canvas] migrate tests away from karma (#73121)
Co-authored-by: spalger <spalger@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
6631a296ef
commit
d66cc3515c
23 changed files with 311 additions and 657 deletions
|
@ -1,25 +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 React from 'react';
|
||||
import expect from '@kbn/expect';
|
||||
import { shallow } from 'enzyme';
|
||||
import { EuiLoadingSpinner, EuiIcon } from '@elastic/eui';
|
||||
import { Loading } from '../loading';
|
||||
|
||||
describe('<Loading />', () => {
|
||||
it('uses EuiIcon by default', () => {
|
||||
const wrapper = shallow(<Loading />);
|
||||
expect(wrapper.contains(<EuiIcon />)).to.be.ok;
|
||||
expect(wrapper.contains(<EuiLoadingSpinner />)).to.not.be.ok;
|
||||
});
|
||||
|
||||
it('uses EuiLoadingSpinner when animating', () => {
|
||||
const wrapper = shallow(<Loading animated />);
|
||||
expect(wrapper.contains(<EuiIcon />)).to.not.be.ok;
|
||||
expect(wrapper.contains(<EuiLoadingSpinner />)).to.be.ok;
|
||||
});
|
||||
});
|
|
@ -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 React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { Loading } from './loading';
|
||||
|
||||
describe('<Loading />', () => {
|
||||
it('uses EuiIcon by default', () => {
|
||||
expect(shallow(<Loading />)).toMatchInlineSnapshot(`
|
||||
<div
|
||||
className="canvasLoading"
|
||||
>
|
||||
<EuiIcon
|
||||
color="ghost"
|
||||
type="clock"
|
||||
/>
|
||||
</div>
|
||||
`);
|
||||
});
|
||||
|
||||
it('uses EuiLoadingSpinner when animating', () => {
|
||||
expect(shallow(<Loading animated />)).toMatchInlineSnapshot(`
|
||||
<div
|
||||
className="canvasLoading"
|
||||
>
|
||||
<EuiLoadingSpinner
|
||||
size="m"
|
||||
/>
|
||||
</div>
|
||||
`);
|
||||
});
|
||||
});
|
|
@ -1,28 +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 { functionWrapper } from '../../../__tests__/helpers/function_wrapper';
|
||||
import { asset } from '../asset';
|
||||
|
||||
// TODO: restore this test
|
||||
// will require the ability to mock the store, or somehow remove the function's dependency on getState
|
||||
describe.skip('asset', () => {
|
||||
const fn = functionWrapper(asset);
|
||||
|
||||
it('throws if asset could not be retrieved by ID', () => {
|
||||
const throwsErr = () => {
|
||||
return fn(null, { id: 'boo' });
|
||||
};
|
||||
expect(throwsErr).to.throwException((err) => {
|
||||
expect(err.message).to.be('Could not get the asset by ID: boo');
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the asset for found asset ID', () => {
|
||||
expect(fn(null, { id: 'yay' })).to.be('here is your image');
|
||||
});
|
||||
});
|
|
@ -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 'expect.js';
|
||||
// import proxyquire from 'proxyquire';
|
||||
// import { Registry } from '../../../common/lib/registry';
|
||||
|
||||
// const registries = {
|
||||
// datasource: new Registry(),
|
||||
// transform: new Registry(),
|
||||
// model: new Registry(),
|
||||
// view: new Registry(),
|
||||
// };
|
||||
|
||||
// const { findExpressionType } = proxyquire.noCallThru().load('../find_expression_type', {
|
||||
// '../expression_types/datasource': {
|
||||
// datasourceRegistry: registries.datasource,
|
||||
// },
|
||||
// '../expression_types/transform': {
|
||||
// transformRegistry: registries.transform,
|
||||
// },
|
||||
// '../expression_types/model': {
|
||||
// modelRegistry: registries.model,
|
||||
// },
|
||||
// '../expression_types/view': {
|
||||
// viewRegistry: registries.view,
|
||||
// },
|
||||
// });
|
||||
|
||||
// describe('findExpressionType', () => {
|
||||
// let expTypes;
|
||||
|
||||
// beforeEach(() => {
|
||||
// expTypes = [];
|
||||
// const keys = Object.keys(registries);
|
||||
// keys.forEach(key => {
|
||||
// const reg = registries[key];
|
||||
// reg.reset();
|
||||
|
||||
// const expObj = () => ({
|
||||
// name: `__test_${key}`,
|
||||
// key,
|
||||
// });
|
||||
// expTypes.push(expObj);
|
||||
// reg.register(expObj);
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('all types', () => {
|
||||
// it('returns the matching item, by name', () => {
|
||||
// const match = findExpressionType('__test_model');
|
||||
// expect(match).to.eql(expTypes[2]());
|
||||
// });
|
||||
|
||||
// it('returns null when nothing is found', () => {
|
||||
// const match = findExpressionType('@@nope_nope_nope');
|
||||
// expect(match).to.equal(null);
|
||||
// });
|
||||
|
||||
// it('throws with multiple matches', () => {
|
||||
// const commonName = 'commonName';
|
||||
// registries.transform.register(() => ({
|
||||
// name: commonName,
|
||||
// }));
|
||||
// registries.model.register(() => ({
|
||||
// name: commonName,
|
||||
// }));
|
||||
|
||||
// const check = () => {
|
||||
// findExpressionType(commonName);
|
||||
// };
|
||||
// expect(check).to.throwException(/Found multiple expressions/i);
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('specific type', () => {
|
||||
// it('return the match item, by name and type', () => {
|
||||
// const match = findExpressionType('__test_view', 'view');
|
||||
// expect(match).to.eql(expTypes[3]());
|
||||
// });
|
||||
|
||||
// it('returns null with no match by name and type', () => {
|
||||
// const match = findExpressionType('__test_view', 'datasource');
|
||||
// expect(match).to.equal(null);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// TODO: restore this test
|
||||
// proxyquire can not be used to inject mock registries
|
||||
|
||||
describe.skip('findExpressionType', () => {});
|
|
@ -1,240 +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 lzString from 'lz-string';
|
||||
import { historyProvider } from '../history_provider';
|
||||
|
||||
function createState() {
|
||||
return {
|
||||
transient: {
|
||||
selectedPage: 'page-f3ce-4bb7-86c8-0417606d6592',
|
||||
selectedToplevelNodes: ['element-d88c-4bbd-9453-db22e949b92e'],
|
||||
resolvedArgs: {},
|
||||
},
|
||||
persistent: {
|
||||
schemaVersion: 0,
|
||||
time: new Date().getTime(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe.skip('historyProvider', () => {
|
||||
let history;
|
||||
let state;
|
||||
|
||||
beforeEach(() => {
|
||||
history = historyProvider();
|
||||
state = createState();
|
||||
});
|
||||
|
||||
describe('instances', () => {
|
||||
it('should return the same instance for the same window object', () => {
|
||||
expect(historyProvider()).to.equal(history);
|
||||
});
|
||||
|
||||
it('should return different instance for different window object', () => {
|
||||
const newWindow = {};
|
||||
expect(historyProvider(newWindow)).not.to.be(history);
|
||||
});
|
||||
});
|
||||
|
||||
describe('push updates', () => {
|
||||
beforeEach(() => {
|
||||
history.push(state);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// reset state back to initial after each test
|
||||
history.undo();
|
||||
});
|
||||
|
||||
describe('push', () => {
|
||||
it('should add state to location', () => {
|
||||
expect(history.getLocation().state).to.eql(state);
|
||||
});
|
||||
|
||||
it('should push compressed state into history', () => {
|
||||
const hist = history.historyInstance;
|
||||
expect(hist.location.state).to.equal(lzString.compress(JSON.stringify(state)));
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('undo', () => {
|
||||
it('should move history back', () => {
|
||||
// pushed location has state value
|
||||
expect(history.getLocation().state).to.eql(state);
|
||||
|
||||
// back to initial location with null state
|
||||
history.undo();
|
||||
expect(history.getLocation().state).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('redo', () => {
|
||||
it('should move history forward', () => {
|
||||
// back to initial location, with null state
|
||||
history.undo();
|
||||
expect(history.getLocation().state).to.be(null);
|
||||
|
||||
// return to pushed location, with state value
|
||||
history.redo();
|
||||
expect(history.getLocation().state).to.eql(state);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('replace updates', () => {
|
||||
beforeEach(() => {
|
||||
history.replace(state);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// reset history to default after each test
|
||||
history.replace(null);
|
||||
});
|
||||
|
||||
describe('replace', () => {
|
||||
it('should replace state in window history', () => {
|
||||
expect(history.getLocation().state).to.eql(state);
|
||||
});
|
||||
|
||||
it('should replace compressed state into history', () => {
|
||||
const hist = history.historyInstance;
|
||||
expect(hist.location.state).to.equal(lzString.compress(JSON.stringify(state)));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('onChange', () => {
|
||||
const createOnceHandler = (history, done, fn) => {
|
||||
const teardown = history.onChange((location, prevLocation) => {
|
||||
if (typeof fn === 'function') {
|
||||
fn(location, prevLocation);
|
||||
}
|
||||
teardown();
|
||||
done();
|
||||
});
|
||||
};
|
||||
|
||||
it('should return a method to remove the listener', () => {
|
||||
const handler = () => 'hello world';
|
||||
const teardownFn = history.onChange(handler);
|
||||
|
||||
expect(teardownFn).to.be.a('function');
|
||||
|
||||
// teardown the listener
|
||||
teardownFn();
|
||||
});
|
||||
|
||||
it('should call handler on state change', (done) => {
|
||||
createOnceHandler(history, done, (loc) => {
|
||||
expect(loc).to.be.a('object');
|
||||
});
|
||||
|
||||
history.push({});
|
||||
});
|
||||
|
||||
it('should pass location object to handler', (done) => {
|
||||
createOnceHandler(history, done, (location) => {
|
||||
expect(location.pathname).to.be.a('string');
|
||||
expect(location.hash).to.be.a('string');
|
||||
expect(location.state).to.be.an('object');
|
||||
expect(location.action).to.equal('push');
|
||||
});
|
||||
|
||||
history.push(state);
|
||||
});
|
||||
|
||||
it('should pass decompressed state to handler', (done) => {
|
||||
createOnceHandler(history, done, ({ state: curState }) => {
|
||||
expect(curState).to.eql(state);
|
||||
});
|
||||
|
||||
history.push(state);
|
||||
});
|
||||
|
||||
it('should pass in the previous location object to handler', (done) => {
|
||||
createOnceHandler(history, done, (location, prevLocation) => {
|
||||
expect(prevLocation.pathname).to.be.a('string');
|
||||
expect(prevLocation.hash).to.be.a('string');
|
||||
expect(prevLocation.state).to.be(null);
|
||||
expect(prevLocation.action).to.equal('push');
|
||||
});
|
||||
|
||||
history.push(state);
|
||||
});
|
||||
});
|
||||
|
||||
describe('resetOnChange', () => {
|
||||
// the history onChange handler was made async and now there's no way to know when the handler was called
|
||||
// TODO: restore these tests.
|
||||
it.skip('removes listeners', () => {
|
||||
const createHandler = () => {
|
||||
let callCount = 0;
|
||||
|
||||
function handlerFn() {
|
||||
callCount += 1;
|
||||
}
|
||||
handlerFn.getCallCount = () => callCount;
|
||||
|
||||
return handlerFn;
|
||||
};
|
||||
|
||||
const handler1 = createHandler();
|
||||
const handler2 = createHandler();
|
||||
|
||||
// attach and test the first handler
|
||||
history.onChange(handler1);
|
||||
|
||||
expect(handler1.getCallCount()).to.equal(0);
|
||||
history.push({});
|
||||
expect(handler1.getCallCount()).to.equal(1);
|
||||
|
||||
// attach and test the second handler
|
||||
history.onChange(handler2);
|
||||
|
||||
expect(handler2.getCallCount()).to.equal(0);
|
||||
history.push({});
|
||||
expect(handler1.getCallCount()).to.equal(2);
|
||||
expect(handler2.getCallCount()).to.equal(1);
|
||||
|
||||
// remove all handlers
|
||||
history.resetOnChange();
|
||||
history.push({});
|
||||
expect(handler1.getCallCount()).to.equal(2);
|
||||
expect(handler2.getCallCount()).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parse', () => {
|
||||
it('returns the decompressed object', () => {
|
||||
history.push(state);
|
||||
|
||||
const hist = history.historyInstance;
|
||||
const rawState = hist.location.state;
|
||||
|
||||
expect(rawState).to.be.a('string');
|
||||
expect(history.parse(rawState)).to.eql(state);
|
||||
});
|
||||
|
||||
it('returns null with invalid JSON', () => {
|
||||
expect(history.parse('hello')).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('encode', () => {
|
||||
it('returns the compressed string', () => {
|
||||
history.push(state);
|
||||
|
||||
const hist = history.historyInstance;
|
||||
const rawState = hist.location.state;
|
||||
|
||||
expect(rawState).to.be.a('string');
|
||||
expect(history.encode(state)).to.eql(rawState);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,34 +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 { prepend, append } from '../modify_path';
|
||||
|
||||
describe('modify paths', () => {
|
||||
describe('prepend', () => {
|
||||
it('prepends a string path', () => {
|
||||
expect(prepend('a.b.c', '0')).to.eql([0, 'a', 'b', 'c']);
|
||||
expect(prepend('a.b.c', ['0', '1'])).to.eql([0, 1, 'a', 'b', 'c']);
|
||||
});
|
||||
|
||||
it('prepends an array path', () => {
|
||||
expect(prepend(['a', 1, 'last'], '0')).to.eql([0, 'a', 1, 'last']);
|
||||
expect(prepend(['a', 1, 'last'], [0, 1])).to.eql([0, 1, 'a', 1, 'last']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('append', () => {
|
||||
it('appends to a string path', () => {
|
||||
expect(append('one.2.3', 'zero')).to.eql(['one', 2, 3, 'zero']);
|
||||
expect(append('one.2.3', ['zero', 'one'])).to.eql(['one', 2, 3, 'zero', 'one']);
|
||||
});
|
||||
|
||||
it('appends to an array path', () => {
|
||||
expect(append(['testString'], 'huzzah')).to.eql(['testString', 'huzzah']);
|
||||
expect(append(['testString'], ['huzzah', 'yosh'])).to.eql(['testString', 'huzzah', 'yosh']);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,7 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getPrettyShortcut } from '../get_pretty_shortcut';
|
||||
import { getPrettyShortcut } from './get_pretty_shortcut';
|
||||
|
||||
describe('getPrettyShortcut', () => {
|
||||
test('uppercases shortcuts', () => {
|
33
x-pack/plugins/canvas/public/lib/modify_path.test.ts
Normal file
33
x-pack/plugins/canvas/public/lib/modify_path.test.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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 { prepend, append } from './modify_path';
|
||||
|
||||
describe('modify paths', () => {
|
||||
describe('prepend', () => {
|
||||
it('prepends a string path', () => {
|
||||
expect(prepend('a.b.c', '0')).toEqual(['0', 'a', 'b', 'c']);
|
||||
expect(prepend('a.b.c', ['0', '1'])).toEqual(['0', '1', 'a', 'b', 'c']);
|
||||
});
|
||||
|
||||
it('prepends an array path', () => {
|
||||
expect(prepend(['a', 1, 'last'], '0')).toEqual(['0', 'a', '1', 'last']);
|
||||
expect(prepend(['a', 1, 'last'], [0, 1])).toEqual(['0', '1', 'a', '1', 'last']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('append', () => {
|
||||
it('appends to a string path', () => {
|
||||
expect(append('one.2.3', 'zero')).toEqual(['one', '2', '3', 'zero']);
|
||||
expect(append('one.2.3', ['zero', 'one'])).toEqual(['one', '2', '3', 'zero', 'one']);
|
||||
});
|
||||
|
||||
it('appends to an array path', () => {
|
||||
expect(append(['testString'], 'huzzah')).toEqual(['testString', 'huzzah']);
|
||||
expect(append(['testString'], ['huzzah', 'yosh'])).toEqual(['testString', 'huzzah', 'yosh']);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -6,14 +6,16 @@
|
|||
|
||||
import { toPath } from 'lodash';
|
||||
|
||||
export function prepend(path, value) {
|
||||
export type Path = Array<string | number>;
|
||||
|
||||
export function prepend(path: string | Path, value: string | Path): Path {
|
||||
return toPath(value).concat(toPath(path));
|
||||
}
|
||||
|
||||
export function append(path, value) {
|
||||
export function append(path: string | Path, value: string | Path): Path {
|
||||
return toPath(path).concat(toPath(value));
|
||||
}
|
||||
|
||||
export function convert(path) {
|
||||
export function convert(path: string | Path): Path {
|
||||
return toPath(path);
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { readableColor } from '../readable_color';
|
||||
import { readableColor } from './readable_color';
|
||||
|
||||
describe('readableColor', () => {
|
||||
test('light', () => {
|
|
@ -4,39 +4,38 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { getState, getValue, getError } from '../resolved_arg';
|
||||
import { getState, getValue, getError } from './resolved_arg';
|
||||
|
||||
describe('resolved arg helper', () => {
|
||||
describe('getState', () => {
|
||||
it('returns pending by default', () => {
|
||||
expect(getState()).to.be(null);
|
||||
expect(getState()).toBe(null);
|
||||
});
|
||||
|
||||
it('returns the state', () => {
|
||||
expect(getState({ state: 'pending' })).to.equal('pending');
|
||||
expect(getState({ state: 'ready' })).to.equal('ready');
|
||||
expect(getState({ state: 'error' })).to.equal('error');
|
||||
expect(getState({ state: 'pending' })).toEqual('pending');
|
||||
expect(getState({ state: 'ready' })).toEqual('ready');
|
||||
expect(getState({ state: 'error' })).toEqual('error');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getValue', () => {
|
||||
it('returns null by default', () => {
|
||||
expect(getValue()).to.be(null);
|
||||
expect(getValue()).toBe(null);
|
||||
});
|
||||
|
||||
it('returns the value', () => {
|
||||
expect(getValue({ value: 'hello test' })).to.equal('hello test');
|
||||
expect(getValue({ value: 'hello test' })).toEqual('hello test');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getError', () => {
|
||||
it('returns null by default', () => {
|
||||
expect(getError()).to.be(null);
|
||||
expect(getError()).toBe(null);
|
||||
});
|
||||
|
||||
it('returns null when state is not error', () => {
|
||||
expect(getError({ state: 'pending', error: 'nope' })).to.be(null);
|
||||
expect(getError({ state: 'pending', error: 'nope' })).toBe(null);
|
||||
});
|
||||
|
||||
it('returns the error', () => {
|
||||
|
@ -46,8 +45,7 @@ describe('resolved arg helper', () => {
|
|||
error: new Error('i failed'),
|
||||
};
|
||||
|
||||
expect(getError(arg)).to.be.an(Error);
|
||||
expect(getError(arg).toString()).to.match(/i failed/);
|
||||
expect(getError(arg)).toMatchInlineSnapshot(`[Error: i failed]`);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -6,15 +6,15 @@
|
|||
|
||||
import { get } from 'lodash';
|
||||
|
||||
export function getState(resolvedArg) {
|
||||
export function getState(resolvedArg?: any): any {
|
||||
return get(resolvedArg, 'state', null);
|
||||
}
|
||||
|
||||
export function getValue(resolvedArg) {
|
||||
export function getValue(resolvedArg?: any): any {
|
||||
return get(resolvedArg, 'value', null);
|
||||
}
|
||||
|
||||
export function getError(resolvedArg) {
|
||||
export function getError(resolvedArg?: any): any {
|
||||
if (getState(resolvedArg) !== 'error') {
|
||||
return null;
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getTimeInterval, createTimeInterval, isValidTimeInterval } from '../time_interval';
|
||||
import { getTimeInterval, createTimeInterval, isValidTimeInterval } from './time_interval';
|
||||
|
||||
describe('time_interval', () => {
|
||||
test('getTimeInterval', () => {
|
|
@ -1,107 +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 { getSiblingContext } from '../elements';
|
||||
|
||||
const state = {
|
||||
transient: {
|
||||
resolvedArgs: {
|
||||
'element-foo': {
|
||||
expressionContext: {
|
||||
'0': {
|
||||
state: 'ready',
|
||||
value: {
|
||||
type: 'datatable',
|
||||
columns: [
|
||||
{ name: 'project', type: 'string' },
|
||||
{ name: 'cost', type: 'string' },
|
||||
{ name: 'age', type: 'string' },
|
||||
],
|
||||
rows: [
|
||||
{ project: 'pandas', cost: '500', age: '18' },
|
||||
{ project: 'tigers', cost: '200', age: '12' },
|
||||
],
|
||||
},
|
||||
error: null,
|
||||
},
|
||||
'1': {
|
||||
state: 'ready',
|
||||
value: {
|
||||
type: 'datatable',
|
||||
columns: [
|
||||
{ name: 'project', type: 'string' },
|
||||
{ name: 'cost', type: 'string' },
|
||||
{ name: 'age', type: 'string' },
|
||||
],
|
||||
rows: [
|
||||
{ project: 'tigers', cost: '200', age: '12' },
|
||||
{ project: 'pandas', cost: '500', age: '18' },
|
||||
],
|
||||
},
|
||||
error: null,
|
||||
},
|
||||
'2': {
|
||||
state: 'ready',
|
||||
value: {
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: { type: 'string', role: 'dimension', expression: 'cost' },
|
||||
y: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
color: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
},
|
||||
rows: [
|
||||
{ x: '200', y: 'tigers', color: 'tigers' },
|
||||
{ x: '500', y: 'pandas', color: 'pandas' },
|
||||
],
|
||||
},
|
||||
error: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
describe('actions/elements getSiblingContext', () => {
|
||||
it('should find context when a previous context value is found', () => {
|
||||
// pointseries map
|
||||
expect(getSiblingContext(state, 'element-foo', 2)).to.eql({
|
||||
index: 2,
|
||||
context: {
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: { type: 'string', role: 'dimension', expression: 'cost' },
|
||||
y: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
color: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
},
|
||||
rows: [
|
||||
{ x: '200', y: 'tigers', color: 'tigers' },
|
||||
{ x: '500', y: 'pandas', color: 'pandas' },
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should find context when a previous context value is not found', () => {
|
||||
// pointseries map
|
||||
expect(getSiblingContext(state, 'element-foo', 1000)).to.eql({
|
||||
index: 2,
|
||||
context: {
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: { type: 'string', role: 'dimension', expression: 'cost' },
|
||||
y: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
color: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
},
|
||||
rows: [
|
||||
{ x: '200', y: 'tigers', color: 'tigers' },
|
||||
{ x: '500', y: 'pandas', color: 'pandas' },
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
106
x-pack/plugins/canvas/public/state/actions/elements.test.js
Normal file
106
x-pack/plugins/canvas/public/state/actions/elements.test.js
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* 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 { getSiblingContext } from './elements';
|
||||
|
||||
describe('getSiblingContext', () => {
|
||||
const state = {
|
||||
transient: {
|
||||
resolvedArgs: {
|
||||
'element-foo': {
|
||||
expressionContext: {
|
||||
'0': {
|
||||
state: 'ready',
|
||||
value: {
|
||||
type: 'datatable',
|
||||
columns: [
|
||||
{ name: 'project', type: 'string' },
|
||||
{ name: 'cost', type: 'string' },
|
||||
{ name: 'age', type: 'string' },
|
||||
],
|
||||
rows: [
|
||||
{ project: 'pandas', cost: '500', age: '18' },
|
||||
{ project: 'tigers', cost: '200', age: '12' },
|
||||
],
|
||||
},
|
||||
error: null,
|
||||
},
|
||||
'1': {
|
||||
state: 'ready',
|
||||
value: {
|
||||
type: 'datatable',
|
||||
columns: [
|
||||
{ name: 'project', type: 'string' },
|
||||
{ name: 'cost', type: 'string' },
|
||||
{ name: 'age', type: 'string' },
|
||||
],
|
||||
rows: [
|
||||
{ project: 'tigers', cost: '200', age: '12' },
|
||||
{ project: 'pandas', cost: '500', age: '18' },
|
||||
],
|
||||
},
|
||||
error: null,
|
||||
},
|
||||
'2': {
|
||||
state: 'ready',
|
||||
value: {
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: { type: 'string', role: 'dimension', expression: 'cost' },
|
||||
y: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
color: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
},
|
||||
rows: [
|
||||
{ x: '200', y: 'tigers', color: 'tigers' },
|
||||
{ x: '500', y: 'pandas', color: 'pandas' },
|
||||
],
|
||||
},
|
||||
error: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
it('should find context when a previous context value is found', () => {
|
||||
// pointseries map
|
||||
expect(getSiblingContext(state, 'element-foo', 2)).toEqual({
|
||||
index: 2,
|
||||
context: {
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: { type: 'string', role: 'dimension', expression: 'cost' },
|
||||
y: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
color: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
},
|
||||
rows: [
|
||||
{ x: '200', y: 'tigers', color: 'tigers' },
|
||||
{ x: '500', y: 'pandas', color: 'pandas' },
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should find context when a previous context value is not found', () => {
|
||||
// pointseries map
|
||||
expect(getSiblingContext(state, 'element-foo', 1000)).toEqual({
|
||||
index: 2,
|
||||
context: {
|
||||
type: 'pointseries',
|
||||
columns: {
|
||||
x: { type: 'string', role: 'dimension', expression: 'cost' },
|
||||
y: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
color: { type: 'string', role: 'dimension', expression: 'project' },
|
||||
},
|
||||
rows: [
|
||||
{ x: '200', y: 'tigers', color: 'tigers' },
|
||||
{ x: '500', y: 'pandas', color: 'pandas' },
|
||||
],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
|
@ -9,7 +9,6 @@ import {
|
|||
loadingIndicator as defaultLoadingIndicator,
|
||||
LoadingIndicatorInterface,
|
||||
} from '../../lib/loading_indicator';
|
||||
// @ts-expect-error
|
||||
import { convert } from '../../lib/modify_path';
|
||||
|
||||
interface InFlightMiddlewareOptions {
|
||||
|
|
|
@ -4,10 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { get } from 'lodash';
|
||||
import { elementsReducer } from '../elements';
|
||||
import { actionCreator } from './fixtures/action_creator';
|
||||
import { elementsReducer } from './elements';
|
||||
import { actionCreator } from './__fixtures__/action_creator';
|
||||
|
||||
describe('elements reducer', () => {
|
||||
let state;
|
||||
|
@ -46,8 +44,8 @@ describe('elements reducer', () => {
|
|||
});
|
||||
|
||||
const newState = elementsReducer(state, action);
|
||||
const newElement = get(newState, ['pages', 0, 'elements', 1]);
|
||||
const newElement = newState?.pages?.[0]?.elements?.[1];
|
||||
|
||||
expect(newElement).to.eql(expected);
|
||||
expect(newElement).toEqual(expected);
|
||||
});
|
||||
});
|
|
@ -4,11 +4,10 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import * as actions from '../../actions/resolved_args';
|
||||
import { flushContextAfterIndex } from '../../actions/elements';
|
||||
import { resolvedArgsReducer } from '../resolved_args';
|
||||
import { actionCreator } from './fixtures/action_creator';
|
||||
import * as actions from '../actions/resolved_args';
|
||||
import { flushContextAfterIndex } from '../actions/elements';
|
||||
import { resolvedArgsReducer } from './resolved_args';
|
||||
import { actionCreator } from './__fixtures__/action_creator';
|
||||
|
||||
describe('resolved args reducer', () => {
|
||||
let state;
|
||||
|
@ -41,13 +40,15 @@ describe('resolved args reducer', () => {
|
|||
});
|
||||
|
||||
const newState = resolvedArgsReducer(state, action);
|
||||
expect(newState.resolvedArgs['element-1']).to.eql([
|
||||
{
|
||||
state: 'pending',
|
||||
value: null,
|
||||
error: null,
|
||||
},
|
||||
]);
|
||||
expect(newState.resolvedArgs['element-1']).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"0": Object {
|
||||
"error": null,
|
||||
"state": "pending",
|
||||
"value": null,
|
||||
},
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('sets state to loading, with array path', () => {
|
||||
|
@ -56,13 +57,15 @@ describe('resolved args reducer', () => {
|
|||
});
|
||||
|
||||
const newState = resolvedArgsReducer(state, action);
|
||||
expect(newState.resolvedArgs['element-1']).to.eql([
|
||||
{
|
||||
state: 'pending',
|
||||
value: null,
|
||||
error: null,
|
||||
},
|
||||
]);
|
||||
expect(newState.resolvedArgs['element-1']).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"0": Object {
|
||||
"error": null,
|
||||
"state": "pending",
|
||||
"value": null,
|
||||
},
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -75,13 +78,15 @@ describe('resolved args reducer', () => {
|
|||
});
|
||||
|
||||
const newState = resolvedArgsReducer(state, action);
|
||||
expect(newState.resolvedArgs['element-1']).to.eql([
|
||||
{
|
||||
state: 'ready',
|
||||
value,
|
||||
error: null,
|
||||
},
|
||||
]);
|
||||
expect(newState.resolvedArgs['element-1']).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"0": Object {
|
||||
"error": null,
|
||||
"state": "ready",
|
||||
"value": "hello world",
|
||||
},
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('handles error values', () => {
|
||||
|
@ -92,13 +97,15 @@ describe('resolved args reducer', () => {
|
|||
});
|
||||
|
||||
const newState = resolvedArgsReducer(state, action);
|
||||
expect(newState.resolvedArgs['element-1']).to.eql([
|
||||
{
|
||||
state: 'error',
|
||||
value: null,
|
||||
error: err,
|
||||
},
|
||||
]);
|
||||
expect(newState.resolvedArgs['element-1']).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"0": Object {
|
||||
"error": [Error: farewell world],
|
||||
"state": "error",
|
||||
"value": null,
|
||||
},
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('preserves old value on error', () => {
|
||||
|
@ -109,11 +116,13 @@ describe('resolved args reducer', () => {
|
|||
});
|
||||
|
||||
const newState = resolvedArgsReducer(state, action);
|
||||
expect(newState.resolvedArgs['element-0'][0]).to.eql({
|
||||
state: 'error',
|
||||
value: 'testing',
|
||||
error: err,
|
||||
});
|
||||
expect(newState.resolvedArgs['element-0'][0]).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"error": [Error: farewell world],
|
||||
"state": "error",
|
||||
"value": "testing",
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -124,14 +133,15 @@ describe('resolved args reducer', () => {
|
|||
});
|
||||
|
||||
const newState = resolvedArgsReducer(state, action);
|
||||
expect(newState.resolvedArgs['element-0']).to.have.length(1);
|
||||
expect(newState.resolvedArgs['element-0']).to.eql([
|
||||
{
|
||||
state: 'ready',
|
||||
value: 'testing',
|
||||
error: null,
|
||||
},
|
||||
]);
|
||||
expect(newState.resolvedArgs['element-0']).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
Object {
|
||||
"error": null,
|
||||
"state": "ready",
|
||||
"value": "testing",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it('deeply removes resolved values', () => {
|
||||
|
@ -140,7 +150,7 @@ describe('resolved args reducer', () => {
|
|||
});
|
||||
|
||||
const newState = resolvedArgsReducer(state, action);
|
||||
expect(newState.resolvedArgs['element-0']).to.be(undefined);
|
||||
expect(newState.resolvedArgs['element-0']).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -183,12 +193,22 @@ describe('resolved args reducer', () => {
|
|||
});
|
||||
|
||||
const newState = resolvedArgsReducer(state, action);
|
||||
expect(newState.resolvedArgs['element-1']).to.eql({
|
||||
expressionContext: {
|
||||
'1': { state: 'ready', value: 'test-1', error: null },
|
||||
'2': { state: 'ready', value: 'test-2', error: null },
|
||||
},
|
||||
});
|
||||
expect(newState.resolvedArgs['element-1']).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"expressionContext": Object {
|
||||
"1": Object {
|
||||
"error": null,
|
||||
"state": "ready",
|
||||
"value": "test-1",
|
||||
},
|
||||
"2": Object {
|
||||
"error": null,
|
||||
"state": "ready",
|
||||
"value": "test-2",
|
||||
},
|
||||
},
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4,8 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import * as selector from '../resolved_args';
|
||||
import * as selector from './resolved_args';
|
||||
|
||||
describe('resolved args selector', () => {
|
||||
let state;
|
||||
|
@ -35,21 +34,20 @@ describe('resolved args selector', () => {
|
|||
});
|
||||
|
||||
it('getValue returns the state', () => {
|
||||
expect(selector.getState(state, 'test1')).to.equal('ready');
|
||||
expect(selector.getState(state, 'test2')).to.equal('pending');
|
||||
expect(selector.getState(state, 'test3')).to.equal('error');
|
||||
expect(selector.getState(state, 'test1')).toEqual('ready');
|
||||
expect(selector.getState(state, 'test2')).toEqual('pending');
|
||||
expect(selector.getState(state, 'test3')).toEqual('error');
|
||||
});
|
||||
|
||||
it('getValue returns the value', () => {
|
||||
expect(selector.getValue(state, 'test1')).to.equal('test value');
|
||||
expect(selector.getValue(state, 'test2')).to.equal(null);
|
||||
expect(selector.getValue(state, 'test3')).to.equal('some old value');
|
||||
expect(selector.getValue(state, 'test1')).toEqual('test value');
|
||||
expect(selector.getValue(state, 'test2')).toEqual(null);
|
||||
expect(selector.getValue(state, 'test3')).toEqual('some old value');
|
||||
});
|
||||
|
||||
it('getError returns the error', () => {
|
||||
expect(selector.getError(state, 'test1')).to.equal(null);
|
||||
expect(selector.getError(state, 'test2')).to.equal(null);
|
||||
expect(selector.getError(state, 'test3')).to.be.an(Error);
|
||||
expect(selector.getError(state, 'test3').toString()).to.match(/i\ have\ failed$/);
|
||||
expect(selector.getError(state, 'test1')).toEqual(null);
|
||||
expect(selector.getError(state, 'test2')).toEqual(null);
|
||||
expect(selector.getError(state, 'test3')).toMatchInlineSnapshot(`[Error: i have failed]`);
|
||||
});
|
||||
});
|
|
@ -5,9 +5,7 @@
|
|||
*/
|
||||
|
||||
import { get } from 'lodash';
|
||||
// @ts-expect-error untyped local
|
||||
import * as argHelper from '../../lib/resolved_arg';
|
||||
// @ts-expect-error untyped local
|
||||
import { prepend } from '../../lib/modify_path';
|
||||
import { State } from '../../../types';
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import * as selector from '../workpad';
|
||||
import * as selector from './workpad';
|
||||
|
||||
describe('workpad selectors', () => {
|
||||
let asts;
|
||||
|
@ -125,42 +124,42 @@ describe('workpad selectors', () => {
|
|||
|
||||
describe('empty state', () => {
|
||||
it('returns undefined', () => {
|
||||
expect(selector.getSelectedPage({})).to.be(undefined);
|
||||
expect(selector.getPageById({}, 'page-1')).to.be(undefined);
|
||||
expect(selector.getSelectedElement({})).to.be(undefined);
|
||||
expect(selector.getElementById({}, 'element-1')).to.be(undefined);
|
||||
expect(selector.getResolvedArgs({}, 'element-1')).to.be(undefined);
|
||||
expect(selector.getSelectedResolvedArgs({})).to.be(undefined);
|
||||
expect(selector.isWriteable({})).to.be(true);
|
||||
expect(selector.getSelectedPage({})).toBe(undefined);
|
||||
expect(selector.getPageById({}, 'page-1')).toBe(undefined);
|
||||
expect(selector.getSelectedElement({})).toBe(undefined);
|
||||
expect(selector.getElementById({}, 'element-1')).toBe(undefined);
|
||||
expect(selector.getResolvedArgs({}, 'element-1')).toBe(undefined);
|
||||
expect(selector.getSelectedResolvedArgs({})).toBe(undefined);
|
||||
expect(selector.isWriteable({})).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSelectedPage', () => {
|
||||
it('returns the selected page', () => {
|
||||
expect(selector.getSelectedPage(state)).to.equal('page-1');
|
||||
expect(selector.getSelectedPage(state)).toEqual('page-1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPages', () => {
|
||||
it('return an empty array with no pages', () => {
|
||||
expect(selector.getPages({})).to.eql([]);
|
||||
expect(selector.getPages({})).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns all pages in persisent state', () => {
|
||||
expect(selector.getPages(state)).to.eql(state.persistent.workpad.pages);
|
||||
expect(selector.getPages(state)).toEqual(state.persistent.workpad.pages);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPageById', () => {
|
||||
it('should return matching page', () => {
|
||||
expect(selector.getPageById(state, 'page-1')).to.eql(state.persistent.workpad.pages[0]);
|
||||
expect(selector.getPageById(state, 'page-1')).toEqual(state.persistent.workpad.pages[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSelectedElement', () => {
|
||||
it('returns selected element', () => {
|
||||
const { elements } = state.persistent.workpad.pages[0];
|
||||
expect(selector.getSelectedElement(state)).to.eql({
|
||||
expect(selector.getSelectedElement(state)).toEqual({
|
||||
...elements[1],
|
||||
ast: asts['element-1'],
|
||||
});
|
||||
|
@ -169,7 +168,7 @@ describe('workpad selectors', () => {
|
|||
|
||||
describe('getElements', () => {
|
||||
it('is an empty array with no state', () => {
|
||||
expect(selector.getElements({})).to.eql([]);
|
||||
expect(selector.getElements({})).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns all elements on the page', () => {
|
||||
|
@ -179,18 +178,18 @@ describe('workpad selectors', () => {
|
|||
...element,
|
||||
ast: asts[element.id],
|
||||
}));
|
||||
expect(selector.getElements(state)).to.eql(expected);
|
||||
expect(selector.getElements(state)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getElementById', () => {
|
||||
it('returns element matching id', () => {
|
||||
const { elements } = state.persistent.workpad.pages[0];
|
||||
expect(selector.getElementById(state, 'element-0')).to.eql({
|
||||
expect(selector.getElementById(state, 'element-0')).toEqual({
|
||||
...elements[0],
|
||||
ast: asts['element-0'],
|
||||
});
|
||||
expect(selector.getElementById(state, 'element-1')).to.eql({
|
||||
expect(selector.getElementById(state, 'element-1')).toEqual({
|
||||
...elements[1],
|
||||
ast: asts['element-1'],
|
||||
});
|
||||
|
@ -199,18 +198,18 @@ describe('workpad selectors', () => {
|
|||
|
||||
describe('getResolvedArgs', () => {
|
||||
it('returns resolved args by element id', () => {
|
||||
expect(selector.getResolvedArgs(state, 'element-0')).to.equal('test resolved arg, el 0');
|
||||
expect(selector.getResolvedArgs(state, 'element-0')).toEqual('test resolved arg, el 0');
|
||||
});
|
||||
|
||||
it('returns resolved args at given path', () => {
|
||||
const arg = selector.getResolvedArgs(state, 'element-2', 'example1');
|
||||
expect(arg).to.equal('first thing');
|
||||
expect(arg).toEqual('first thing');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSelectedResolvedArgs', () => {
|
||||
it('returns resolved args for selected element', () => {
|
||||
expect(selector.getSelectedResolvedArgs(state)).to.equal('test resolved arg, el 1');
|
||||
expect(selector.getSelectedResolvedArgs(state)).toEqual('test resolved arg, el 1');
|
||||
});
|
||||
|
||||
it('returns resolved args at given path', () => {
|
||||
|
@ -222,7 +221,7 @@ describe('workpad selectors', () => {
|
|||
},
|
||||
};
|
||||
const arg = selector.getSelectedResolvedArgs(tmpState, 'example2');
|
||||
expect(arg).to.eql(['why not', 'an array?']);
|
||||
expect(arg).toEqual(['why not', 'an array?']);
|
||||
});
|
||||
|
||||
it('returns resolved args at given deep path', () => {
|
||||
|
@ -234,14 +233,14 @@ describe('workpad selectors', () => {
|
|||
},
|
||||
};
|
||||
const arg = selector.getSelectedResolvedArgs(tmpState, ['example3', 'deeper', 'object']);
|
||||
expect(arg).to.be(true);
|
||||
expect(arg).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getGlobalFilters', () => {
|
||||
it('gets filters from all elements', () => {
|
||||
const filters = selector.getGlobalFilters(state);
|
||||
expect(filters).to.eql([
|
||||
expect(filters).toEqual([
|
||||
'exactly value="beats" column="project"',
|
||||
'timefilter filterGroup=one column=@timestamp from=now-24h to=now',
|
||||
]);
|
||||
|
@ -249,17 +248,14 @@ describe('workpad selectors', () => {
|
|||
|
||||
it('gets returns empty array with no elements', () => {
|
||||
const filters = selector.getGlobalFilters({});
|
||||
expect(filters).to.be.an(Array);
|
||||
expect(filters).to.have.length(0);
|
||||
expect(filters).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getGlobalFilterGroups', () => {
|
||||
it('gets filter group from elements', () => {
|
||||
const filterGroups = selector.getGlobalFilterGroups(state);
|
||||
expect(filterGroups).to.be.an(Array);
|
||||
expect(filterGroups).to.have.length(1);
|
||||
expect(filterGroups[0]).to.equal('one');
|
||||
expect(filterGroups).toEqual(['one']);
|
||||
});
|
||||
|
||||
it('gets all unique filter groups', () => {
|
||||
|
@ -282,7 +278,7 @@ describe('workpad selectors', () => {
|
|||
});
|
||||
|
||||
// filters are alphabetical
|
||||
expect(filterGroups).to.eql(['one', 'two']);
|
||||
expect(filterGroups).toEqual(['one', 'two']);
|
||||
});
|
||||
|
||||
it('gets filter groups in filter function args', () => {
|
||||
|
@ -311,13 +307,13 @@ describe('workpad selectors', () => {
|
|||
// {string two} is skipped, only primitive values are extracted
|
||||
// filterGroup=one and {filters one} are de-duped
|
||||
// filters are alphabetical
|
||||
expect(filterGroups).to.eql(['four', 'one', 'three']);
|
||||
expect(filterGroups).toEqual(['four', 'one', 'three']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isWriteable', () => {
|
||||
it('returns boolean for if the workpad is writeable', () => {
|
||||
expect(selector.isWriteable(state)).to.equal(false);
|
||||
expect(selector.isWriteable(state)).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -7,7 +7,6 @@
|
|||
import { get, omit } from 'lodash';
|
||||
// @ts-expect-error untyped local
|
||||
import { safeElementFromExpression, fromExpression } from '@kbn/interpreter/common';
|
||||
// @ts-expect-error untyped local
|
||||
import { append } from '../../lib/modify_path';
|
||||
import { getAssets } from './assets';
|
||||
import {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue