Add tests for isZoomed.
[dygraphs.git] / auto_tests / tests / rolling_average.js
CommitLineData
77b5e09d
DV
1/**
2 * @fileoverview Tests for rolling averages.
3 *
4 * @author danvk@google.com (Dan Vanderkam)
5 */
6var rollingAverageTestCase = TestCase("rolling-average");
7
8rollingAverageTestCase.prototype.setUp = function() {
9 document.body.innerHTML = "<div id='graph'></div>";
10};
11
12rollingAverageTestCase.prototype.tearDown = function() {
13};
14
15rollingAverageTestCase.prototype.getLegend = function() {
16 return document.getElementsByClassName("dygraph-legend")[0].textContent;
17};
18
19rollingAverageTestCase.prototype.testRollingAverage = function() {
20 var opts = {
21 width: 480,
22 height: 320,
23 rollPeriod: 1,
24 showRoller: true
25 };
26 var data = "X,Y\n" +
27 "0,0\n" +
28 "1,1\n" +
29 "2,2\n" +
30 "3,3\n"
31 ;
32
33 var graph = document.getElementById("graph");
34 var g = new Dygraph(graph, data, opts);
35
36 g.setSelection(0); assertEquals("0: Y:0", this.getLegend());
37 g.setSelection(1); assertEquals("1: Y:1", this.getLegend());
38 g.setSelection(2); assertEquals("2: Y:2", this.getLegend());
39 g.setSelection(3); assertEquals("3: Y:3", this.getLegend());
40 assertEquals(1, g.rollPeriod());
41
42 g.updateOptions({rollPeriod: 2});
43 g.setSelection(0); assertEquals("0: Y:0", this.getLegend());
44 g.setSelection(1); assertEquals("1: Y:0.5", this.getLegend());
45 g.setSelection(2); assertEquals("2: Y:1.5", this.getLegend());
46 g.setSelection(3); assertEquals("3: Y:2.5", this.getLegend());
47 assertEquals(2, g.rollPeriod());
48
49 g.updateOptions({rollPeriod: 3});
50 g.setSelection(0); assertEquals("0: Y:0", this.getLegend());
51 g.setSelection(1); assertEquals("1: Y:0.5", this.getLegend());
52 g.setSelection(2); assertEquals("2: Y:1", this.getLegend());
53 g.setSelection(3); assertEquals("3: Y:2", this.getLegend());
54 assertEquals(3, g.rollPeriod());
55
56 g.updateOptions({rollPeriod: 4});
57 g.setSelection(0); assertEquals("0: Y:0", this.getLegend());
58 g.setSelection(1); assertEquals("1: Y:0.5", this.getLegend());
59 g.setSelection(2); assertEquals("2: Y:1", this.getLegend());
60 g.setSelection(3); assertEquals("3: Y:1.5", this.getLegend());
61 assertEquals(4, g.rollPeriod());
62};
63
64rollingAverageTestCase.prototype.testRollBoxDoesntDisapper = function() {
65 var opts = {
66 showRoller: true
67 };
68 var data = "X,Y\n" +
69 "0,0\n" +
70 "1,1\n" +
71 "2,2\n" +
72 "3,3\n"
73 ;
74
75 var graph = document.getElementById("graph");
76 var g = new Dygraph(graph, data, opts);
77
78 var roll_box = graph.getElementsByTagName("input");
79 assertEquals(1, roll_box.length);
80 assertEquals("1", roll_box[0].value);
81
82 graph.style.width = "500px";
83 g.resize();
84 assertEquals(1, roll_box.length);
85 assertEquals("1", roll_box[0].value);
86};
87