+
+ describe('merging with adjacent content', function() {
+
+ describe('when text preceded by element', function() {
+ describe('when text followed by element', function() {
+ it('appends text to the preceding element, following elements stays in place', function() {
+ var doc = getDocumentFromXML('<section><a>A</a>text<b>B</b></section>'),
+ text = getTextNode('text', doc);
+
+ text.mergeContentUp();
+ var contents = doc.root.contents();
+
+ expect(contents.length).to.equal(2);
+ expect(contents[0].getTagName()).to.equal('a');
+ expect(contents[0].contents()[0].getText()).to.equal('Atext');
+ expect(contents[1].getTagName()).to.equal('b');
+ });
+ });
+ describe('when text is a last child', function() {
+ it('appends text to the preceding element', function() {
+ var doc = getDocumentFromXML('<section><a>A</a>text</section>'),
+ text = getTextNode('text', doc);
+
+ text.mergeContentUp();
+ var contents = doc.root.contents();
+
+ expect(contents.length).to.equal(1);
+ expect(contents[0].getTagName()).to.equal('a');
+ expect(contents[0].contents()[0].getText()).to.equal('Atext');
+ });
+ });
+ });
+
+ describe('when text is a first child', function() {
+ describe('when text followed by element', function() {
+ it('appends text and its siblings to the parent preceding element', function() {
+ var doc = getDocumentFromXML('<section><b>B</b><div>text<a>A</a></div></section>'),
+ text = getTextNode('text', doc);
+
+ text.mergeContentUp();
+ var contents = doc.root.contents();
+
+ expect(contents.length).to.equal(3);
+ expect(contents[0].getTagName()).to.equal('b');
+ expect(contents[1].getText()).to.equal('text');
+ expect(contents[2].getTagName()).to.equal('a');
+ });
+ it('appends text and its siblings after the parent preceding text', function() {
+ var doc = getDocumentFromXML('<section>B<div>text<a>A</a></div></section>'),
+ text = getTextNode('text', doc);
+
+ text.mergeContentUp();
+ var contents = doc.root.contents();
+
+ expect(contents.length).to.equal(2);
+ expect(contents[0].getText()).to.equal('Btext');
+ expect(contents[1].getTagName()).to.equal('a');
+ });
+ });
+ });
+ });