smartxml: allow for removing node data for a specified key
[fnpeditor.git] / src / smartxml / smartxml.test.js
index e4e2724..2a6c5e0 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() {
@@ -1679,6 +1700,29 @@ describe('smartxml', function() {
                 doc.redo();
                 expect(doc.root.getAttr('t')).to.equal('1');
             });
+            it('can perform undo of an operation performed after automatic transaction rollback', function() {
+                var doc = getDocumentFromXML('<section></section>'),
+                    extension = {document: {transformations: {
+                        throwingTransformation: function() { throw new Error(); }
+                    }}};
+
+                doc.registerExtension(extension);
+
+                doc.throwingTransformation();
+
+                doc.transaction(function() {
+                    doc.root.setAttr('x', '2');
+                });
+
+                expect(doc.undoStack.length).to.equal(1);
+                expect(doc.root.getAttr('x')).to.equal('2');
+
+                doc.undo();
+
+                expect(doc.undoStack.length).to.equal(0);
+                expect(doc.root.getAttr('x')).to.be.undefined;
+
+            });
         });
     });