Add tests for changing classList.
R=ojan@chromium.org Review URL: https://codereview.chromium.org/776493002
This commit is contained in:
12
engine/src/flutter/tests/lowlevel/classlist-expected.txt
Normal file
12
engine/src/flutter/tests/lowlevel/classlist-expected.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
Running 8 tests
|
||||
ok 1 Class list should add multiple classes
|
||||
ok 2 Class list should add classes in order
|
||||
ok 3 Class list should remove classes
|
||||
ok 4 Class list should remove multiple classes
|
||||
ok 5 Class list should check for classes
|
||||
ok 6 Class list should get classes by index
|
||||
ok 7 Class list should toggle classes
|
||||
ok 8 Class list should dynamically update style
|
||||
8 tests
|
||||
8 pass
|
||||
0 fail
|
||||
102
engine/src/flutter/tests/lowlevel/classlist.sky
Normal file
102
engine/src/flutter/tests/lowlevel/classlist.sky
Normal file
@@ -0,0 +1,102 @@
|
||||
<!DOCTYPE html>
|
||||
<sky>
|
||||
<import src="../resources/mocha.sky" />
|
||||
<import src="../resources/chai.sky" />
|
||||
<style>
|
||||
div { font-size: 5px; }
|
||||
.font-10 { font-size: 10px; }
|
||||
.font-12 { font-size: 12px; }
|
||||
.font-24 { font-size: 24px; }
|
||||
</style>
|
||||
<div id="sandbox"></div>
|
||||
<script>
|
||||
describe("Class list", function() {
|
||||
var sandbox = document.getElementById("sandbox");
|
||||
var target;
|
||||
|
||||
beforeEach(function() {
|
||||
target = document.createElement("div");
|
||||
sandbox.appendChild(target);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
target.remove();
|
||||
});
|
||||
|
||||
it("should add multiple classes", function() {
|
||||
target.classList.add("first", "second", "third");
|
||||
assert.equal(target.classList.toString(), "first second third");
|
||||
});
|
||||
|
||||
it("should add classes in order", function() {
|
||||
target.classList.add("first");
|
||||
target.classList.add("second");
|
||||
assert.equal(target.classList.toString(), "first second");
|
||||
});
|
||||
|
||||
it("should remove classes", function() {
|
||||
target.classList.add("first");
|
||||
target.classList.add("second");
|
||||
target.classList.add("third");
|
||||
target.classList.remove("second");
|
||||
assert.equal(target.classList.toString(), "first third");
|
||||
});
|
||||
|
||||
it("should remove multiple classes", function() {
|
||||
target.classList.add("first", "second", "third");
|
||||
target.classList.remove("first", "third");
|
||||
assert.equal(target.classList.toString(), "second");
|
||||
});
|
||||
|
||||
it("should check for classes", function() {
|
||||
target.classList.add("first", "second", "third");
|
||||
assert.isTrue(target.classList.contains("first"));
|
||||
assert.isTrue(target.classList.contains("second"));
|
||||
assert.isTrue(target.classList.contains("third"));
|
||||
target.classList.remove("second");
|
||||
assert.isTrue(target.classList.contains("first"));
|
||||
assert.isFalse(target.classList.contains("second"));
|
||||
assert.isTrue(target.classList.contains("third"));
|
||||
});
|
||||
|
||||
it("should get classes by index", function() {
|
||||
target.classList.add("first", "second", "third");
|
||||
assert.equal(target.classList[0], "first");
|
||||
assert.equal(target.classList[1], "second");
|
||||
assert.equal(target.classList[2], "third");
|
||||
assert.equal(target.classList.item(0), "first");
|
||||
assert.equal(target.classList.item(1), "second");
|
||||
assert.equal(target.classList.item(2), "third");
|
||||
});
|
||||
|
||||
it("should toggle classes", function() {
|
||||
target.classList.add("first", "second");
|
||||
assert.isFalse(target.classList.toggle("first"));
|
||||
assert.equal(target.classList.toString(), "second");
|
||||
assert.isTrue(target.classList.toggle("first"));
|
||||
assert.equal(target.classList.toString(), "second first");
|
||||
assert.isTrue(target.classList.toggle("second", true));
|
||||
assert.equal(target.classList.toString(), "second first");
|
||||
assert.isTrue(target.classList.toggle("second", true));
|
||||
assert.isFalse(target.classList.toggle("second", false));
|
||||
assert.isFalse(target.classList.toggle("second", false));
|
||||
assert.equal(target.classList.toString(), "first");
|
||||
});
|
||||
|
||||
it("should dynamically update style", function() {
|
||||
assert.equal(getComputedStyle(target).fontSize, "5px");
|
||||
target.classList.add("font-10");
|
||||
target.classList.add("font-12");
|
||||
assert.equal(getComputedStyle(target).fontSize, "12px");
|
||||
target.classList.add("font-24");
|
||||
assert.equal(getComputedStyle(target).fontSize, "24px");
|
||||
target.classList.remove("font-12");
|
||||
assert.equal(getComputedStyle(target).fontSize, "24px");
|
||||
target.classList.remove("font-24");
|
||||
assert.equal(getComputedStyle(target).fontSize, "10px");
|
||||
target.classList.remove("font-10");
|
||||
assert.equal(getComputedStyle(target).fontSize, "5px");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</sky>
|
||||
Reference in New Issue
Block a user