Skip to content

Commit

Permalink
util.svg: fix null className (#1851)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumilingus authored Oct 21, 2022
1 parent 909c1f5 commit e0636ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/util/svgTagTemplate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ function build(root) {
}

const className = attributes.getNamedItem('class');
markupNode.className = (className ? className.value : null);
if (className) {
markupNode.className = className.value;
}

if (textContent) {
markupNode.textContent = textContent;
Expand Down
21 changes: 8 additions & 13 deletions test/jointjs/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1360,19 +1360,24 @@ QUnit.module('util', function(hooks) {

QUnit.module('svgTaggedTemplate', function() {

QUnit.test('function', function(assert) {
const markup = joint.util.svg(['<rect @selector="selector1"/><circle @group-selector="group-selector1, group-selector2" class="circle"/><g><rect style="pointer-events:auto"/><circle stroke="red"/>textContent</g>']);
function testMarkup(assert, markup) {
assert.equal(markup.length, 3);
assert.equal(markup[0].namespaceURI, 'http://www.w3.org/2000/svg');
assert.equal(markup[0].tagName, 'rect');
assert.equal(markup[0].selector, 'selector1');
assert.strictEqual(markup[0].className, undefined);
assert.equal(markup[1].groupSelector[0], 'group-selector1');
assert.equal(markup[1].groupSelector[1], 'group-selector2');
assert.equal(markup[1].className, 'circle');
assert.equal(markup[2].children.length, 2);
assert.equal(markup[2].textContent, 'textContent');
assert.equal(markup[2].children[0].style['pointer-events'], 'auto');
assert.equal(markup[2].children[1].attributes['stroke'], 'red');
}

QUnit.test('function', function(assert) {
const markup = joint.util.svg(['<rect @selector="selector1"/><circle @group-selector="group-selector1, group-selector2" class="circle"/><g><rect style="pointer-events:auto"/><circle stroke="red"/>textContent</g>']);
testMarkup(assert, markup);
});

QUnit.test('tagged template', function(assert) {
Expand All @@ -1383,17 +1388,7 @@ QUnit.module('util', function(hooks) {
<circle @group-selector="${groupSelector1}, group-selector2" class="circle"/>
<g><rect style="pointer-events:auto"/><circle stroke="${color}"/>textContent</g>
`;
assert.equal(markup.length, 3);
assert.equal(markup[0].namespaceURI, 'http://www.w3.org/2000/svg');
assert.equal(markup[0].tagName, 'rect');
assert.equal(markup[0].selector, 'selector1');
assert.equal(markup[1].groupSelector[0], 'group-selector1');
assert.equal(markup[1].groupSelector[1], 'group-selector2');
assert.equal(markup[1].className, 'circle');
assert.equal(markup[2].children.length, 2);
assert.equal(markup[2].textContent, 'textContent');
assert.equal(markup[2].children[0].style['pointer-events'], 'auto');
assert.equal(markup[2].children[1].attributes['stroke'], 'red');
testMarkup(assert, markup);
});
});

Expand Down

0 comments on commit e0636ed

Please sign in to comment.