1 module("wysihtml5.dom.domNode", {
3 this.container = document.createElement("div");
7 test("Simple .prev() test", function() {
8 this.container.innerHTML = "<span></span><div></div>";
9 var lastItem = this.container.querySelector("div"),
10 firstItem = this.container.querySelector("span");
11 equal(wysihtml5.dom.domNode(lastItem).prev(), firstItem);
14 test(".prev() test with textnode in between", function() {
15 this.container.innerHTML = "<span></span> confusing text node <div></div>";
16 var lastItem = this.container.querySelector("div"),
17 firstItem = this.container.querySelector("span");
18 equal(wysihtml5.dom.domNode(lastItem).prev({nodeTypes: [1]}), firstItem);
21 test(".prev() test if no prev element exists", function() {
22 this.container.innerHTML = "<div></div>";
23 var lastItem = this.container.querySelector("div");
24 equal(wysihtml5.dom.domNode(lastItem).prev(), null);
27 test(".prev() test if no prev element exists with textnode", function() {
28 this.container.innerHTML = "confusing text node <div></div>";
29 var lastItem = this.container.querySelector("div");
30 equal(wysihtml5.dom.domNode(lastItem).prev({nodeTypes: [1]}), null);
33 test(".prev() test with empty textnode in between and ignoreBlankTexts", function() {
34 this.container.innerHTML = "<span></span> <div></div>";
35 var lastItem = this.container.querySelector("div"),
36 firstItem = this.container.querySelector("span");
37 equal(wysihtml5.dom.domNode(lastItem).prev({ignoreBlankTexts: true}), firstItem);
40 test("Simple .next() test", function() {
41 this.container.innerHTML = "<div></div><span></span>";
42 var firstItem = this.container.querySelector("div"),
43 lastItem = this.container.querySelector("span");
44 equal(wysihtml5.dom.domNode(firstItem).next(), lastItem);
47 test(".next() test with textnode in between", function() {
48 this.container.innerHTML = "<div></div> confusing text node <span></span>";
49 var firstItem = this.container.querySelector("div"),
50 lastItem = this.container.querySelector("span");
51 equal(wysihtml5.dom.domNode(firstItem).next({nodeTypes: [1]}), lastItem);
54 test(".next() test if no next element exists", function() {
55 this.container.innerHTML = "<div></div>";
56 var lastItem = this.container.querySelector("div");
57 equal(wysihtml5.dom.domNode(lastItem).next(), null);
60 test(".next() test if no next element exists with textnode", function() {
61 this.container.innerHTML = "<div></div> confusing text node ";
62 var lastItem = this.container.querySelector("div");
63 equal(wysihtml5.dom.domNode(lastItem).next({nodeTypes: [1]}), null);
66 test(".next() test with empty textnode in between and ignoreBlankTexts", function() {
67 this.container.innerHTML = "<div></div> <span></span>";
68 var firstItem = this.container.querySelector("div"),
69 lastItem = this.container.querySelector("span");
70 equal(wysihtml5.dom.domNode(firstItem).next({ignoreBlankTexts: true}), lastItem);
73 test(".lastLeafNode() test for element that is last leaf itself", function () {
74 this.container.innerHTML = "";
75 equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), this.container);
78 test(".lastLeafNode() test for inner elements traversing", function () {
79 var txtNode = document.createTextNode("test"),
80 elementNode = document.createElement('div'),
81 innerElementNode = document.createElement('div');
83 this.container.innerHTML = "";
85 this.container.appendChild(txtNode);
86 equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), txtNode, "Found last only child textnode");
88 this.container.appendChild(elementNode);
89 equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), elementNode, "Found last div element");
91 elementNode.appendChild(innerElementNode);
92 equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), innerElementNode, "Found last wrapped div element");
94 this.container.insertBefore(elementNode, txtNode);
95 equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), txtNode, "Found last textnode after reordering elements");
98 test(".lastLeafNode() test for leafClasses option", function () {
99 var elementNode = document.createElement('div'),
100 innerElementNode = document.createElement('div');
102 this.container.innerHTML = "";
104 elementNode.className = "forced-leaf";
105 elementNode.appendChild(innerElementNode);
106 this.container.appendChild(elementNode);
108 equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), innerElementNode, "Wihout leafClasses option finds inner element node");
109 equal(wysihtml5.dom.domNode(this.container).lastLeafNode({leafClasses: ['forced-leaf']}), elementNode, "With leafClasses option, stops search and returns the element with leafClass");