OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <!-- |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 7 Code distributed by Google as part of the polymer project is also |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> |
| 10 <html> |
| 11 <head> |
| 12 <title>active-state</title> |
| 13 |
| 14 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
| 15 <script src="../../web-component-tester/browser.js"></script> |
| 16 <script src="../../test-fixture/test-fixture-mocha.js"></script> |
| 17 <script src="../../iron-test-helpers/mock-interactions.js"></script> |
| 18 |
| 19 <link rel="import" href="../../polymer/polymer.html"> |
| 20 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 21 <link rel="import" href="test-elements.html"> |
| 22 </head> |
| 23 <body> |
| 24 <test-fixture id="TrivialActiveState"> |
| 25 <template> |
| 26 <test-button></test-button> |
| 27 </template> |
| 28 </test-fixture> |
| 29 |
| 30 <test-fixture id="ToggleActiveState"> |
| 31 <template> |
| 32 <test-button toggles></test-button> |
| 33 </template> |
| 34 </test-fixture> |
| 35 |
| 36 <script> |
| 37 suite('active-state', function() { |
| 38 var activeTarget; |
| 39 |
| 40 setup(function() { |
| 41 activeTarget = fixture('TrivialActiveState'); |
| 42 }); |
| 43 |
| 44 suite('active state with toggles attribute', function() { |
| 45 setup(function() { |
| 46 activeTarget = fixture('ToggleActiveState'); |
| 47 }); |
| 48 |
| 49 suite('when clicked', function() { |
| 50 test('is activated', function(done) { |
| 51 MockInteractions.downAndUp(activeTarget, function() { |
| 52 try { |
| 53 expect(activeTarget.hasAttribute('active')).to.be.eql(true); |
| 54 done(); |
| 55 } catch (e) { |
| 56 done(e); |
| 57 } |
| 58 }); |
| 59 }); |
| 60 |
| 61 test('is deactivated by a subsequent click', function(done) { |
| 62 MockInteractions.downAndUp(activeTarget, function() { |
| 63 MockInteractions.downAndUp(activeTarget, function() { |
| 64 try { |
| 65 expect(activeTarget.hasAttribute('active')).to.be.eql(false); |
| 66 done(); |
| 67 } catch (e) { |
| 68 done(e); |
| 69 } |
| 70 }); |
| 71 }); |
| 72 }); |
| 73 }); |
| 74 }); |
| 75 |
| 76 suite('without toggles attribute', function() { |
| 77 suite('when mouse is down', function() { |
| 78 test('does not get an active attribute', function() { |
| 79 expect(activeTarget.hasAttribute('active')).to.be.eql(false); |
| 80 MockInteractions.down(activeTarget); |
| 81 expect(activeTarget.hasAttribute('active')).to.be.eql(false); |
| 82 }); |
| 83 }); |
| 84 |
| 85 suite('when mouse is up', function() { |
| 86 test('does not get an active attribute', function() { |
| 87 MockInteractions.down(activeTarget); |
| 88 expect(activeTarget.hasAttribute('active')).to.be.eql(false); |
| 89 MockInteractions.up(activeTarget); |
| 90 expect(activeTarget.hasAttribute('active')).to.be.eql(false); |
| 91 }); |
| 92 }); |
| 93 }); |
| 94 |
| 95 suite('when space is pressed', function() { |
| 96 test('triggers a click event', function(done) { |
| 97 activeTarget.addEventListener('click', function() { |
| 98 done(); |
| 99 }); |
| 100 MockInteractions.pressSpace(activeTarget); |
| 101 }); |
| 102 |
| 103 test('only triggers click after the key is released', function(done) { |
| 104 var keyupTriggered = false; |
| 105 |
| 106 activeTarget.addEventListener('keyup', function() { |
| 107 keyupTriggered = true; |
| 108 }); |
| 109 |
| 110 activeTarget.addEventListener('click', function() { |
| 111 try { |
| 112 expect(keyupTriggered).to.be.eql(true); |
| 113 done(); |
| 114 } catch (e) { |
| 115 done(e); |
| 116 } |
| 117 }); |
| 118 |
| 119 MockInteractions.pressSpace(activeTarget); |
| 120 }); |
| 121 }); |
| 122 |
| 123 suite('when enter is pressed', function() { |
| 124 test('triggers a click event', function(done) { |
| 125 activeTarget.addEventListener('click', function() { |
| 126 done(); |
| 127 }); |
| 128 |
| 129 MockInteractions.pressEnter(activeTarget); |
| 130 }); |
| 131 |
| 132 test('only triggers click before the key is released', function(done) { |
| 133 var keyupTriggered = false; |
| 134 |
| 135 activeTarget.addEventListener('keyup', function() { |
| 136 keyupTriggered = true; |
| 137 }); |
| 138 |
| 139 activeTarget.addEventListener('click', function() { |
| 140 try { |
| 141 expect(keyupTriggered).to.be.eql(false); |
| 142 done(); |
| 143 } catch (e) { |
| 144 done(e); |
| 145 } |
| 146 }); |
| 147 |
| 148 MockInteractions.pressEnter(activeTarget); |
| 149 }); |
| 150 }); |
| 151 }); |
| 152 </script> |
| 153 </body> |
| 154 </html> |
OLD | NEW |