X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=auto_tests%2Ftests%2Fplugins_legend.js;h=124d929bcc38fa5ff8012f76cbdcdc9e5cc10e41;hb=refs%2Fheads%2F558-fill-artifacts;hp=3288329fc60c1169be9782559b44847193334d50;hpb=4c13b75ff4ce8fe42106749f5823dd96ee7a1990;p=dygraphs.git diff --git a/auto_tests/tests/plugins_legend.js b/auto_tests/tests/plugins_legend.js index 3288329..124d929 100644 --- a/auto_tests/tests/plugins_legend.js +++ b/auto_tests/tests/plugins_legend.js @@ -1,18 +1,13 @@ -/** - * @fileoverview FILL THIS IN - * - * @author akiya.mizukoshi@gmail.com (Akiyah) - */ -var pluginsLegendTestCase = TestCase("plugins-legend"); +describe("plugins-legend", function() { -pluginsLegendTestCase.prototype.setUp = function() { - document.body.innerHTML = "
"; -}; +beforeEach(function() { + document.body.innerHTML = ""; +}); -pluginsLegendTestCase.prototype.tearDown = function() { -}; +afterEach(function() { +}); -pluginsLegendTestCase.prototype.testLegendEscape = function() { +it('testLegendEscape', function() { var opts = { width: 480, height: 320 @@ -40,7 +35,40 @@ pluginsLegendTestCase.prototype.testLegendEscape = function() { } legendPlugin.select(e); - var legendSpan = $(legendPlugin.legend_div_).find("span b span"); - assertEquals("<script>alert('XSS')</script>", legendSpan.html()); -}; + var legendSpan = legendPlugin.legend_div_.querySelector("span b span"); + assert.equal(legendSpan.innerHTML, "<script>alert('XSS')</script>"); +}); + +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)); +}); + +it('should render dashed patterns', function() { + var g = new Dygraph('graph', 'X,Y\n1,2\n', { + strokePattern: [5, 5], + color: 'red', + legend: 'always' + }); + + // The legend has a dashed line and a label. + var legendEl = document.querySelector('.dygraph-legend > span'); + assert.equal(' Y', legendEl.textContent); + var dashEl = document.querySelector('.dygraph-legend > span > div'); + assert.equal(window.getComputedStyle(dashEl)['border-bottom-color'], + 'rgb(255, 0, 0)'); +}); + +});