2 * @fileoverview Test cases for DygraphOptions.
5 import Dygraph from
'../../src/dygraph';
6 import DygraphOptions from
'../../src/dygraph-options';
7 import OPTIONS_REFERENCE from
'../../src/dygraph-options-reference';
9 describe("dygraph-options-tests", function() {
15 beforeEach(function() {
16 graph
= document
.getElementById("graph");
20 * Pathalogical test to ensure getSeriesNames works
22 it('testGetSeriesNames', function() {
27 var data
= "X,Y,Y2,Y3\n" +
30 // Kind of annoying that you need a DOM to test the object.
31 var g
= new Dygraph(graph
, data
, opts
);
33 // We don't need to get at g's attributes_ object just
34 // to test DygraphOptions.
35 var o
= new DygraphOptions(g
);
36 assert
.deepEqual(["Y", "Y2", "Y3"], o
.seriesNames());
40 * Ensures that even if logscale is set globally, it doesn't impact the
43 it('testGetLogscaleForX', function() {
48 var data
= "X,Y,Y2,Y3\n" +
51 // Kind of annoying that you need a DOM to test the object.
52 var g
= new Dygraph(graph
, data
, opts
);
54 assert
.isFalse(!!g
.getOptionForAxis('logscale', 'x'));
55 assert
.isFalse(!!g
.getOptionForAxis('logscale', 'y'));
57 g
.updateOptions({ logscale
: true });
58 assert
.isFalse(!!g
.getOptionForAxis('logscale', 'x'));
59 assert
.isTrue(!!g
.getOptionForAxis('logscale', 'y'));
62 // Helper to gather all warnings emitted by Dygraph constructor.
63 // Removes everything after the first open parenthesis in each warning.
64 // Returns them in a (possibly empty) list.
65 var getWarnings
= function(div
, data
, opts
) {
67 var oldWarn
= console
.warn
;
68 console
.warn
= function(message
) {
69 warnings
.push(message
.replace(/ \(.*/, ''));
72 new Dygraph(graph
, data
, opts
);
75 console
.warn
= oldWarn
;
79 it('testLogWarningForNonexistentOption', function() {
80 if (!OPTIONS_REFERENCE
) {
81 return; // this test won't pass in non-debug mode.
84 var data
= "X,Y,Y2,Y3\n" +
87 var expectWarning
= function(opts
, badOptionName
) {
88 DygraphOptions
.resetWarnings_();
89 var warnings
= getWarnings(graph
, data
, opts
);
90 assert
.deepEqual(['Unknown option ' + badOptionName
], warnings
);
92 var expectNoWarning
= function(opts
) {
93 DygraphOptions
.resetWarnings_();
94 var warnings
= getWarnings(graph
, data
, opts
);
95 assert
.deepEqual([], warnings
);
99 expectWarning({nonExistentOption
: true}, 'nonExistentOption');
100 expectWarning({series
: {Y
: {nonExistentOption
: true}}}, 'nonExistentOption');
101 // expectWarning({Y: {nonExistentOption: true}});
102 expectWarning({axes
: {y
: {anotherNonExistentOption
: true}}}, 'anotherNonExistentOption');
103 expectWarning({highlightSeriesOpts
: {anotherNonExistentOption
: true}}, 'anotherNonExistentOption');
104 expectNoWarning({highlightSeriesOpts
: {strokeWidth
: 20}});
105 expectNoWarning({strokeWidth
: 20});
108 it('testOnlyLogsEachWarningOnce', function() {
109 if (!OPTIONS_REFERENCE
) {
110 return; // this test won't pass in non-debug mode.
113 var data
= "X,Y,Y2,Y3\n" +
116 var warnings1
= getWarnings(graph
, data
, {nonExistent
: true});
117 var warnings2
= getWarnings(graph
, data
, {nonExistent
: true});
118 assert
.deepEqual(['Unknown option nonExistent'], warnings1
);
119 assert
.deepEqual([], warnings2
);