From 7f38a1faea9aafbc276069623b54df8df0f03865 Mon Sep 17 00:00:00 2001 From: Uladzislau Lasitsa Date: Thu, 9 Jul 2020 16:10:34 +0300 Subject: [PATCH] Migrated vislib tests to the NP (#70309) (#71206) * Migrated vislib tests to the NP * fixed tests * Fixed tests * Fixed test --- .../charts/public/services/colors/mock.ts | 2 +- .../public/vislib/lib/chart_title.test.js} | 40 +++- .../public/vislib/lib/dispatch.test.js} | 82 +++++--- .../public/vislib/lib/handler.test.js} | 69 ++++--- .../public/vislib/lib/layout/layout.test.js} | 98 ++++++---- .../public/vislib/vis.test.js} | 119 +++++++----- .../vislib/visualizations}/_vis_fixture.js | 18 +- .../vislib/visualizations/chart.test.js} | 30 ++- .../visualizations/gauge_chart.test.js} | 67 ++++--- .../vislib/visualizations/pie_chart.test.js} | 109 ++++++++--- .../visualizations/pie_chart_mock_data.js | 0 .../point_series/area_chart.test.js} | 120 ++++++------ .../point_series/column_chart.test.js} | 180 ++++++++++++------ .../point_series/heatmap_chart.test.js} | 89 +++++---- .../point_series/line_chart.test.js} | 92 +++++---- src/test_utils/public/helpers/index.ts | 7 +- .../public/helpers/jsdom_svg_mocks.ts | 28 +++ src/test_utils/public/index.ts | 7 +- 18 files changed, 743 insertions(+), 414 deletions(-) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/chart_title.js => plugins/vis_type_vislib/public/vislib/lib/chart_title.test.js} (73%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/dispatch.js => plugins/vis_type_vislib/public/vislib/lib/dispatch.test.js} (67%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/handler/handler.js => plugins/vis_type_vislib/public/vislib/lib/handler.test.js} (58%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/layout/layout.js => plugins/vis_type_vislib/public/vislib/lib/layout/layout.test.js} (55%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/vis.js => plugins/vis_type_vislib/public/vislib/vis.test.js} (56%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib => plugins/vis_type_vislib/public/vislib/visualizations}/_vis_fixture.js (83%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/chart.js => plugins/vis_type_vislib/public/vislib/visualizations/chart.test.js} (77%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/gauge_chart.js => plugins/vis_type_vislib/public/vislib/visualizations/gauge_chart.test.js} (65%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/pie_chart.js => plugins/vis_type_vislib/public/vislib/visualizations/pie_chart.test.js} (65%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib => plugins/vis_type_vislib/public/vislib}/visualizations/pie_chart_mock_data.js (100%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/area_chart.js => plugins/vis_type_vislib/public/vislib/visualizations/point_series/area_chart.test.js} (64%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/column_chart.js => plugins/vis_type_vislib/public/vislib/visualizations/point_series/column_chart.test.js} (59%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/heatmap_chart.js => plugins/vis_type_vislib/public/vislib/visualizations/point_series/heatmap_chart.test.js} (65%) rename src/{legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/line_chart.js => plugins/vis_type_vislib/public/vislib/visualizations/point_series/line_chart.test.js} (67%) diff --git a/src/plugins/charts/public/services/colors/mock.ts b/src/plugins/charts/public/services/colors/mock.ts index 924dbd6aa52a46..f88980e521dda3 100644 --- a/src/plugins/charts/public/services/colors/mock.ts +++ b/src/plugins/charts/public/services/colors/mock.ts @@ -24,5 +24,5 @@ const colors = new ColorsService(); colors.init(coreMock.createSetup().uiSettings); export const colorsServiceMock: ColorsService = { - createColorLookupFunction: jest.fn(colors.createColorLookupFunction), + createColorLookupFunction: jest.fn(colors.createColorLookupFunction.bind(colors)), } as any; diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/chart_title.js b/src/plugins/vis_type_vislib/public/vislib/lib/chart_title.test.js similarity index 73% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/chart_title.js rename to src/plugins/vis_type_vislib/public/vislib/lib/chart_title.test.js index 6790c49691dfd0..d8d5087f8c3802 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/chart_title.js +++ b/src/plugins/vis_type_vislib/public/vislib/lib/chart_title.test.js @@ -19,11 +19,15 @@ import d3 from 'd3'; import _ from 'lodash'; -import expect from '@kbn/expect'; +import { + setHTMLElementClientSizes, + setSVGElementGetBBox, + setSVGElementGetComputedTextLength, +} from '../../../../../test_utils/public'; -import { ChartTitle } from '../../../../../../../plugins/vis_type_vislib/public/vislib/lib/chart_title'; -import { VisConfig } from '../../../../../../../plugins/vis_type_vislib/public/vislib/lib/vis_config'; -import { getMockUiState } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; +import { ChartTitle } from './chart_title'; +import { VisConfig } from './vis_config'; +import { getMockUiState } from '../../fixtures/mocks'; describe('Vislib ChartTitle Class Test Suite', function () { let mockUiState; @@ -88,6 +92,16 @@ describe('Vislib ChartTitle Class Test Suite', function () { yAxisLabel: 'Count', }; + let mockedHTMLElementClientSizes; + let mockedSVGElementGetBBox; + let mockedSVGElementGetComputedTextLength; + + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + }); + beforeEach(() => { mockUiState = getMockUiState(); el = d3.select('body').append('div').attr('class', 'visWrapper').datum(data); @@ -113,23 +127,29 @@ describe('Vislib ChartTitle Class Test Suite', function () { el.remove(); }); + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + }); + describe('render Method', function () { beforeEach(function () { chartTitle.render(); }); - it('should append an svg to div', function () { - expect(el.select('.chart-title').selectAll('svg').length).to.be(1); + test('should append an svg to div', function () { + expect(el.select('.chart-title').selectAll('svg').length).toBe(1); }); - it('should append text', function () { - expect(!!el.select('.chart-title').selectAll('svg').selectAll('text')).to.be(true); + test('should append text', function () { + expect(!!el.select('.chart-title').selectAll('svg').selectAll('text')).toBe(true); }); }); describe('draw Method', function () { - it('should be a function', function () { - expect(_.isFunction(chartTitle.draw())).to.be(true); + test('should be a function', function () { + expect(_.isFunction(chartTitle.draw())).toBe(true); }); }); }); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/dispatch.js b/src/plugins/vis_type_vislib/public/vislib/lib/dispatch.test.js similarity index 67% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/dispatch.js rename to src/plugins/vis_type_vislib/public/vislib/lib/dispatch.test.js index 20281d8479ab4d..9c714af4d8434b 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/dispatch.js +++ b/src/plugins/vis_type_vislib/public/vislib/lib/dispatch.test.js @@ -19,13 +19,21 @@ import _ from 'lodash'; import d3 from 'd3'; -import expect from '@kbn/expect'; +import { + setHTMLElementClientSizes, + setSVGElementGetBBox, + setSVGElementGetComputedTextLength, +} from '../../../../../test_utils/public'; // Data -import data from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series'; +import data from '../../fixtures/mock_data/date_histogram/_series'; -import { getMockUiState } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; -import { getVis } from '../_vis_fixture'; +import { getMockUiState } from '../../fixtures/mocks'; +import { getVis } from '../visualizations/_vis_fixture'; + +let mockedHTMLElementClientSizes; +let mockedSVGElementGetBBox; +let mockedSVGElementGetComputedTextLength; describe('Vislib Dispatch Class Test Suite', function () { function destroyVis(vis) { @@ -36,6 +44,18 @@ describe('Vislib Dispatch Class Test Suite', function () { return d3.select(element).data(new Array(n)).enter().append(type); } + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + }); + + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + }); + describe('', function () { let vis; let mockUiState; @@ -50,13 +70,13 @@ describe('Vislib Dispatch Class Test Suite', function () { destroyVis(vis); }); - it('implements on, off, emit methods', function () { + test('implements on, off, emit methods', function () { const events = _.map(vis.handler.charts, 'events'); - expect(events.length).to.be.above(0); + expect(events.length).toBeGreaterThan(0); events.forEach(function (dispatch) { - expect(dispatch).to.have.property('on'); - expect(dispatch).to.have.property('off'); - expect(dispatch).to.have.property('emit'); + expect(dispatch).toHaveProperty('on'); + expect(dispatch).toHaveProperty('off'); + expect(dispatch).toHaveProperty('emit'); }); }); }); @@ -77,15 +97,15 @@ describe('Vislib Dispatch Class Test Suite', function () { }); describe('addEvent method', function () { - it('returns a function that binds the passed event to a selection', function () { + test('returns a function that binds the passed event to a selection', function () { const chart = _.first(vis.handler.charts); const apply = chart.events.addEvent('event', _.noop); - expect(apply).to.be.a('function'); + expect(apply).toBeInstanceOf(Function); const els = getEls(vis.element, 3, 'div'); apply(els); els.each(function () { - expect(d3.select(this).on('event')).to.be(_.noop); + expect(d3.select(this).on('event')).toBe(_.noop); }); }); }); @@ -94,21 +114,21 @@ describe('Vislib Dispatch Class Test Suite', function () { // checking that they return function which bind the events expected function checkBoundAddMethod(name, event) { describe(name + ' method', function () { - it('should be a function', function () { + test('should be a function', function () { vis.handler.charts.forEach(function (chart) { - expect(chart.events[name]).to.be.a('function'); + expect(chart.events[name]).toBeInstanceOf(Function); }); }); - it('returns a function that binds ' + event + ' events to a selection', function () { + test('returns a function that binds ' + event + ' events to a selection', function () { const chart = _.first(vis.handler.charts); const apply = chart.events[name](chart.series[0].chartEl); - expect(apply).to.be.a('function'); + expect(apply).toBeInstanceOf(Function); const els = getEls(vis.element, 3, 'div'); apply(els); els.each(function () { - expect(d3.select(this).on(event)).to.be.a('function'); + expect(d3.select(this).on(event)).toBeInstanceOf(Function); }); }); }); @@ -119,26 +139,26 @@ describe('Vislib Dispatch Class Test Suite', function () { checkBoundAddMethod('addClickEvent', 'click'); describe('addMousePointer method', function () { - it('should be a function', function () { + test('should be a function', function () { vis.handler.charts.forEach(function (chart) { const pointer = chart.events.addMousePointer; - expect(_.isFunction(pointer)).to.be(true); + expect(_.isFunction(pointer)).toBe(true); }); }); }); describe('clickEvent handler', () => { describe('for pie chart', () => { - it('prepares data points', () => { + test('prepares data points', () => { const expectedResponse = [{ column: 0, row: 0, table: {}, value: 0 }]; const d = { rawData: { column: 0, row: 0, table: {}, value: 0 } }; const chart = _.first(vis.handler.charts); const response = chart.events.clickEventResponse(d, { isSlices: true }); - expect(response.data).to.eql(expectedResponse); + expect(response.data).toEqual(expectedResponse); }); - it('remove invalid points', () => { + test('remove invalid points', () => { const expectedResponse = [{ column: 0, row: 0, table: {}, value: 0 }]; const d = { rawData: { column: 0, row: 0, table: {}, value: 0 }, @@ -146,20 +166,20 @@ describe('Vislib Dispatch Class Test Suite', function () { }; const chart = _.first(vis.handler.charts); const response = chart.events.clickEventResponse(d, { isSlices: true }); - expect(response.data).to.eql(expectedResponse); + expect(response.data).toEqual(expectedResponse); }); }); describe('for xy charts', () => { - it('prepares data points', () => { + test('prepares data points', () => { const expectedResponse = [{ column: 0, row: 0, table: {}, value: 0 }]; const d = { xRaw: { column: 0, row: 0, table: {}, value: 0 } }; const chart = _.first(vis.handler.charts); const response = chart.events.clickEventResponse(d, { isSlices: false }); - expect(response.data).to.eql(expectedResponse); + expect(response.data).toEqual(expectedResponse); }); - it('remove invalid points', () => { + test('remove invalid points', () => { const expectedResponse = [{ column: 0, row: 0, table: {}, value: 0 }]; const d = { xRaw: { column: 0, row: 0, table: {}, value: 0 }, @@ -167,35 +187,35 @@ describe('Vislib Dispatch Class Test Suite', function () { }; const chart = _.first(vis.handler.charts); const response = chart.events.clickEventResponse(d, { isSlices: false }); - expect(response.data).to.eql(expectedResponse); + expect(response.data).toEqual(expectedResponse); }); }); }); }); describe('Custom event handlers', function () { - it('should attach whatever gets passed on vis.on() to chart.events', function (done) { + test('should attach whatever gets passed on vis.on() to chart.events', function (done) { const vis = getVis(); const mockUiState = getMockUiState(); vis.on('someEvent', _.noop); vis.render(data, mockUiState); vis.handler.charts.forEach(function (chart) { - expect(chart.events.listenerCount('someEvent')).to.be(1); + expect(chart.events.listenerCount('someEvent')).toBe(1); }); destroyVis(vis); done(); }); - it('can be added after rendering', function () { + test('can be added after rendering', function () { const vis = getVis(); const mockUiState = getMockUiState(); vis.render(data, mockUiState); vis.on('someEvent', _.noop); vis.handler.charts.forEach(function (chart) { - expect(chart.events.listenerCount('someEvent')).to.be(1); + expect(chart.events.listenerCount('someEvent')).toBe(1); }); destroyVis(vis); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/handler/handler.js b/src/plugins/vis_type_vislib/public/vislib/lib/handler.test.js similarity index 58% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/handler/handler.js rename to src/plugins/vis_type_vislib/public/vislib/lib/handler.test.js index e4f75c47e621c3..d50c70de1bb483 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/handler/handler.js +++ b/src/plugins/vis_type_vislib/public/vislib/lib/handler.test.js @@ -17,25 +17,38 @@ * under the License. */ -import expect from '@kbn/expect'; import $ from 'jquery'; +import { + setHTMLElementClientSizes, + setSVGElementGetBBox, + setSVGElementGetComputedTextLength, +} from '../../../../../test_utils/public'; // Data -import series from '../../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series'; -import columns from '../../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_columns'; -import rows from '../../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_rows'; -import stackedSeries from '../../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_stacked_series'; -import { getMockUiState } from '../../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; -import { getVis } from '../../_vis_fixture'; +import series from '../../fixtures/mock_data/date_histogram/_series'; +import columns from '../../fixtures/mock_data/date_histogram/_columns'; +import rows from '../../fixtures/mock_data/date_histogram/_rows'; +import stackedSeries from '../../fixtures/mock_data/date_histogram/_stacked_series'; +import { getMockUiState } from '../../fixtures/mocks'; +import { getVis } from '../visualizations/_vis_fixture'; const dateHistogramArray = [series, columns, rows, stackedSeries]; const names = ['series', 'columns', 'rows', 'stackedSeries']; +let mockedHTMLElementClientSizes; +let mockedSVGElementGetBBox; +let mockedSVGElementGetComputedTextLength; dateHistogramArray.forEach(function (data, i) { describe('Vislib Handler Test Suite for ' + names[i] + ' Data', function () { const events = ['click', 'brush']; let vis; + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + }); + beforeEach(() => { vis = getVis(); vis.render(data, getMockUiState()); @@ -45,11 +58,17 @@ dateHistogramArray.forEach(function (data, i) { vis.destroy(); }); + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + }); + describe('render Method', function () { - it('should render charts', function () { - expect(vis.handler.charts.length).to.be.greaterThan(0); + test('should render charts', function () { + expect(vis.handler.charts.length).toBeGreaterThan(0); vis.handler.charts.forEach(function (chart) { - expect($(chart.chartEl).find('svg').length).to.be(1); + expect($(chart.chartEl).find('svg').length).toBe(1); }); }); }); @@ -67,10 +86,10 @@ dateHistogramArray.forEach(function (data, i) { }); }); - it('should add events to chart and emit to the Events class', function () { + test('should add events to chart and emit to the Events class', function () { charts.forEach(function (chart) { events.forEach(function (event) { - expect(chart.events.listenerCount(event)).to.be.above(0); + expect(chart.events.listenerCount(event)).toBeGreaterThan(0); }); }); }); @@ -89,10 +108,10 @@ dateHistogramArray.forEach(function (data, i) { }); }); - it('should remove events from the chart', function () { + test('should remove events from the chart', function () { charts.forEach(function (chart) { events.forEach(function (event) { - expect(chart.events.listenerCount(event)).to.be(0); + expect(chart.events.listenerCount(event)).toBe(0); }); }); }); @@ -103,8 +122,8 @@ dateHistogramArray.forEach(function (data, i) { vis.handler.removeAll(vis.element); }); - it('should remove all DOM elements from the el', function () { - expect($(vis.element).children().length).to.be(0); + test('should remove all DOM elements from the el', function () { + expect($(vis.element).children().length).toBe(0); }); }); @@ -113,9 +132,9 @@ dateHistogramArray.forEach(function (data, i) { vis.handler.error('This is an error!'); }); - it('should return an error classed DOM element with a text message', function () { - expect($(vis.element).find('.error').length).to.be(1); - expect($('.error h4').html()).to.be('This is an error!'); + test('should return an error classed DOM element with a text message', function () { + expect($(vis.element).find('.error').length).toBe(1); + expect($('.error h4').html()).toBe('This is an error!'); }); }); @@ -124,21 +143,21 @@ dateHistogramArray.forEach(function (data, i) { vis.handler.destroy(); }); - it('should destroy all the charts in the visualization', function () { - expect(vis.handler.charts.length).to.be(0); + test('should destroy all the charts in the visualization', function () { + expect(vis.handler.charts.length).toBe(0); }); }); describe('event proxying', function () { - it('should only pass the original event object to downstream handlers', function (done) { + test('should only pass the original event object to downstream handlers', function (done) { const event = {}; const chart = vis.handler.charts[0]; const mockEmitter = function () { const args = Array.from(arguments); - expect(args.length).to.be(2); - expect(args[0]).to.be('click'); - expect(args[1]).to.be(event); + expect(args.length).toBe(2); + expect(args[0]).toBe('click'); + expect(args[1]).toBe(event); done(); }; diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/layout/layout.js b/src/plugins/vis_type_vislib/public/vislib/lib/layout/layout.test.js similarity index 55% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/layout/layout.js rename to src/plugins/vis_type_vislib/public/vislib/lib/layout/layout.test.js index 7ad962fefc3413..824d7073d6db5b 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/lib/layout/layout.js +++ b/src/plugins/vis_type_vislib/public/vislib/lib/layout/layout.test.js @@ -18,22 +18,30 @@ */ import d3 from 'd3'; -import expect from '@kbn/expect'; import $ from 'jquery'; +import { + setHTMLElementClientSizes, + setSVGElementGetBBox, + setSVGElementGetComputedTextLength, +} from '../../../../../../test_utils/public'; // Data -import series from '../../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series'; -import columns from '../../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_columns'; -import rows from '../../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_rows'; -import stackedSeries from '../../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_stacked_series'; -import { getMockUiState } from '../../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; -import { Layout } from '../../../../../../../../plugins/vis_type_vislib/public/vislib/lib/layout/layout'; -import { VisConfig } from '../../../../../../../../plugins/vis_type_vislib/public/vislib/lib/vis_config'; -import { getVis } from '../../_vis_fixture'; +import series from '../../../fixtures/mock_data/date_histogram/_series'; +import columns from '../../../fixtures/mock_data/date_histogram/_columns'; +import rows from '../../../fixtures/mock_data/date_histogram/_rows'; +import stackedSeries from '../../../fixtures/mock_data/date_histogram/_stacked_series'; +import { getMockUiState } from '../../../fixtures/mocks'; +import { Layout } from './layout'; +import { VisConfig } from '../vis_config'; +import { getVis } from '../../visualizations/_vis_fixture'; const dateHistogramArray = [series, columns, rows, stackedSeries]; const names = ['series', 'columns', 'rows', 'stackedSeries']; +let mockedHTMLElementClientSizes; +let mockedSVGElementGetBBox; +let mockedSVGElementGetComputedTextLength; + dateHistogramArray.forEach(function (data, i) { describe('Vislib Layout Class Test Suite for ' + names[i] + ' Data', function () { let vis; @@ -41,6 +49,12 @@ dateHistogramArray.forEach(function (data, i) { let numberOfCharts; let testLayout; + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + }); + beforeEach(() => { vis = getVis(); mockUiState = getMockUiState(); @@ -52,19 +66,25 @@ dateHistogramArray.forEach(function (data, i) { vis.destroy(); }); + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + }); + describe('createLayout Method', function () { - it('should append all the divs', function () { - expect($(vis.element).find('.visWrapper').length).to.be(1); - expect($(vis.element).find('.visAxis--y').length).to.be(2); - expect($(vis.element).find('.visWrapper__column').length).to.be(1); - expect($(vis.element).find('.visAxis__column--y').length).to.be(2); - expect($(vis.element).find('.y-axis-title').length).to.be.above(0); - expect($(vis.element).find('.visAxis__splitAxes--y').length).to.be(2); - expect($(vis.element).find('.visAxis__spacer--y').length).to.be(4); - expect($(vis.element).find('.visWrapper__chart').length).to.be(numberOfCharts); - expect($(vis.element).find('.visAxis--x').length).to.be(2); - expect($(vis.element).find('.visAxis__splitAxes--x').length).to.be(2); - expect($(vis.element).find('.x-axis-title').length).to.be.above(0); + test('should append all the divs', function () { + expect($(vis.element).find('.visWrapper').length).toBe(1); + expect($(vis.element).find('.visAxis--y').length).toBe(2); + expect($(vis.element).find('.visWrapper__column').length).toBe(1); + expect($(vis.element).find('.visAxis__column--y').length).toBe(2); + expect($(vis.element).find('.y-axis-title').length).toBeGreaterThan(0); + expect($(vis.element).find('.visAxis__splitAxes--y').length).toBe(2); + expect($(vis.element).find('.visAxis__spacer--y').length).toBe(4); + expect($(vis.element).find('.visWrapper__chart').length).toBe(numberOfCharts); + expect($(vis.element).find('.visAxis--x').length).toBe(2); + expect($(vis.element).find('.visAxis__splitAxes--x').length).toBe(2); + expect($(vis.element).find('.x-axis-title').length).toBeGreaterThan(0); }); }); @@ -82,44 +102,44 @@ dateHistogramArray.forEach(function (data, i) { testLayout = new Layout(visConfig); }); - it('should append a div with the correct class name', function () { - expect($(vis.element).find('.chart').length).to.be(numberOfCharts); + test('should append a div with the correct class name', function () { + expect($(vis.element).find('.chart').length).toBe(numberOfCharts); }); - it('should bind data to the DOM element', function () { - expect(!!$(vis.element).find('.chart').data()).to.be(true); + test('should bind data to the DOM element', function () { + expect(!!$(vis.element).find('.chart').data()).toBe(true); }); - it('should create children', function () { - expect(typeof $(vis.element).find('.x-axis-div')).to.be('object'); + test('should create children', function () { + expect(typeof $(vis.element).find('.x-axis-div')).toBe('object'); }); - it('should call split function when provided', function () { - expect(typeof $(vis.element).find('.x-axis-div')).to.be('object'); + test('should call split function when provided', function () { + expect(typeof $(vis.element).find('.x-axis-div')).toBe('object'); }); - it('should throw errors when incorrect arguments provided', function () { + test('should throw errors when incorrect arguments provided', function () { expect(function () { testLayout.layout({ parent: vis.element, type: undefined, class: 'chart', }); - }).to.throwError(); + }).toThrowError(); expect(function () { testLayout.layout({ type: 'div', class: 'chart', }); - }).to.throwError(); + }).toThrowError(); expect(function () { testLayout.layout({ parent: 'histogram', type: 'div', }); - }).to.throwError(); + }).toThrowError(); expect(function () { testLayout.layout({ @@ -129,7 +149,7 @@ dateHistogramArray.forEach(function (data, i) { }, class: 'chart', }); - }).to.throwError(); + }).toThrowError(); }); }); @@ -139,9 +159,9 @@ dateHistogramArray.forEach(function (data, i) { vis.handler.layout.appendElem('.visChart', 'div', 'test'); }); - it('should append DOM element to el with a class name', function () { - expect(typeof $(vis.element).find('.column')).to.be('object'); - expect(typeof $(vis.element).find('.test')).to.be('object'); + test('should append DOM element to el with a class name', function () { + expect(typeof $(vis.element).find('.column')).toBe('object'); + expect(typeof $(vis.element).find('.test')).toBe('object'); }); }); @@ -151,8 +171,8 @@ dateHistogramArray.forEach(function (data, i) { vis.handler.layout.removeAll(vis.element); }); - it('should remove all DOM elements from the el', function () { - expect($(vis.element).children().length).to.be(0); + test('should remove all DOM elements from the el', function () { + expect($(vis.element).children().length).toBe(0); }); }); }); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/vis.js b/src/plugins/vis_type_vislib/public/vislib/vis.test.js similarity index 56% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/vis.js rename to src/plugins/vis_type_vislib/public/vislib/vis.test.js index 36decdc415ed8c..0c4fac97ccb9c5 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/vis.js +++ b/src/plugins/vis_type_vislib/public/vislib/vis.test.js @@ -19,18 +19,25 @@ import _ from 'lodash'; import $ from 'jquery'; -import expect from '@kbn/expect'; - -import series from '../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series'; -import columns from '../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_columns'; -import rows from '../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_rows'; -import stackedSeries from '../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_stacked_series'; -import { getMockUiState } from '../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; -import { getVis } from './_vis_fixture'; +import { + setHTMLElementClientSizes, + setSVGElementGetBBox, + setSVGElementGetComputedTextLength, +} from '../../../../test_utils/public'; +import series from '../fixtures/mock_data/date_histogram/_series'; +import columns from '../fixtures/mock_data/date_histogram/_columns'; +import rows from '../fixtures/mock_data/date_histogram/_rows'; +import stackedSeries from '../fixtures/mock_data/date_histogram/_stacked_series'; +import { getMockUiState } from '../fixtures/mocks'; +import { getVis } from './visualizations/_vis_fixture'; const dataArray = [series, columns, rows, stackedSeries]; const names = ['series', 'columns', 'rows', 'stackedSeries']; +let mockedHTMLElementClientSizes; +let mockedSVGElementGetBBox; +let mockedSVGElementGetComputedTextLength; + dataArray.forEach(function (data, i) { describe('Vislib Vis Test Suite for ' + names[i] + ' Data', function () { const beforeEvent = 'click'; @@ -40,6 +47,12 @@ dataArray.forEach(function (data, i) { let secondVis; let numberOfCharts; + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + }); + beforeEach(() => { vis = getVis(); secondVis = getVis(); @@ -51,34 +64,40 @@ dataArray.forEach(function (data, i) { secondVis.destroy(); }); + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + }); + describe('render Method', function () { beforeEach(function () { vis.render(data, mockUiState); numberOfCharts = vis.handler.charts.length; }); - it('should bind data to this object', function () { - expect(_.isObject(vis.data)).to.be(true); + test('should bind data to this object', function () { + expect(_.isObject(vis.data)).toBe(true); }); - it('should instantiate a handler object', function () { - expect(_.isObject(vis.handler)).to.be(true); + test('should instantiate a handler object', function () { + expect(_.isObject(vis.handler)).toBe(true); }); - it('should append a chart', function () { - expect($('.chart').length).to.be(numberOfCharts); + test('should append a chart', function () { + expect($('.chart').length).toBe(numberOfCharts); }); - it('should throw an error if no data is provided', function () { + test('should throw an error if no data is provided', function () { expect(function () { vis.render(null, mockUiState); - }).to.throwError(); + }).toThrowError(); }); }); describe('getLegendColors method', () => { - it('should return null if no colors are defined', () => { - expect(vis.getLegendColors()).to.equal(null); + test('should return null if no colors are defined', () => { + expect(vis.getLegendColors()).toEqual(null); }); }); @@ -89,12 +108,12 @@ dataArray.forEach(function (data, i) { secondVis.destroy(); }); - it('should remove all DOM elements from el', function () { - expect($(secondVis.el).find('.visWrapper').length).to.be(0); + test('should remove all DOM elements from el', function () { + expect($(secondVis.el).find('.visWrapper').length).toBe(0); }); - it('should not remove visualizations that have not been destroyed', function () { - expect($(vis.element).find('.visWrapper').length).to.be(1); + test('should not remove visualizations that have not been destroyed', function () { + expect($(vis.element).find('.visWrapper').length).toBe(1); }); }); @@ -105,9 +124,9 @@ dataArray.forEach(function (data, i) { vis.set('offset', 'wiggle'); }); - it('should set an attribute', function () { - expect(vis.get('addLegend')).to.be(false); - expect(vis.get('offset')).to.be('wiggle'); + test('should set an attribute', function () { + expect(vis.get('addLegend')).toBe(false); + expect(vis.get('offset')).toBe('wiggle'); }); }); @@ -116,10 +135,10 @@ dataArray.forEach(function (data, i) { vis.render(data, mockUiState); }); - it('should get attribute values', function () { - expect(vis.get('addLegend')).to.be(true); - expect(vis.get('addTooltip')).to.be(true); - expect(vis.get('type')).to.be('point_series'); + test('should get attribute values', function () { + expect(vis.get('addLegend')).toBe(true); + expect(vis.get('addTooltip')).toBe(true); + expect(vis.get('type')).toBe('point_series'); }); }); @@ -148,22 +167,22 @@ dataArray.forEach(function (data, i) { vis.removeAllListeners(afterEvent); }); - it('should add an event and its listeners', function () { + test('should add an event and its listeners', function () { listeners.forEach(function (listener) { - expect(vis.listeners(beforeEvent)).to.contain(listener); + expect(vis.listeners(beforeEvent)).toContain(listener); }); listeners.forEach(function (listener) { - expect(vis.listeners(afterEvent)).to.contain(listener); + expect(vis.listeners(afterEvent)).toContain(listener); }); }); - it('should cause a listener for each event to be attached to each chart', function () { + test('should cause a listener for each event to be attached to each chart', function () { const charts = vis.handler.charts; charts.forEach(function (chart) { - expect(chart.events.listenerCount(beforeEvent)).to.be.above(0); - expect(chart.events.listenerCount(afterEvent)).to.be.above(0); + expect(chart.events.listenerCount(beforeEvent)).toBeGreaterThan(0); + expect(chart.events.listenerCount(afterEvent)).toBeGreaterThan(0); }); }); }); @@ -205,45 +224,45 @@ dataArray.forEach(function (data, i) { vis.removeAllListeners(afterEvent); }); - it('should remove a listener', function () { + test('should remove a listener', function () { const charts = vis.handler.charts; - expect(vis.listeners(beforeEvent)).to.not.contain(listener1); - expect(vis.listeners(beforeEvent)).to.contain(listener2); + expect(vis.listeners(beforeEvent)).not.toContain(listener1); + expect(vis.listeners(beforeEvent)).toContain(listener2); - expect(vis.listeners(afterEvent)).to.not.contain(listener1); - expect(vis.listeners(afterEvent)).to.contain(listener2); + expect(vis.listeners(afterEvent)).not.toContain(listener1); + expect(vis.listeners(afterEvent)).toContain(listener2); // Events should still be attached to charts charts.forEach(function (chart) { - expect(chart.events.listenerCount(beforeEvent)).to.be.above(0); - expect(chart.events.listenerCount(afterEvent)).to.be.above(0); + expect(chart.events.listenerCount(beforeEvent)).toBeGreaterThan(0); + expect(chart.events.listenerCount(afterEvent)).toBeGreaterThan(0); }); }); - it('should remove the event and all listeners when only event passed an argument', function () { + test('should remove the event and all listeners when only event passed an argument', function () { const charts = vis.handler.charts; vis.removeAllListeners(afterEvent); // should remove 'brush' event - expect(vis.listeners(beforeEvent)).to.contain(listener2); - expect(vis.listeners(afterEvent)).to.not.contain(listener2); + expect(vis.listeners(beforeEvent)).toContain(listener2); + expect(vis.listeners(afterEvent)).not.toContain(listener2); // should remove the event from the charts charts.forEach(function (chart) { - expect(chart.events.listenerCount(beforeEvent)).to.be.above(0); - expect(chart.events.listenerCount(afterEvent)).to.be(0); + expect(chart.events.listenerCount(beforeEvent)).toBeGreaterThan(0); + expect(chart.events.listenerCount(afterEvent)).toBe(0); }); }); - it('should remove the event from the chart when the last listener is removed', function () { + test('should remove the event from the chart when the last listener is removed', function () { const charts = vis.handler.charts; vis.off(afterEvent, listener2); - expect(vis.listenerCount(afterEvent)).to.be(0); + expect(vis.listenerCount(afterEvent)).toBe(0); charts.forEach(function (chart) { - expect(chart.events.listenerCount(afterEvent)).to.be(0); + expect(chart.events.listenerCount(afterEvent)).toBe(0); }); }); }); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/_vis_fixture.js b/src/plugins/vis_type_vislib/public/vislib/visualizations/_vis_fixture.js similarity index 83% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/_vis_fixture.js rename to src/plugins/vis_type_vislib/public/vislib/visualizations/_vis_fixture.js index 7a68e847f13b16..0ffa53fc7ca9ce 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/_vis_fixture.js +++ b/src/plugins/vis_type_vislib/public/vislib/visualizations/_vis_fixture.js @@ -19,11 +19,10 @@ import _ from 'lodash'; import $ from 'jquery'; +import { coreMock } from '../../../../../core/public/mocks'; +import { chartPluginMock } from '../../../../charts/public/mocks'; -import { Vis } from '../../../../../../plugins/vis_type_vislib/public/vislib/vis'; - -// TODO: Remove when converted to jest mocks -import { ColorsService } from '../../../../../../plugins/charts/public/services'; +import { Vis } from '../vis'; const $visCanvas = $('
') .attr('id', 'vislib-vis-fixtures') @@ -55,15 +54,12 @@ afterEach(function () { }); const getDeps = () => { - const uiSettings = new Map(); - const colors = new ColorsService(); - colors.init(uiSettings); + const mockUiSettings = coreMock.createSetup().uiSettings; + const charts = chartPluginMock.createStartContract(); return { - uiSettings, - charts: { - colors, - }, + uiSettings: mockUiSettings, + charts: charts, }; }; diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/chart.js b/src/plugins/vis_type_vislib/public/vislib/visualizations/chart.test.js similarity index 77% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/chart.js rename to src/plugins/vis_type_vislib/public/vislib/visualizations/chart.test.js index 2b41ce5d1a5c6a..94c9693819b69b 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/chart.js +++ b/src/plugins/vis_type_vislib/public/vislib/visualizations/chart.test.js @@ -18,11 +18,10 @@ */ import d3 from 'd3'; -import expect from '@kbn/expect'; - -import { Chart } from '../../../../../../../plugins/vis_type_vislib/public/vislib/visualizations/_chart'; -import { getMockUiState } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; -import { getVis } from '../_vis_fixture'; +import { setHTMLElementClientSizes, setSVGElementGetBBox } from '../../../../../test_utils/public'; +import { Chart } from './_chart'; +import { getMockUiState } from '../../fixtures/mocks'; +import { getVis } from './_vis_fixture'; describe('Vislib _chart Test Suite', function () { let vis; @@ -106,6 +105,14 @@ describe('Vislib _chart Test Suite', function () { yAxisLabel: 'Count', }; + let mockedHTMLElementClientSizes; + let mockedSVGElementGetBBox; + + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + }); + beforeEach(() => { el = d3.select('body').append('div').attr('class', 'column-chart'); @@ -127,11 +134,16 @@ describe('Vislib _chart Test Suite', function () { vis.destroy(); }); - it('should be a constructor for visualization modules', function () { - expect(myChart instanceof Chart).to.be(true); + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + }); + + test('should be a constructor for visualization modules', function () { + expect(myChart instanceof Chart).toBe(true); }); - it('should have a render method', function () { - expect(typeof myChart.render === 'function').to.be(true); + test('should have a render method', function () { + expect(typeof myChart.render === 'function').toBe(true); }); }); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/gauge_chart.js b/src/plugins/vis_type_vislib/public/vislib/visualizations/gauge_chart.test.js similarity index 65% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/gauge_chart.js rename to src/plugins/vis_type_vislib/public/vislib/visualizations/gauge_chart.test.js index 7c588800ae659b..6fdc2a134b820e 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/gauge_chart.js +++ b/src/plugins/vis_type_vislib/public/vislib/visualizations/gauge_chart.test.js @@ -19,11 +19,11 @@ import $ from 'jquery'; import _ from 'lodash'; -import expect from '@kbn/expect'; +import { setHTMLElementClientSizes, setSVGElementGetBBox } from '../../../../../test_utils/public'; -import data from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/terms/_series_multiple'; -import { getMockUiState } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; -import { getVis } from '../_vis_fixture'; +import data from '../../fixtures/mock_data/terms/_series_multiple'; +import { getMockUiState } from '../../fixtures/mocks'; +import { getVis } from './_vis_fixture'; describe('Vislib Gauge Chart Test Suite', function () { let vis; @@ -82,6 +82,14 @@ describe('Vislib Gauge Chart Test Suite', function () { chartEl = vis.handler.charts[0].chartEl; } + let mockedHTMLElementClientSizes; + let mockedSVGElementGetBBox; + + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + }); + beforeEach(() => { generateVis(); }); @@ -91,55 +99,60 @@ describe('Vislib Gauge Chart Test Suite', function () { $('.visChart').remove(); }); - it('creates meter gauge', function () { - expect($(chartEl).find('svg').length).to.equal(5); - expect($(chartEl).find('svg > g > g > text').text()).to.equal('2820231918357341352'); + afterAll(function () { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + }); + + test('creates meter gauge', function () { + expect($(chartEl).find('svg').length).toEqual(5); + expect($(chartEl).find('svg > g > g > text').text()).toEqual('2820231918357341352'); }); - it('creates circle gauge', function () { + test('creates circle gauge', function () { generateVis({ gauge: { minAngle: 0, maxAngle: 2 * Math.PI, }, }); - expect($(chartEl).find('svg').length).to.equal(5); + expect($(chartEl).find('svg').length).toEqual(5); }); - it('creates gauge with automatic mode', function () { + test('creates gauge with automatic mode', function () { generateVis({ gauge: { alignment: 'automatic', }, }); - expect($(chartEl).find('svg').width()).to.equal(197); + expect($(chartEl).find('svg')[0].getAttribute('width')).toEqual('97'); }); - it('creates gauge with vertical mode', function () { + test('creates gauge with vertical mode', function () { generateVis({ gauge: { alignment: 'vertical', }, }); - expect($(chartEl).find('svg').width()).to.equal($(chartEl).width()); + expect($(chartEl).find('svg').width()).toEqual($(chartEl).width()); }); - it('applies range settings correctly', function () { + test('applies range settings correctly', function () { const paths = $(chartEl).find('svg > g > g:nth-child(1) > path:nth-child(2)'); const fills = []; paths.each(function () { fills.push(this.style.fill); }); - expect(fills).to.eql([ - 'rgb(165, 0, 38)', - 'rgb(255, 255, 190)', - 'rgb(255, 255, 190)', - 'rgb(0, 104, 55)', - 'rgb(0, 104, 55)', + expect(fills).toEqual([ + 'rgb(165,0,38)', + 'rgb(255,255,190)', + 'rgb(255,255,190)', + 'rgb(0,104,55)', + 'rgb(0,104,55)', ]); }); - it('applies color schema correctly', function () { + test('applies color schema correctly', function () { generateVis({ gauge: { colorSchema: 'Blues', @@ -150,12 +163,12 @@ describe('Vislib Gauge Chart Test Suite', function () { paths.each(function () { fills.push(this.style.fill); }); - expect(fills).to.eql([ - 'rgb(8, 48, 107)', - 'rgb(107, 174, 214)', - 'rgb(107, 174, 214)', - 'rgb(247, 251, 255)', - 'rgb(247, 251, 255)', + expect(fills).toEqual([ + 'rgb(8,48,107)', + 'rgb(107,174,214)', + 'rgb(107,174,214)', + 'rgb(247,251,255)', + 'rgb(247,251,255)', ]); }); }); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/pie_chart.js b/src/plugins/vis_type_vislib/public/vislib/visualizations/pie_chart.test.js similarity index 65% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/pie_chart.js rename to src/plugins/vis_type_vislib/public/vislib/visualizations/pie_chart.test.js index d245905729c7ed..e2da33d0808ba6 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/pie_chart.js +++ b/src/plugins/vis_type_vislib/public/vislib/visualizations/pie_chart.test.js @@ -20,16 +20,25 @@ import d3 from 'd3'; import _ from 'lodash'; import $ from 'jquery'; -import expect from '@kbn/expect'; - -import { getMockUiState } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; -import { getVis } from '../_vis_fixture'; +import { + setHTMLElementClientSizes, + setSVGElementGetBBox, + setSVGElementGetComputedTextLength, +} from '../../../../../test_utils/public'; +import { getMockUiState } from '../../fixtures/mocks'; +import { getVis } from './_vis_fixture'; import { pieChartMockData } from './pie_chart_mock_data'; const names = ['rows', 'columns', 'slices']; const sizes = [0, 5, 15, 30, 60, 120]; +let mockedHTMLElementClientSizes = {}; +let mockWidth; +let mockHeight; +let mockedSVGElementGetBBox; +let mockedSVGElementGetComputedTextLength; + describe('No global chart settings', function () { const visLibParams1 = { el: '
', @@ -40,6 +49,14 @@ describe('No global chart settings', function () { let chart1; let mockUiState; + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + mockWidth = jest.spyOn($.prototype, 'width').mockReturnValue(120); + mockHeight = jest.spyOn($.prototype, 'height').mockReturnValue(120); + }); + beforeEach(() => { chart1 = getVis(visLibParams1); mockUiState = getMockUiState(); @@ -53,8 +70,16 @@ describe('No global chart settings', function () { chart1.destroy(); }); - it('should render chart titles for all charts', function () { - expect($(chart1.element).find('.visAxis__splitTitles--y').length).to.be(1); + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + mockWidth.mockRestore(); + mockHeight.mockRestore(); + }); + + test('should render chart titles for all charts', function () { + expect($(chart1.element).find('.visAxis__splitTitles--y').length).toBe(1); }); describe('_validatePieData method', function () { @@ -76,24 +101,54 @@ describe('No global chart settings', function () { { slices: { children: [{}] } }, ]; - it('should throw an error when all charts contain zeros', function () { + test('should throw an error when all charts contain zeros', function () { expect(function () { chart1.handler.ChartClass.prototype._validatePieData(allZeros); - }).to.throwError(); + }).toThrowError(); }); - it('should not throw an error when only some or no charts contain zeros', function () { + test('should not throw an error when only some or no charts contain zeros', function () { expect(function () { chart1.handler.ChartClass.prototype._validatePieData(someZeros); - }).to.not.throwError(); + }).not.toThrowError(); expect(function () { chart1.handler.ChartClass.prototype._validatePieData(noZeros); - }).to.not.throwError(); + }).not.toThrowError(); }); }); }); describe('Vislib PieChart Class Test Suite', function () { + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + let width = 120; + let height = 120; + const mockWidth = jest.spyOn($.prototype, 'width'); + mockWidth.mockImplementation((size) => { + if (size === undefined) { + return width; + } + width = size; + }); + const mockHeight = jest.spyOn($.prototype, 'height'); + mockHeight.mockImplementation((size) => { + if (size === undefined) { + return height; + } + height = size; + }); + }); + + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + mockWidth.mockRestore(); + mockHeight.mockRestore(); + }); + ['rowData', 'columnData', 'sliceData'].forEach(function (aggItem, i) { describe('Vislib PieChart Class Test Suite for ' + names[i] + ' data', function () { const mockPieData = pieChartMockData[aggItem]; @@ -132,15 +187,15 @@ describe('Vislib PieChart Class Test Suite', function () { }); }); - it('should attach a click event', function () { + test('should attach a click event', function () { vis.handler.charts.forEach(function () { - expect(onClick).to.be(true); + expect(onClick).toBe(true); }); }); - it('should attach a hover event', function () { + test('should attach a hover event', function () { vis.handler.charts.forEach(function () { - expect(onMouseOver).to.be(true); + expect(onMouseOver).toBe(true); }); }); }); @@ -151,25 +206,25 @@ describe('Vislib PieChart Class Test Suite', function () { let svg; let slices; - it('should return an SVG object', function () { + test('should return an SVG object', function () { vis.handler.charts.forEach(function (chart) { $(chart.chartEl).find('svg').empty(); width = $(chart.chartEl).width(); height = $(chart.chartEl).height(); svg = d3.select($(chart.chartEl).find('svg')[0]); slices = chart.chartData.slices; - expect(_.isObject(chart.addPath(width, height, svg, slices))).to.be(true); + expect(_.isObject(chart.addPath(width, height, svg, slices))).toBe(true); }); }); - it('should draw path elements', function () { + test('should draw path elements', function () { vis.handler.charts.forEach(function (chart) { // test whether path elements are drawn - expect($(chart.chartEl).find('path').length).to.be.greaterThan(0); + expect($(chart.chartEl).find('path').length).toBeGreaterThan(0); }); }); - it('should draw labels', function () { + test('should draw labels', function () { vis.handler.charts.forEach(function (chart) { $(chart.chartEl).find('svg').empty(); width = $(chart.chartEl).width(); @@ -178,22 +233,22 @@ describe('Vislib PieChart Class Test Suite', function () { slices = chart.chartData.slices; chart._attr.labels.show = true; chart.addPath(width, height, svg, slices); - expect($(chart.chartEl).find('text.label-text').length).to.be.greaterThan(0); + expect($(chart.chartEl).find('text.label-text').length).toBeGreaterThan(0); }); }); }); describe('draw method', function () { - it('should return a function', function () { + test('should return a function', function () { vis.handler.charts.forEach(function (chart) { - expect(_.isFunction(chart.draw())).to.be(true); + expect(_.isFunction(chart.draw())).toBe(true); }); }); }); sizes.forEach(function (size) { describe('containerTooSmall error', function () { - it('should throw an error', function () { + test('should throw an error', function () { // 20px is the minimum height and width vis.handler.charts.forEach(function (chart) { $(chart.chartEl).height(size); @@ -202,12 +257,12 @@ describe('Vislib PieChart Class Test Suite', function () { if (size < 20) { expect(function () { chart.render(); - }).to.throwError(); + }).toThrowError(); } }); }); - it('should not throw an error', function () { + test('should not throw an error', function () { vis.handler.charts.forEach(function (chart) { $(chart.chartEl).height(size); $(chart.chartEl).width(size); @@ -215,7 +270,7 @@ describe('Vislib PieChart Class Test Suite', function () { if (size > 20) { expect(function () { chart.render(); - }).to.not.throwError(); + }).not.toThrowError(); } }); }); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/pie_chart_mock_data.js b/src/plugins/vis_type_vislib/public/vislib/visualizations/pie_chart_mock_data.js similarity index 100% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/pie_chart_mock_data.js rename to src/plugins/vis_type_vislib/public/vislib/visualizations/pie_chart_mock_data.js diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/area_chart.js b/src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/area_chart.test.js similarity index 64% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/area_chart.js rename to src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/area_chart.test.js index 97589628e5ae9d..3cd58060978ee7 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/area_chart.js +++ b/src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/area_chart.test.js @@ -20,24 +20,22 @@ import d3 from 'd3'; import _ from 'lodash'; import $ from 'jquery'; -import expect from '@kbn/expect'; +import { + setHTMLElementClientSizes, + setSVGElementGetBBox, + setSVGElementGetComputedTextLength, +} from '../../../../../../test_utils/public'; -import { getMockUiState } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; +import { getMockUiState } from '../../../fixtures/mocks'; import { getVis } from '../_vis_fixture'; const dataTypesArray = { - 'series pos': require('../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series') - .default, - 'series pos neg': require('../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series_pos_neg') - .default, - 'series neg': require('../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series_neg') - .default, - 'term columns': require('../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/terms/_columns') - .default, - 'range rows': require('../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/range/_rows') - .default, - stackedSeries: require('../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_stacked_series') - .default, + 'series pos': import('../../../fixtures/mock_data/date_histogram/_series'), + 'series pos neg': import('../../../fixtures/mock_data/date_histogram/_series_pos_neg'), + 'series neg': import('../../../fixtures/mock_data/date_histogram/_series_neg'), + 'term columns': import('../../../fixtures/mock_data/terms/_columns'), + 'range rows': import('../../../fixtures/mock_data/range/_rows'), + stackedSeries: import('../../../fixtures/mock_data/date_histogram/_stacked_series'), }; const visLibParams = { @@ -47,22 +45,38 @@ const visLibParams = { mode: 'stacked', }; +let mockedHTMLElementClientSizes; +let mockedSVGElementGetBBox; +let mockedSVGElementGetComputedTextLength; + _.forOwn(dataTypesArray, function (dataType, dataTypeName) { describe('Vislib Area Chart Test Suite for ' + dataTypeName + ' Data', function () { let vis; let mockUiState; - beforeEach(() => { + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + }); + + beforeEach(async () => { vis = getVis(visLibParams); mockUiState = getMockUiState(); vis.on('brush', _.noop); - vis.render(dataType, mockUiState); + vis.render(await dataType, mockUiState); }); afterEach(function () { vis.destroy(); }); + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + }); + describe('stackData method', function () { let stackedData; let isStacked; @@ -79,15 +93,15 @@ _.forOwn(dataTypesArray, function (dataType, dataTypeName) { }); }); - it('should append a d.y0 key to the data object', function () { - expect(isStacked).to.be(true); + test('should append a d.y0 key to the data object', function () { + expect(isStacked).toBe(true); }); }); describe('addPath method', function () { - it('should append a area paths', function () { + test('should append a area paths', function () { vis.handler.charts.forEach(function (chart) { - expect($(chart.chartEl).find('path').length).to.be.greaterThan(0); + expect($(chart.chartEl).find('path').length).toBeGreaterThan(0); }); }); }); @@ -107,9 +121,9 @@ _.forOwn(dataTypesArray, function (dataType, dataTypeName) { }); }); - it('should attach a hover event', function () { + test('should attach a hover event', function () { vis.handler.charts.forEach(function () { - expect(onMouseOver).to.be(true); + expect(onMouseOver).toBe(true); }); }); }); @@ -140,33 +154,33 @@ _.forOwn(dataTypesArray, function (dataType, dataTypeName) { // listeners, however, I was not able to test for the listener // function being present. I will need to update this test // in the future. - it('should attach a brush g element', function () { + test('should attach a brush g element', function () { vis.handler.charts.forEach(function () { - expect(onBrush).to.be(true); + expect(onBrush).toBe(true); }); }); - it('should attach a click event', function () { + test('should attach a click event', function () { vis.handler.charts.forEach(function () { - expect(onClick).to.be(true); + expect(onClick).toBe(true); }); }); - it('should attach a hover event', function () { + test('should attach a hover event', function () { vis.handler.charts.forEach(function () { - expect(onMouseOver).to.be(true); + expect(onMouseOver).toBe(true); }); }); }); describe('addCircles method', function () { - it('should append circles', function () { + test('should append circles', function () { vis.handler.charts.forEach(function (chart) { - expect($(chart.chartEl).find('circle').length).to.be.greaterThan(0); + expect($(chart.chartEl).find('circle').length).toBeGreaterThan(0); }); }); - it('should not draw circles where d.y === 0', function () { + test('should not draw circles where d.y === 0', function () { vis.handler.charts.forEach(function (chart) { const series = chart.chartData.series; const isZero = series.some(function (d) { @@ -178,80 +192,80 @@ _.forOwn(dataTypesArray, function (dataType, dataTypeName) { }); if (isZero) { - expect(isNotDrawn).to.be(false); + expect(isNotDrawn).toBe(false); } }); }); }); describe('draw method', function () { - it('should return a function', function () { + test('should return a function', function () { vis.handler.charts.forEach(function (chart) { - expect(_.isFunction(chart.draw())).to.be(true); + expect(_.isFunction(chart.draw())).toBe(true); }); }); - it('should return a yMin and yMax', function () { + test('should return a yMin and yMax', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; const domain = yAxis.getScale().domain(); - expect(domain[0]).to.not.be(undefined); - expect(domain[1]).to.not.be(undefined); + expect(domain[0]).not.toBe(undefined); + expect(domain[1]).not.toBe(undefined); }); }); - it('should render a zero axis line', function () { + test('should render a zero axis line', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; if (yAxis.yMin < 0 && yAxis.yMax > 0) { - expect($(chart.chartEl).find('line.zero-line').length).to.be(1); + expect($(chart.chartEl).find('line.zero-line').length).toBe(1); } }); }); }); describe('defaultYExtents is true', function () { - beforeEach(function () { + beforeEach(async function () { vis.visConfigArgs.defaultYExtents = true; - vis.render(dataType, mockUiState); + vis.render(await dataType, mockUiState); }); - it('should return yAxis extents equal to data extents', function () { + test('should return yAxis extents equal to data extents', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; const min = vis.handler.valueAxes[0].axisScale.getYMin(); const max = vis.handler.valueAxes[0].axisScale.getYMax(); const domain = yAxis.getScale().domain(); - expect(domain[0]).to.equal(min); - expect(domain[1]).to.equal(max); + expect(domain[0]).toEqual(min); + expect(domain[1]).toEqual(max); }); }); }); [0, 2, 4, 8].forEach(function (boundsMarginValue) { describe('defaultYExtents is true and boundsMargin is defined', function () { - beforeEach(function () { + beforeEach(async function () { vis.visConfigArgs.defaultYExtents = true; vis.visConfigArgs.boundsMargin = boundsMarginValue; - vis.render(dataType, mockUiState); + vis.render(await dataType, mockUiState); }); - it('should return yAxis extents equal to data extents with boundsMargin', function () { + test('should return yAxis extents equal to data extents with boundsMargin', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; const min = vis.handler.valueAxes[0].axisScale.getYMin(); const max = vis.handler.valueAxes[0].axisScale.getYMax(); const domain = yAxis.getScale().domain(); if (min < 0 && max < 0) { - expect(domain[0]).to.equal(min); - expect(domain[1] - boundsMarginValue).to.equal(max); + expect(domain[0]).toEqual(min); + expect(domain[1] - boundsMarginValue).toEqual(max); } else if (min > 0 && max > 0) { - expect(domain[0] + boundsMarginValue).to.equal(min); - expect(domain[1]).to.equal(max); + expect(domain[0] + boundsMarginValue).toEqual(min); + expect(domain[1]).toEqual(max); } else { - expect(domain[0]).to.equal(min); - expect(domain[1]).to.equal(max); + expect(domain[0]).toEqual(min); + expect(domain[1]).toEqual(max); } }); }); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/column_chart.js b/src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/column_chart.test.js similarity index 59% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/column_chart.js rename to src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/column_chart.test.js index 6b7ccaed25d492..f3d8d66df2d853 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/column_chart.js +++ b/src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/column_chart.test.js @@ -20,20 +20,24 @@ import _ from 'lodash'; import d3 from 'd3'; import $ from 'jquery'; -import expect from '@kbn/expect'; +import { + setHTMLElementClientSizes, + setSVGElementGetBBox, + setSVGElementGetComputedTextLength, +} from '../../../../../../test_utils/public'; // Data -import series from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series'; -import seriesPosNeg from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series_pos_neg'; -import seriesNeg from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series_neg'; -import termsColumns from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/terms/_columns'; -import histogramRows from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/histogram/_rows'; -import stackedSeries from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_stacked_series'; - -import { seriesMonthlyInterval } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series_monthly_interval'; -import { rowsSeriesWithHoles } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_rows_series_with_holes'; -import rowsWithZeros from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_rows'; -import { getMockUiState } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; +import series from '../../../fixtures/mock_data/date_histogram/_series'; +import seriesPosNeg from '../../../fixtures/mock_data/date_histogram/_series_pos_neg'; +import seriesNeg from '../../../fixtures/mock_data/date_histogram/_series_neg'; +import termsColumns from '../../../fixtures/mock_data/terms/_columns'; +import histogramRows from '../../../fixtures/mock_data/histogram/_rows'; +import stackedSeries from '../../../fixtures/mock_data/date_histogram/_stacked_series'; + +import { seriesMonthlyInterval } from '../../../fixtures/mock_data/date_histogram/_series_monthly_interval'; +import { rowsSeriesWithHoles } from '../../../fixtures/mock_data/date_histogram/_rows_series_with_holes'; +import rowsWithZeros from '../../../fixtures/mock_data/date_histogram/_rows'; +import { getMockUiState } from '../../../fixtures/mocks'; import { getVis } from '../_vis_fixture'; // tuple, with the format [description, mode, data] @@ -46,6 +50,10 @@ const dataTypesArray = [ ['stackedSeries', 'stacked', stackedSeries], ]; +let mockedHTMLElementClientSizes; +let mockedSVGElementGetBBox; +let mockedSVGElementGetComputedTextLength; + dataTypesArray.forEach(function (dataType) { const name = dataType[0]; const mode = dataType[1]; @@ -66,6 +74,12 @@ dataTypesArray.forEach(function (dataType) { }, }; + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + }); + beforeEach(() => { vis = getVis(visLibParams); mockUiState = getMockUiState(); @@ -77,6 +91,12 @@ dataTypesArray.forEach(function (dataType) { vis.destroy(); }); + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + }); + describe('stackData method', function () { let stackedData; let isStacked; @@ -93,21 +113,21 @@ dataTypesArray.forEach(function (dataType) { }); }); - it('should stack values when mode is stacked', function () { + test('should stack values when mode is stacked', function () { if (mode === 'stacked') { - expect(isStacked).to.be(true); + expect(isStacked).toBe(true); } }); - it('should stack values when mode is percentage', function () { + test('should stack values when mode is percentage', function () { if (mode === 'percentage') { - expect(isStacked).to.be(true); + expect(isStacked).toBe(true); } }); }); describe('addBars method', function () { - it('should append rects', function () { + test('should append rects', function () { let numOfSeries; let numOfValues; let product; @@ -116,7 +136,7 @@ dataTypesArray.forEach(function (dataType) { numOfSeries = chart.chartData.series.length; numOfValues = chart.chartData.series[0].values.length; product = numOfSeries * numOfValues; - expect($(chart.chartEl).find('.series rect')).to.have.length(product); + expect($(chart.chartEl).find('.series rect')).toHaveLength(product); }); }); }); @@ -138,53 +158,53 @@ dataTypesArray.forEach(function (dataType) { }; } - it('should attach the brush if data is a set is ordered', function () { + test('should attach the brush if data is a set is ordered', function () { vis.handler.charts.forEach(function (chart) { const has = checkChart(chart); const ordered = vis.handler.data.get('ordered'); const allowBrushing = Boolean(ordered); - expect(has.brush).to.be(allowBrushing); + expect(has.brush).toBe(allowBrushing); }); }); - it('should attach a click event', function () { + test('should attach a click event', function () { vis.handler.charts.forEach(function (chart) { const has = checkChart(chart); - expect(has.click).to.be(true); + expect(has.click).toBe(true); }); }); - it('should attach a hover event', function () { + test('should attach a hover event', function () { vis.handler.charts.forEach(function (chart) { const has = checkChart(chart); - expect(has.mouseOver).to.be(true); + expect(has.mouseOver).toBe(true); }); }); }); describe('draw method', function () { - it('should return a function', function () { + test('should return a function', function () { vis.handler.charts.forEach(function (chart) { - expect(_.isFunction(chart.draw())).to.be(true); + expect(_.isFunction(chart.draw())).toBe(true); }); }); - it('should return a yMin and yMax', function () { + test('should return a yMin and yMax', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; const domain = yAxis.getScale().domain(); - expect(domain[0]).to.not.be(undefined); - expect(domain[1]).to.not.be(undefined); + expect(domain[0]).not.toBe(undefined); + expect(domain[1]).not.toBe(undefined); }); }); - it('should render a zero axis line', function () { + test('should render a zero axis line', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; if (yAxis.yMin < 0 && yAxis.yMax > 0) { - expect($(chart.chartEl).find('line.zero-line').length).to.be(1); + expect($(chart.chartEl).find('line.zero-line').length).toBe(1); } }); }); @@ -196,14 +216,14 @@ dataTypesArray.forEach(function (dataType) { vis.render(data, mockUiState); }); - it('should return yAxis extents equal to data extents', function () { + test('should return yAxis extents equal to data extents', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; const min = vis.handler.valueAxes[0].axisScale.getYMin(); const max = vis.handler.valueAxes[0].axisScale.getYMax(); const domain = yAxis.getScale().domain(); - expect(domain[0]).to.equal(min); - expect(domain[1]).to.equal(max); + expect(domain[0]).toEqual(min); + expect(domain[1]).toEqual(max); }); }); }); @@ -215,21 +235,21 @@ dataTypesArray.forEach(function (dataType) { vis.render(data, mockUiState); }); - it('should return yAxis extents equal to data extents with boundsMargin', function () { + test('should return yAxis extents equal to data extents with boundsMargin', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; const min = vis.handler.valueAxes[0].axisScale.getYMin(); const max = vis.handler.valueAxes[0].axisScale.getYMax(); const domain = yAxis.getScale().domain(); if (min < 0 && max < 0) { - expect(domain[0]).to.equal(min); - expect(domain[1] - boundsMarginValue).to.equal(max); + expect(domain[0]).toEqual(min); + expect(domain[1] - boundsMarginValue).toEqual(max); } else if (min > 0 && max > 0) { - expect(domain[0] + boundsMarginValue).to.equal(min); - expect(domain[1]).to.equal(max); + expect(domain[0] + boundsMarginValue).toEqual(min); + expect(domain[1]).toEqual(max); } else { - expect(domain[0]).to.equal(min); - expect(domain[1]).to.equal(max); + expect(domain[0]).toEqual(min); + expect(domain[1]).toEqual(max); } }); }); @@ -249,6 +269,12 @@ describe('stackData method - data set with zeros in percentage mode', function ( zeroFill: true, }; + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + }); + beforeEach(() => { vis = getVis(visLibParams); mockUiState = getMockUiState(); @@ -259,29 +285,35 @@ describe('stackData method - data set with zeros in percentage mode', function ( vis.destroy(); }); - it('should not mutate the injected zeros', function () { + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + }); + + test('should not mutate the injected zeros', function () { vis.render(seriesMonthlyInterval, mockUiState); - expect(vis.handler.charts).to.have.length(1); + expect(vis.handler.charts).toHaveLength(1); const chart = vis.handler.charts[0]; - expect(chart.chartData.series).to.have.length(1); + expect(chart.chartData.series).toHaveLength(1); const series = chart.chartData.series[0].values; // with the interval set in seriesMonthlyInterval data, the point at x=1454309600000 does not exist const point = _.find(series, ['x', 1454309600000]); - expect(point).to.not.be(undefined); - expect(point.y).to.be(0); + expect(point).not.toBe(undefined); + expect(point.y).toBe(0); }); - it('should not mutate zeros that exist in the data', function () { + test('should not mutate zeros that exist in the data', function () { vis.render(rowsWithZeros, mockUiState); - expect(vis.handler.charts).to.have.length(2); + expect(vis.handler.charts).toHaveLength(2); const chart = vis.handler.charts[0]; - expect(chart.chartData.series).to.have.length(5); + expect(chart.chartData.series).toHaveLength(5); const series = chart.chartData.series[0].values; const point = _.find(series, ['x', 1415826240000]); - expect(point).to.not.be(undefined); - expect(point.y).to.be(0); + expect(point).not.toBe(undefined); + expect(point.y).toBe(0); }); }); @@ -296,6 +328,12 @@ describe('datumWidth - split chart data set with holes', function () { zeroFill: true, }; + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + }); + beforeEach(() => { vis = getVis(visLibParams); mockUiState = getMockUiState(); @@ -307,14 +345,20 @@ describe('datumWidth - split chart data set with holes', function () { vis.destroy(); }); - it('should not have bar widths that span multiple time bins', function () { - expect(vis.handler.charts.length).to.equal(1); + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + }); + + test('should not have bar widths that span multiple time bins', function () { + expect(vis.handler.charts.length).toEqual(1); const chart = vis.handler.charts[0]; const rects = $(chart.chartEl).find('.series rect'); const MAX_WIDTH_IN_PIXELS = 27; rects.each(function () { - const width = $(this).attr('width'); - expect(width).to.be.lessThan(MAX_WIDTH_IN_PIXELS); + const width = parseInt($(this).attr('width'), 10); + expect(width).toBeLessThan(MAX_WIDTH_IN_PIXELS); }); }); }); @@ -330,6 +374,15 @@ describe('datumWidth - monthly interval', function () { zeroFill: true, }; + let mockWidth; + + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + mockWidth = jest.spyOn($.prototype, 'width').mockReturnValue(900); + }); + beforeEach(() => { vis = getVis(visLibParams); mockUiState = getMockUiState(); @@ -341,12 +394,19 @@ describe('datumWidth - monthly interval', function () { vis.destroy(); }); - it('should vary bar width when date histogram intervals are not equal', function () { - expect(vis.handler.charts.length).to.equal(1); + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + mockWidth.mockRestore(); + }); + + test('should vary bar width when date histogram intervals are not equal', function () { + expect(vis.handler.charts.length).toEqual(1); const chart = vis.handler.charts[0]; const rects = $(chart.chartEl).find('.series rect'); - const januaryBarWidth = $(rects.get(0)).attr('width'); - const februaryBarWidth = $(rects.get(1)).attr('width'); - expect(februaryBarWidth).to.be.lessThan(januaryBarWidth); + const januaryBarWidth = parseInt($(rects.get(0)).attr('width'), 10); + const februaryBarWidth = parseInt($(rects.get(1)).attr('width'), 10); + expect(februaryBarWidth).toBeLessThan(januaryBarWidth); }); }); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/heatmap_chart.js b/src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/heatmap_chart.test.js similarity index 65% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/heatmap_chart.js rename to src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/heatmap_chart.test.js index 9fa51fb59ed48d..8c727d225c6c3c 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/heatmap_chart.js +++ b/src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/heatmap_chart.test.js @@ -20,15 +20,19 @@ import _ from 'lodash'; import $ from 'jquery'; import d3 from 'd3'; -import expect from '@kbn/expect'; +import { + setHTMLElementClientSizes, + setSVGElementGetBBox, + setSVGElementGetComputedTextLength, +} from '../../../../../../test_utils/public'; // Data -import series from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series'; -import seriesPosNeg from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series_pos_neg'; -import seriesNeg from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series_neg'; -import termsColumns from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/terms/_columns'; -import stackedSeries from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_stacked_series'; -import { getMockUiState } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; +import series from '../../../fixtures/mock_data/date_histogram/_series'; +import seriesPosNeg from '../../../fixtures/mock_data/date_histogram/_series_pos_neg'; +import seriesNeg from '../../../fixtures/mock_data/date_histogram/_series_neg'; +import termsColumns from '../../../fixtures/mock_data/terms/_columns'; +import stackedSeries from '../../../fixtures/mock_data/date_histogram/_stacked_series'; +import { getMockUiState } from '../../../fixtures/mocks'; import { getVis } from '../_vis_fixture'; // tuple, with the format [description, mode, data] @@ -40,7 +44,26 @@ const dataTypesArray = [ ['stackedSeries', stackedSeries], ]; +let mockedHTMLElementClientSizes; +let mockedSVGElementGetBBox; +let mockedSVGElementGetComputedTextLength; +let mockWidth; + describe('Vislib Heatmap Chart Test Suite', function () { + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + mockWidth = jest.spyOn($.prototype, 'width').mockReturnValue(900); + }); + + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + mockWidth.mockRestore(); + }); + dataTypesArray.forEach(function (dataType) { const name = dataType[0]; const data = dataType[1]; @@ -76,7 +99,7 @@ describe('Vislib Heatmap Chart Test Suite', function () { vis.destroy(); }); - it('category axes should be rendered in reverse order', () => { + test('category axes should be rendered in reverse order', () => { const renderedCategoryAxes = vis.handler.renderArray.filter((item) => { return ( item.constructor && @@ -84,22 +107,22 @@ describe('Vislib Heatmap Chart Test Suite', function () { item.axisConfig.get('type') === 'category' ); }); - expect(vis.handler.categoryAxes.length).to.equal(renderedCategoryAxes.length); - expect(vis.handler.categoryAxes[0].axisConfig.get('id')).to.equal( + expect(vis.handler.categoryAxes.length).toEqual(renderedCategoryAxes.length); + expect(vis.handler.categoryAxes[0].axisConfig.get('id')).toEqual( renderedCategoryAxes[1].axisConfig.get('id') ); - expect(vis.handler.categoryAxes[1].axisConfig.get('id')).to.equal( + expect(vis.handler.categoryAxes[1].axisConfig.get('id')).toEqual( renderedCategoryAxes[0].axisConfig.get('id') ); }); describe('addSquares method', function () { - it('should append rects', function () { + test('should append rects', function () { vis.handler.charts.forEach(function (chart) { const numOfRects = chart.chartData.series.reduce((result, series) => { return result + series.values.length; }, 0); - expect($(chart.chartEl).find('.series rect')).to.have.length(numOfRects); + expect($(chart.chartEl).find('.series rect')).toHaveLength(numOfRects); }); }); }); @@ -120,53 +143,53 @@ describe('Vislib Heatmap Chart Test Suite', function () { }; } - it('should attach the brush if data is a set of ordered dates', function () { + test('should attach the brush if data is a set of ordered dates', function () { vis.handler.charts.forEach(function (chart) { const has = checkChart(chart); const ordered = vis.handler.data.get('ordered'); const date = Boolean(ordered && ordered.date); - expect(has.brush).to.be(date); + expect(has.brush).toBe(date); }); }); - it('should attach a click event', function () { + test('should attach a click event', function () { vis.handler.charts.forEach(function (chart) { const has = checkChart(chart); - expect(has.click).to.be(true); + expect(has.click).toBe(true); }); }); - it('should attach a hover event', function () { + test('should attach a hover event', function () { vis.handler.charts.forEach(function (chart) { const has = checkChart(chart); - expect(has.mouseOver).to.be(true); + expect(has.mouseOver).toBe(true); }); }); }); describe('draw method', function () { - it('should return a function', function () { + test('should return a function', function () { vis.handler.charts.forEach(function (chart) { - expect(_.isFunction(chart.draw())).to.be(true); + expect(_.isFunction(chart.draw())).toBe(true); }); }); - it('should return a yMin and yMax', function () { + test('should return a yMin and yMax', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; const domain = yAxis.getScale().domain(); - expect(domain[0]).to.not.be(undefined); - expect(domain[1]).to.not.be(undefined); + expect(domain[0]).not.toBe(undefined); + expect(domain[1]).not.toBe(undefined); }); }); }); - it('should define default colors', function () { - expect(mockUiState.get('vis.defaultColors')).to.not.be(undefined); + test('should define default colors', function () { + expect(mockUiState.get('vis.defaultColors')).not.toBe(undefined); }); - it('should set custom range', function () { + test('should set custom range', function () { vis.destroy(); generateVis({ setColorRange: true, @@ -178,14 +201,14 @@ describe('Vislib Heatmap Chart Test Suite', function () { ], }); const labels = vis.getLegendLabels(); - expect(labels[0]).to.be('0 - 200'); - expect(labels[1]).to.be('200 - 400'); - expect(labels[2]).to.be('400 - 500'); - expect(labels[3]).to.be('500 - Infinity'); + expect(labels[0]).toBe('0 - 200'); + expect(labels[1]).toBe('200 - 400'); + expect(labels[2]).toBe('400 - 500'); + expect(labels[3]).toBe('500 - Infinity'); }); - it('should show correct Y axis title', function () { - expect(vis.handler.categoryAxes[1].axisConfig.get('title.text')).to.equal(''); + test('should show correct Y axis title', function () { + expect(vis.handler.categoryAxes[1].axisConfig.get('title.text')).toEqual(''); }); }); }); diff --git a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/line_chart.js b/src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/line_chart.test.js similarity index 67% rename from src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/line_chart.js rename to src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/line_chart.test.js index dae92c831cd8de..a84c74c0950519 100644 --- a/src/legacy/core_plugins/kibana/public/__tests__/vis_type_vislib/visualizations/line_chart.js +++ b/src/plugins/vis_type_vislib/public/vislib/visualizations/point_series/line_chart.test.js @@ -18,18 +18,22 @@ */ import d3 from 'd3'; -import expect from '@kbn/expect'; import $ from 'jquery'; import _ from 'lodash'; +import { + setHTMLElementClientSizes, + setSVGElementGetBBox, + setSVGElementGetComputedTextLength, +} from '../../../../../../test_utils/public'; // Data -import seriesPos from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series'; -import seriesPosNeg from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series_pos_neg'; -import seriesNeg from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/date_histogram/_series_neg'; -import histogramColumns from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/histogram/_columns'; -import rangeRows from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/range/_rows'; -import termSeries from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mock_data/terms/_series'; -import { getMockUiState } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks'; +import seriesPos from '../../../fixtures/mock_data/date_histogram/_series'; +import seriesPosNeg from '../../../fixtures/mock_data/date_histogram/_series_pos_neg'; +import seriesNeg from '../../../fixtures/mock_data/date_histogram/_series_neg'; +import histogramColumns from '../../../fixtures/mock_data/histogram/_columns'; +import rangeRows from '../../../fixtures/mock_data/range/_rows'; +import termSeries from '../../../fixtures/mock_data/terms/_series'; +import { getMockUiState } from '../../../fixtures/mocks'; import { getVis } from '../_vis_fixture'; const dataTypes = [ @@ -41,7 +45,23 @@ const dataTypes = [ ['term series', termSeries], ]; +let mockedHTMLElementClientSizes; +let mockedSVGElementGetBBox; +let mockedSVGElementGetComputedTextLength; + describe('Vislib Line Chart', function () { + beforeAll(() => { + mockedHTMLElementClientSizes = setHTMLElementClientSizes(512, 512); + mockedSVGElementGetBBox = setSVGElementGetBBox(100); + mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength(100); + }); + + afterAll(() => { + mockedHTMLElementClientSizes.mockRestore(); + mockedSVGElementGetBBox.mockRestore(); + mockedSVGElementGetComputedTextLength.mockRestore(); + }); + dataTypes.forEach(function (type) { const name = type[0]; const data = type[1]; @@ -94,37 +114,37 @@ describe('Vislib Line Chart', function () { // listeners, however, I was not able to test for the listener // function being present. I will need to update this test // in the future. - it('should attach a brush g element', function () { + test('should attach a brush g element', function () { vis.handler.charts.forEach(function () { - expect(onBrush).to.be(true); + expect(onBrush).toBe(true); }); }); - it('should attach a click event', function () { + test('should attach a click event', function () { vis.handler.charts.forEach(function () { - expect(onClick).to.be(true); + expect(onClick).toBe(true); }); }); - it('should attach a hover event', function () { + test('should attach a hover event', function () { vis.handler.charts.forEach(function () { - expect(onMouseOver).to.be(true); + expect(onMouseOver).toBe(true); }); }); }); describe('addCircles method', function () { - it('should append circles', function () { + test('should append circles', function () { vis.handler.charts.forEach(function (chart) { - expect($(chart.chartEl).find('circle').length).to.be.greaterThan(0); + expect($(chart.chartEl).find('circle').length).toBeGreaterThan(0); }); }); }); describe('addLines method', function () { - it('should append a paths', function () { + test('should append a paths', function () { vis.handler.charts.forEach(function (chart) { - expect($(chart.chartEl).find('path').length).to.be.greaterThan(0); + expect($(chart.chartEl).find('path').length).toBeGreaterThan(0); }); }); }); @@ -132,7 +152,7 @@ describe('Vislib Line Chart', function () { // Cannot seem to get these tests to work on the box // They however pass in the browsers //describe('addClipPath method', function () { - // it('should append a clipPath', function () { + // test('should append a clipPath', function () { // vis.handler.charts.forEach(function (chart) { // expect($(chart.chartEl).find('clipPath').length).to.be(1); // }); @@ -140,27 +160,27 @@ describe('Vislib Line Chart', function () { //}); describe('draw method', function () { - it('should return a function', function () { + test('should return a function', function () { vis.handler.charts.forEach(function (chart) { - expect(chart.draw()).to.be.a(Function); + expect(chart.draw()).toBeInstanceOf(Function); }); }); - it('should return a yMin and yMax', function () { + test('should return a yMin and yMax', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; const domain = yAxis.getScale().domain(); - expect(domain[0]).to.not.be(undefined); - expect(domain[1]).to.not.be(undefined); + expect(domain[0]).not.toBe(undefined); + expect(domain[1]).not.toBe(undefined); }); }); - it('should render a zero axis line', function () { + test('should render a zero axis line', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; if (yAxis.yMin < 0 && yAxis.yMax > 0) { - expect($(chart.chartEl).find('line.zero-line').length).to.be(1); + expect($(chart.chartEl).find('line.zero-line').length).toBe(1); } }); }); @@ -172,14 +192,14 @@ describe('Vislib Line Chart', function () { vis.render(data, mockUiState); }); - it('should return yAxis extents equal to data extents', function () { + test('should return yAxis extents equal to data extents', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; const min = vis.handler.valueAxes[0].axisScale.getYMin(); const max = vis.handler.valueAxes[0].axisScale.getYMax(); const domain = yAxis.getScale().domain(); - expect(domain[0]).to.equal(min); - expect(domain[1]).to.equal(max); + expect(domain[0]).toEqual(min); + expect(domain[1]).toEqual(max); }); }); }); @@ -191,21 +211,21 @@ describe('Vislib Line Chart', function () { vis.render(data, mockUiState); }); - it('should return yAxis extents equal to data extents with boundsMargin', function () { + test('should return yAxis extents equal to data extents with boundsMargin', function () { vis.handler.charts.forEach(function (chart) { const yAxis = chart.handler.valueAxes[0]; const min = vis.handler.valueAxes[0].axisScale.getYMin(); const max = vis.handler.valueAxes[0].axisScale.getYMax(); const domain = yAxis.getScale().domain(); if (min < 0 && max < 0) { - expect(domain[0]).to.equal(min); - expect(domain[1] - boundsMarginValue).to.equal(max); + expect(domain[0]).toEqual(min); + expect(domain[1] - boundsMarginValue).toEqual(max); } else if (min > 0 && max > 0) { - expect(domain[0] + boundsMarginValue).to.equal(min); - expect(domain[1]).to.equal(max); + expect(domain[0] + boundsMarginValue).toEqual(min); + expect(domain[1]).toEqual(max); } else { - expect(domain[0]).to.equal(min); - expect(domain[1]).to.equal(max); + expect(domain[0]).toEqual(min); + expect(domain[1]).toEqual(max); } }); }); diff --git a/src/test_utils/public/helpers/index.ts b/src/test_utils/public/helpers/index.ts index c8447743ee287e..fcc0102c766834 100644 --- a/src/test_utils/public/helpers/index.ts +++ b/src/test_utils/public/helpers/index.ts @@ -25,4 +25,9 @@ export { WithMemoryRouter, WithRoute, reactRouterMock } from './router_helpers'; export * from './utils'; -export { setSVGElementGetBBox, setHTMLElementOffset } from './jsdom_svg_mocks'; +export { + setSVGElementGetBBox, + setHTMLElementOffset, + setHTMLElementClientSizes, + setSVGElementGetComputedTextLength, +} from './jsdom_svg_mocks'; diff --git a/src/test_utils/public/helpers/jsdom_svg_mocks.ts b/src/test_utils/public/helpers/jsdom_svg_mocks.ts index dbc8266f663f19..6ef4204baa2ffd 100644 --- a/src/test_utils/public/helpers/jsdom_svg_mocks.ts +++ b/src/test_utils/public/helpers/jsdom_svg_mocks.ts @@ -17,6 +17,20 @@ * under the License. */ +export const setHTMLElementClientSizes = (width: number, height: number) => { + const spyWidth = jest.spyOn(window.HTMLElement.prototype, 'clientWidth', 'get'); + spyWidth.mockReturnValue(width); + const spyHeight = jest.spyOn(window.HTMLElement.prototype, 'clientHeight', 'get'); + spyHeight.mockReturnValue(height); + + return { + mockRestore: () => { + spyWidth.mockRestore(); + spyHeight.mockRestore(); + }, + }; +}; + export const setSVGElementGetBBox = ( width: number, height: number, @@ -41,6 +55,20 @@ export const setSVGElementGetBBox = ( }; }; +export const setSVGElementGetComputedTextLength = (width: number) => { + const SVGElementPrototype = SVGElement.prototype as any; + const originalGetComputedTextLength = SVGElementPrototype.getComputedTextLength; + + // getComputedTextLength is not in the SVGElement.prototype object by default, so we cannot use jest.spyOn for that case + SVGElementPrototype.getComputedTextLength = jest.fn(() => width); + + return { + mockRestore: () => { + SVGElementPrototype.getComputedTextLength = originalGetComputedTextLength; + }, + }; +}; + export const setHTMLElementOffset = (width: number, height: number) => { const offsetWidthSpy = jest.spyOn(window.HTMLElement.prototype, 'offsetWidth', 'get'); offsetWidthSpy.mockReturnValue(width); diff --git a/src/test_utils/public/index.ts b/src/test_utils/public/index.ts index 4f46dfe1578db2..e57f1ae8ea7a9e 100644 --- a/src/test_utils/public/index.ts +++ b/src/test_utils/public/index.ts @@ -17,4 +17,9 @@ * under the License. */ -export { setSVGElementGetBBox, setHTMLElementOffset } from './helpers'; +export { + setSVGElementGetBBox, + setHTMLElementOffset, + setHTMLElementClientSizes, + setSVGElementGetComputedTextLength, +} from './helpers';