OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <!-- |
| 3 @license |
| 4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 5 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 7 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 8 Code distributed by Google as part of the polymer project is also |
| 9 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 10 --> |
| 11 <html> |
| 12 <head> |
| 13 |
| 14 <meta charset="UTF-8"> |
| 15 <title>paper-ripple</title> |
| 16 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0"> |
| 17 |
| 18 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
| 19 <script src="../../web-component-tester/browser.js"></script> |
| 20 <script src="../../test-fixture/test-fixture-mocha.js"></script> |
| 21 |
| 22 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 23 <link rel="import" href="../paper-ripple.html"> |
| 24 |
| 25 <style> |
| 26 #RippleContainer { |
| 27 display: block; |
| 28 position: relative; |
| 29 width: 100px; |
| 30 height: 50px; |
| 31 } |
| 32 </style> |
| 33 </head> |
| 34 <body> |
| 35 <test-fixture id="TrivialRipple"> |
| 36 <template> |
| 37 <div id="RippleContainer"> |
| 38 <paper-ripple></paper-ripple> |
| 39 </div> |
| 40 </template> |
| 41 </test-fixture> |
| 42 |
| 43 <test-fixture id="CenteringRipple"> |
| 44 <template> |
| 45 <div id="RippleContainer"> |
| 46 <paper-ripple center></paper-ripple> |
| 47 </div> |
| 48 </template> |
| 49 </test-fixture> |
| 50 |
| 51 <test-fixture id="RecenteringRipple"> |
| 52 <template> |
| 53 <div id="RippleContainer"> |
| 54 <paper-ripple recenters></paper-ripple> |
| 55 </div> |
| 56 </template> |
| 57 </test-fixture> |
| 58 |
| 59 <script> |
| 60 function FakeMouseEvent (target, relativeX, relativeX) { |
| 61 var rect = target.getBoundingClientRect(); |
| 62 |
| 63 return { |
| 64 detail: { |
| 65 x: rect.left + relativeX, |
| 66 y: rect.top + relativeX |
| 67 } |
| 68 }; |
| 69 } |
| 70 |
| 71 suite('<paper-ripple>', function () { |
| 72 var mouseEvent; |
| 73 var rippleContainer; |
| 74 var ripple; |
| 75 |
| 76 suite('when tapped', function () { |
| 77 setup(function () { |
| 78 rippleContainer = fixture('TrivialRipple'); |
| 79 ripple = rippleContainer.firstElementChild; |
| 80 |
| 81 mouseEvent = new FakeMouseEvent(ripple, 10, 10); |
| 82 }); |
| 83 |
| 84 test('creates a ripple', function () { |
| 85 expect(ripple.ripples.length).to.be.eql(0); |
| 86 ripple.downAction(mouseEvent); |
| 87 expect(ripple.ripples.length).to.be.eql(1); |
| 88 }); |
| 89 |
| 90 test('may create multiple ripples that overlap', function () { |
| 91 expect(ripple.ripples.length).to.be.eql(0); |
| 92 |
| 93 for (var i = 0; i < 3; ++i) { |
| 94 ripple.downAction(mouseEvent); |
| 95 expect(ripple.ripples.length).to.be.eql(i + 1); |
| 96 } |
| 97 }); |
| 98 }); |
| 99 |
| 100 suite('with the `center` attribute set to true', function () { |
| 101 setup(function () { |
| 102 rippleContainer = fixture('CenteringRipple'); |
| 103 ripple = rippleContainer.firstElementChild; |
| 104 |
| 105 mouseEvent = new FakeMouseEvent(ripple, 10, 10); |
| 106 }); |
| 107 |
| 108 test('ripples will center', function (done) { |
| 109 var waveContainerElement; |
| 110 // let's ask the browser what `translate3d(0px, 0px, 0)` will actually
look like |
| 111 var div = document.createElement('div'); |
| 112 div.style.webkitTransform = 'translate3d(0px, 0px, 0px)'; |
| 113 div.style.transform = 'translate3d(0px, 0px, 0)'; |
| 114 |
| 115 ripple.downAction(mouseEvent); |
| 116 |
| 117 waveContainerElement = ripple.ripples[0].waveContainer; |
| 118 |
| 119 ripple.upAction(mouseEvent); |
| 120 |
| 121 window.requestAnimationFrame(function () { |
| 122 var currentTransform = waveContainerElement.style.transform; |
| 123 try { |
| 124 expect(div.style.transform).to.be.ok; |
| 125 expect(currentTransform).to.be.ok; |
| 126 expect(currentTransform).to.be.eql(div.style.transform); |
| 127 |
| 128 done(); |
| 129 } catch (e) { |
| 130 done(e); |
| 131 } |
| 132 }); |
| 133 }); |
| 134 }); |
| 135 |
| 136 suite('with the `recenters` attribute set to true', function () { |
| 137 setup(function () { |
| 138 rippleContainer = fixture('RecenteringRipple'); |
| 139 ripple = rippleContainer.firstElementChild; |
| 140 mouseEvent = new FakeMouseEvent(ripple, 10, 10); |
| 141 }); |
| 142 test('ripples will gravitate towards the center', function (done) { |
| 143 var waveContainerElement; |
| 144 var waveTranslateString; |
| 145 ripple.downAction(mouseEvent); |
| 146 waveContainerElement = ripple.ripples[0].waveContainer; |
| 147 waveTranslateString = waveContainerElement.style.transform; |
| 148 ripple.upAction(mouseEvent); |
| 149 window.requestAnimationFrame(function () { |
| 150 try { |
| 151 expect(waveTranslateString).to.be.ok; |
| 152 expect(waveContainerElement.style.transform).to.be.ok; |
| 153 expect(waveContainerElement.style.transform).to.not.be.eql(waveTra
nslateString); |
| 154 done(); |
| 155 } catch (e) { |
| 156 done(e); |
| 157 } |
| 158 }); |
| 159 }); |
| 160 }); |
| 161 |
| 162 }); |
| 163 </script> |
| 164 |
| 165 </body> |
| 166 </html> |
OLD | NEW |