1cc3764b29bbd7249fdcea1206cb7b5db5ef8330
[dygraphs.git] / auto_tests / tests / visibility.js
1 /**
2 * @fileoverview Tests for the setVisibility function.
3 * @author sergeyslepian@gmail.com
4 */
5
6 import Dygraph from '../../src/dygraph';
7 import Util from './Util';
8
9 describe("visibility", function() {
10
11 cleanupAfterEach();
12
13 /**
14 * Does a bunch of the shared busywork of setting up a graph and changing its visibility.
15 * @param {boolean} startingVisibility The starting visibility of all series on the graph
16 * @param {*[]} setVisibilityArgs An array of arguments to be passed directly to setVisibility()
17 * @returns {string} The output of Util.getLegend() called after the visibility is set
18 */
19 var getVisibleSeries = function(startingVisibility, setVisibilityArgs) {
20 var opts = {
21 width: 480,
22 height: 320,
23 labels: ['x', 'A', 'B', 'C', 'D', 'E'],
24 legend: 'always',
25 visibility: []
26 };
27
28 // set the starting visibility
29 var numSeries = opts.labels.length - 1;
30 for(var i = 0; i < numSeries; i++) {
31 opts.visibility[i] = startingVisibility;
32 }
33
34 var data = [];
35 for (var j = 0; j < 10; j++) {
36 data.push([j, 1, 2, 3, 4, 5]);
37 }
38
39 var graph = document.getElementById("graph");
40 var g = new Dygraph(graph, data, opts);
41
42 g.setVisibility.apply(g, setVisibilityArgs);
43
44 return Util.getLegend();
45 };
46
47 it('testDefaultCases', function() {
48 assert.equal(' A B C D E', getVisibleSeries(true, [[], true]));
49 assert.equal('', getVisibleSeries(false, [[], true]));
50 });
51
52 it('testSingleSeriesHide', function() {
53 assert.equal(' A C D E', getVisibleSeries(true, [1, false]));
54 });
55
56 it('testSingleSeriesShow', function() {
57 assert.equal(' E', getVisibleSeries(false, [4, true]));
58 });
59
60 it('testMultiSeriesHide', function() {
61 assert.equal(' A E', getVisibleSeries(true, [[1,2,3], false]));
62 });
63
64 it('testMultiSeriesShow', function() {
65 assert.equal(' B D', getVisibleSeries(false, [[1,3], true]));
66 });
67
68 it('testObjectSeriesShowAndHide', function() {
69 assert.equal(' B D', getVisibleSeries(false, [{1:true, 2:false, 3:true}, null]));
70 });
71
72 it('testBooleanArraySeriesShowAndHide', function() {
73 assert.equal(' B D', getVisibleSeries(false, [[false, true, false, true], null]));
74 });
75
76 });