Jumping to paren parent on text unwrap
[fnpeditor.git] / modules / documentCanvas / canvas / canvas.test3.js
index edc81ee..23061d9 100644 (file)
@@ -118,14 +118,43 @@ describe('Canvas', function() {
             });
 
             it('knows WLXML class of a WLXML tag it renders', function(){
-                var c = canvas.fromXML('<section class="some.class"></section>'),
+                var c = canvas.fromXML('<section class="some.class.A"></section>'),
                     section = c.doc();
-                expect(section.getWlxmlClass()).to.equal('some.class');
-                section.setWlxmlClass('some.other.class');
-                expect(section.getWlxmlClass()).to.equal('some.other.class');
+                expect(section.getWlxmlClass()).to.equal('some.class.A');
+                section.setWlxmlClass('some.class.B');
+                expect(section.getWlxmlClass()).to.equal('some.class.B');
                 section.setWlxmlClass(null);
                 expect(section.getWlxmlClass()).to.be.undefined;
             });
+
+
+
+            describe('element has meta attributes', function() {
+                it('can change its meta attributes', function() {
+                    var c = canvas.fromXML('<section><span class="uri" meta-uri="someuri"></span></section>'),
+                    span = c.doc().children()[0];
+                    
+                    expect(span.getWlxmlMetaAttr('uri')).to.equal('someuri');
+                    span.setWlxmlMetaAttr('uri', 'otheruri');
+                    expect(span.getWlxmlMetaAttr('uri')).to.equal('otheruri');
+                });
+
+                it('changes its meta attributes with class change', function() {
+                    var c = canvas.fromXML('<section><span class="uri" meta-uri="someuri"></span></section>'),
+                    span = c.doc().children()[0];
+                    
+                    expect(span.getWlxmlMetaAttr('uri')).to.equal('someuri');
+                    span.setWlxmlClass('author');
+                    expect(span.getWlxmlMetaAttr('uri')).to.be.undefined;
+                });
+
+                it('keeps meta attribute value on class change if a new class has this attribute', function() {
+                    var c = canvas.fromXML('<section><span class="uri" meta-uri="someuri"></span></section>'),
+                    span = c.doc().children()[0];
+                    span.setWlxmlClass('uri.some.subclass');
+                    expect(span.getWlxmlMetaAttr('uri')).to.equal('someuri');
+                });
+            });
         });
 
         it('returns DocumentNodeElement instance from HTMLElement', function() {
@@ -547,10 +576,11 @@ describe('Canvas', function() {
                     section = c.doc(),
                     text = section.children()[1].children()[0];
 
-                    text.unwrap();
+                    var newTextContainer = text.unwrap();
 
                     expect(section.children().length).to.equal(1, 'section has one child');
                     expect(section.children()[0].getText()).to.equal('Alice has a cat');
+                    expect(newTextContainer.sameNode(c.doc())).to.equal(true, 'unwrap returns new text parent DocumentNodeElement');
                 })
             });
         });