OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <sky> | |
3 <style> | |
4 div { font-size: 5px; } | |
5 .font-10 { font-size: 10px; } | |
6 .font-12 { font-size: 12px; } | |
7 .font-24 { font-size: 24px; } | |
8 </style> | |
9 <div id="sandbox"></div> | |
10 <script> | |
11 import "../resources/third_party/unittest/unittest.dart"; | |
12 import "../resources/unit.dart"; | |
13 | |
14 import "dart:sky"; | |
15 | |
16 main() { | |
17 initUnit(); | |
18 | |
19 var sandbox = document.getElementById("sandbox"); | |
20 var target = null; | |
21 | |
22 setUp(() { | |
23 target = document.createElement("div"); | |
24 sandbox.appendChild(target); | |
25 }); | |
26 | |
27 tearDown(() { | |
28 target.remove(); | |
29 }); | |
30 | |
31 // test("should add multiple classes", () { | |
32 // target.classList..add("first", "second", "third"); | |
33 // expect(target.classList.toString(), equals("first second third")); | |
34 // }); | |
35 | |
36 test("should add classes in order", () { | |
37 target.classList..add("first") | |
38 ..add("second"); | |
39 expect(target.classList.toString(), equals("first second")); | |
40 }); | |
41 | |
42 test("should remove classes", () { | |
43 target.classList..add("first") | |
44 ..add("second") | |
45 ..add("third") | |
46 ..remove("second"); | |
47 expect(target.classList.toString(), equals("first third")); | |
48 }); | |
49 | |
50 // test("should remove multiple classes", () { | |
51 // target.classList.add("first", "second", "third"); | |
52 // target.classList.remove("first", "third"); | |
53 // expect(target.classList.toString(), equals("second")); | |
54 // }); | |
55 | |
56 test("should clear all classes", () { | |
57 target.classList.add("first"); | |
58 target.classList.add("second"); | |
59 target.classList.clear(); | |
60 expect(target.classList.toString(), equals("")); | |
61 expect(target.hasAttribute("class"), isFalse); | |
62 }); | |
63 | |
64 test("should check for classes", () { | |
65 target.classList..add("first") | |
66 ..add("second") | |
67 ..add("third"); | |
68 expect(target.classList.contains("first"), isTrue); | |
69 expect(target.classList.contains("second"), isTrue); | |
70 expect(target.classList.contains("third"), isTrue); | |
71 target.classList.remove("second"); | |
72 expect(target.classList.contains("first"), isTrue); | |
73 expect(target.classList.contains("second"), isFalse); | |
74 expect(target.classList.contains("third"), isTrue); | |
75 }); | |
76 | |
77 test("should get classes by index", () { | |
78 target.classList..add("first") | |
79 ..add("second") | |
80 ..add("third"); | |
81 // expect(target.classList[0], equals("first")); | |
82 // expect(target.classList[1], equals("second")); | |
83 // expect(target.classList[2], equals("third")); | |
84 expect(target.classList.item(0), equals("first")); | |
85 expect(target.classList.item(1), equals("second")); | |
86 expect(target.classList.item(2), equals("third")); | |
87 }); | |
88 | |
89 test("should toggle classes", () { | |
90 target.classList..add("first") | |
91 ..add("second"); | |
92 expect(target.classList.toggle("first"), isFalse); | |
93 expect(target.classList.toString(), equals("second")); | |
94 expect(target.classList.toggle("first"), isTrue); | |
95 expect(target.classList.toString(), equals("second first")); | |
96 // expect(target.classList.toggle("second", true), isTrue); | |
97 // expect(target.classList.toString(), equals("second first")); | |
98 // expect(target.classList.toggle("second", true), isTrue); | |
99 // expect(target.classList.toggle("second", false), isFalse); | |
100 // expect(target.classList.toggle("second", false), isFalse); | |
101 // expect(target.classList.toString(), equals("first")); | |
102 }); | |
103 | |
104 test("should dynamically update style", () { | |
105 expect(window.getComputedStyle(target)["font-size"], | |
106 equals("5px")); | |
107 target.classList.add("font-10"); | |
108 target.classList.add("font-12"); | |
109 expect(window.getComputedStyle(target)["font-size"], | |
110 equals("12px")); | |
111 target.classList.add("font-24"); | |
112 expect(window.getComputedStyle(target)["font-size"], | |
113 equals("24px")); | |
114 target.classList.remove("font-12"); | |
115 expect(window.getComputedStyle(target)["font-size"], | |
116 equals("24px")); | |
117 target.classList.remove("font-24"); | |
118 expect(window.getComputedStyle(target)["font-size"], | |
119 equals("10px")); | |
120 target.classList.remove("font-10"); | |
121 expect(window.getComputedStyle(target)["font-size"], | |
122 equals("5px")); | |
123 }); | |
124 } | |
125 </script> | |
126 </sky> | |
OLD | NEW |