1<!doctype html> 2<!-- 3@license 4Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 5This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 6The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 7The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 8Code distributed by Google as part of the polymer project is also 9subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 10--> 11<html> 12<head> 13 <meta charset="UTF-8"> 14 <title>paper-radio-button basic tests</title> 15 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> 16 17 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> 18 <script src="../../web-component-tester/browser.js"></script> 19 <script src="../../test-fixture/test-fixture-mocha.js"></script> 20 <script src="../../iron-test-helpers/mock-interactions.js"></script> 21 22 <link rel="import" href="../../test-fixture/test-fixture.html"> 23 <link rel="import" href="../paper-radio-button.html"> 24 25 <style is="custom-style"> 26 paper-radio-button.tiny { 27 --paper-radio-button-size: 5px; 28 } 29 paper-radio-button.medium { 30 --paper-radio-button-size: 37px; 31 } 32 paper-radio-button.giant { 33 --paper-radio-button-size: 50px; 34 } 35 paper-radio-button.enormous { 36 --paper-radio-button-size: 71px; 37 } 38 39 paper-radio-button.custom-ink-size { 40 --paper-radio-button-size: 25px; 41 --paper-radio-button-ink-size: 30px; 42 } 43 </style> 44</head> 45<body> 46 <test-fixture id="NoLabel"> 47 <template> 48 <paper-radio-button id="radio1"></paper-radio-button> 49 </template> 50 </test-fixture> 51 52 <test-fixture id="WithLabel"> 53 <template> 54 <paper-radio-button id="radio2">Batman</paper-radio-button> 55 </template> 56 </test-fixture> 57 58 <test-fixture id="AriaLabel"> 59 <template> 60 <paper-radio-button aria-label="Batman">Robin</paper-radio-button> 61 </template> 62 </test-fixture> 63 64 <test-fixture id="WithDifferentSizes"> 65 <template> 66 <paper-radio-button class="tiny"></paper-radio-button> 67 <paper-radio-button></paper-radio-button> 68 <paper-radio-button class="medium"></paper-radio-button> 69 <paper-radio-button class="giant"></paper-radio-button> 70 <paper-radio-button class="enormous"></paper-radio-button> 71 </template> 72 </test-fixture> 73 74 <test-fixture id="CustomInkSize"> 75 <template> 76 <paper-radio-button class="custom-ink-size"></paper-radio-button> 77 </template> 78 </test-fixture> 79 80 <script> 81 suite('defaults', function() { 82 var r1; 83 84 setup(function() { 85 r1 = fixture('NoLabel'); 86 }); 87 88 test('check button via click', function(done) { 89 r1.addEventListener('click', function() { 90 assert.isTrue(r1.getAttribute('aria-checked') == 'true'); 91 assert.isTrue(r1.checked); 92 done(); 93 }); 94 MockInteractions.tap(r1); 95 }); 96 97 test('toggle button via click', function(done) { 98 r1.checked = true; 99 r1.addEventListener('click', function() { 100 assert.isFalse(r1.getAttribute('aria-checked') == 'true'); 101 assert.isFalse(r1.checked); 102 done(); 103 }); 104 MockInteractions.tap(r1); 105 }); 106 107 test('disabled button cannot be clicked', function(done) { 108 r1.disabled = true; 109 r1.checked = true; 110 MockInteractions.tap(r1); 111 112 setTimeout(function() { 113 assert.isTrue(r1.getAttribute('aria-checked') == 'true'); 114 assert.isTrue(r1.checked); 115 done(); 116 }, 1); 117 }); 118 119 test('can be styled with different sizes', function() { 120 var r2 = fixture('WithDifferentSizes'); 121 var small = r2[0].getBoundingClientRect(); 122 var medium = r2[1].getBoundingClientRect(); 123 var large = r2[2].getBoundingClientRect(); 124 125 console.log(small.width, medium.width, large.width); 126 127 assert.isTrue(4 < small.height); 128 assert.isTrue(small.height < medium.height); 129 assert.isTrue(medium.height < large.height); 130 assert.isTrue(large.height < 72); 131 132 assert.isTrue(4 < small.width); 133 assert.isTrue(small.width < medium.width); 134 assert.isTrue(medium.width < large.width); 135 assert.isTrue(large.width < 72); 136 }); 137 }); 138 139 suite('ink size', function() { 140 var radioButtons; 141 142 setup(function() { 143 radioButtons = fixture('WithDifferentSizes'); 144 }); 145 146 test('`--paper-radio-button-ink-size` sets the ink size', function() { 147 var radioButton = fixture('CustomInkSize'); 148 assert.equal(radioButton.getComputedStyleValue('--calculated-paper-radio-button-size').trim(), '25px'); 149 assert.equal(radioButton.getComputedStyleValue('--calculated-paper-radio-button-ink-size').trim(), '30px'); 150 }); 151 152 test('ink sizes are near (3 * radio button size) by default', function() { 153 radioButtons.forEach(function(radioButton) { 154 var size = parseFloat(radioButton.getComputedStyleValue('--calculated-paper-radio-button-size'), 10); 155 var inkSize = parseFloat(radioButton.getComputedStyleValue('--calculated-paper-radio-button-ink-size'), 10); 156 assert.approximately(inkSize / size, 3, 0.1); 157 }); 158 }); 159 160 test('ink sizes are integers', function() { 161 radioButtons.forEach(function(radioButton) { 162 var unparsedInkSize = radioButton.getComputedStyleValue('--calculated-paper-radio-button-ink-size'); 163 var floatInkSize = parseFloat(unparsedInkSize, 10); 164 var intInkSize = parseInt(unparsedInkSize, 10); 165 assert.equal(floatInkSize, intInkSize); 166 }); 167 }); 168 169 test('ink size parity matches radio button size parity (centers are aligned)', function() { 170 radioButtons.forEach(function(radioButton) { 171 var size = parseInt(radioButton.getComputedStyleValue('--calculated-paper-radio-button-size'), 10); 172 var inkSize = parseInt(radioButton.getComputedStyleValue('--calculated-paper-radio-button-ink-size'), 10); 173 assert.equal(size % 2, inkSize % 2); 174 }); 175 }); 176 }); 177 178 suite('a11y', function() { 179 var r1; 180 var r2; 181 182 setup(function() { 183 r1 = fixture('NoLabel'); 184 r2 = fixture('WithLabel'); 185 }); 186 187 test('has aria role "radio"', function() { 188 assert.isTrue(r1.getAttribute('role') == 'radio'); 189 assert.isTrue(r2.getAttribute('role') == 'radio'); 190 }); 191 192 test('button with no label has no aria label', function() { 193 assert.isTrue(!r1.getAttribute('aria-label')); 194 }); 195 196 test('button respects the user set aria-label', function() { 197 var c = fixture('AriaLabel'); 198 assert.isTrue(c.getAttribute('aria-label') == "Batman"); 199 }); 200 201 a11ySuite('NoLabel'); 202 a11ySuite('WithLabel'); 203 a11ySuite('AriaLabel'); 204 }); 205 </script> 206</body> 207</html> 208