Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame^] | 3 | @license |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 4 | Copyright (C) 2016 The Android Open Source Project |
| 5 | |
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | you may not use this file except in compliance with the License. |
| 8 | You may obtain a copy of the License at |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 12 | Unless required by applicable law or agreed to in writing, software |
| 13 | distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | See the License for the specific language governing permissions and |
| 16 | limitations under the License. |
| 17 | --> |
| 18 | |
| 19 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> |
| 20 | <title>gr-button</title> |
| 21 | |
Viktar Donich | 29e1ce5 | 2017-03-28 17:02:44 -0700 | [diff] [blame] | 22 | <script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script> |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 23 | <script src="../../../bower_components/web-component-tester/browser.js"></script> |
Mike Samuel | e07c4b2 | 2017-06-02 13:08:19 -0400 | [diff] [blame] | 24 | <link rel="import" href="../../../test/common-test-setup.html"/> |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 25 | <link rel="import" href="gr-button.html"> |
| 26 | |
Viktar Donich | 29e1ce5 | 2017-03-28 17:02:44 -0700 | [diff] [blame] | 27 | <script>void(0);</script> |
| 28 | |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 29 | <test-fixture id="basic"> |
| 30 | <template> |
| 31 | <gr-button></gr-button> |
| 32 | </template> |
| 33 | </test-fixture> |
| 34 | |
| 35 | <script> |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 36 | suite('gr-select tests', () => { |
| 37 | let element; |
| 38 | let sandbox; |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 39 | |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 40 | const addSpyOn = function(eventName) { |
| 41 | const spy = sandbox.spy(); |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 42 | element.addEventListener(eventName, spy); |
| 43 | return spy; |
| 44 | }; |
| 45 | |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 46 | setup(() => { |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 47 | element = fixture('basic'); |
| 48 | sandbox = sinon.sandbox.create(); |
| 49 | }); |
| 50 | |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 51 | teardown(() => { |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 52 | sandbox.restore(); |
| 53 | }); |
| 54 | |
Becky Siegel | e662f67 | 2017-11-03 12:22:24 -0700 | [diff] [blame] | 55 | test('disabled is set by disabled or loading', () => { |
| 56 | assert.isFalse(element.$$('paper-button').disabled); |
| 57 | element.disabled = true; |
| 58 | assert.isTrue(element.$$('paper-button').disabled); |
| 59 | element.disabled = false; |
| 60 | assert.isFalse(element.$$('paper-button').disabled); |
| 61 | element.loading = true; |
| 62 | assert.isTrue(element.$$('paper-button').disabled); |
| 63 | }); |
| 64 | |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 65 | for (const eventName of ['tap', 'click']) { |
| 66 | test('dispatches ' + eventName + ' event', () => { |
| 67 | const spy = addSpyOn(eventName); |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 68 | MockInteractions.tap(element); |
| 69 | assert.isTrue(spy.calledOnce); |
| 70 | }); |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 71 | } |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 72 | |
| 73 | // Keycodes: 32 for Space, 13 for Enter. |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 74 | for (const key of [32, 13]) { |
| 75 | test('dispatches tap event on keycode ' + key, () => { |
| 76 | const tapSpy = sandbox.spy(); |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 77 | element.addEventListener('tap', tapSpy); |
| 78 | MockInteractions.pressAndReleaseKeyOn(element, key); |
| 79 | assert.isTrue(tapSpy.calledOnce); |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 80 | }); |
Kasper Nilsson | 2de6749 | 2017-10-24 11:03:07 -0700 | [diff] [blame] | 81 | |
| 82 | test('dispatches no tap event with modifier on keycode ' + key, () => { |
| 83 | const tapSpy = sandbox.spy(); |
| 84 | element.addEventListener('tap', tapSpy); |
| 85 | MockInteractions.pressAndReleaseKeyOn(element, key, 'shift'); |
| 86 | MockInteractions.pressAndReleaseKeyOn(element, key, 'ctrl'); |
| 87 | MockInteractions.pressAndReleaseKeyOn(element, key, 'meta'); |
| 88 | MockInteractions.pressAndReleaseKeyOn(element, key, 'alt'); |
| 89 | assert.isFalse(tapSpy.calledOnce); |
| 90 | }); |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 91 | } |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 92 | |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 93 | suite('disabled', () => { |
| 94 | setup(() => { |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 95 | element.disabled = true; |
| 96 | }); |
| 97 | |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 98 | for (const eventName of ['tap', 'click']) { |
| 99 | test('stops ' + eventName + ' event', () => { |
| 100 | const spy = addSpyOn(eventName); |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 101 | MockInteractions.tap(element); |
| 102 | assert.isFalse(spy.called); |
| 103 | }); |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 104 | } |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 105 | |
| 106 | // Keycodes: 32 for Space, 13 for Enter. |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 107 | for (const key of [32, 13]) { |
| 108 | test('stops tap event on keycode ' + key, () => { |
| 109 | const tapSpy = sandbox.spy(); |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 110 | element.addEventListener('tap', tapSpy); |
| 111 | MockInteractions.pressAndReleaseKeyOn(element, key); |
| 112 | assert.isFalse(tapSpy.called); |
Kasper Nilsson | d41ecff | 2017-05-15 16:10:56 -0700 | [diff] [blame] | 113 | }); |
| 114 | } |
Viktar Donich | d828629 | 2016-11-11 16:33:03 -0800 | [diff] [blame] | 115 | }); |
| 116 | }); |
| 117 | </script> |