1
1
var Plotly = require ( '@lib/index' ) ;
2
2
var Lib = require ( '@src/lib' ) ;
3
3
var constants = require ( '@src/components/legend/constants' ) ;
4
+ var DBLCLICKDELAY = require ( '@src/constants/interactions' ) . DBLCLICKDELAY ;
4
5
5
6
var d3 = require ( 'd3' ) ;
6
7
var createGraph = require ( '../assets/create_graph_div' ) ;
7
8
var destroyGraph = require ( '../assets/destroy_graph_div' ) ;
8
9
var getBBox = require ( '../assets/get_bbox' ) ;
9
10
var mock = require ( '../../image/mocks/legend_scroll.json' ) ;
10
11
11
-
12
12
describe ( 'The legend' , function ( ) {
13
13
'use strict' ;
14
14
@@ -96,7 +96,7 @@ describe('The legend', function() {
96
96
'translate(0, ' + finalDataScroll + ')' ) ;
97
97
} ) ;
98
98
99
- it ( 'should keep the scrollbar position after a toggle event' , function ( ) {
99
+ it ( 'should keep the scrollbar position after a toggle event' , function ( done ) {
100
100
var legend = getLegend ( ) ,
101
101
scrollBox = getScrollBox ( ) ,
102
102
toggle = getToggle ( ) ,
@@ -105,14 +105,18 @@ describe('The legend', function() {
105
105
legend . dispatchEvent ( scrollTo ( wheelDeltaY ) ) ;
106
106
107
107
var dataScroll = scrollBox . getAttribute ( 'data-scroll' ) ;
108
- toggle . dispatchEvent ( new MouseEvent ( 'click' ) ) ;
109
- expect ( + toggle . parentNode . style . opacity ) . toBeLessThan ( 1 ) ;
110
- expect ( scrollBox . getAttribute ( 'data-scroll' ) ) . toBe ( dataScroll ) ;
111
- expect ( scrollBox . getAttribute ( 'transform' ) ) . toBe (
112
- 'translate(0, ' + dataScroll + ')' ) ;
108
+ toggle . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
109
+ toggle . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
110
+ setTimeout ( function ( ) {
111
+ expect ( + toggle . parentNode . style . opacity ) . toBeLessThan ( 1 ) ;
112
+ expect ( scrollBox . getAttribute ( 'data-scroll' ) ) . toBe ( dataScroll ) ;
113
+ expect ( scrollBox . getAttribute ( 'transform' ) ) . toBe (
114
+ 'translate(0, ' + dataScroll + ')' ) ;
115
+ done ( ) ;
116
+ } , DBLCLICKDELAY * 2 ) ;
113
117
} ) ;
114
118
115
- it ( 'should be restored and functional after relayout' , function ( ) {
119
+ it ( 'should be restored and functional after relayout' , function ( done ) {
116
120
var wheelDeltaY = 100 ,
117
121
legend = getLegend ( ) ,
118
122
scrollBox ,
@@ -139,13 +143,17 @@ describe('The legend', function() {
139
143
expect ( scrollBar . getAttribute ( 'y' ) ) . toBe ( scrollBarY ) ;
140
144
141
145
var dataScroll = scrollBox . getAttribute ( 'data-scroll' ) ;
142
- toggle . dispatchEvent ( new MouseEvent ( 'click' ) ) ;
143
- expect ( + toggle . parentNode . style . opacity ) . toBeLessThan ( 1 ) ;
144
- expect ( scrollBox . getAttribute ( 'data-scroll' ) ) . toBe ( dataScroll ) ;
145
- expect ( scrollBox . getAttribute ( 'transform' ) ) . toBe (
146
- 'translate(0, ' + dataScroll + ')' ) ;
147
- expect ( scrollBar . getAttribute ( 'width' ) ) . toBeGreaterThan ( 0 ) ;
148
- expect ( scrollBar . getAttribute ( 'height' ) ) . toBeGreaterThan ( 0 ) ;
146
+ toggle . dispatchEvent ( new MouseEvent ( 'mousedown' ) ) ;
147
+ toggle . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
148
+ setTimeout ( function ( ) {
149
+ expect ( + toggle . parentNode . style . opacity ) . toBeLessThan ( 1 ) ;
150
+ expect ( scrollBox . getAttribute ( 'data-scroll' ) ) . toBe ( dataScroll ) ;
151
+ expect ( scrollBox . getAttribute ( 'transform' ) ) . toBe (
152
+ 'translate(0, ' + dataScroll + ')' ) ;
153
+ expect ( scrollBar . getAttribute ( 'width' ) ) . toBeGreaterThan ( 0 ) ;
154
+ expect ( scrollBar . getAttribute ( 'height' ) ) . toBeGreaterThan ( 0 ) ;
155
+ done ( ) ;
156
+ } , DBLCLICKDELAY * 2 ) ;
149
157
} ) ;
150
158
151
159
it ( 'should constrain scrolling to the contents' , function ( ) {
0 commit comments