1 import Dygraph from
'../../src/dygraph';
2 import LegendPlugin from
'../../src/plugins/legend';
3 import Util from
'./Util';
5 describe("plugins-legend", function() {
10 beforeEach(function() {
11 var testDiv
= document
.getElementById('graph');
12 testDiv
.innerHTML
= "<div id='inner-graph'></div><div id='label'></div>";
13 graph
= document
.getElementById('inner-graph');
16 it('testLegendEscape', function() {
21 var data
= "X,<script>alert('XSS')</script>\n" +
28 var g
= new Dygraph(graph
, data
, opts
);
30 var legendPlugin
= new LegendPlugin();
31 legendPlugin
.activate(g
);
33 selectedX
: 'selectedX',
36 name
: "<script>alert('XSS')</script>",
41 legendPlugin
.select(e
);
43 var legendSpan
= legendPlugin
.legend_div_
.querySelector("span b span");
44 assert
.equal(legendSpan
.innerHTML
, "<script>alert('XSS')</script>");
48 it('should let labelsDiv be a string', function() {
49 var labelsDiv
= document
.getElementById('label');
50 var g
= new Dygraph(graph
, 'X,Y\n1,2\n', {labelsDiv
: 'label'});
53 assert
.equal('1: Y: 2', Util
.nbspToSpace(labelsDiv
.textContent
));
56 it('should let labelsDiv be an Element', function() {
57 var labelsDiv
= document
.getElementById('label');
58 var g
= new Dygraph(graph
, 'X,Y\n1,2\n', { labelsDiv
: labelsDiv
});
59 assert
.isNull(labelsDiv
.getAttribute('class')); // dygraph-legend not added.
61 assert
.equal('1: Y: 2', Util
.nbspToSpace(labelsDiv
.textContent
));
64 it('should render dashed patterns', function() {
65 var g
= new Dygraph(graph
, 'X,Y\n1,2\n', {
66 strokePattern
: [5, 5],
71 // The legend has a dashed line and a label.
72 var legendEl
= document
.querySelector('.dygraph-legend > span');
73 assert
.equal(' Y', legendEl
.textContent
);
74 var dashEl
= document
.querySelector('.dygraph-legend > span > div');
75 assert
.equal(window
.getComputedStyle(dashEl
)['border-bottom-color'],