@@ -6,6 +6,7 @@ var customMatchers = require('../assets/custom_matchers');
66var createGraphDiv = require ( '../assets/create_graph_div' ) ;
77var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
88
9+ var d3 = require ( 'd3' ) ;
910var click = require ( '../assets/click' ) ;
1011var getClientPosition = require ( '../assets/get_client_position' ) ;
1112var mouseEvent = require ( '../assets/mouse_event' ) ;
@@ -175,9 +176,7 @@ describe('pie hovering', function() {
175176 } ) ;
176177
177178 describe ( 'labels' , function ( ) {
178-
179- var gd ,
180- mockCopy ;
179+ var gd , mockCopy ;
181180
182181 beforeEach ( function ( ) {
183182 gd = createGraphDiv ( ) ;
@@ -186,44 +185,60 @@ describe('pie hovering', function() {
186185
187186 afterEach ( destroyGraphDiv ) ;
188187
189- it ( 'should show the default selected values' , function ( done ) {
190-
191- var expected = [ '4' , '5' , '33.3%' ] ;
192-
193- Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
188+ function _hover ( ) {
189+ mouseEvent ( 'mouseover' , 223 , 143 ) ;
190+ }
194191
195- mouseEvent ( 'mouseover' , 223 , 143 ) ;
192+ function assertLabel ( expected ) {
193+ var labels = d3 . selectAll ( '.hovertext .nums .line' ) ;
196194
197- var labels = Plotly . d3 . selectAll ( '.hovertext .nums .line' ) ;
195+ expect ( labels [ 0 ] . length ) . toBe ( expected . length ) ;
198196
199- expect ( labels [ 0 ] . length ) . toBe ( 3 ) ;
197+ labels . each ( function ( _ , i ) {
198+ expect ( d3 . select ( this ) . text ( ) ) . toBe ( expected [ i ] ) ;
199+ } ) ;
200+ }
200201
201- labels . each ( function ( _ , i ) {
202- expect ( Plotly . d3 . select ( this ) . text ( ) ) . toBe ( expected [ i ] ) ;
203- } ) ;
204- } ) . then ( done ) ;
202+ it ( 'should show the default selected values' , function ( done ) {
203+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout )
204+ . then ( _hover )
205+ . then ( function ( ) {
206+ assertLabel ( [ '4' , '5' , '33.3%' ] ) ;
207+
208+ return Plotly . restyle ( gd , 'text' , [ [ 'A' , 'B' , 'C' , 'D' , 'E' ] ] ) ;
209+ } )
210+ . then ( _hover )
211+ . then ( function ( ) {
212+ assertLabel ( [ '4' , 'E' , '5' , '33.3%' ] ) ;
213+
214+ return Plotly . restyle ( gd , 'hovertext' , [ [
215+ 'Apple' , 'Banana' , 'Clementine' , 'Dragon Fruit' , 'Eggplant'
216+ ] ] ) ;
217+ } )
218+ . then ( _hover )
219+ . then ( function ( ) {
220+ assertLabel ( [ '4' , 'Eggplant' , '5' , '33.3%' ] ) ;
221+
222+ return Plotly . restyle ( gd , 'hovertext' , 'SUP' ) ;
223+ } )
224+ . then ( _hover )
225+ . then ( function ( ) {
226+ assertLabel ( [ '4' , 'SUP' , '5' , '33.3%' ] ) ;
227+ } )
228+ . then ( done ) ;
205229 } ) ;
206230
207231 it ( 'should show the correct separators for values' , function ( done ) {
208-
209- var expected = [ '0' , '12|345|678@91' , '99@9%' ] ;
210-
211232 mockCopy . layout . separators = '@|' ;
212233 mockCopy . data [ 0 ] . values [ 0 ] = 12345678.912 ;
213234 mockCopy . data [ 0 ] . values [ 1 ] = 10000 ;
214235
215- Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( function ( ) {
216-
217- mouseEvent ( 'mouseover' , 223 , 143 ) ;
218-
219- var labels = Plotly . d3 . selectAll ( '.hovertext .nums .line' ) ;
220-
221- expect ( labels [ 0 ] . length ) . toBe ( 3 ) ;
222-
223- labels . each ( function ( _ , i ) {
224- expect ( Plotly . d3 . select ( this ) . text ( ) ) . toBe ( expected [ i ] ) ;
225- } ) ;
226- } ) . then ( done ) ;
236+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout )
237+ . then ( _hover )
238+ . then ( function ( ) {
239+ assertLabel ( [ '0' , '12|345|678@91' , '99@9%' ] ) ;
240+ } )
241+ . then ( done ) ;
227242 } ) ;
228243 } ) ;
229244} ) ;
0 commit comments