OLD | NEW |
1 <html> | 1 <html> |
2 <import src="../resources/mocha.sky" /> | |
3 <import src="../resources/chai.sky" /> | |
4 <div id="tests"> | 2 <div id="tests"> |
5 <div id="id1"> | 3 <div id="id1"> |
6 <div class="class2"></div> | 4 <div class="class2"></div> |
7 </div> | 5 </div> |
8 <tag-name-3 class="class7" id="tag1"></tag-name-3> | 6 <tag-name-3 class="class7" id="tag1"></tag-name-3> |
9 <tag-name-3 class="class7" id="tag2"></tag-name-3> | 7 <tag-name-3 class="class7" id="tag2"></tag-name-3> |
10 <span class="class2"> | 8 <span class="class2"> |
11 <span class="class5" id="id5" testAttr></span> | 9 <span class="class5" id="id5" testAttr></span> |
12 </span> | 10 </span> |
13 <div id="id5"></div> | 11 <div id="id5"></div> |
14 <tag-name-6 class="class6" id="id6" testAttr="the value"> | 12 <tag-name-6 class="class6" id="id6" testAttr="the value"> |
15 <tag-name-3 class="class7" id="tag2"></tag-name-3> | 13 <tag-name-3 class="class7" id="tag2"></tag-name-3> |
16 </tag-name-6> | 14 </tag-name-6> |
17 </div> | 15 </div> |
18 <script> | 16 <script> |
19 function query(selector) { return document.querySelector(selector); } | 17 import "../resources/third_party/unittest/unittest.dart"; |
20 function queryAll(selector) { return document.querySelectorAll(selector); } | 18 import "../resources/unit.dart"; |
21 | 19 |
22 describe("querySelector", function() { | 20 import "dart:sky"; |
23 it("should find elements by class name", function() { | 21 |
24 assert.ok(query(".class2")); | 22 query(selector) => document.querySelector(selector); |
25 assert.equal(query(".class2").classList.toString(), "class2"); | 23 queryAll(selector) => document.querySelectorAll(selector); |
26 assert.equal(queryAll(".class2").length, 2); | 24 |
27 assert.equal(queryAll(".class2")[0].classList.toString(), "class2"); | 25 main() { |
28 assert.equal(queryAll(".class2")[1].classList.toString(), "class2"); | 26 initUnit(); |
29 assert.notEqual(queryAll(".class2")[0], queryAll(".class2")[1]); | 27 |
| 28 test("should find elements by class name", () { |
| 29 expect(query(".class2"), isNotNull); |
| 30 expect(query(".class2").classList.toString(), equals("class2")); |
| 31 expect(queryAll(".class2").length, 2); |
| 32 expect(queryAll(".class2").item(0).classList.toString(), equals("class2")); |
| 33 expect(queryAll(".class2").item(1).classList.toString(), equals("class2")); |
| 34 expect(queryAll(".class2").item(0), isNot(equals(queryAll(".class2").item(1)
))); |
30 }); | 35 }); |
31 it("should find elements by id", function() { | 36 |
32 assert.ok(query("#id5")); | 37 test("should find elements by id", () { |
33 assert.equal(query("#id5").id, "id5"); | 38 expect(query("#id5"), isNotNull); |
34 assert.equal(query("#id5").classList.toString(), "class5"); | 39 expect(query("#id5").id, equals("id5")); |
| 40 expect(query("#id5").classList.toString(), equals("class5")); |
35 // FIXME(sky): Do we still want to allow multiple id stuff like this? | 41 // FIXME(sky): Do we still want to allow multiple id stuff like this? |
36 assert.equal(queryAll("#id5").length, 2); | 42 expect(queryAll("#id5").length, equals(2)); |
37 assert.equal(queryAll("#id5")[0], query("#id5")); | 43 expect(queryAll("#id5").item(0), equals(query("#id5"))); |
38 assert.notEqual(queryAll("#id5")[1], query("#id5")); | 44 expect(queryAll("#id5").item(1), isNot(equals(query("#id5")))); |
39 assert.equal(queryAll("#id5")[1].id, "id5"); | 45 expect(queryAll("#id5").item(1).id, equals("id5")); |
40 }); | 46 }); |
41 it("should find elements by tag name", function() { | 47 |
42 assert.ok(query("tag-name-6")); | 48 test("should find elements by tag name", () { |
43 assert.equal(query("tag-name-6").tagName, "tag-name-6"); | 49 expect(query("tag-name-6"), isNotNull); |
44 assert.equal(query("tag-name-6").classList.toString(), "class6"); | 50 expect(query("tag-name-6").tagName, equals("tag-name-6")); |
| 51 expect(query("tag-name-6").classList.toString(), equals("class6")); |
45 var context = query("#tests"); | 52 var context = query("#tests"); |
46 assert.equal(context.querySelectorAll("span").length, 2); | 53 expect(context.querySelectorAll("span").length, equals(2)); |
47 }); | 54 }); |
48 it("should find an element by compound selector", function() { | 55 |
49 assert.ok(query("tag-name-6.class6#id6")); | 56 test("should find an element by compound selector", () { |
50 assert.equal(query("tag-name-6.class6#id6").id, "id6"); | 57 expect(query("tag-name-6.class6#id6"), isNotNull); |
51 assert.equal(query("tag-name-6.class6#id6").classList.toString(), "class6"); | 58 expect(query("tag-name-6.class6#id6").id, equals("id6")); |
52 assert.equal(query("tag-name-6.class6#id6").tagName, "tag-name-6"); | 59 expect(query("tag-name-6.class6#id6").classList.toString(), equals("class6")
); |
| 60 expect(query("tag-name-6.class6#id6").tagName, equals("tag-name-6")); |
53 }); | 61 }); |
54 it("should find all elements by compound selector", function() { | 62 |
55 assert.ok(queryAll("tag-name-3.class7")); | 63 test("should find all elements by compound selector", () { |
56 assert.equal(queryAll("tag-name-3.class7").length, 3); | 64 expect(queryAll("tag-name-3.class7"), isNotNull); |
57 assert.equal(queryAll("tag-name-3.class7")[0].id, "tag1"); | 65 expect(queryAll("tag-name-3.class7").length, equals(3)); |
58 assert.equal(queryAll("tag-name-3.class7")[1].id, "tag2"); | 66 expect(queryAll("tag-name-3.class7").item(0).id, equals("tag1")); |
| 67 expect(queryAll("tag-name-3.class7").item(1).id, equals("tag2")); |
59 }); | 68 }); |
60 it("should find all elements by attribute presence selector", function() { | 69 |
61 assert.ok(queryAll("[testAttr]")); | 70 test("should find all elements by attribute presence selector", () { |
62 assert.equal(queryAll("[testAttr]").length, 2); | 71 expect(queryAll("[testAttr]"), isNotNull); |
63 assert.equal(queryAll("[testAttr]")[0].id, "id5"); | 72 expect(queryAll("[testAttr]").length, equals(2)); |
64 assert.equal(queryAll("[testAttr]")[1].id, "id6"); | 73 expect(queryAll("[testAttr]").item(0).id, equals("id5")); |
| 74 expect(queryAll("[testAttr]").item(1).id, equals("id6")); |
65 }); | 75 }); |
66 it("should find all elements by attribute value selector", function() { | 76 |
67 assert.ok(queryAll("[testAttr='the value']")); | 77 test("should find all elements by attribute value selector", () { |
68 assert.equal(queryAll("[testAttr='the value']").length, 1); | 78 expect(queryAll("[testAttr='the value']"), isNotNull); |
69 assert.equal(queryAll("[testAttr='the value']")[0].id, "id6"); | 79 expect(queryAll("[testAttr='the value']").length, equals(1)); |
| 80 expect(queryAll("[testAttr='the value']").item(0).id, equals("id6")); |
70 }); | 81 }); |
71 }); | 82 } |
72 </script> | 83 </script> |
73 </html> | 84 </html> |
OLD | NEW |