| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <link rel="import" href="../resources/mocha.sky" /> | 2 <link rel="import" href="../resources/mocha.sky" /> |
| 3 <link rel="import" href="../resources/chai.sky" /> | 3 <link rel="import" href="../resources/chai.sky" /> |
| 4 <script> | 4 <script> |
| 5 describe("Attribute collection", function() { | 5 describe("Attribute collection", function() { |
| 6 var div; | 6 var div; |
| 7 beforeEach(function() { | 7 beforeEach(function() { |
| 8 div = document.createElement("div"); | 8 div = document.createElement("div"); |
| 9 }); | 9 }); |
| 10 | 10 |
| 11 it("should get by index", function() { | 11 it("should get by index", function() { |
| 12 div.setAttribute("attr0", "value0"); | 12 div.setAttribute("attr0", "value0"); |
| 13 div.setAttribute("attr1", "value1"); | 13 div.setAttribute("attr1", "value1"); |
| 14 assert.equal(div.attributes.length, 2); | |
| 15 assert.equal(div.attributes[0].name, "attr0"); | |
| 16 assert.equal(div.attributes[0].value, "value0"); | |
| 17 assert.equal(div.attributes[1].name, "attr1"); | |
| 18 assert.equal(div.attributes[1].value, "value1"); | |
| 19 }); | |
| 20 it("should get by name", function() { | |
| 21 div.setAttribute("attr0", "value0"); | |
| 22 div.setAttribute("attr1", "value1"); | |
| 23 assert.equal(div.attributes.length, 2); | |
| 24 assert.equal(div.attributes.attr0.value, "value0"); | |
| 25 assert.equal(div.attributes.attr1.value, "value1"); | |
| 26 }); | |
| 27 it("should get all at once", function() { | |
| 28 div.setAttribute("attr0", "value0"); | |
| 29 div.setAttribute("attr1", "value1"); | |
| 30 var attrs = div.getAttributes(); | 14 var attrs = div.getAttributes(); |
| 31 assert.equal(attrs.length, 2); | 15 assert.equal(attrs.length, 2); |
| 32 assert.equal(attrs[0].name, "attr0"); | 16 assert.equal(attrs[0].name, "attr0"); |
| 33 assert.equal(attrs[0].value, "value0"); | 17 assert.equal(attrs[0].value, "value0"); |
| 34 assert.equal(attrs[1].name, "attr1"); | 18 assert.equal(attrs[1].name, "attr1"); |
| 35 assert.equal(attrs[1].value, "value1"); | 19 assert.equal(attrs[1].value, "value1"); |
| 36 }); | 20 }); |
| 37 it("should set by name", function() { | 21 it("should set by name", function() { |
| 38 div.setAttribute("attrName", "value0"); | 22 div.setAttribute("attrName", "value0"); |
| 39 div.attributes.attrName.value = "new value"; | 23 assert.equal(div.getAttribute("attrName"), "value0"); |
| 24 assert.equal(div.getAttributes()[0].name, "attrName"); |
| 25 assert.equal(div.getAttributes()[0].value, "value0"); |
| 26 div.setAttribute("attrName", "new value"); |
| 40 assert.equal(div.getAttribute("attrName"), "new value"); | 27 assert.equal(div.getAttribute("attrName"), "new value"); |
| 41 assert.equal(div.attributes.attrName.value, "new value"); | 28 assert.equal(div.getAttributes()[0].name, "attrName"); |
| 29 assert.equal(div.getAttributes()[0].value, "new value"); |
| 42 }); | 30 }); |
| 43 it("should be case sensitive", function() { | 31 it("should be case sensitive", function() { |
| 44 div.setAttribute("attrName", "value0"); | 32 div.setAttribute("attrName", "value0"); |
| 45 assert.isUndefined(div.attributes.attrname); | 33 assert.isNull(div.getAttribute("attrname")); |
| 46 assert.ok(div.attributes.attrName); | 34 assert.equal(div.getAttribute("attrName"), "value0"); |
| 47 assert.equal(div.attributes.attrName.value, "value0"); | |
| 48 }); | 35 }); |
| 49 it("should live update", function() { | 36 it("should not live update", function() { |
| 50 div.setAttribute("attr0", ""); | 37 div.setAttribute("attr0", "0"); |
| 51 div.setAttribute("attr1", ""); | 38 div.setAttribute("attr1", "1"); |
| 52 div.setAttribute("attr2", ""); | 39 div.setAttribute("attr2", "2"); |
| 53 assert.equal(div.attributes.length, 3); | 40 var oldAttributes = div.getAttributes(); |
| 41 assert.equal(oldAttributes.length, 3); |
| 54 div.removeAttribute("attr1"); | 42 div.removeAttribute("attr1"); |
| 55 assert.equal(div.attributes.length, 2); | 43 assert.equal(oldAttributes.length, 3); |
| 56 assert.equal(div.attributes[0].name, "attr0"); | 44 div.setAttribute("attr0", "value0"); |
| 57 assert.equal(div.attributes[1].name, "attr2"); | |
| 58 div.setAttribute("attr3", ""); | |
| 59 div.setAttribute("attr2", "value2"); | 45 div.setAttribute("attr2", "value2"); |
| 60 assert.equal(div.attributes.length, 3); | 46 var newAttributes = div.getAttributes(); |
| 61 assert.equal(div.attributes[2].name, "attr3"); | 47 assert.equal(newAttributes.length, 2); |
| 62 assert.equal(div.attributes.attr2.value, "value2"); | 48 assert.equal(newAttributes[0].name, "attr0"); |
| 49 assert.equal(newAttributes[0].value, "value0"); |
| 50 assert.equal(newAttributes[1].name, "attr2"); |
| 51 assert.equal(newAttributes[1].value, "value2"); |
| 52 assert.notEqual(newAttributes, oldAttributes); |
| 53 assert.equal(oldAttributes[0].name, "attr0"); |
| 54 assert.equal(oldAttributes[0].value, "0"); |
| 55 assert.equal(oldAttributes[1].name, "attr1"); |
| 56 assert.equal(oldAttributes[1].value, "1"); |
| 57 assert.equal(oldAttributes[2].name, "attr2"); |
| 58 assert.equal(oldAttributes[2].value, "2"); |
| 63 }); | 59 }); |
| 64 }); | 60 }); |
| 65 </script> | 61 </script> |
| 66 </html> | 62 </html> |
| OLD | NEW |