smartxml: fix - merge newly adjacent text nodes on middle element node moved
[fnpeditor.git] / src / smartxml / smartxml.test.js
index 5d1ca3e..7fc69a3 100644 (file)
@@ -163,6 +163,12 @@ describe('smartxml', function() {
                 node.setData({key1: 'value1', key2: 'value2'});
                 expect(node.getData()).to.eql({key1: 'value1', key2: 'value2'});
             });
+
+            it('can remove specific data', function() {
+                node.setData('key', 'value');
+                node.setData('key', undefined);
+                expect(node.getData('key')).to.be.undefined;
+            });
         });
 
         describe('Changing node tag', function() {
@@ -219,6 +225,21 @@ describe('smartxml', function() {
                 expect(event.meta.oldVal).to.equal('value1');
             });
         });
+
+        describe('Searching for the last child text node', function() {
+            [
+                '<div>xxx<div></div>last</div>',
+                '<div><div>last</div></div>',
+                '<div>xxx<div>last</div><div></div></div>'
+            ].forEach(function(xml, i) {
+                var example = 'example ' + i;
+                it('returns last child text node ' + example + ')', function() {
+                    var doc = getDocumentFromXML(xml),
+                        lastTextNode = doc.root.getLastTextNode();
+                    expect(lastTextNode.getText()).to.equal('last', example);
+                });
+            });
+        });
     });
 
     describe('Basic TextNode properties', function() {
@@ -401,6 +422,18 @@ describe('smartxml', function() {
             expect(rootContents[0].getText()).to.equal('Alice a cat');
         });
 
+        it('merges adjacent text nodes resulting from moving an element node in between', function() {
+            var doc = getDocumentFromXML('<div><a></a>Alice <span>has</span>a cat</div>'),
+                span = doc.root.contents()[2],
+                a = doc.root.contents()[0];
+
+            a.append(span);
+
+            var rootContents = doc.root.contents();
+            expect(rootContents).to.have.length(2, 'one child left');
+            expect(rootContents[1].getText()).to.equal('Alice a cat');
+        });
+
         it('inserts node at index', function() {
             var doc = getDocumentFromXML('<div><a></a><b></b><c></c></div>'),
                 b = doc.root.contents()[1];