2 * @fileoverview Test cases for DygraphOptions.
4 var DygraphOptionsTestCase
= TestCase("dygraph-options-tests");
6 DygraphOptionsTestCase
.prototype.setUp
= function() {
7 document
.body
.innerHTML
= "<div id='graph'></div>";
10 DygraphOptionsTestCase
.prototype.tearDown
= function() {
14 * Pathalogical test to ensure getSeriesNames works
16 DygraphOptionsTestCase
.prototype.testGetSeriesNames
= function() {
21 var data
= "X,Y,Y2,Y3\n" +
24 // Kind of annoying that you need a DOM to test the object.
25 var graph
= document
.getElementById("graph");
26 var g
= new Dygraph(graph
, data
, opts
);
28 // We don't need to get at g's attributes_ object just
29 // to test DygraphOptions.
30 var o
= new DygraphOptions(g
);
31 assertEquals(["Y", "Y2", "Y3"], o
.seriesNames());
35 * Ensures that even if logscale is set globally, it doesn't impact the
38 DygraphOptionsTestCase
.prototype.testGetLogscaleForX
= function() {
43 var data
= "X,Y,Y2,Y3\n" +
46 // Kind of annoying that you need a DOM to test the object.
47 var graph
= document
.getElementById("graph");
48 var g
= new Dygraph(graph
, data
, opts
);
50 assertFalse(!!g
.getOptionForAxis('logscale', 'x'));
51 assertFalse(!!g
.getOptionForAxis('logscale', 'y'));
53 g
.updateOptions({ logscale
: true });
54 assertFalse(!!g
.getOptionForAxis('logscale', 'x'));
55 assertTrue(!!g
.getOptionForAxis('logscale', 'y'));
58 // Helper to gather all warnings emitted by Dygraph constructor.
59 // Removes everything after the first open parenthesis in each warning.
60 // Returns them in a (possibly empty) list.
61 var getWarnings
= function(div
, data
, opts
) {
63 var oldWarn
= console
.warn
;
64 console
.warn
= function(message
) {
65 warnings
.push(message
.replace(/ \(.*/, ''));
68 new Dygraph(graph
, data
, opts
);
71 console
.warn
= oldWarn
;
75 DygraphOptionsTestCase
.prototype.testLogWarningForNonexistentOption
= function() {
76 if (typeof(Dygraph
.OPTIONS_REFERENCE
) === 'undefined') {
77 return; // this test won't pass in non-debug mode.
80 var graph
= document
.getElementById("graph");
81 var data
= "X,Y,Y2,Y3\n" +
84 var expectWarning
= function(opts
, badOptionName
) {
85 DygraphOptions
.resetWarnings_();
86 var warnings
= getWarnings(graph
, data
, opts
);
87 assertEquals(['Unknown option ' + badOptionName
], warnings
);
89 var expectNoWarning
= function(opts
) {
90 DygraphOptions
.resetWarnings_();
91 var warnings
= getWarnings(graph
, data
, opts
);
92 assertEquals([], warnings
);
96 expectWarning({nonExistentOption
: true}, 'nonExistentOption');
97 expectWarning({series
: {Y
: {nonExistentOption
: true}}}, 'nonExistentOption');
98 // expectWarning({Y: {nonExistentOption: true}});
99 expectWarning({axes
: {y
: {anotherNonExistentOption
: true}}}, 'anotherNonExistentOption');
100 expectWarning({highlightSeriesOpts
: {anotherNonExistentOption
: true}}, 'anotherNonExistentOption');
101 expectNoWarning({highlightSeriesOpts
: {strokeWidth
: 20}});
102 expectNoWarning({strokeWidth
: 20});
105 DygraphOptionsTestCase
.prototype.testOnlyLogsEachWarningOnce
= function() {
106 if (typeof(Dygraph
.OPTIONS_REFERENCE
) === 'undefined') {
107 return; // this test won't pass in non-debug mode.
110 var graph
= document
.getElementById("graph");
111 var data
= "X,Y,Y2,Y3\n" +
114 var warnings1
= getWarnings(graph
, data
, {nonExistent
: true});
115 var warnings2
= getWarnings(graph
, data
, {nonExistent
: true});
116 assertEquals(['Unknown option nonExistent'], warnings1
);
117 assertEquals([], warnings2
);