WIP: Note editing, markdown to html
[oweals/karmaworld.git] / karmaworld / apps / wysihtml5 / static / wysihtml5 / wysihtml-0.4.17 / test / dom / dom_node_test.js
1 module("wysihtml5.dom.domNode", {
2   setup: function() {
3     this.container = document.createElement("div");
4   }
5 });
6
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);
12 });
13
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);
19 });
20
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);
25 });
26
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);
31 });
32
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);
38 });
39
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);
45 });
46
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);
52 });
53
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);
58 });
59
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);
64 });
65
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);
71 });
72
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);
76 });
77
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');
82
83   this.container.innerHTML = "";
84
85   this.container.appendChild(txtNode);
86   equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), txtNode, "Found last only child textnode");
87
88   this.container.appendChild(elementNode);
89   equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), elementNode, "Found last div element");
90
91   elementNode.appendChild(innerElementNode);
92   equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), innerElementNode, "Found last wrapped div element");
93
94   this.container.insertBefore(elementNode, txtNode);
95   equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), txtNode, "Found last textnode after reordering elements");
96 });
97
98 test(".lastLeafNode() test for leafClasses option", function () {
99   var elementNode = document.createElement('div'),
100       innerElementNode = document.createElement('div');
101
102   this.container.innerHTML = "";
103
104   elementNode.className = "forced-leaf";
105   elementNode.appendChild(innerElementNode);
106   this.container.appendChild(elementNode);
107   
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");
110 });
111
112
113
114
115
116