Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiefu committed Sep 10, 2014
1 parent 95654e6 commit a0f407a
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 6 deletions.
1 change: 1 addition & 0 deletions tests/html/core-selector-activate-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
});
assert.equal(s.selected, '0');
requestAnimationFrame(function() {
// select Item 2
s.children[1].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
});
});
Expand Down
8 changes: 4 additions & 4 deletions tests/html/core-selector-basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
// set selected
s.selected = 'item5';
Platform.flush();
requestAnimationFrame(function() {
setTimeout(function() {
// check core-select event
assert.equal(selectEventCounter, 1);
// check selected class
Expand All @@ -87,11 +87,11 @@
selectEventCounter = 0;
s.selected = 'item5';
Platform.flush();
requestAnimationFrame(function() {
setTimeout(function() {
assert.equal(selectEventCounter, 0);
done();
});
});
}, 50);
}, 50);
});

</script>
Expand Down
4 changes: 2 additions & 2 deletions tests/html/core-selector-multi.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
// set selected
s.selected = [0, 2];
Platform.flush();
requestAnimationFrame(function() {
setTimeout(function() {
// check core-select event
assert.equal(selectEventCounter, 2);
// check selected class
Expand All @@ -74,7 +74,7 @@
assert.equal(s.selected.length, 1);
assert.isFalse(s.children[0].classList.contains('core-selected'));
done();
});
}, 50);
});

</script>
Expand Down
87 changes: 87 additions & 0 deletions tests/html/core-selector-next-previous-wrap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>core-selector-next-previous-wrap</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

<script src="../../../platform/platform.js"></script>
<script src="../../../polymer-test-tools/chai/chai.js"></script>
<script src="../../../polymer-test-tools/htmltest.js"></script>

<link rel="import" href="../../core-selector.html">

<style>
.core-selected {
background: #ccc;
}
</style>

</head>
<body unresolved>

<core-selector id="selector" selected="0">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</core-selector>

<script>

function async(fn) {
setTimeout(function() {
fn();
Platform.flush();
}, 50);
}

document.addEventListener('polymer-ready', function() {
var assert = chai.assert;
var s = document.querySelector('#selector');
assert.equal(s.selected, 0);
async(function() {
// select next item
s.selectNext(true);
async(function() {
assert.equal(s.selected, 1);
// select next item
s.selectNext(true);
async(function() {
assert.equal(s.selected, 2);
// select next item (already at the end)
s.selectNext(true);
async(function() {
assert.equal(s.selected, 0);
// select previous item (already at the beginning)
s.selectPrevious(true);
async(function() {
assert.equal(s.selected, 2);
// select previous item
s.selectPrevious(true);
async(function() {
assert.equal(s.selected, 1);
// select previous item
s.selectPrevious(true);
async(function() {
assert.equal(s.selected, 0);
done();
});
});
});
});
});
});
});
});

</script>

</body>
</html>
87 changes: 87 additions & 0 deletions tests/html/core-selector-next-previous.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>core-selector-next-previous</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

<script src="../../../platform/platform.js"></script>
<script src="../../../polymer-test-tools/chai/chai.js"></script>
<script src="../../../polymer-test-tools/htmltest.js"></script>

<link rel="import" href="../../core-selector.html">

<style>
.core-selected {
background: #ccc;
}
</style>

</head>
<body unresolved>

<core-selector id="selector" selected="0">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</core-selector>

<script>

function async(fn) {
setTimeout(function() {
fn();
Platform.flush();
}, 50);
}

document.addEventListener('polymer-ready', function() {
var assert = chai.assert;
var s = document.querySelector('#selector');
assert.equal(s.selected, 0);
async(function() {
// select next item
s.selectNext();
async(function() {
assert.equal(s.selected, 1);
// select next item
s.selectNext();
async(function() {
assert.equal(s.selected, 2);
// select next item (already at the end)
s.selectNext();
async(function() {
assert.equal(s.selected, 2);
// select previous item
s.selectPrevious();
async(function() {
assert.equal(s.selected, 1);
// select previous item
s.selectPrevious();
async(function() {
assert.equal(s.selected, 0);
// select previous item (already at the beginning)
s.selectPrevious();
async(function() {
assert.equal(s.selected, 0);
done();
});
});
});
});
});
});
});
});

</script>

</body>
</html>
60 changes: 60 additions & 0 deletions tests/html/core-selector-selected-attr-prop.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>core-selector-selected-attr-prop</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

<script src="../../../platform/platform.js"></script>
<script src="../../../polymer-test-tools/chai/chai.js"></script>
<script src="../../../polymer-test-tools/htmltest.js"></script>

<link rel="import" href="../../core-selector.html">

<style>
.core-selected {
background: #ccc;
}
</style>

</head>
<body>

<core-selector id="selector" selected="2" selectedProperty="myprop">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
<div>Item 4</div>
<div>Item 5</div>
</core-selector>

<script>

document.addEventListener('polymer-ready', function() {
var assert = chai.assert;
var s = document.querySelector('#selector');
// select Item 4
s.selected = 4;
Platform.flush();
setTimeout(function() {
// check Item2's attribute and property (should be unselect)
assert.isFalse(s.children[2].hasAttribute('active'));
assert.notEqual(s.children[2].myprop, true);
// check Item4's attribute and property
assert.isTrue(s.children[4].hasAttribute('active'));
assert.isTrue(s.children[4].myprop);
done();
}, 50);
});

</script>

</body>
</html>
3 changes: 3 additions & 0 deletions tests/js/htmltests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ htmlSuite('core-selector', function() {
htmlTest('html/core-selector-basic.html');
htmlTest('html/core-selector-activate-event.html');
htmlTest('html/core-selector-multi.html');
htmlTest('html/core-selector-next-previous.html');
htmlTest('html/core-selector-next-previous-wrap.html');
htmlTest('html/core-selector-selected-attr-prop.html');
});

0 comments on commit a0f407a

Please sign in to comment.