Skip to content

Commit

Permalink
Tests for labelsDiv option
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Mar 29, 2015
1 parent 4431021 commit 457deb3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
9 changes: 7 additions & 2 deletions auto_tests/tests/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ Util.getClassTexts = function(css_class, parent) {
return texts;
};

// Convert   to a normal space
Util.nbspToSpace = function(str) {
var re = new RegExp(String.fromCharCode(160), 'g');
return str.replace(re, ' ');
};

Util.getLegend = function(parent) {
parent = parent || document;
var legend = parent.getElementsByClassName("dygraph-legend")[0];
var re = new RegExp(String.fromCharCode(160), 'g');
return legend.textContent.replace(re, ' ');
return Util.nbspToSpace(legend.textContent);
};

/**
Expand Down
24 changes: 18 additions & 6 deletions auto_tests/tests/plugins_legend.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/**
* @fileoverview FILL THIS IN
*
* @author akiya.mizukoshi@gmail.com (Akiyah)
*/
describe("plugins-legend", function() {

beforeEach(function() {
document.body.innerHTML = "<div id='graph'></div>";
document.body.innerHTML = "<div id='graph'></div><div id='label'></div>";
});

afterEach(function() {
Expand Down Expand Up @@ -45,4 +40,21 @@ it('testLegendEscape', function() {
});


it('should let labelsDiv be a string', function() {
var labelsDiv = document.getElementById('label');
var g = new Dygraph('graph', 'X,Y\n1,2\n', {labelsDiv: 'label'});
null
g.setSelection(0);
assert.equal('1: Y: 2', Util.nbspToSpace(labelsDiv.textContent));
});

it('should let labelsDiv be an Element', function() {
var labelsDiv = document.getElementById('label');
var g = new Dygraph('graph', 'X,Y\n1,2\n', { labelsDiv: labelsDiv });
assert.isNull(labelsDiv.getAttribute('class')); // dygraph-legend not added.
g.setSelection(0);
assert.equal('1: Y: 2', Util.nbspToSpace(labelsDiv.textContent));
});


});

0 comments on commit 457deb3

Please sign in to comment.