Splitting text: Returning node elements involved
[fnpeditor.git] / modules / documentCanvas / canvas / canvas.test3.js
index 3778698..0b71ee0 100644 (file)
@@ -267,6 +267,32 @@ describe('Canvas', function() {
                     expect(c.doc().children()[2].getText()).to.equal(' cat');
                 });
             });
+
+            describe('getting vertically first text element', function() {
+                it('returns the first child if it\'s text element, ignores metadata', function() {
+                    var c = canvas.fromXML('<section><metadata><dc:author>author</dc:author></metadata>Alice<div>has</div>a cat</section>'),
+                        first = c.doc().getVerticallyFirstTextElement();
+
+                    expect(first.sameNode(c.doc().children()[1])).to.be.true;
+                });
+
+                it('looks recursively inside node elements if they precede text element', function() {
+                    var c = canvas.fromXML('\
+                            <section>\
+                                <div>\
+                                    <div>\
+                                        Alice\
+                                    </div>\
+                                </div>\
+                                Some text\
+                            </section>'),
+                        textAlice = c.doc().children()[0].children()[0].children()[0],
+                        first = c.doc().getVerticallyFirstTextElement();
+
+                    expect(textAlice).to.be.instanceOf(documentElement.DocumentTextElement);
+                    expect(first.sameNode(textAlice)).to.be.true;
+                });
+            });
         });
 
         describe('manipulation api', function() {
@@ -342,7 +368,7 @@ describe('Canvas', function() {
                         section = c.doc(),
                         text = section.children()[0].children()[0];
 
-                    text.split({offset: 5});
+                    var returnedValue = text.split({offset: 5});
                     expect(section.children().length).to.equal(2, 'section has two children');
                     
                     var header1 = section.children()[0];
@@ -354,6 +380,9 @@ describe('Canvas', function() {
                     expect(header2.getWlxmlTag()).to.equal('header', 'second section child represents wlxml header');
                     expect(header2.children().length).to.equal(1, 'second header has one text child');
                     expect(header2.children()[0].getText()).to.equal('header', 'second header has correct content');
+
+                    expect(returnedValue.first.sameNode(header1)).to.equal(true, 'first node returnde');
+                    expect(returnedValue.second.sameNode(header2)).to.equal(true, 'second node returned');
                 });
 
                 it('leaves empty copy of DocumentNodeElement if splitting at the very beginning', function() {