@@ -252,5 +252,80 @@ describe('update sliders interactions', function() {
252252 function assertNodeCount ( query , cnt ) {
253253 expect ( d3 . selectAll ( query ) . size ( ) ) . toEqual ( cnt ) ;
254254 }
255+ } ) ;
256+
257+ describe ( 'updateevent and updatevalue' , function ( ) {
258+ 'use strict' ;
259+
260+ var mock = require ( '@mocks/sliders.json' ) ;
261+
262+ var gd ;
263+
264+ beforeEach ( function ( done ) {
265+ gd = createGraphDiv ( ) ;
266+
267+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
268+
269+ mockCopy . layout . sliders [ 0 ] . updateevent = 'plotly_someevent' ;
270+ mockCopy . layout . sliders [ 0 ] . updateevent = 'plotly_someevent' ;
271+
272+ Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( done ) ;
273+ } ) ;
274+
275+ afterEach ( function ( ) {
276+ Plotly . purge ( gd ) ;
277+ destroyGraphDiv ( ) ;
278+ } ) ;
279+
280+ it ( 'updates a slider when an event is triggered' , function ( done ) {
281+ Plotly . relayout ( gd , {
282+ 'sliders[0].updateevent' : 'plotly_someevent' ,
283+ 'sliders[0].updatevalue' : 'value'
284+ } ) . then ( function ( ) {
285+ expect ( gd . _fullLayout . sliders [ 0 ] . active ) . toEqual ( 2 ) ;
286+ gd . emit ( 'plotly_someevent' , { value : 'green' } ) ;
287+ } ) . then ( function ( ) {
288+ expect ( gd . _fullLayout . sliders [ 0 ] . active ) . toEqual ( 3 ) ;
289+ } ) . catch ( fail ) . then ( done ) ;
290+ } ) ;
291+
292+ it ( 'updates a slider when updatevalue unspecified' , function ( done ) {
293+ Plotly . relayout ( gd , {
294+ 'sliders[0].updateevent' : 'plotly_someevent'
295+ } ) . then ( function ( ) {
296+ expect ( gd . _fullLayout . sliders [ 0 ] . active ) . toEqual ( 2 ) ;
297+ gd . emit ( 'plotly_someevent' , 'green' ) ;
298+ } ) . then ( function ( ) {
299+ expect ( gd . _fullLayout . sliders [ 0 ] . active ) . toEqual ( 3 ) ;
300+ } ) . catch ( fail ) . then ( done ) ;
301+ } ) ;
255302
303+ it ( 'updates a slider when any of multiple updateevents occurs' , function ( done ) {
304+ Plotly . relayout ( gd , {
305+ 'sliders[0].updateevent' : [ 'plotly_someevent' , 'plotly_anotherevent' ]
306+ } ) . then ( function ( ) {
307+ expect ( gd . _fullLayout . sliders [ 0 ] . active ) . toEqual ( 2 ) ;
308+ gd . emit ( 'plotly_someevent' , 'green' ) ;
309+ } ) . then ( function ( ) {
310+ expect ( gd . _fullLayout . sliders [ 0 ] . active ) . toEqual ( 3 ) ;
311+ gd . emit ( 'plotly_anotherevent' , 'yellow' ) ;
312+ } ) . then ( function ( ) {
313+ expect ( gd . _fullLayout . sliders [ 0 ] . active ) . toEqual ( 2 ) ;
314+ } ) . catch ( fail ) . then ( done ) ;
315+ } ) ;
316+
317+ it ( 'matches update events with update values' , function ( done ) {
318+ Plotly . relayout ( gd , {
319+ 'sliders[0].updateevent' : [ 'plotly_someevent' , 'plotly_anotherevent' ] ,
320+ 'sliders[0].updatevalue' : [ 'foo' , 'bar' ]
321+ } ) . then ( function ( ) {
322+ expect ( gd . _fullLayout . sliders [ 0 ] . active ) . toEqual ( 2 ) ;
323+ gd . emit ( 'plotly_someevent' , { foo : 'green' } ) ;
324+ } ) . then ( function ( ) {
325+ expect ( gd . _fullLayout . sliders [ 0 ] . active ) . toEqual ( 3 ) ;
326+ gd . emit ( 'plotly_anotherevent' , { bar : 'yellow' } ) ;
327+ } ) . then ( function ( ) {
328+ expect ( gd . _fullLayout . sliders [ 0 ] . active ) . toEqual ( 2 ) ;
329+ } ) . catch ( fail ) . then ( done ) ;
330+ } ) ;
256331} ) ;
0 commit comments