X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/e7d1ef97b3d612aaa64a4bc0742b7ede49e807d4..fea8fda1a2f6a07eac7bb37c3c40a053d398ef92:/src/smartxml/smartxml.test.js diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index cf7ef2a..e045788 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -6,7 +6,7 @@ define([ 'use strict'; /*jshint expr:true */ -/* global describe, it, beforeEach */ +/* global describe, it, beforeEach, Node, DOMParser */ var expect = chai.expect; @@ -336,6 +336,27 @@ describe('smartxml', function() { expect(rootContents[0].getText()).to.equal('Alice a cat'); }); + it('inserts node at index', function() { + var doc = getDocumentFromXML('
'), + 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(''); + + 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'}), @@ -438,8 +459,8 @@ describe('smartxml', function() { lastDiv = section.contents()[section.contents().length -1]; var returned = section.document.wrapNodes({ - element1: aliceText, - element2: lastDiv, + node1: aliceText, + node2: lastDiv, _with: {tagName: 'header'} }); @@ -462,8 +483,8 @@ describe('smartxml', function() { div3 = section.contents()[2]; section.document.wrapNodes({ - element1: div2, - element2: div3, + node1: div2, + node2: div3, _with: {tagName: 'header'} });