@@ -3,11 +3,12 @@ var Lib = require('@src/lib');
33
44var RangeSlider = require ( '@src/components/rangeslider' ) ;
55var constants = require ( '@src/components/rangeslider/constants' ) ;
6+ var mock = require ( '../../image/mocks/range_slider.json' ) ;
67
78var createGraphDiv = require ( '../assets/create_graph_div' ) ;
89var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
9- var mock = require ( '../../image/mocks/range_slider.json' ) ;
1010var mouseEvent = require ( '../assets/mouse_event' ) ;
11+ var customMatchers = require ( '../assets/custom_matchers' ) ;
1112
1213
1314describe ( 'the range slider' , function ( ) {
@@ -23,9 +24,18 @@ describe('the range slider', function() {
2324 return document . getElementsByClassName ( className ) [ 0 ] ;
2425 }
2526
27+ function testTranslate1D ( node , val ) {
28+ var transformParts = node . getAttribute ( 'transform' ) . split ( '(' ) ;
29+ expect ( transformParts [ 0 ] ) . toEqual ( 'translate' ) ;
30+ expect ( + transformParts [ 1 ] . split ( ',0)' ) [ 0 ] ) . toBeCloseTo ( val , 0 ) ;
31+ }
2632
2733 describe ( 'when specified as visible' , function ( ) {
2834
35+ beforeAll ( function ( ) {
36+ jasmine . addMatchers ( customMatchers ) ;
37+ } ) ;
38+
2939 beforeEach ( function ( done ) {
3040 gd = createGraphDiv ( ) ;
3141
@@ -67,73 +77,73 @@ describe('the range slider', function() {
6777 it ( 'should react to resizing the minimum handle' , function ( done ) {
6878 var start = 85 ,
6979 end = 140 ,
70- dataMinStart = rangeSlider . getAttribute ( 'data-min' ) ,
7180 diff = end - start ;
7281
82+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 0 , 49 ] ) ;
83+
7384 slide ( start , sliderY , end , sliderY ) . then ( function ( ) {
7485 var maskMin = children [ 2 ] ,
7586 handleMin = children [ 5 ] ;
7687
77- expect ( rangeSlider . getAttribute ( 'data-min' ) ) . toEqual ( String ( + dataMinStart + diff ) ) ;
88+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 4.35 , 49 ] ) ;
7889 expect ( maskMin . getAttribute ( 'width' ) ) . toEqual ( String ( diff ) ) ;
7990 expect ( handleMin . getAttribute ( 'transform' ) ) . toBe ( 'translate(' + ( diff - 3 ) + ',0)' ) ;
8091 } ) . then ( done ) ;
8192 } ) ;
8293
83- function testTranslate1D ( node , val ) {
84- var transformParts = node . getAttribute ( 'transform' ) . split ( '(' ) ;
85- expect ( transformParts [ 0 ] ) . toEqual ( 'translate' ) ;
86- expect ( + transformParts [ 1 ] . split ( ',0)' ) [ 0 ] ) . toBeCloseTo ( val , 0 ) ;
87- }
88-
8994 it ( 'should react to resizing the maximum handle' , function ( done ) {
9095 var start = 695 ,
9196 end = 490 ,
92- dataMaxStart = rangeSlider . getAttribute ( 'data-max' ) ,
97+ dataMaxStart = gd . _fullLayout . xaxis . rangeslider . d2p ( 49 ) ,
9398 diff = end - start ;
9499
100+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 0 , 49 ] ) ;
101+
95102 slide ( start , sliderY , end , sliderY ) . then ( function ( ) {
96103 var maskMax = children [ 3 ] ,
97104 handleMax = children [ 6 ] ;
98105
99- expect ( + rangeSlider . getAttribute ( 'data-max' ) ) . toBeCloseTo ( + dataMaxStart + diff , 0 ) ;
106+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 0 , 32.77 ] ) ;
100107 expect ( + maskMax . getAttribute ( 'width' ) ) . toBeCloseTo ( - diff ) ;
101- testTranslate1D ( handleMax , + dataMaxStart + diff ) ;
108+
109+ testTranslate1D ( handleMax , dataMaxStart + diff ) ;
102110 } ) . then ( done ) ;
103111 } ) ;
104112
105113 it ( 'should react to moving the slidebox left to right' , function ( done ) {
106114 var start = 250 ,
107115 end = 300 ,
108- dataMinStart = rangeSlider . getAttribute ( 'data-min' ) ,
116+ dataMinStart = gd . _fullLayout . xaxis . rangeslider . d2p ( 0 ) ,
109117 diff = end - start ;
110118
119+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 0 , 49 ] ) ;
120+
111121 slide ( start , sliderY , end , sliderY ) . then ( function ( ) {
112122 var maskMin = children [ 2 ] ,
113123 handleMin = children [ 5 ] ;
114124
115- expect ( + rangeSlider . getAttribute ( 'data-min' ) ) . toBeCloseTo ( String ( + dataMinStart + diff ) ) ;
125+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 3.96 , 49 ] ) ;
116126 expect ( + maskMin . getAttribute ( 'width' ) ) . toBeCloseTo ( String ( diff ) ) ;
117- testTranslate1D ( handleMin , + dataMinStart + diff - 3 ) ;
127+ testTranslate1D ( handleMin , dataMinStart + diff - 3 ) ;
118128 } ) . then ( done ) ;
119129 } ) ;
120130
121131 it ( 'should react to moving the slidebox right to left' , function ( done ) {
122132 var start = 300 ,
123133 end = 250 ,
124- dataMaxStart = rangeSlider . getAttribute ( 'data-max' ) ,
134+ dataMaxStart = gd . _fullLayout . xaxis . rangeslider . d2p ( 49 ) ,
125135 diff = end - start ;
126136
137+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 0 , 49 ] ) ;
138+
127139 slide ( start , sliderY , end , sliderY ) . then ( function ( ) {
128140 var maskMax = children [ 3 ] ,
129141 handleMax = children [ 6 ] ;
130142
131- expect ( + rangeSlider . getAttribute ( 'data-max' ) ) . toBeCloseTo ( + dataMaxStart + diff ) ;
143+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( [ 0 , 45.04 ] ) ;
132144 expect ( + maskMax . getAttribute ( 'width' ) ) . toBeCloseTo ( - diff ) ;
133- testTranslate1D ( handleMax , + dataMaxStart + diff ) ;
145+ testTranslate1D ( handleMax , dataMaxStart + diff ) ;
134146 } ) . then ( done ) ;
135-
136-
137147 } ) ;
138148
139149 it ( 'should resize the main plot when rangeslider has moved' , function ( done ) {
@@ -158,22 +168,35 @@ describe('the range slider', function() {
158168 } ) ;
159169
160170 it ( 'should relayout with relayout "array syntax"' , function ( done ) {
161- Plotly . relayout ( gd , 'xaxis.range' , [ 10 , 20 ] )
162- . then ( function ( ) {
163- expect ( gd . _fullLayout . xaxis . range ) . toEqual ( [ 10 , 20 ] ) ;
164- expect ( + rangeSlider . getAttribute ( 'data-min' ) ) . toBeCloseTo ( 124.69 , - 1 ) ;
165- expect ( + rangeSlider . getAttribute ( 'data-max' ) ) . toBeCloseTo ( 249.39 , - 1 ) ;
166- } )
167- . then ( done ) ;
171+ Plotly . relayout ( gd , 'xaxis.range' , [ 10 , 20 ] ) . then ( function ( ) {
172+ var maskMin = children [ 2 ] ,
173+ maskMax = children [ 3 ] ,
174+ handleMin = children [ 5 ] ,
175+ handleMax = children [ 6 ] ;
176+
177+ expect ( + maskMin . getAttribute ( 'width' ) ) . toBeCloseTo ( 126.32 , 0 ) ;
178+ expect ( + maskMax . getAttribute ( 'width' ) ) . toBeCloseTo ( 366.34 , 0 ) ;
179+ testTranslate1D ( handleMin , 123.32 ) ;
180+ testTranslate1D ( handleMax , 252.65 ) ;
181+ } )
182+ . then ( done ) ;
168183 } ) ;
169184
170185 it ( 'should relayout with relayout "element syntax"' , function ( done ) {
171- Plotly . relayout ( gd , 'xaxis.range[0]' , 10 )
172- . then ( function ( ) {
173- expect ( gd . _fullLayout . xaxis . range [ 0 ] ) . toEqual ( 10 ) ;
174- expect ( + rangeSlider . getAttribute ( 'data-min' ) ) . toBeCloseTo ( 124.69 , - 1 ) ;
175- } )
176- . then ( done ) ;
186+ Plotly . relayout ( gd , 'xaxis.range[0]' , 10 ) . then ( function ( ) {
187+ var maskMin = children [ 2 ] ,
188+ maskMax = children [ 3 ] ,
189+ handleMin = children [ 5 ] ,
190+ handleMax = children [ 6 ] ;
191+
192+ expect ( + maskMin . getAttribute ( 'width' ) ) . toBeCloseTo ( 126.32 , 0 ) ;
193+ expect ( + maskMax . getAttribute ( 'width' ) ) . toBeCloseTo ( 0 ) ;
194+ testTranslate1D ( handleMin , 123.32 ) ;
195+ testTranslate1D ( handleMax , 619 ) ;
196+ } )
197+ . then ( done ) ;
198+ } ) ;
199+
177200 } ) ;
178201 } ) ;
179202
0 commit comments