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

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvonne Yip committed Sep 9, 2014
1 parent 085af70 commit 6ef6e10
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
112 changes: 112 additions & 0 deletions tests/html/paper-ripple-position.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<!doctype html>
<html>
<head>
<title>paper-ripple</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">

<script src="../../../platform/platform.js"></script>

<link href="../../paper-ripple.html" rel="import">

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

<style>
.ripple-container {
border: 1px solid black;
position: relative;
margin: 16px;
}

.ripple-container > span {
pointer-events: none;
}

.ripple-1 {
width: 320px;
height: 480px;
}

.ripple-1-tap {
top: 10px;
}

.ripple-2 {
width: 480px;
height: 320px;
}

.ripple-2-tap {
pointer-events: none;
}

.ripple-3 {
width: 320px;
height: 320px;
}
</style>

</head>
<body unresolved>

<p>ripple originates from the tap position 1:</p>
<div class="ripple-container ripple-1" layout vertical center>
<paper-ripple fit></paper-ripple>
<span class="ripple-1-tap">tap here</span>
</div>

<p>ripple originates from the tap position 2:</p>
<div class="ripple-container ripple-2" layout horizontal center>
<paper-ripple fit></paper-ripple>
<span class="ripple-2-tap">tap here</span>
</div>

<script>
var fake = new Fake();

function centerOf(node) {
var rect = node.getBoundingClientRect();
return {x: rect.left + rect.width / 2, y: rect.top + rect.height / 2};
}

function approxEqual(p1, p2) {
return Math.floor(p1.x) == Math.floor(p2.x) && Math.floor(p1.y) == Math.floor(p2.y);
}

function test1() {
var ripple1 = document.querySelector('.ripple-1-tap');
fake.downOnNode(ripple1, function() {

requestAnimationFrame(function() {
var wave = document.querySelector('.ripple-1 /deep/ .wave');
chai.assert(approxEqual(centerOf(ripple1), centerOf(wave)), 'ripple position is incorrect in tall container');

test2();
});

});
}

function test2() {
var ripple1 = document.querySelector('.ripple-2-tap');
fake.downOnNode(ripple1, function() {

requestAnimationFrame(function() {
var wave = document.querySelector('.ripple-2 /deep/ .wave');
chai.assert(approxEqual(centerOf(ripple1), centerOf(wave)), 'ripple position is incorrect in wide container');

done();
});

});
}

document.addEventListener('polymer-ready', test1);
</script>

</body>
</html>
5 changes: 5 additions & 0 deletions tests/js/htmltests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mocha.setup({ui: 'tdd', htmlbase: ''});

htmlSuite('paper-ripple', function() {
htmlTest('html/paper-ripple-position.html');
});
22 changes: 22 additions & 0 deletions tests/runner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>Web Component Test Runner</title>

<link href="../../polymer-test-tools/tools.html" rel="import">

<script src="../../polymer-test-tools/mocha-htmltest.js"></script>
<script src="js/htmltests.js"></script>
</head>
<body>

<div id="mocha"></div>

<script>
mocha.run();
</script>

</body>
</html>
6 changes: 6 additions & 0 deletions tests/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tools": ["chai", "mocha-tdd"],
"tests": [
"js/htmltests.js"
]
}

0 comments on commit 6ef6e10

Please sign in to comment.