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