OLD | NEW |
---|---|
1 <sky> | 1 <sky> |
2 <import src="../resources/dom-utils.sky" as="DomUtils" /> | 2 <import src="../resources/dom-utils.sky" as="DomUtils" /> |
3 <script> | 3 <script> |
4 import "../resources/third_party/unittest/unittest.dart"; | 4 import "../resources/third_party/unittest/unittest.dart"; |
5 import "../resources/unit.dart"; | 5 import "../resources/unit.dart"; |
6 | 6 |
7 import "dart:sky"; | 7 import "dart:sky"; |
8 | 8 |
9 void main() { | 9 void main() { |
10 initUnit(); | 10 initUnit(); |
11 | 11 |
12 var doc; | 12 var doc; |
13 | 13 |
14 var childElementCount = DomUtils.childElementCount; | 14 var childElementCount = DomUtils.childElementCount; |
15 var childNodeCount = DomUtils.childNodeCount; | 15 var childNodeCount = DomUtils.childNodeCount; |
16 | 16 |
17 setUp(() { | 17 setUp(() { |
18 doc = new Document(); | 18 doc = new Document(); |
19 }); | 19 }); |
20 | 20 |
21 test("should allow replacing the document element", () { | 21 test("should allow replacing the document element", () { |
22 var oldChild = doc.appendChild(doc.createElement("div")); | 22 var oldChild = doc.appendChild(doc.createElement("div")); |
23 expect(childElementCount(doc), equals(1)); | 23 expect(childElementCount(doc), equals(1)); |
24 var newChild = doc.createElement("div"); | 24 var newChild = doc.createElement("div"); |
25 doc.replaceChild(newChild, oldChild); | 25 oldChild.replaceWith([newChild]); |
eseidel
2015/02/14 00:12:23
Feels like we're going to want a single vs. list v
abarth-chromium
2015/02/14 00:27:19
There's some discussion about this in the Sky chat
| |
26 expect(childElementCount(doc), equals(1)); | 26 expect(childElementCount(doc), equals(1)); |
27 expect(newChild.parentNode, equals(doc)); | 27 expect(newChild.parentNode, equals(doc)); |
28 expect(oldChild.parentNode, isNull); | 28 expect(oldChild.parentNode, isNull); |
29 }); | 29 }); |
30 | 30 |
31 test("should allow replacing a text child with an element", () { | 31 test("should allow replacing a text child with an element", () { |
32 var oldChild = doc.appendChild(new Text("text here")); | 32 var oldChild = doc.appendChild(new Text("text here")); |
33 expect(childElementCount(doc), equals(0)); | 33 expect(childElementCount(doc), equals(0)); |
34 expect(childNodeCount(doc), equals(1)); | 34 expect(childNodeCount(doc), equals(1)); |
35 var newChild = doc.createElement("div"); | 35 var newChild = doc.createElement("div"); |
36 doc.replaceChild(newChild, oldChild); | 36 oldChild.replaceWith([newChild]); |
37 expect(childElementCount(doc), equals(1)); | 37 expect(childElementCount(doc), equals(1)); |
38 expect(childNodeCount(doc), equals(1)); | 38 expect(childNodeCount(doc), equals(1)); |
39 expect(newChild.parentNode, equals(doc)); | 39 expect(newChild.parentNode, equals(doc)); |
40 expect(oldChild.parentNode, isNull); | 40 expect(oldChild.parentNode, isNull); |
41 }); | 41 }); |
42 | 42 |
43 test("should allow replacing the document element with text", () { | 43 test("should allow replacing the document element with text", () { |
44 var oldChild = doc.appendChild(doc.createElement("div")); | 44 var oldChild = doc.appendChild(doc.createElement("div")); |
45 expect(childElementCount(doc), equals(1)); | 45 expect(childElementCount(doc), equals(1)); |
46 var newChild = new Text(" text "); | 46 var newChild = new Text(" text "); |
47 doc.replaceChild(newChild, oldChild); | 47 oldChild.replaceWith([newChild]); |
48 expect(childElementCount(doc), equals(0)); | 48 expect(childElementCount(doc), equals(0)); |
49 expect(childNodeCount(doc), equals(1)); | 49 expect(childNodeCount(doc), equals(1)); |
50 expect(newChild.parentNode, equals(doc)); | 50 expect(newChild.parentNode, equals(doc)); |
51 expect(oldChild.parentNode, isNull); | 51 expect(oldChild.parentNode, isNull); |
52 }); | 52 }); |
53 | 53 |
54 test("should allow inserting text with a fragment", () { | 54 test("should allow inserting text with a fragment", () { |
55 var fragment = doc.createDocumentFragment(); | 55 var fragment = doc.createDocumentFragment(); |
56 fragment.appendChild(new Text(" text ")); | 56 fragment.appendChild(new Text(" text ")); |
57 fragment.appendChild(new Text(" text ")); | 57 fragment.appendChild(new Text(" text ")); |
58 expect(childNodeCount(doc), equals(0)); | 58 expect(childNodeCount(doc), equals(0)); |
59 doc.appendChild(fragment); | 59 doc.appendChild(fragment); |
60 expect(childElementCount(doc), equals(0)); | 60 expect(childElementCount(doc), equals(0)); |
61 expect(childNodeCount(doc), equals(2)); | 61 expect(childNodeCount(doc), equals(2)); |
62 }); | 62 }); |
63 | 63 |
64 test("should allow replacing the document element with a fragment", () { | 64 test("should allow replacing the document element with a fragment", () { |
65 var oldChild = doc.appendChild(doc.createElement("div")); | 65 var oldChild = doc.appendChild(doc.createElement("div")); |
66 expect(childElementCount(doc), equals(1)); | 66 expect(childElementCount(doc), equals(1)); |
67 var fragment = doc.createDocumentFragment(); | 67 var fragment = doc.createDocumentFragment(); |
68 fragment.appendChild(new Text(" text ")); | 68 fragment.appendChild(new Text(" text ")); |
69 var newChild = fragment.appendChild(doc.createElement("div")); | 69 var newChild = fragment.appendChild(doc.createElement("div")); |
70 fragment.appendChild(new Text(" ")); | 70 fragment.appendChild(new Text(" ")); |
71 doc.replaceChild(fragment, oldChild); | 71 oldChild.replaceWith([fragment]); |
72 expect(childElementCount(doc), equals(1)); | 72 expect(childElementCount(doc), equals(1)); |
73 expect(childNodeCount(doc), equals(3)); | 73 expect(childNodeCount(doc), equals(3)); |
74 expect(newChild.parentNode, equals(doc)); | 74 expect(newChild.parentNode, equals(doc)); |
75 expect(oldChild.parentNode, isNull); | 75 expect(oldChild.parentNode, isNull); |
76 }); | 76 }); |
77 | 77 |
78 test("should throw when inserting multiple elements", () { | 78 test("should throw when inserting multiple elements", () { |
79 doc.appendChild(doc.createElement("div")); | 79 doc.appendChild(doc.createElement("div")); |
80 var oldChild = doc.appendChild(new Text(" text ")); | 80 var oldChild = doc.appendChild(new Text(" text ")); |
81 expect(childElementCount(doc), equals(1)); | 81 expect(childElementCount(doc), equals(1)); |
(...skipping 17 matching lines...) Expand all Loading... | |
99 // expect(() { | 99 // expect(() { |
100 // doc.replaceChild(fragment, 0); | 100 // doc.replaceChild(fragment, 0); |
101 // }, throws); | 101 // }, throws); |
102 // expect(() { | 102 // expect(() { |
103 // doc.insertBefore(fragment, oldChild); | 103 // doc.insertBefore(fragment, oldChild); |
104 // }, throws); | 104 // }, throws); |
105 }); | 105 }); |
106 } | 106 } |
107 </script> | 107 </script> |
108 </sky> | 108 </sky> |
OLD | NEW |