Linting, minor test description fix
[fnpeditor.git] / src / smartxml / smartxml.test.js
index 4049dff..5d2bbb7 100644 (file)
@@ -736,15 +736,14 @@ describe('smartxml', function() {
                 expect(event.meta.node.sameNode(a));
             });
 
-            it('doesn\'t emit nodeDetached event for already out of document moved to out of document node: ' + insertionMethod, function() {
+            it('doesn\'t emit nodeDetached event for already out of document node moved to out of document node' + insertionMethod, function() {
                 var doc = getDocumentFromXML('<div><a></a></div>'),
-                    a = doc.root.contents()[0],
                     spy = sinon.spy();
 
                 doc.on('change', spy);
 
                 var newNode = doc.createDocumentNode({tagName: 'b'});
-                    var newNodeInner = newNode.append({tagName:'c'});
+                newNode.append({tagName:'c'});
 
                 expect(spy.callCount).to.equal(0);
             });
@@ -831,7 +830,7 @@ describe('smartxml', function() {
     });
 
     describe('Extension API', function() {
-        var doc, extension, elementNode, textNode, testClassNode;
+        var doc, extension, elementNode, textNode;
 
         beforeEach(function() {
             doc = getDocumentFromXML('<section>Alice<div class="test_class"></div></section>');
@@ -1150,60 +1149,46 @@ describe('smartxml', function() {
             });
         });
 
-        // it('does work', function() {
-        //     var doc = getDocumentFromXML('<section><span>Alice</span></section>'),
-        //         span = doc.root.contents()[0];
-
-        //     span.transform('smartxml.detach');
-
-
-        //     doc.undo();
+        it('smoke tests nested transformations', function() {
+            var doc = getDocumentFromXML('<div></div>');
 
-        //     expect(doc.root.contents()).to.have.length(1);
-        //     expect(doc.root.contents()[0].getTagName()).to.equal('span');
-        //     expect(doc.root.contents()[0].contents()[0].getText()).to.equal('Alice');
+            doc.registerExtension({elementNode: {transformations: {
+                nested: function(v) {
+                    this._$.attr('innerAttr', v);
+                },
+                outer: function(v) {
+                    this.nested(v);
+                    this._$.attr('outerAttr', v);
+                }
+            }}});
 
-        //     doc.redo();
-        //     expect(doc.root.contents()).to.have.length(0);
+            doc.root.outer('test1');
+            doc.root.outer('test2');
 
-        //     doc.undo();
-        //     expect(doc.root.contents()).to.have.length(1);
-        //     expect(doc.root.contents()[0].getTagName()).to.equal('span');
-        //     expect(doc.root.contents()[0].contents()[0].getText()).to.equal('Alice');
+            expect(doc.root.getAttr('innerAttr')).to.equal('test2');
+            expect(doc.root.getAttr('outerAttr')).to.equal('test2');
 
-        // });
-        // it('does work - merged text nodes case', function() {
-        //     var doc = getDocumentFromXML('<section>Alice <span>has</span> a cat.</section>'),
-        //         span = doc.root.contents()[1];
+            doc.undo();
 
-        //     span.transform('smartxml.detach');
+            expect(doc.root.getAttr('innerAttr')).to.equal('test1');
+            expect(doc.root.getAttr('outerAttr')).to.equal('test1');
 
+            doc.undo();
 
-        //     doc.undo();
+            expect(doc.root.getAttr('innerAttr')).to.equal(undefined);
+            expect(doc.root.getAttr('outerAttr')).to.equal(undefined);
 
-        //     expect(doc.root.contents().length).to.equal(3);
-        //     //console.log(doc.toXML());
-        //     expect(doc.root.contents()[1].contents()[0].getText()).to.equal('has');
+            doc.redo();
 
-        // });
-        // it('dbg - don not store nodes in tranformation state!', function() {
-        //     var doc = getDocumentFromXML('<section><a></a><b></b></section>'),
-        //         a = doc.root.contents()[0],
-        //         b = doc.root.contents()[1];
+            expect(doc.root.getAttr('innerAttr')).to.equal('test1');
+            expect(doc.root.getAttr('outerAttr')).to.equal('test1');
 
-        //     a.transform('smartxml.detach');
-        //     b.transform('smartxml.detach');
-        //     doc.undo();
-        //     doc.undo();
-        //     expect(doc.root.contents().length).to.equal(2);
-        //     expect(doc.root.contents()[0].getTagName()).to.equal('a');
-        //     expect(doc.root.contents()[1].getTagName()).to.equal('b');
+            doc.redo();
 
-        //     doc.redo();
-        //     doc.redo();
-        //     expect(doc.root.contents().length).to.equal(0);
+            expect(doc.root.getAttr('innerAttr')).to.equal('test2');
+            expect(doc.root.getAttr('outerAttr')).to.equal('test2');
 
-        // });
+        });
     });
 
 });