Skip to content

Commit cb8c331

Browse files
committed
test close/reopen multiple unclosed tags at breaks
also show zero-width-space characters explicitly
1 parent e905b5d commit cb8c331

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

test/jasmine/tests/svg_text_utils_test.js

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,24 +265,24 @@ describe('svg+text utils', function() {
265265
it('supports superscript by itself', function() {
266266
var node = mockTextSVGElement('<sup>123</sup>');
267267
expect(node.html()).toBe(
268-
'<tspan style="font-size:70%" dy="-0.6em">123</tspan>' +
269-
'<tspan dy="0.42em"></tspan>');
268+
'\u200b<tspan style="font-size:70%" dy="-0.6em">123</tspan>' +
269+
'<tspan dy="0.42em">\u200b</tspan>');
270270
});
271271

272272
it('supports subscript by itself', function() {
273273
var node = mockTextSVGElement('<sub>123</sub>');
274274
expect(node.html()).toBe(
275-
'<tspan style="font-size:70%" dy="0.3em">123</tspan>' +
276-
'<tspan dy="-0.21em"></tspan>');
275+
'\u200b<tspan style="font-size:70%" dy="0.3em">123</tspan>' +
276+
'<tspan dy="-0.21em">\u200b</tspan>');
277277
});
278278

279279
it('supports superscript and subscript together with normal text', function() {
280280
var node = mockTextSVGElement('SO<sub>4</sub><sup>2-</sup>');
281281
expect(node.html()).toBe(
282-
'SO<tspan style="font-size:70%" dy="0.3em">4</tspan>' +
283-
'<tspan dy="-0.21em"></tspan>' +
282+
'SO\u200b<tspan style="font-size:70%" dy="0.3em">4</tspan>' +
283+
'<tspan dy="-0.21em">\u200b</tspan>\u200b' +
284284
'<tspan style="font-size:70%" dy="-0.6em">2-</tspan>' +
285-
'<tspan dy="0.42em"></tspan>');
285+
'<tspan dy="0.42em">\u200b</tspan>');
286286
});
287287

288288
it('allows one <b> to span <br>s', function() {
@@ -300,12 +300,36 @@ describe('svg+text utils', function() {
300300
it('allows one <sub> to span <br>s', function() {
301301
var node = mockTextSVGElement('SO<sub>4<br>44</sub>');
302302
expect(node.html()).toBe(
303-
'<tspan class="line" dy="0em">SO' +
303+
'<tspan class="line" dy="0em">SO\u200b' +
304304
'<tspan style="font-size:70%" dy="0.3em">4</tspan>' +
305-
'<tspan dy="-0.21em"></tspan></tspan>' +
306-
'<tspan class="line" dy="1.3em">' +
305+
'<tspan dy="-0.21em">\u200b</tspan></tspan>' +
306+
'<tspan class="line" dy="1.3em">\u200b' +
307307
'<tspan style="font-size:70%" dy="0.3em">44</tspan>' +
308-
'<tspan dy="-0.21em">​</tspan></tspan>');
308+
'<tspan dy="-0.21em">\u200b</tspan></tspan>');
309+
});
310+
311+
it('allows nested tags to break at <br>, eventually closed or not', function() {
312+
var textCases = [
313+
'<b><i><sup>many<br>lines<br>modified',
314+
'<b><i><sup>many<br>lines<br>modified</sup></i></b>',
315+
'<b><i><sup>many</sup><br><sup>lines</sup></i><br><i><sup>modified',
316+
];
317+
318+
textCases.forEach(function(textCase) {
319+
var node = mockTextSVGElement(textCase);
320+
function opener(dy) {
321+
return '<tspan class="line" dy="' + dy + 'em">' +
322+
'<tspan style="font-weight:bold">' +
323+
'<tspan style="font-style:italic">' +
324+
'\u200b<tspan style="font-size:70%" dy="-0.6em">';
325+
}
326+
var closer = '</tspan><tspan dy="0.42em">\u200b</tspan>' +
327+
'</tspan></tspan></tspan>';
328+
expect(node.html()).toBe(
329+
opener(0) + 'many' + closer +
330+
opener(1.3) + 'lines' + closer +
331+
opener(2.6) + 'modified' + closer, textCase);
332+
});
309333
});
310334
});
311335
});

0 commit comments

Comments
 (0)