From 0cb281ada4d4cf6f6566b1475434e2aef2924c45 Mon Sep 17 00:00:00 2001 From: Daniil Suleiman <31325372+sulemanof@users.noreply.github.com> Date: Sun, 19 Jan 2020 17:01:49 +0300 Subject: [PATCH] Convert tests to jest in vis_type_timeseries/public & common folders (#55023) (#55182) * Convert tests to jest in vis_type_timeseries/public & common folders * Remove unused translation --- .../common/__tests__/agg_lookup.js | 61 ---------------- .../vis_type_timeseries/common/agg_lookup.js | 22 ------ .../common/agg_lookup.test.js | 31 +++++++++ ...ulate_label.js => calculate_label.test.js} | 43 ++++++------ ...siblings.js => calculate_siblings.test.js} | 7 +- ..._actions.js => collection_actions.test.js} | 32 ++++----- ...vars.js => convert_series_to_vars.test.js} | 2 +- ...ndler.js => create_number_handler.test.js} | 16 ++--- ...ndler.js => create_select_handler.test.js} | 12 ++-- ...handler.js => create_text_handler.test.js} | 16 ++--- ...tring.js => get_axis_label_string.test.js} | 17 ++--- .../re_id_series.js => re_id_series.test.js} | 38 +++++----- .../replace_vars.js => replace_vars.test.js} | 15 ++-- ...ck_formatter.js => tick_formatter.test.js} | 69 +++++++++++++------ .../translations/translations/ja-JP.json | 1 - .../translations/translations/zh-CN.json | 1 - 16 files changed, 174 insertions(+), 209 deletions(-) delete mode 100644 src/legacy/core_plugins/vis_type_timeseries/common/__tests__/agg_lookup.js create mode 100644 src/legacy/core_plugins/vis_type_timeseries/common/agg_lookup.test.js rename src/legacy/core_plugins/vis_type_timeseries/common/{__tests__/calculate_label.js => calculate_label.test.js} (59%) rename src/legacy/core_plugins/vis_type_timeseries/public/components/lib/{__tests__/calculate_siblings.js => calculate_siblings.test.js} (88%) rename src/legacy/core_plugins/vis_type_timeseries/public/components/lib/{__tests__/collection_actions.js => collection_actions.test.js} (65%) rename src/legacy/core_plugins/vis_type_timeseries/public/components/lib/{__tests__/convert_series_to_vars.js => convert_series_to_vars.test.js} (95%) rename src/legacy/core_plugins/vis_type_timeseries/public/components/lib/{__tests__/create_number_handler.js => create_number_handler.test.js} (70%) rename src/legacy/core_plugins/vis_type_timeseries/public/components/lib/{__tests__/create_select_handler.js => create_select_handler.test.js} (77%) rename src/legacy/core_plugins/vis_type_timeseries/public/components/lib/{__tests__/create_text_handler.js => create_text_handler.test.js} (70%) rename src/legacy/core_plugins/vis_type_timeseries/public/components/lib/{__tests__/get_axis_label_string.js => get_axis_label_string.test.js} (65%) rename src/legacy/core_plugins/vis_type_timeseries/public/components/lib/{__tests__/re_id_series.js => re_id_series.test.js} (64%) rename src/legacy/core_plugins/vis_type_timeseries/public/components/lib/{__tests__/replace_vars.js => replace_vars.test.js} (74%) rename src/legacy/core_plugins/vis_type_timeseries/public/components/lib/{__tests__/tick_formatter.js => tick_formatter.test.js} (50%) diff --git a/src/legacy/core_plugins/vis_type_timeseries/common/__tests__/agg_lookup.js b/src/legacy/core_plugins/vis_type_timeseries/common/__tests__/agg_lookup.js deleted file mode 100644 index f78f0a56604190..00000000000000 --- a/src/legacy/core_plugins/vis_type_timeseries/common/__tests__/agg_lookup.js +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { expect } from 'chai'; -import { createOptions, isBasicAgg } from '../agg_lookup'; - -describe('aggLookup', () => { - describe('isBasicAgg(metric)', () => { - it('returns true for a basic metric (count)', () => { - expect(isBasicAgg({ type: 'count' })).to.equal(true); - }); - it('returns false for a pipeline metric (derivative)', () => { - expect(isBasicAgg({ type: 'derivative' })).to.equal(false); - }); - }); - - describe('createOptions(type, siblings)', () => { - it('returns options for all aggs', () => { - const options = createOptions(); - expect(options).to.have.length(30); - options.forEach(option => { - expect(option).to.have.property('label'); - expect(option).to.have.property('value'); - expect(option).to.have.property('disabled'); - }); - }); - - it('returns options for basic', () => { - const options = createOptions('basic'); - expect(options).to.have.length(15); - expect(options.every(opt => isBasicAgg({ type: opt.value }))).to.equal(true); - }); - - it('returns options for pipeline', () => { - const options = createOptions('pipeline'); - expect(options).to.have.length(15); - expect(options.every(opt => !isBasicAgg({ type: opt.value }))).to.equal(true); - }); - - it('returns options for all if given unknown key', () => { - const options = createOptions('foo'); - expect(options).to.have.length(30); - }); - }); -}); diff --git a/src/legacy/core_plugins/vis_type_timeseries/common/agg_lookup.js b/src/legacy/core_plugins/vis_type_timeseries/common/agg_lookup.js index 0f6eba4add596b..4dfdc83dcfabb8 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/common/agg_lookup.js +++ b/src/legacy/core_plugins/vis_type_timeseries/common/agg_lookup.js @@ -127,25 +127,3 @@ const byType = { export function isBasicAgg(item) { return _.includes(Object.keys(byType.basic), item.type); } - -export function createOptions(type = '_all', siblings = []) { - let aggs = byType[type]; - if (!aggs) aggs = byType._all; - let enablePipelines = siblings.some(isBasicAgg); - if (siblings.length <= 1) enablePipelines = false; - return _(aggs) - .map((label, value) => { - const disabled = _.includes(pipeline, value) ? !enablePipelines : false; - return { - label: disabled - ? i18n.translate('visTypeTimeseries.aggLookup.addPipelineAggDescription', { - defaultMessage: '{label} (use the "+" button to add this pipeline agg)', - values: { label }, - }) - : label, - value, - disabled, - }; - }) - .value(); -} diff --git a/src/legacy/core_plugins/vis_type_timeseries/common/agg_lookup.test.js b/src/legacy/core_plugins/vis_type_timeseries/common/agg_lookup.test.js new file mode 100644 index 00000000000000..a7c5d362e669cd --- /dev/null +++ b/src/legacy/core_plugins/vis_type_timeseries/common/agg_lookup.test.js @@ -0,0 +1,31 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { isBasicAgg } from './agg_lookup'; + +describe('aggLookup', () => { + describe('isBasicAgg(metric)', () => { + test('returns true for a basic metric (count)', () => { + expect(isBasicAgg({ type: 'count' })).toEqual(true); + }); + test('returns false for a pipeline metric (derivative)', () => { + expect(isBasicAgg({ type: 'derivative' })).toEqual(false); + }); + }); +}); diff --git a/src/legacy/core_plugins/vis_type_timeseries/common/__tests__/calculate_label.js b/src/legacy/core_plugins/vis_type_timeseries/common/calculate_label.test.js similarity index 59% rename from src/legacy/core_plugins/vis_type_timeseries/common/__tests__/calculate_label.js rename to src/legacy/core_plugins/vis_type_timeseries/common/calculate_label.test.js index 955c052a3906e7..a5af6d114c894c 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/common/__tests__/calculate_label.js +++ b/src/legacy/core_plugins/vis_type_timeseries/common/calculate_label.test.js @@ -17,51 +17,50 @@ * under the License. */ -import { expect } from 'chai'; -import { calculateLabel } from '../calculate_label'; +import { calculateLabel } from './calculate_label'; describe('calculateLabel(metric, metrics)', () => { - it('returns "Unknown" for empty metric', () => { - expect(calculateLabel()).to.equal('Unknown'); + test('returns "Unknown" for empty metric', () => { + expect(calculateLabel()).toEqual('Unknown'); }); - it('returns the metric.alias if set', () => { - expect(calculateLabel({ alias: 'Example' })).to.equal('Example'); + test('returns the metric.alias if set', () => { + expect(calculateLabel({ alias: 'Example' })).toEqual('Example'); }); - it('returns "Count" for a count metric', () => { - expect(calculateLabel({ type: 'count' })).to.equal('Count'); + test('returns "Count" for a count metric', () => { + expect(calculateLabel({ type: 'count' })).toEqual('Count'); }); - it('returns "Calculation" for a bucket script metric', () => { - expect(calculateLabel({ type: 'calculation' })).to.equal('Bucket Script'); + test('returns "Calculation" for a bucket script metric', () => { + expect(calculateLabel({ type: 'calculation' })).toEqual('Bucket Script'); }); - it('returns formated label for series_agg', () => { + test('returns formated label for series_agg', () => { const label = calculateLabel({ type: 'series_agg', function: 'max' }); - expect(label).to.equal('Series Agg (max)'); + expect(label).toEqual('Series Agg (max)'); }); - it('returns formated label for basic aggs', () => { + test('returns formated label for basic aggs', () => { const label = calculateLabel({ type: 'avg', field: 'memory' }); - expect(label).to.equal('Average of memory'); + expect(label).toEqual('Average of memory'); }); - it('returns formated label for pipeline aggs', () => { + test('returns formated label for pipeline aggs', () => { const metric = { id: 2, type: 'derivative', field: 1 }; const metrics = [{ id: 1, type: 'max', field: 'network.out.bytes' }, metric]; const label = calculateLabel(metric, metrics); - expect(label).to.equal('Derivative of Max of network.out.bytes'); + expect(label).toEqual('Derivative of Max of network.out.bytes'); }); - it('returns formated label for derivative of percentile', () => { + test('returns formated label for derivative of percentile', () => { const metric = { id: 2, type: 'derivative', field: '1[50.0]' }; const metrics = [{ id: 1, type: 'percentile', field: 'network.out.bytes' }, metric]; const label = calculateLabel(metric, metrics); - expect(label).to.equal('Derivative of Percentile of network.out.bytes (50.0)'); + expect(label).toEqual('Derivative of Percentile of network.out.bytes (50.0)'); }); - it('returns formated label for pipeline aggs (deep)', () => { + test('returns formated label for pipeline aggs (deep)', () => { const metric = { id: 3, type: 'derivative', field: 2 }; const metrics = [ { id: 1, type: 'max', field: 'network.out.bytes' }, @@ -69,16 +68,16 @@ describe('calculateLabel(metric, metrics)', () => { metric, ]; const label = calculateLabel(metric, metrics); - expect(label).to.equal('Derivative of Moving Average of Max of network.out.bytes'); + expect(label).toEqual('Derivative of Moving Average of Max of network.out.bytes'); }); - it('returns formated label for pipeline aggs uses alias for field metric', () => { + test('returns formated label for pipeline aggs uses alias for field metric', () => { const metric = { id: 2, type: 'derivative', field: 1 }; const metrics = [ { id: 1, type: 'max', field: 'network.out.bytes', alias: 'Outbound Traffic' }, metric, ]; const label = calculateLabel(metric, metrics); - expect(label).to.equal('Derivative of Outbound Traffic'); + expect(label).toEqual('Derivative of Outbound Traffic'); }); }); diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/calculate_siblings.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/calculate_siblings.test.js similarity index 88% rename from src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/calculate_siblings.js rename to src/legacy/core_plugins/vis_type_timeseries/public/components/lib/calculate_siblings.test.js index 40807399a35a21..4f343022c4b0ff 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/calculate_siblings.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/calculate_siblings.test.js @@ -17,11 +17,10 @@ * under the License. */ -import { calculateSiblings } from '../calculate_siblings'; -import { expect } from 'chai'; +import { calculateSiblings } from './calculate_siblings'; describe('calculateSiblings(metrics, metric)', () => { - it('should return all siblings', () => { + test('should return all siblings', () => { const metrics = [ { id: 1, type: 'max', field: 'network.bytes' }, { id: 2, type: 'derivative', field: 1 }, @@ -30,7 +29,7 @@ describe('calculateSiblings(metrics, metric)', () => { { id: 5, type: 'count' }, ]; const siblings = calculateSiblings(metrics, { id: 2 }); - expect(siblings).to.eql([ + expect(siblings).toEqual([ { id: 1, type: 'max', field: 'network.bytes' }, { id: 5, type: 'count' }, ]); diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/collection_actions.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/collection_actions.test.js similarity index 65% rename from src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/collection_actions.js rename to src/legacy/core_plugins/vis_type_timeseries/public/components/lib/collection_actions.test.js index 5f97f559aa4bde..c76943cc8d6d75 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/collection_actions.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/collection_actions.test.js @@ -17,37 +17,35 @@ * under the License. */ -import sinon from 'sinon'; -import { expect } from 'chai'; -import { handleChange, handleAdd, handleDelete } from '../collection_actions'; +import { handleChange, handleAdd, handleDelete } from './collection_actions'; describe('collection actions', () => { - it('handleChange() calls props.onChange() with updated collection', () => { - const fn = sinon.spy(); + test('handleChange() calls props.onChange() with updated collection', () => { + const fn = jest.fn(); const props = { model: { test: [{ id: 1, title: 'foo' }] }, name: 'test', onChange: fn, }; handleChange.call(null, props, { id: 1, title: 'bar' }); - expect(fn.calledOnce).to.equal(true); - expect(fn.firstCall.args[0]).to.eql({ + expect(fn.mock.calls.length).toEqual(1); + expect(fn.mock.calls[0][0]).toEqual({ test: [{ id: 1, title: 'bar' }], }); }); - it('handleAdd() calls props.onChange() with update collection', () => { - const newItemFn = sinon.stub().returns({ id: 2, title: 'example' }); - const fn = sinon.spy(); + test('handleAdd() calls props.onChange() with update collection', () => { + const newItemFn = jest.fn(() => ({ id: 2, title: 'example' })); + const fn = jest.fn(); const props = { model: { test: [{ id: 1, title: 'foo' }] }, name: 'test', onChange: fn, }; handleAdd.call(null, props, newItemFn); - expect(fn.calledOnce).to.equal(true); - expect(newItemFn.calledOnce).to.equal(true); - expect(fn.firstCall.args[0]).to.eql({ + expect(fn.mock.calls.length).toEqual(1); + expect(newItemFn.mock.calls.length).toEqual(1); + expect(fn.mock.calls[0][0]).toEqual({ test: [ { id: 1, title: 'foo' }, { id: 2, title: 'example' }, @@ -55,16 +53,16 @@ describe('collection actions', () => { }); }); - it('handleDelete() calls props.onChange() with update collection', () => { - const fn = sinon.spy(); + test('handleDelete() calls props.onChange() with update collection', () => { + const fn = jest.fn(); const props = { model: { test: [{ id: 1, title: 'foo' }] }, name: 'test', onChange: fn, }; handleDelete.call(null, props, { id: 1 }); - expect(fn.calledOnce).to.equal(true); - expect(fn.firstCall.args[0]).to.eql({ + expect(fn.mock.calls.length).toEqual(1); + expect(fn.mock.calls[0][0]).toEqual({ test: [], }); }); diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/convert_series_to_vars.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/convert_series_to_vars.test.js similarity index 95% rename from src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/convert_series_to_vars.js rename to src/legacy/core_plugins/vis_type_timeseries/public/components/lib/convert_series_to_vars.test.js index 40e3b302c1cf67..689b62962256af 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/convert_series_to_vars.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/convert_series_to_vars.test.js @@ -18,5 +18,5 @@ */ describe('convertSeriesToVars(series, model)', () => { - it('returns and object', () => {}); + test('returns and object', () => {}); }); diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/create_number_handler.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/create_number_handler.test.js similarity index 70% rename from src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/create_number_handler.js rename to src/legacy/core_plugins/vis_type_timeseries/public/components/lib/create_number_handler.test.js index fdbef9eac2d023..e24fe1f1d88d34 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/create_number_handler.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/create_number_handler.test.js @@ -17,9 +17,7 @@ * under the License. */ -import sinon from 'sinon'; -import { expect } from 'chai'; -import { createNumberHandler } from '../create_number_handler'; +import { createNumberHandler } from './create_number_handler'; describe('createNumberHandler()', () => { let handleChange; @@ -27,17 +25,17 @@ describe('createNumberHandler()', () => { let event; beforeEach(() => { - handleChange = sinon.spy(); + handleChange = jest.fn(); changeHandler = createNumberHandler(handleChange); - event = { preventDefault: sinon.spy(), target: { value: '1' } }; + event = { preventDefault: jest.fn(), target: { value: '1' } }; const fn = changeHandler('test'); fn(event); }); - it('calls handleChange() function with partial', () => { - expect(event.preventDefault.calledOnce).to.equal(true); - expect(handleChange.calledOnce).to.equal(true); - expect(handleChange.firstCall.args[0]).to.eql({ + test('calls handleChange() function with partial', () => { + expect(event.preventDefault.mock.calls.length).toEqual(1); + expect(handleChange.mock.calls.length).toEqual(1); + expect(handleChange.mock.calls[0][0]).toEqual({ test: 1, }); }); diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/create_select_handler.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/create_select_handler.test.js similarity index 77% rename from src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/create_select_handler.js rename to src/legacy/core_plugins/vis_type_timeseries/public/components/lib/create_select_handler.test.js index 7bc9ae5de01628..a8d5351341c174 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/create_select_handler.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/create_select_handler.test.js @@ -17,24 +17,22 @@ * under the License. */ -import sinon from 'sinon'; -import { expect } from 'chai'; -import { createSelectHandler } from '../create_select_handler'; +import { createSelectHandler } from './create_select_handler'; describe('createSelectHandler()', () => { let handleChange; let changeHandler; beforeEach(() => { - handleChange = sinon.spy(); + handleChange = jest.fn(); changeHandler = createSelectHandler(handleChange); const fn = changeHandler('test'); fn([{ value: 'foo' }]); }); - it('calls handleChange() function with partial', () => { - expect(handleChange.calledOnce).to.equal(true); - expect(handleChange.firstCall.args[0]).to.eql({ + test('calls handleChange() function with partial', () => { + expect(handleChange.mock.calls.length).toEqual(1); + expect(handleChange.mock.calls[0][0]).toEqual({ test: 'foo', }); }); diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/create_text_handler.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/create_text_handler.test.js similarity index 70% rename from src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/create_text_handler.js rename to src/legacy/core_plugins/vis_type_timeseries/public/components/lib/create_text_handler.test.js index 689fc5c4d7df03..a8a5377b4b0840 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/create_text_handler.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/create_text_handler.test.js @@ -17,9 +17,7 @@ * under the License. */ -import sinon from 'sinon'; -import { expect } from 'chai'; -import { createTextHandler } from '../create_text_handler'; +import { createTextHandler } from './create_text_handler'; describe('createTextHandler()', () => { let handleChange; @@ -27,17 +25,17 @@ describe('createTextHandler()', () => { let event; beforeEach(() => { - handleChange = sinon.spy(); + handleChange = jest.fn(); changeHandler = createTextHandler(handleChange); - event = { preventDefault: sinon.spy(), target: { value: 'foo' } }; + event = { preventDefault: jest.fn(), target: { value: 'foo' } }; const fn = changeHandler('test'); fn(event); }); - it('calls handleChange() function with partial', () => { - expect(event.preventDefault.calledOnce).to.equal(true); - expect(handleChange.calledOnce).to.equal(true); - expect(handleChange.firstCall.args[0]).to.eql({ + test('calls handleChange() function with partial', () => { + expect(event.preventDefault.mock.calls.length).toEqual(1); + expect(handleChange.mock.calls.length).toEqual(1); + expect(handleChange.mock.calls[0][0]).toEqual({ test: 'foo', }); }); diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/get_axis_label_string.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/get_axis_label_string.test.js similarity index 65% rename from src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/get_axis_label_string.js rename to src/legacy/core_plugins/vis_type_timeseries/public/components/lib/get_axis_label_string.test.js index 455a5b262c9295..cfbd5ecb7bf655 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/get_axis_label_string.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/get_axis_label_string.test.js @@ -17,17 +17,18 @@ * under the License. */ -import { expect } from 'chai'; -import { getAxisLabelString } from '../get_axis_label_string'; +import { getAxisLabelString } from './get_axis_label_string'; + +jest.mock('ui/new_platform'); describe('getAxisLabelString(interval)', () => { - it('should return a valid label for 10 seconds', () => { - expect(getAxisLabelString(10000)).to.equal('per 10 seconds'); + test('should return a valid label for 10 seconds', () => { + expect(getAxisLabelString(10000)).toEqual('per 10 seconds'); }); - it('should return a valid label for 2 minutes', () => { - expect(getAxisLabelString(120000)).to.equal('per 2 minutes'); + test('should return a valid label for 2 minutes', () => { + expect(getAxisLabelString(120000)).toEqual('per 2 minutes'); }); - it('should return a valid label for 2 hour', () => { - expect(getAxisLabelString(7200000)).to.equal('per 2 hours'); + test('should return a valid label for 2 hour', () => { + expect(getAxisLabelString(7200000)).toEqual('per 2 hours'); }); }); diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/re_id_series.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/re_id_series.test.js similarity index 64% rename from src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/re_id_series.js rename to src/legacy/core_plugins/vis_type_timeseries/public/components/lib/re_id_series.test.js index b629e284a0fe43..7c646c7dde2e86 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/re_id_series.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/re_id_series.test.js @@ -18,24 +18,24 @@ */ import uuid from 'uuid'; -import { expect } from 'chai'; -import { reIdSeries } from '../re_id_series'; + +import { reIdSeries } from './re_id_series'; describe('reIdSeries()', () => { - it('reassign ids for series with just basic metrics', () => { + test('reassign ids for series with just basic metrics', () => { const series = { id: uuid.v1(), metrics: [{ id: uuid.v1() }, { id: uuid.v1() }], }; const newSeries = reIdSeries(series); - expect(newSeries).to.not.equal(series); - expect(newSeries.id).to.not.equal(series.id); + expect(newSeries).not.toEqual(series); + expect(newSeries.id).not.toEqual(series.id); newSeries.metrics.forEach((val, key) => { - expect(val.id).to.not.equal(series.metrics[key].id); + expect(val.id).not.toEqual(series.metrics[key].id); }); }); - it('reassign ids for series with just basic metrics and group by', () => { + test('reassign ids for series with just basic metrics and group by', () => { const firstMetricId = uuid.v1(); const series = { id: uuid.v1(), @@ -43,27 +43,27 @@ describe('reIdSeries()', () => { terms_order_by: firstMetricId, }; const newSeries = reIdSeries(series); - expect(newSeries).to.not.equal(series); - expect(newSeries.id).to.not.equal(series.id); + expect(newSeries).not.toEqual(series); + expect(newSeries.id).not.toEqual(series.id); newSeries.metrics.forEach((val, key) => { - expect(val.id).to.not.equal(series.metrics[key].id); + expect(val.id).not.toEqual(series.metrics[key].id); }); - expect(newSeries.terms_order_by).to.equal(newSeries.metrics[0].id); + expect(newSeries.terms_order_by).toEqual(newSeries.metrics[0].id); }); - it('reassign ids for series with pipeline metrics', () => { + test('reassign ids for series with pipeline metrics', () => { const firstMetricId = uuid.v1(); const series = { id: uuid.v1(), metrics: [{ id: firstMetricId }, { id: uuid.v1(), field: firstMetricId }], }; const newSeries = reIdSeries(series); - expect(newSeries).to.not.equal(series); - expect(newSeries.id).to.not.equal(series.id); - expect(newSeries.metrics[0].id).to.equal(newSeries.metrics[1].field); + expect(newSeries).not.toEqual(series); + expect(newSeries.id).not.toEqual(series.id); + expect(newSeries.metrics[0].id).toEqual(newSeries.metrics[1].field); }); - it('reassign ids for series with calculation vars', () => { + test('reassign ids for series with calculation vars', () => { const firstMetricId = uuid.v1(); const series = { id: uuid.v1(), @@ -77,8 +77,8 @@ describe('reIdSeries()', () => { ], }; const newSeries = reIdSeries(series); - expect(newSeries).to.not.equal(series); - expect(newSeries.id).to.not.equal(series.id); - expect(newSeries.metrics[1].variables[0].field).to.equal(newSeries.metrics[0].id); + expect(newSeries).not.toEqual(series); + expect(newSeries.id).not.toEqual(series.id); + expect(newSeries.metrics[1].variables[0].field).toEqual(newSeries.metrics[0].id); }); }); diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/replace_vars.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/replace_vars.test.js similarity index 74% rename from src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/replace_vars.js rename to src/legacy/core_plugins/vis_type_timeseries/public/components/lib/replace_vars.test.js index 0ac7427f6faccf..517958692dd2cd 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/replace_vars.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/replace_vars.test.js @@ -17,26 +17,25 @@ * under the License. */ -import { expect } from 'chai'; -import { replaceVars } from '../replace_vars'; +import { replaceVars } from './replace_vars'; describe('replaceVars(str, args, vars)', () => { - it('replaces vars with values', () => { + test('replaces vars with values', () => { const vars = { total: 100 }; const args = { host: 'test-01' }; const template = '# {{args.host}} {{total}}'; - expect(replaceVars(template, args, vars)).to.equal('# test-01 100'); + expect(replaceVars(template, args, vars)).toEqual('# test-01 100'); }); - it('replaces args override vars', () => { + test('replaces args override vars', () => { const vars = { total: 100, args: { test: 'foo-01' } }; const args = { test: 'bar-01' }; const template = '# {{args.test}} {{total}}'; - expect(replaceVars(template, args, vars)).to.equal('# bar-01 100'); + expect(replaceVars(template, args, vars)).toEqual('# bar-01 100'); }); - it('returns original string if error', () => { + test('returns original string if error', () => { const vars = { total: 100 }; const args = { host: 'test-01' }; const template = '# {{args.host}} {{total'; - expect(replaceVars(template, args, vars)).to.equal('# {{args.host}} {{total'); + expect(replaceVars(template, args, vars)).toEqual('# {{args.host}} {{total'); }); }); diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/tick_formatter.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/tick_formatter.test.js similarity index 50% rename from src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/tick_formatter.js rename to src/legacy/core_plugins/vis_type_timeseries/public/components/lib/tick_formatter.test.js index f31af4e8463055..76d3cff17343e1 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/__tests__/tick_formatter.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/lib/tick_formatter.test.js @@ -17,64 +17,93 @@ * under the License. */ -import { expect } from 'chai'; -import { createTickFormatter } from '../tick_formatter'; +import { npStart } from 'ui/new_platform'; +import { createTickFormatter } from './tick_formatter'; +import { getFieldFormatsRegistry } from '../../../../../../test_utils/public/stub_field_formats'; + +const mockUiSettings = { + get: item => { + return mockUiSettings[item]; + }, + getUpdate$: () => ({ + subscribe: jest.fn(), + }), + 'query:allowLeadingWildcards': true, + 'query:queryString:options': {}, + 'courier:ignoreFilterIfFieldNotInIndex': true, + 'dateFormat:tz': 'Browser', + 'format:defaultTypeMap': {}, +}; + +const mockCore = { + chrome: {}, + uiSettings: mockUiSettings, + http: { + basePath: { + get: jest.fn(), + }, + }, +}; describe('createTickFormatter(format, template)', () => { - it('returns a number with two decimal place by default', () => { + npStart.plugins.data = { + fieldFormats: getFieldFormatsRegistry(mockCore), + }; + + test('returns a number with two decimal place by default', () => { const fn = createTickFormatter(); - expect(fn(1.5556)).to.equal('1.56'); + expect(fn(1.5556)).toEqual('1.56'); }); - it('returns a percent with percent formatter', () => { + test('returns a percent with percent formatter', () => { const config = { 'format:percent:defaultPattern': '0.[00]%', }; const fn = createTickFormatter('percent', null, key => config[key]); - expect(fn(0.5556)).to.equal('55.56%'); + expect(fn(0.5556)).toEqual('55.56%'); }); - it('returns a byte formatted string with byte formatter', () => { + test('returns a byte formatted string with byte formatter', () => { const config = { 'format:bytes:defaultPattern': '0.0b', }; const fn = createTickFormatter('bytes', null, key => config[key]); - expect(fn(1500 ^ 10)).to.equal('1.5KB'); + expect(fn(1500 ^ 10)).toEqual('1.5KB'); }); - it('returns a custom formatted string with custom formatter', () => { + test('returns a custom formatted string with custom formatter', () => { const fn = createTickFormatter('0.0a'); - expect(fn(1500)).to.equal('1.5k'); + expect(fn(1500)).toEqual('1.5k'); }); - it('returns a located string with custom locale setting', () => { + test('returns a located string with custom locale setting', () => { const config = { 'format:number:defaultLocale': 'fr', }; const fn = createTickFormatter('0,0.0', null, key => config[key]); - expect(fn(1500)).to.equal('1 500,0'); + expect(fn(1500)).toEqual('1 500,0'); }); - it('returns a custom formatted string with custom formatter and template', () => { + test('returns a custom formatted string with custom formatter and template', () => { const fn = createTickFormatter('0.0a', '{{value}}/s'); - expect(fn(1500)).to.equal('1.5k/s'); + expect(fn(1500)).toEqual('1.5k/s'); }); - it('returns "foo" if passed a string', () => { + test('returns "foo" if passed a string', () => { const fn = createTickFormatter(); - expect(fn('foo')).to.equal('foo'); + expect(fn('foo')).toEqual('foo'); }); - it('returns value if passed a bad formatter', () => { + test('returns value if passed a bad formatter', () => { const fn = createTickFormatter('102'); - expect(fn(100)).to.equal('100'); + expect(fn(100)).toEqual('100'); }); - it('returns formatted value if passed a bad template', () => { + test('returns formatted value if passed a bad template', () => { const config = { 'format:number:defaultPattern': '0,0.[00]', }; const fn = createTickFormatter('number', '{{value', key => config[key]); - expect(fn(1.5556)).to.equal('1.56'); + expect(fn(1.5556)).toEqual('1.56'); }); }); diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index f1c2c2a6dd49f8..c0a41cbfee8daa 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -3232,7 +3232,6 @@ "visTypeTimeseries.addDeleteButtons.deleteButtonDefaultTooltip": "削除", "visTypeTimeseries.addDeleteButtons.reEnableTooltip": "再度有効にする", "visTypeTimeseries.addDeleteButtons.temporarilyDisableTooltip": "一時的に無効にする", - "visTypeTimeseries.aggLookup.addPipelineAggDescription": "{label} (「+」ボタンでこのパイプライン集約を追加します)", "visTypeTimeseries.aggLookup.averageLabel": "平均", "visTypeTimeseries.aggLookup.calculationLabel": "計算", "visTypeTimeseries.aggLookup.cardinalityLabel": "基数", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index d55b45225bea86..8587500d86321a 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -3232,7 +3232,6 @@ "visTypeTimeseries.addDeleteButtons.deleteButtonDefaultTooltip": "删除", "visTypeTimeseries.addDeleteButtons.reEnableTooltip": "重新启用", "visTypeTimeseries.addDeleteButtons.temporarilyDisableTooltip": "暂时禁用", - "visTypeTimeseries.aggLookup.addPipelineAggDescription": "{label}(使用“+”按钮添加此管道聚合)", "visTypeTimeseries.aggLookup.averageLabel": "平均值", "visTypeTimeseries.aggLookup.calculationLabel": "计算", "visTypeTimeseries.aggLookup.cardinalityLabel": "基数",