1 // Copyright 2011 Google Inc. All Rights Reserved.
4 * @fileoverview Regression tests for range selector.
5 * @author paul.eric.felix@gmail.com (Paul Felix)
7 var RangeSelectorTestCase
= TestCase("range-selector");
9 RangeSelectorTestCase
.prototype.setUp
= function() {
10 document
.body
.innerHTML
= "<div id='graph'></div>";
13 RangeSelectorTestCase
.prototype.tearDown
= function() {
16 RangeSelectorTestCase
.prototype.testRangeSelector
= function() {
20 showRangeSelector
: true
33 var graph
= document
.getElementById("graph");
34 var g
= new Dygraph(graph
, data
, opts
);
35 this.assertGraphExistence(g
, graph
);
38 RangeSelectorTestCase
.prototype.testRangeSelectorWithErrorBars
= function() {
43 showRangeSelector
: true
56 var graph
= document
.getElementById("graph");
57 var g
= new Dygraph(graph
, data
, opts
);
58 this.assertGraphExistence(g
, graph
);
61 RangeSelectorTestCase
.prototype.testRangeSelectorWithCustomBars
= function() {
66 showRangeSelector
: true
79 var graph
= document
.getElementById("graph");
80 var g
= new Dygraph(graph
, data
, opts
);
81 this.assertGraphExistence(g
, graph
);
84 RangeSelectorTestCase
.prototype.testRangeSelectorWithLogScale
= function() {
89 showRangeSelector
: true
102 var graph
= document
.getElementById("graph");
103 var g
= new Dygraph(graph
, data
, opts
);
104 this.assertGraphExistence(g
, graph
);
107 RangeSelectorTestCase
.prototype.testRangeSelectorOptions
= function() {
111 showRangeSelector
: true,
112 rangeSelectorHeight
: 30,
113 rangeSelectorPlotFillColor
: 'lightyellow',
114 rangeSelectorPlotStyleColor
: 'yellow'
127 var graph
= document
.getElementById("graph");
128 var g
= new Dygraph(graph
, data
, opts
);
129 this.assertGraphExistence(g
, graph
);
132 RangeSelectorTestCase
.prototype.testRangeSelectorEnablingAfterCreation
= function() {
148 var graph
= document
.getElementById("graph");
149 var g
= new Dygraph(graph
, data
, opts
);
150 g
.updateOptions({showRangeSelector
: true});
151 this.assertGraphExistence(g
, graph
);
154 // The animatedZooms option does not work with the range selector. Make sure it gets turned off.
155 RangeSelectorTestCase
.prototype.testRangeSelectorWithAnimatedZoomsOption
= function() {
159 showRangeSelector
: true,
173 var graph
= document
.getElementById("graph");
174 var g
= new Dygraph(graph
, data
, opts
);
175 this.assertGraphExistence(g
, graph
);
176 assertFalse(g
.getOption('animatedZooms'));
179 RangeSelectorTestCase
.prototype.testRangeSelectorWithAnimatedZoomsOption2
= function() {
196 var graph
= document
.getElementById("graph");
197 var g
= new Dygraph(graph
, data
, opts
);
198 g
.updateOptions({showRangeSelector
: true});
199 this.assertGraphExistence(g
, graph
);
200 assertFalse(g
.getOption('animatedZooms'));
203 RangeSelectorTestCase
.prototype.testRangeSelectorInteraction
= function() {
207 showRangeSelector
: true
220 var graph
= document
.getElementById("graph");
221 var g
= new Dygraph(graph
, data
, opts
);
222 this.assertGraphExistence(g
, graph
);
223 var zoomhandles
= graph
.getElementsByClassName('dygraph-rangesel-zoomhandle');
225 // Move left zoomhandle in
226 var xRange
= g
.xAxisRange().slice();
228 var mouseDownEvent
= DygraphOps
.createEvent({
234 zoomhandles
[0].dispatchEvent(mouseDownEvent
);
236 var mouseMoveEvent
= DygraphOps
.createEvent({
241 zoomhandles
[0].dispatchEvent(mouseMoveEvent
);
243 var mouseUpEvent
= DygraphOps
.createEvent({
249 zoomhandles
[0].dispatchEvent(mouseUpEvent
);
251 var newXRange
= g
.xAxisRange().slice();
252 assert('left zoomhandle should have moved: '+newXRange
[0]+'>'+xRange
[0], newXRange
[0] > xRange
[0]);
253 assertEquals('right zoomhandle should not have moved', xRange
[1], newXRange
[1]);
255 // Move right zoomhandle in
258 mouseDownEvent
= DygraphOps
.createEvent({
264 zoomhandles
[1].dispatchEvent(mouseDownEvent
);
266 mouseMoveEvent
= DygraphOps
.createEvent({
271 zoomhandles
[1].dispatchEvent(mouseMoveEvent
);
273 mouseUpEvent
= DygraphOps
.createEvent({
279 zoomhandles
[1].dispatchEvent(mouseUpEvent
);
281 var newXRange
= g
.xAxisRange().slice();
282 assert('right zoomhandle should have moved: '+newXRange
[1]+'<'+xRange
[1], newXRange
[1] < xRange
[1]);
283 assertEquals('left zoomhandle should not have moved', xRange
[0], newXRange
[0]);
287 var fgcanvas
= graph
.getElementsByClassName('dygraph-rangesel-fgcanvas')[0];
288 var x
= parseInt(zoomhandles
[0].style
.left
) + 20;
289 var y
= parseInt(zoomhandles
[0].style
.top
);
291 mouseDownEvent
= DygraphOps
.createEvent({
297 fgcanvas
.dispatchEvent(mouseDownEvent
);
301 mouseMoveEvent
= DygraphOps
.createEvent({
306 fgcanvas
.dispatchEvent(mouseMoveEvent
);
308 mouseUpEvent
= DygraphOps
.createEvent({
314 fgcanvas
.dispatchEvent(mouseUpEvent
);
316 var newXRange
= g
.xAxisRange().slice();
317 assert(newXRange
[0]+'<'+xRange
[0], newXRange
[0] < xRange
[0]);
318 assert(newXRange
[1]+'<'+xRange
[1], newXRange
[1] < xRange
[1]);
321 RangeSelectorTestCase
.prototype.assertGraphExistence
= function(g
, graph
) {
323 var zoomhandles
= graph
.getElementsByClassName('dygraph-rangesel-zoomhandle');
324 assertEquals(2, zoomhandles
.length
);
325 var bgcanvas
= graph
.getElementsByClassName('dygraph-rangesel-bgcanvas');
326 assertEquals(1, bgcanvas
.length
);
327 var fgcanvas
= graph
.getElementsByClassName('dygraph-rangesel-fgcanvas');
328 assertEquals(1, fgcanvas
.length
);