This repository has been archived by the owner on Mar 8, 2019. It is now read-only.
/
get_as_dom_test.js
55 lines (41 loc) · 1.7 KB
/
get_as_dom_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module("wysihtml5.dom.getAsDom", {
teardown: function() {
var iframe;
while (iframe = document.querySelector("iframe.wysihtml5-sandbox")) {
iframe.parentNode.removeChild(iframe);
}
}
});
test("Basic test", function() {
var result;
result = wysihtml5.dom.getAsDom('<span id="get-in-dom-element-test">foo</span>');
equals(result.nodeName, "DIV");
equals(result.ownerDocument, document);
equals(result.firstChild.nodeName, "SPAN");
equals(result.childNodes.length , 1);
equals(result.firstChild.innerHTML, "foo");
ok(!document.getElementById("get-in-dom-element-test"));
result = wysihtml5.dom.getAsDom("<i>1</i> <b>2</b>");
equals(result.childNodes.length, 3);
result = wysihtml5.dom.getAsDom(document.createElement("div"));
equals(result.innerHTML.toLowerCase(), "<div></div>");
});
test("HTML5 elements", function() {
var result;
result = wysihtml5.dom.getAsDom("<article><span>foo</span></article>");
equals(result.firstChild.nodeName.toLowerCase(), "article");
equals(result.firstChild.innerHTML.toLowerCase(), "<span>foo</span>");
result = wysihtml5.dom.getAsDom("<output>foo</output>");
equals(result.innerHTML.toLowerCase(), "<output>foo</output>");
});
asyncTest("Different document context", function() {
expect(2);
new wysihtml5.dom.Sandbox(function(sandbox) {
var result;
result = wysihtml5.dom.getAsDom("<div>hello</div>", sandbox.getDocument());
equals(result.firstChild.ownerDocument, sandbox.getDocument());
result = wysihtml5.dom.getAsDom("<header>hello</header>", sandbox.getDocument());
equals(result.innerHTML.toLowerCase(), "<header>hello</header>");
start();
}).insertInto(document.body);
});