2 * @fileoverview Tests for the setVisibility function.
3 * @author sergeyslepian@gmail.com
6 describe("visibility", function() {
8 beforeEach(function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 afterEach(function() {
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
21 var getVisibleSeries
= function(startingVisibility
, setVisibilityArgs
) {
25 labels
: ['x', 'A', 'B', 'C', 'D', 'E'],
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
;
37 for (var j
= 0; j
< 10; j
++) {
38 data
.push([j
, 1, 2, 3, 4, 5]);
41 var graph
= document
.getElementById("graph");
42 var g
= new Dygraph(graph
, data
, opts
);
44 g
.setVisibility
.apply(g
, setVisibilityArgs
);
46 return Util
.getLegend();
49 it('testDefaultCases', function() {
50 assert
.equal(' A B C D E', getVisibleSeries(true, [[], true]));
51 assert
.equal('', getVisibleSeries(false, [[], true]));
54 it('testSingleSeriesHide', function() {
55 assert
.equal(' A C D E', getVisibleSeries(true, [1, false]));
58 it('testSingleSeriesShow', function() {
59 assert
.equal(' E', getVisibleSeries(false, [4, true]));
62 it('testMultiSeriesHide', function() {
63 assert
.equal(' A E', getVisibleSeries(true, [[1,2,3], false]));
66 it('testMultiSeriesShow', function() {
67 assert
.equal(' B D', getVisibleSeries(false, [[1,3], true]));
70 it('testObjectSeriesShowAndHide', function() {
71 assert
.equal(' B D', getVisibleSeries(false, [{1:true, 2:false, 3:true}, null]));
74 it('testBooleanArraySeriesShowAndHide', function() {
75 assert
.equal(' B D', getVisibleSeries(false, [[false, true, false, true], null]));