From 457deb39f97d91a101e63cd54108716ea9e1c13a Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sun, 29 Mar 2015 18:59:04 -0400 Subject: [PATCH] Tests for labelsDiv option --- auto_tests/tests/Util.js | 9 +++++++-- auto_tests/tests/plugins_legend.js | 24 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/auto_tests/tests/Util.js b/auto_tests/tests/Util.js index 7c1eaa6..8937e43 100644 --- a/auto_tests/tests/Util.js +++ b/auto_tests/tests/Util.js @@ -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); }; /** diff --git a/auto_tests/tests/plugins_legend.js b/auto_tests/tests/plugins_legend.js index 9d5df46..7fd673f 100644 --- a/auto_tests/tests/plugins_legend.js +++ b/auto_tests/tests/plugins_legend.js @@ -1,12 +1,7 @@ -/** - * @fileoverview FILL THIS IN - * - * @author akiya.mizukoshi@gmail.com (Akiyah) - */ describe("plugins-legend", function() { beforeEach(function() { - document.body.innerHTML = "
"; + document.body.innerHTML = "
"; }); afterEach(function() { @@ -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)); +}); + + }); -- 2.7.4