aa9db33d08e54693721d32e7744d0cd3ec4e7f81
2 * @fileoverview Test cases for DygraphOptions.
5 import Dygraph from
'../../src/dygraph';
6 import DygraphOptions from
'../../src/dygraph-options';
8 describe("dygraph-options-tests", function() {
14 beforeEach(function() {
15 graph
= document
.getElementById("graph");
19 * Pathalogical test to ensure getSeriesNames works
21 it('testGetSeriesNames', function() {
26 var data
= "X,Y,Y2,Y3\n" +
29 // Kind of annoying that you need a DOM to test the object.
30 var g
= new Dygraph(graph
, data
, opts
);
32 // We don't need to get at g's attributes_ object just
33 // to test DygraphOptions.
34 var o
= new DygraphOptions(g
);
35 assert
.deepEqual(["Y", "Y2", "Y3"], o
.seriesNames());
39 * Ensures that even if logscale is set globally, it doesn't impact the
42 it('testGetLogscaleForX', function() {
47 var data
= "X,Y,Y2,Y3\n" +
50 // Kind of annoying that you need a DOM to test the object.
51 var g
= new Dygraph(graph
, data
, opts
);
53 assert
.isFalse(!!g
.getOptionForAxis('logscale', 'x'));
54 assert
.isFalse(!!g
.getOptionForAxis('logscale', 'y'));
56 g
.updateOptions({ logscale
: true });
57 assert
.isFalse(!!g
.getOptionForAxis('logscale', 'x'));
58 assert
.isTrue(!!g
.getOptionForAxis('logscale', 'y'));
61 // Helper to gather all warnings emitted by Dygraph constructor.
62 // Removes everything after the first open parenthesis in each warning.
63 // Returns them in a (possibly empty) list.
64 var getWarnings
= function(div
, data
, opts
) {
66 var oldWarn
= console
.warn
;
67 console
.warn
= function(message
) {
68 warnings
.push(message
.replace(/ \(.*/, ''));
71 new Dygraph(graph
, data
, opts
);
74 console
.warn
= oldWarn
;
78 it('testLogWarningForNonexistentOption', function() {
79 if (typeof(Dygraph
.OPTIONS_REFERENCE
) === 'undefined') {
80 return; // this test won't pass in non-debug mode.
83 var data
= "X,Y,Y2,Y3\n" +
86 var expectWarning
= function(opts
, badOptionName
) {
87 DygraphOptions
.resetWarnings_();
88 var warnings
= getWarnings(graph
, data
, opts
);
89 assert
.deepEqual(['Unknown option ' + badOptionName
], warnings
);
91 var expectNoWarning
= function(opts
) {
92 DygraphOptions
.resetWarnings_();
93 var warnings
= getWarnings(graph
, data
, opts
);
94 assert
.deepEqual([], warnings
);
98 expectWarning({nonExistentOption
: true}, 'nonExistentOption');
99 expectWarning({series
: {Y
: {nonExistentOption
: true}}}, 'nonExistentOption');
100 // expectWarning({Y: {nonExistentOption: true}});
101 expectWarning({axes
: {y
: {anotherNonExistentOption
: true}}}, 'anotherNonExistentOption');
102 expectWarning({highlightSeriesOpts
: {anotherNonExistentOption
: true}}, 'anotherNonExistentOption');
103 expectNoWarning({highlightSeriesOpts
: {strokeWidth
: 20}});
104 expectNoWarning({strokeWidth
: 20});
107 it('testOnlyLogsEachWarningOnce', function() {
108 if (typeof(Dygraph
.OPTIONS_REFERENCE
) === 'undefined') {
109 return; // this test won't pass in non-debug mode.
112 var data
= "X,Y,Y2,Y3\n" +
115 var warnings1
= getWarnings(graph
, data
, {nonExistent
: true});
116 var warnings2
= getWarnings(graph
, data
, {nonExistent
: true});
117 assert
.deepEqual(['Unknown option nonExistent'], warnings1
);
118 assert
.deepEqual([], warnings2
);