2 * @fileoverview Test cases for DygraphOptions.
4 describe("dygraph-options-tests", function() {
8 beforeEach(function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
10 graph
= document
.getElementById("graph");
13 afterEach(function() {
17 * Pathalogical test to ensure getSeriesNames works
19 it('testGetSeriesNames', function() {
24 var data
= "X,Y,Y2,Y3\n" +
27 // Kind of annoying that you need a DOM to test the object.
28 var g
= new Dygraph(graph
, data
, opts
);
30 // We don't need to get at g's attributes_ object just
31 // to test DygraphOptions.
32 var o
= new DygraphOptions(g
);
33 assert
.deepEqual(["Y", "Y2", "Y3"], o
.seriesNames());
37 * Ensures that even if logscale is set globally, it doesn't impact the
40 it('testGetLogscaleForX', function() {
45 var data
= "X,Y,Y2,Y3\n" +
48 // Kind of annoying that you need a DOM to test the object.
49 var g
= new Dygraph(graph
, data
, opts
);
51 assert
.isFalse(!!g
.getOptionForAxis('logscale', 'x'));
52 assert
.isFalse(!!g
.getOptionForAxis('logscale', 'y'));
54 g
.updateOptions({ logscale
: true });
55 assert
.isFalse(!!g
.getOptionForAxis('logscale', 'x'));
56 assert
.isTrue(!!g
.getOptionForAxis('logscale', 'y'));
59 // Helper to gather all warnings emitted by Dygraph constructor.
60 // Removes everything after the first open parenthesis in each warning.
61 // Returns them in a (possibly empty) list.
62 var getWarnings
= function(div
, data
, opts
) {
64 var oldWarn
= console
.warn
;
65 console
.warn
= function(message
) {
66 warnings
.push(message
.replace(/ \(.*/, ''));
69 new Dygraph(graph
, data
, opts
);
72 console
.warn
= oldWarn
;
76 it('testLogWarningForNonexistentOption', function() {
77 if (typeof(Dygraph
.OPTIONS_REFERENCE
) === 'undefined') {
78 return; // this test won't pass in non-debug mode.
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 assert
.deepEqual(['Unknown option ' + badOptionName
], warnings
);
89 var expectNoWarning
= function(opts
) {
90 DygraphOptions
.resetWarnings_();
91 var warnings
= getWarnings(graph
, data
, opts
);
92 assert
.deepEqual([], 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 it('testOnlyLogsEachWarningOnce', function() {
106 if (typeof(Dygraph
.OPTIONS_REFERENCE
) === 'undefined') {
107 return; // this test won't pass in non-debug mode.
110 var data
= "X,Y,Y2,Y3\n" +
113 var warnings1
= getWarnings(graph
, data
, {nonExistent
: true});
114 var warnings2
= getWarnings(graph
, data
, {nonExistent
: true});
115 assert
.deepEqual(['Unknown option nonExistent'], warnings1
);
116 assert
.deepEqual([], warnings2
);