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