Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9bccb43

Browse files
scjodyetpinard
authored andcommitted
Add tests of <tspan> generation
1 parent 14cfcd1 commit 9bccb43

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

test/jasmine/tests/svg_text_utils_test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ describe('svg+text utils', function() {
2525
expect(a.attr('xlink:show')).toBe(href === null ? null : 'new');
2626
}
2727

28+
function assertTspanStyle(node, style) {
29+
var tspan = node.select('tspan');
30+
expect(tspan.attr('style')).toBe(style);
31+
}
32+
2833
function assertAnchorAttrs(node) {
2934
var a = node.select('a');
3035

@@ -134,5 +139,50 @@ describe('svg+text utils', function() {
134139
assertAnchorLink(node, 'https://abc.com/myFeature.jsp?name=abc&pwd=def');
135140
});
136141
});
142+
143+
it('allow basic spans', function() {
144+
var node = mockTextSVGElement(
145+
'<span>text</span>'
146+
);
147+
148+
expect(node.text()).toEqual('text');
149+
assertTspanStyle(node, null);
150+
});
151+
152+
it('ignore unquoted styles in spans', function() {
153+
var node = mockTextSVGElement(
154+
'<span style=unquoted>text</span>'
155+
);
156+
157+
expect(node.text()).toEqual('text');
158+
assertTspanStyle(node, null);
159+
});
160+
161+
it('allow quoted styles in spans', function() {
162+
var node = mockTextSVGElement(
163+
'<span style="quoted: yeah;">text</span>'
164+
);
165+
166+
expect(node.text()).toEqual('text');
167+
assertTspanStyle(node, 'quoted: yeah;');
168+
});
169+
170+
it('ignore extra stuff after span styles', function() {
171+
var node = mockTextSVGElement(
172+
'<span style="quoted: yeah;"disallowed: indeed;">text</span>'
173+
);
174+
175+
expect(node.text()).toEqual('text');
176+
assertTspanStyle(node, 'quoted: yeah;');
177+
});
178+
179+
it('escapes HTML entities in span styles', function() {
180+
var node = mockTextSVGElement(
181+
'<span style="quoted: yeah&\';;">text</span>'
182+
);
183+
184+
expect(node.text()).toEqual('text');
185+
assertTspanStyle(node, 'quoted: yeah&\';;');
186+
});
137187
});
138188
});

0 commit comments

Comments
 (0)