2 * @fileoverview Tests for the setVisibility function.
3 * @author sergeyslepian@gmail.com
6 var VisibilityTestCase
= TestCase("visibility");
8 VisibilityTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 VisibilityTestCase
.prototype.tearDown
= 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 VisibilityTestCase
.prototype.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 VisibilityTestCase
.prototype.testDefaultCases
= function() {
50 assertEquals(' A B C D E', this.getVisibleSeries(true, [[], true]));
51 assertEquals('', this.getVisibleSeries(false, [[], true]));
54 VisibilityTestCase
.prototype.testSingleSeriesHide
= function() {
55 assertEquals(' A C D E', this.getVisibleSeries(true, [1, false]));
58 VisibilityTestCase
.prototype.testSingleSeriesShow
= function() {
59 assertEquals(' E', this.getVisibleSeries(false, [4, true]));
62 VisibilityTestCase
.prototype.testMultiSeriesHide
= function() {
63 assertEquals(' A E', this.getVisibleSeries(true, [[1,2,3], false]));
66 VisibilityTestCase
.prototype.testMultiSeriesShow
= function() {
67 assertEquals(' B D', this.getVisibleSeries(false, [[1,3], true]));