+
+ it('can divide DocumentTextElement with a new DocumentNodeElement', function() {
+ var c = canvas.fromXML('<section>Alice has a cat</section>'),
+ section = c.doc(),
+ text = section.children()[0];
+
+ var returned = text.divide({tag: 'aside', klass: 'footnote', offset: 5}),
+ sectionChildren = section.children(),
+ lhsText = sectionChildren[0],
+ rhsText = sectionChildren[2];
+
+ expect(lhsText.getText()).to.equal('Alice');
+ expect(returned.sameNode(sectionChildren[1]));
+ expect(rhsText.getText()).to.equal(' has a cat');
+ });
+
+ it('treats dividing DocumentTextElement at the very end as appending after it', function() {
+ var c = canvas.fromXML('<section>Alice has a cat</section>'),
+ section = c.doc(),
+ text = section.children()[0];
+
+ var returned = text.divide({tag: 'aside', klass: 'footnote', offset: 15}),
+ sectionChildren = section.children(),
+ textElement = sectionChildren[0],
+ nodeElement = sectionChildren[1];
+
+ expect(sectionChildren.length).to.equal(2);
+ expect(textElement.getText()).to.equal('Alice has a cat');
+ expect(returned.sameNode(nodeElement)).to.be.true;
+ expect(nodeElement.getWlxmlTag()).to.equal('aside');
+ });
+
+ it('treats dividing DocumentTextElement at the very beginning as appending before it', function() {
+ var c = canvas.fromXML('<section>Alice has a cat</section>'),
+ section = c.doc(),
+ text = section.children()[0];
+
+ var returned = text.divide({tag: 'aside', klass: 'footnote', offset: 0}),
+ sectionChildren = section.children(),
+ nodeElement = sectionChildren[0],
+ textElement = sectionChildren[1];
+
+ expect(sectionChildren.length).to.equal(2);
+ expect(textElement.getText()).to.equal('Alice has a cat');
+ expect(returned.sameNode(nodeElement)).to.be.true;
+ expect(nodeElement.getWlxmlTag()).to.equal('aside');
+ });
+ });
+
+ describe('Removing elements', function() {
+ it('merges left and right DocumentTextElement sibling of a detached DocumentNodeElement', function() {
+ var c = canvas.fromXML('<section>Alice<div>has</div>a cat</section>'),
+ section = c.doc(),
+ div = section.children()[1];
+
+ div.detach();
+
+ var sectionChildren = section.children(),
+ textElement = sectionChildren[0];
+
+ expect(sectionChildren).to.have.length(1);
+ expect(textElement.getText()).to.equal('Alicea cat');
+ });