Setting caret after wrapping text
[fnpeditor.git] / modules / documentCanvas / canvas / canvas.test3.js
index 030ff19..23061d9 100644 (file)
@@ -126,6 +126,35 @@ describe('Canvas', function() {
                 section.setWlxmlClass(null);
                 expect(section.getWlxmlClass()).to.be.undefined;
             });
                 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() {
         });
 
         it('returns DocumentNodeElement instance from HTMLElement', function() {
@@ -547,10 +576,11 @@ describe('Canvas', function() {
                     section = c.doc(),
                     text = section.children()[1].children()[0];
 
                     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(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');
                 })
             });
         });
                 })
             });
         });