Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 3 | @license |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [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-select</title> |
Ole Rehmsen | 6290935 | 2019-05-16 16:10:33 +0200 | [diff] [blame] | 21 | <script src="/test/common-test-setup.js"></script> |
| 22 | <script src="/bower_components/webcomponentsjs/custom-elements-es5-adapter.js"></script> |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 23 | |
Ole Rehmsen | ecf0b78 | 2019-05-16 11:29:39 +0200 | [diff] [blame] | 24 | <script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script> |
Ole Rehmsen | 3164074 | 2019-05-16 11:24:47 +0200 | [diff] [blame] | 25 | <script src="/bower_components/web-component-tester/browser.js"></script> |
Mike Samuel | e07c4b2 | 2017-06-02 13:08:19 -0400 | [diff] [blame] | 26 | <link rel="import" href="../../../test/common-test-setup.html"/> |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 27 | <link rel="import" href="gr-select.html"> |
| 28 | |
Viktar Donich | 29e1ce5 | 2017-03-28 17:02:44 -0700 | [diff] [blame] | 29 | <script>void(0);</script> |
| 30 | |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 31 | <test-fixture id="basic"> |
| 32 | <template> |
Becky Siegel | 8e174ab | 2017-07-05 14:12:44 -0700 | [diff] [blame] | 33 | <gr-select> |
| 34 | <select> |
| 35 | <option value="1">One</option> |
| 36 | <option value="2">Two</option> |
| 37 | <option value="3">Three</option> |
| 38 | </select> |
| 39 | </gr-select> |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 40 | </template> |
| 41 | </test-fixture> |
| 42 | |
| 43 | <script> |
Kasper Nilsson | 659a44d | 2017-05-15 16:52:50 -0700 | [diff] [blame] | 44 | suite('gr-select tests', () => { |
| 45 | let element; |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 46 | |
Kasper Nilsson | 659a44d | 2017-05-15 16:52:50 -0700 | [diff] [blame] | 47 | setup(() => { |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 48 | element = fixture('basic'); |
| 49 | }); |
| 50 | |
Becky Siegel | aae6d670 | 2017-12-05 17:07:26 -0800 | [diff] [blame] | 51 | test('value of 0 should still trigger value updates', () => { |
| 52 | element.bindValue = 0; |
| 53 | assert.equal(element.nativeSelect.value, 0); |
| 54 | }); |
| 55 | |
Kasper Nilsson | 659a44d | 2017-05-15 16:52:50 -0700 | [diff] [blame] | 56 | test('bidirectional binding property-to-attribute', () => { |
| 57 | const changeStub = sinon.stub(); |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 58 | element.addEventListener('bind-value-changed', changeStub); |
| 59 | |
| 60 | // The selected element should be the first one by default. |
Becky Siegel | 8e174ab | 2017-07-05 14:12:44 -0700 | [diff] [blame] | 61 | assert.equal(element.nativeSelect.value, '1'); |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 62 | assert.equal(element.bindValue, '1'); |
| 63 | assert.isFalse(changeStub.called); |
| 64 | |
| 65 | // Now change the value. |
| 66 | element.bindValue = '2'; |
| 67 | |
| 68 | // It should be updated. |
Becky Siegel | 8e174ab | 2017-07-05 14:12:44 -0700 | [diff] [blame] | 69 | assert.equal(element.nativeSelect.value, '2'); |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 70 | assert.equal(element.bindValue, '2'); |
| 71 | assert.isTrue(changeStub.called); |
| 72 | }); |
| 73 | |
Kasper Nilsson | 659a44d | 2017-05-15 16:52:50 -0700 | [diff] [blame] | 74 | test('bidirectional binding attribute-to-property', () => { |
| 75 | const changeStub = sinon.stub(); |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 76 | element.addEventListener('bind-value-changed', changeStub); |
| 77 | |
| 78 | // The selected element should be the first one by default. |
Becky Siegel | 8e174ab | 2017-07-05 14:12:44 -0700 | [diff] [blame] | 79 | assert.equal(element.nativeSelect.value, '1'); |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 80 | assert.equal(element.bindValue, '1'); |
| 81 | assert.isFalse(changeStub.called); |
| 82 | |
| 83 | // Now change the value. |
Becky Siegel | 8e174ab | 2017-07-05 14:12:44 -0700 | [diff] [blame] | 84 | element.nativeSelect.value = '3'; |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 85 | element.fire('change'); |
| 86 | |
| 87 | // It should be updated. |
Becky Siegel | 8e174ab | 2017-07-05 14:12:44 -0700 | [diff] [blame] | 88 | assert.equal(element.nativeSelect.value, '3'); |
Wyatt Allen | 8fee90b | 2016-06-04 18:21:01 -0700 | [diff] [blame] | 89 | assert.equal(element.bindValue, '3'); |
| 90 | assert.isTrue(changeStub.called); |
| 91 | }); |
| 92 | }); |
| 93 | </script> |