1919
2020import _ from 'lodash' ;
2121import d3 from 'd3' ;
22- import expect from '@kbn/expect' ;
22+ import {
23+ setHTMLElementClientSizes ,
24+ setSVGElementGetBBox ,
25+ setSVGElementGetComputedTextLength ,
26+ } from '../../../../../test_utils/public' ;
2327
2428// Data
25- import data from '../../../../../../../plugins/vis_type_vislib/public/ fixtures/mock_data/date_histogram/_series' ;
29+ import data from '../../fixtures/mock_data/date_histogram/_series' ;
2630
27- import { getMockUiState } from '../../../../../../../plugins/vis_type_vislib/public/fixtures/mocks' ;
28- import { getVis } from '../_vis_fixture' ;
31+ import { getMockUiState } from '../../fixtures/mocks' ;
32+ import { getVis } from '../visualizations/_vis_fixture' ;
33+
34+ let mockedHTMLElementClientSizes ;
35+ let mockedSVGElementGetBBox ;
36+ let mockedSVGElementGetComputedTextLength ;
2937
3038describe ( 'Vislib Dispatch Class Test Suite' , function ( ) {
3139 function destroyVis ( vis ) {
@@ -36,6 +44,18 @@ describe('Vislib Dispatch Class Test Suite', function () {
3644 return d3 . select ( element ) . data ( new Array ( n ) ) . enter ( ) . append ( type ) ;
3745 }
3846
47+ beforeAll ( ( ) => {
48+ mockedHTMLElementClientSizes = setHTMLElementClientSizes ( 512 , 512 ) ;
49+ mockedSVGElementGetBBox = setSVGElementGetBBox ( 100 ) ;
50+ mockedSVGElementGetComputedTextLength = setSVGElementGetComputedTextLength ( 100 ) ;
51+ } ) ;
52+
53+ afterAll ( ( ) => {
54+ mockedHTMLElementClientSizes . mockRestore ( ) ;
55+ mockedSVGElementGetBBox . mockRestore ( ) ;
56+ mockedSVGElementGetComputedTextLength . mockRestore ( ) ;
57+ } ) ;
58+
3959 describe ( '' , function ( ) {
4060 let vis ;
4161 let mockUiState ;
@@ -50,13 +70,13 @@ describe('Vislib Dispatch Class Test Suite', function () {
5070 destroyVis ( vis ) ;
5171 } ) ;
5272
53- it ( 'implements on, off, emit methods' , function ( ) {
73+ test ( 'implements on, off, emit methods' , function ( ) {
5474 const events = _ . map ( vis . handler . charts , 'events' ) ;
55- expect ( events . length ) . to . be . above ( 0 ) ;
75+ expect ( events . length ) . toBeGreaterThan ( 0 ) ;
5676 events . forEach ( function ( dispatch ) {
57- expect ( dispatch ) . to . have . property ( 'on' ) ;
58- expect ( dispatch ) . to . have . property ( 'off' ) ;
59- expect ( dispatch ) . to . have . property ( 'emit' ) ;
77+ expect ( dispatch ) . toHaveProperty ( 'on' ) ;
78+ expect ( dispatch ) . toHaveProperty ( 'off' ) ;
79+ expect ( dispatch ) . toHaveProperty ( 'emit' ) ;
6080 } ) ;
6181 } ) ;
6282 } ) ;
@@ -77,15 +97,15 @@ describe('Vislib Dispatch Class Test Suite', function () {
7797 } ) ;
7898
7999 describe ( 'addEvent method' , function ( ) {
80- it ( 'returns a function that binds the passed event to a selection' , function ( ) {
100+ test ( 'returns a function that binds the passed event to a selection' , function ( ) {
81101 const chart = _ . first ( vis . handler . charts ) ;
82102 const apply = chart . events . addEvent ( 'event' , _ . noop ) ;
83- expect ( apply ) . to . be . a ( 'function' ) ;
103+ expect ( apply ) . toBeInstanceOf ( Function ) ;
84104
85105 const els = getEls ( vis . element , 3 , 'div' ) ;
86106 apply ( els ) ;
87107 els . each ( function ( ) {
88- expect ( d3 . select ( this ) . on ( 'event' ) ) . to . be ( _ . noop ) ;
108+ expect ( d3 . select ( this ) . on ( 'event' ) ) . toBe ( _ . noop ) ;
89109 } ) ;
90110 } ) ;
91111 } ) ;
@@ -94,21 +114,21 @@ describe('Vislib Dispatch Class Test Suite', function () {
94114 // checking that they return function which bind the events expected
95115 function checkBoundAddMethod ( name , event ) {
96116 describe ( name + ' method' , function ( ) {
97- it ( 'should be a function' , function ( ) {
117+ test ( 'should be a function' , function ( ) {
98118 vis . handler . charts . forEach ( function ( chart ) {
99- expect ( chart . events [ name ] ) . to . be . a ( 'function' ) ;
119+ expect ( chart . events [ name ] ) . toBeInstanceOf ( Function ) ;
100120 } ) ;
101121 } ) ;
102122
103- it ( 'returns a function that binds ' + event + ' events to a selection' , function ( ) {
123+ test ( 'returns a function that binds ' + event + ' events to a selection' , function ( ) {
104124 const chart = _ . first ( vis . handler . charts ) ;
105125 const apply = chart . events [ name ] ( chart . series [ 0 ] . chartEl ) ;
106- expect ( apply ) . to . be . a ( 'function' ) ;
126+ expect ( apply ) . toBeInstanceOf ( Function ) ;
107127
108128 const els = getEls ( vis . element , 3 , 'div' ) ;
109129 apply ( els ) ;
110130 els . each ( function ( ) {
111- expect ( d3 . select ( this ) . on ( event ) ) . to . be . a ( 'function' ) ;
131+ expect ( d3 . select ( this ) . on ( event ) ) . toBeInstanceOf ( Function ) ;
112132 } ) ;
113133 } ) ;
114134 } ) ;
@@ -119,83 +139,83 @@ describe('Vislib Dispatch Class Test Suite', function () {
119139 checkBoundAddMethod ( 'addClickEvent' , 'click' ) ;
120140
121141 describe ( 'addMousePointer method' , function ( ) {
122- it ( 'should be a function' , function ( ) {
142+ test ( 'should be a function' , function ( ) {
123143 vis . handler . charts . forEach ( function ( chart ) {
124144 const pointer = chart . events . addMousePointer ;
125145
126- expect ( _ . isFunction ( pointer ) ) . to . be ( true ) ;
146+ expect ( _ . isFunction ( pointer ) ) . toBe ( true ) ;
127147 } ) ;
128148 } ) ;
129149 } ) ;
130150
131151 describe ( 'clickEvent handler' , ( ) => {
132152 describe ( 'for pie chart' , ( ) => {
133- it ( 'prepares data points' , ( ) => {
153+ test ( 'prepares data points' , ( ) => {
134154 const expectedResponse = [ { column : 0 , row : 0 , table : { } , value : 0 } ] ;
135155 const d = { rawData : { column : 0 , row : 0 , table : { } , value : 0 } } ;
136156 const chart = _ . first ( vis . handler . charts ) ;
137157 const response = chart . events . clickEventResponse ( d , { isSlices : true } ) ;
138- expect ( response . data ) . to . eql ( expectedResponse ) ;
158+ expect ( response . data ) . toEqual ( expectedResponse ) ;
139159 } ) ;
140160
141- it ( 'remove invalid points' , ( ) => {
161+ test ( 'remove invalid points' , ( ) => {
142162 const expectedResponse = [ { column : 0 , row : 0 , table : { } , value : 0 } ] ;
143163 const d = {
144164 rawData : { column : 0 , row : 0 , table : { } , value : 0 } ,
145165 yRaw : { table : { } , value : 0 } ,
146166 } ;
147167 const chart = _ . first ( vis . handler . charts ) ;
148168 const response = chart . events . clickEventResponse ( d , { isSlices : true } ) ;
149- expect ( response . data ) . to . eql ( expectedResponse ) ;
169+ expect ( response . data ) . toEqual ( expectedResponse ) ;
150170 } ) ;
151171 } ) ;
152172
153173 describe ( 'for xy charts' , ( ) => {
154- it ( 'prepares data points' , ( ) => {
174+ test ( 'prepares data points' , ( ) => {
155175 const expectedResponse = [ { column : 0 , row : 0 , table : { } , value : 0 } ] ;
156176 const d = { xRaw : { column : 0 , row : 0 , table : { } , value : 0 } } ;
157177 const chart = _ . first ( vis . handler . charts ) ;
158178 const response = chart . events . clickEventResponse ( d , { isSlices : false } ) ;
159- expect ( response . data ) . to . eql ( expectedResponse ) ;
179+ expect ( response . data ) . toEqual ( expectedResponse ) ;
160180 } ) ;
161181
162- it ( 'remove invalid points' , ( ) => {
182+ test ( 'remove invalid points' , ( ) => {
163183 const expectedResponse = [ { column : 0 , row : 0 , table : { } , value : 0 } ] ;
164184 const d = {
165185 xRaw : { column : 0 , row : 0 , table : { } , value : 0 } ,
166186 yRaw : { table : { } , value : 0 } ,
167187 } ;
168188 const chart = _ . first ( vis . handler . charts ) ;
169189 const response = chart . events . clickEventResponse ( d , { isSlices : false } ) ;
170- expect ( response . data ) . to . eql ( expectedResponse ) ;
190+ expect ( response . data ) . toEqual ( expectedResponse ) ;
171191 } ) ;
172192 } ) ;
173193 } ) ;
174194 } ) ;
175195
176196 describe ( 'Custom event handlers' , function ( ) {
177- it ( 'should attach whatever gets passed on vis.on() to chart.events' , function ( done ) {
197+ test ( 'should attach whatever gets passed on vis.on() to chart.events' , function ( done ) {
178198 const vis = getVis ( ) ;
179199 const mockUiState = getMockUiState ( ) ;
180200 vis . on ( 'someEvent' , _ . noop ) ;
181201 vis . render ( data , mockUiState ) ;
182202
183203 vis . handler . charts . forEach ( function ( chart ) {
184- expect ( chart . events . listenerCount ( 'someEvent' ) ) . to . be ( 1 ) ;
204+ expect ( chart . events . listenerCount ( 'someEvent' ) ) . toBe ( 1 ) ;
185205 } ) ;
186206
187207 destroyVis ( vis ) ;
188208 done ( ) ;
189209 } ) ;
190210
191- it ( 'can be added after rendering' , function ( ) {
211+ test ( 'can be added after rendering' , function ( ) {
192212 const vis = getVis ( ) ;
193213 const mockUiState = getMockUiState ( ) ;
194214 vis . render ( data , mockUiState ) ;
195215 vis . on ( 'someEvent' , _ . noop ) ;
196216
197217 vis . handler . charts . forEach ( function ( chart ) {
198- expect ( chart . events . listenerCount ( 'someEvent' ) ) . to . be ( 1 ) ;
218+ expect ( chart . events . listenerCount ( 'someEvent' ) ) . toBe ( 1 ) ;
199219 } ) ;
200220
201221 destroyVis ( vis ) ;
0 commit comments