consolidating scripts
[dygraphs.git] / auto_tests / tests / sanity.js
CommitLineData
718ad8e2 1// Copyright (c) 2011 Google, Inc.
644eff8b
RK
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21
22/**
23 * @fileoverview Test cases that ensure Dygraphs works at all.
24 *
25 * @author konigsberg@google.com (Robert Konigsberg)
26 */
644eff8b 27
e8c70e4e
DV
28import Dygraph from '../../src/dygraph';
29
89fdcedb 30describe("dygraphs-sanity", function() {
644eff8b 31
1b7afc93
DV
32var DEAD_SIMPLE_DATA = 'X,Y\n10,2100';
33var ZERO_TO_FIFTY = 'X,Y\n10,0\n20,50';
34
e8c70e4e 35cleanupAfterEach();
644eff8b
RK
36
37/**
38 * The sanity test of sanity tests.
39 */
89fdcedb
DV
40it('testTrue', function() {
41 assert.isTrue(true);
42});
644eff8b
RK
43
44/**
45 * Sanity test that ensures the graph element exists.
46 */
89fdcedb 47it('testGraphExists', function() {
644eff8b 48 var graph = document.getElementById("graph");
89fdcedb
DV
49 assert.isNotNull(graph);
50});
644eff8b 51
7165f97b
RK
52// TODO(konigsberg): Move the following tests to a new package that
53// tests all kinds of toDomCoords, toDataCoords, toPercent, et cetera.
54
644eff8b
RK
55/**
56 * A sanity test of sorts, by ensuring the dygraph is created, and
57 * isn't just some piece of junk object.
58 */
89fdcedb 59it('testToString', function() {
644eff8b
RK
60 var graph = document.getElementById("graph");
61 var g = new Dygraph(graph, DEAD_SIMPLE_DATA, {});
89fdcedb
DV
62 assert.isNotNull(g);
63 assert.equal("[Dygraph graph]", g.toString());
64});
644eff8b
RK
65
66/**
67 * Test that when no valueRange is specified, the y axis range is
68 * adjusted by 10% on top.
69 */
89fdcedb 70it('testYAxisRange_default', function() {
644eff8b 71 var graph = document.getElementById("graph");
89fdcedb 72 assert.equal(0, graph.style.length);
644eff8b 73 var g = new Dygraph(graph, ZERO_TO_FIFTY, {});
89fdcedb
DV
74 assert.deepEqual([0, 55], g.yAxisRange(0));
75});
644eff8b
RK
76
77/**
78 * Test that valueRange matches the y-axis range specifically.
79 */
89fdcedb 80it('testYAxisRange_custom', function() {
644eff8b
RK
81 var graph = document.getElementById("graph");
82 var g = new Dygraph(graph, ZERO_TO_FIFTY, { valueRange: [0,50] });
89fdcedb 83 assert.deepEqual([0, 50], g.yAxisRange(0));
4dd0ac55 84 g.updateOptions({valueRange: null, axes: {y: {valueRange: [10, 40]}}});
89fdcedb
DV
85 assert.deepEqual([10, 40], g.yAxisRange(0));
86});
644eff8b 87
7165f97b 88/**
644eff8b
RK
89 * Test that valueRange matches the y-axis range specifically.
90 *
91 * This is based on the assumption that 20 pixels are dedicated to the
92 * axis label and tick marks.
93 * TODO(konigsberg): change yAxisLabelWidth to 0 (or 20) and try again.
94 */
89fdcedb 95it('testToDomYCoord', function() {
644eff8b
RK
96 var graph = document.getElementById("graph");
97 var g = new Dygraph(graph, ZERO_TO_FIFTY, { height: 70, valueRange: [0,50] });
98
89fdcedb
DV
99 assert.equal(50, g.toDomYCoord(0));
100 assert.equal(0, g.toDomYCoord(50));
4dd0ac55
RV
101
102 for (var x = 0; x <= 50; x++) {
dc910fce 103 assert.closeTo(50 - x, g.toDomYCoord(x), 0.00001);
4dd0ac55
RV
104 }
105 g.updateOptions({valueRange: null, axes: {y: {valueRange: [0, 50]}}});
106
89fdcedb
DV
107 assert.equal(50, g.toDomYCoord(0));
108 assert.equal(0, g.toDomYCoord(50));
4dd0ac55 109
644eff8b 110 for (var x = 0; x <= 50; x++) {
dc910fce 111 assert.closeTo(50 - x, g.toDomYCoord(x), 0.00001);
644eff8b 112 }
89fdcedb 113});
e0ca6cd3 114
758a629f
DV
115/**
116 * Test that the two-argument form of the constructor (no options) works.
117 */
89fdcedb 118it('testTwoArgumentConstructor', function() {
758a629f
DV
119 var graph = document.getElementById("graph");
120 new Dygraph(graph, ZERO_TO_FIFTY);
89fdcedb 121});
758a629f 122
e0ca6cd3
RK
123// Here is the first of a series of tests that just ensure the graph is drawn
124// without exception.
125//TODO(konigsberg): Move to its own test case.
89fdcedb 126it('testFillStack1', function() {
e0ca6cd3
RK
127 var graph = document.getElementById("graph");
128 new Dygraph(graph, ZERO_TO_FIFTY, { stackedGraph: true });
89fdcedb 129});
e0ca6cd3 130
89fdcedb 131it('testFillStack2', function() {
e0ca6cd3
RK
132 var graph = document.getElementById("graph");
133 new Dygraph(graph, ZERO_TO_FIFTY, { stackedGraph: true, fillGraph: true });
89fdcedb 134});
e0ca6cd3 135
89fdcedb 136it('testFillStack3', function() {
e0ca6cd3
RK
137 var graph = document.getElementById("graph");
138 new Dygraph(graph, ZERO_TO_FIFTY, { fillGraph: true });
89fdcedb
DV
139});
140
141});