'use strict';
/*jshint expr:true */
-/* global describe, it, beforeEach */
+/* global describe, it, beforeEach, Node, DOMParser */
var expect = chai.expect;
expect(rootContents[0].getText()).to.equal('Alice a cat');
});
+ it('inserts node at index', function() {
+ var doc = getDocumentFromXML('<div><a></a><b></b><c></c></div>'),
+ b = doc.root.contents()[1];
+
+ var inserted = doc.root.insertAtIndex({tagName: 'test'}, 1);
+
+ expect(doc.root.contents()[1].sameNode(inserted)).to.equal(true, 'inserted node returned');
+ expect(b.getIndex()).to.equal(2, 'b node shifted right');
+ });
+
+ it('appends node when inserting node at index out of range', function() {
+ var doc = getDocumentFromXML('<div></div>');
+
+ var test1 = doc.root.insertAtIndex({tagName: 'test1'}, 0),
+ test2 = doc.root.insertAtIndex({tagName: 'test1'}, 10);
+
+ expect(doc.root.contents()[0].sameNode(test1)).to.equal(true, 'inserting at index 0 of empty nodes appends node');
+ expect(doc.root.contents().length).to.equal(1, 'inserting at index out of range does nothing');
+ expect(test2).to.equal(undefined, 'inserting at index out of range returns undefined');
+ });
+
it('appends element node to another element node', function() {
var node1 = elementNodeFromParams({tag: 'div'}),
node2 = elementNodeFromParams({tag: 'a'}),
lastDiv = section.contents()[section.contents().length -1];
var returned = section.document.wrapNodes({
- element1: aliceText,
- element2: lastDiv,
+ node1: aliceText,
+ node2: lastDiv,
_with: {tagName: 'header'}
});
div3 = section.contents()[2];
section.document.wrapNodes({
- element1: div2,
- element2: div3,
+ node1: div2,
+ node2: div3,
_with: {tagName: 'header'}
});