Commit | Line | Data |
---|---|---|
1f0f434a SS |
1 | /** |
2 | * @fileoverview Tests for the setVisibility function. | |
3 | * @author sergeyslepian@gmail.com | |
4 | */ | |
5 | ||
89fdcedb | 6 | describe("visibility", function() { |
1f0f434a | 7 | |
89fdcedb | 8 | beforeEach(function() { |
1f0f434a | 9 | document.body.innerHTML = "<div id='graph'></div>"; |
89fdcedb | 10 | }); |
1f0f434a | 11 | |
89fdcedb DV |
12 | afterEach(function() { |
13 | }); | |
1f0f434a SS |
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 | */ | |
319d0361 | 21 | var getVisibleSeries = function(startingVisibility, setVisibilityArgs) { |
1f0f434a SS |
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 | ||
89fdcedb DV |
49 | it('testDefaultCases', function() { |
50 | assert.equal(' A B C D E', getVisibleSeries(true, [[], true])); | |
51 | assert.equal('', getVisibleSeries(false, [[], true])); | |
52 | }); | |
1f0f434a | 53 | |
89fdcedb DV |
54 | it('testSingleSeriesHide', function() { |
55 | assert.equal(' A C D E', getVisibleSeries(true, [1, false])); | |
56 | }); | |
1f0f434a | 57 | |
89fdcedb DV |
58 | it('testSingleSeriesShow', function() { |
59 | assert.equal(' E', getVisibleSeries(false, [4, true])); | |
60 | }); | |
1f0f434a | 61 | |
89fdcedb DV |
62 | it('testMultiSeriesHide', function() { |
63 | assert.equal(' A E', getVisibleSeries(true, [[1,2,3], false])); | |
64 | }); | |
1f0f434a | 65 | |
89fdcedb DV |
66 | it('testMultiSeriesShow', function() { |
67 | assert.equal(' B D', getVisibleSeries(false, [[1,3], true])); | |
68 | }); | |
69 | ||
70 | }); |