blob: 66ebb7950a518294112263581a517f29a4d8382f [file] [log] [blame]
Wyatt Allen8fee90b2016-06-04 18:21:01 -07001<!DOCTYPE html>
2<!--
Dave Borowitz8cdc76b2018-03-26 10:04:27 -04003@license
Wyatt Allen8fee90b2016-06-04 18:21:01 -07004Copyright (C) 2016 The Android Open Source Project
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations 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 Rehmsen62909352019-05-16 16:10:33 +020021<script src="/test/common-test-setup.js"></script>
22<script src="/bower_components/webcomponentsjs/custom-elements-es5-adapter.js"></script>
Wyatt Allen8fee90b2016-06-04 18:21:01 -070023
Ole Rehmsenecf0b782019-05-16 11:29:39 +020024<script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
Ole Rehmsen31640742019-05-16 11:24:47 +020025<script src="/bower_components/web-component-tester/browser.js"></script>
Mike Samuele07c4b22017-06-02 13:08:19 -040026<link rel="import" href="../../../test/common-test-setup.html"/>
Wyatt Allen8fee90b2016-06-04 18:21:01 -070027<link rel="import" href="gr-select.html">
28
Viktar Donich29e1ce52017-03-28 17:02:44 -070029<script>void(0);</script>
30
Wyatt Allen8fee90b2016-06-04 18:21:01 -070031<test-fixture id="basic">
32 <template>
Becky Siegel8e174ab2017-07-05 14:12:44 -070033 <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 Allen8fee90b2016-06-04 18:21:01 -070040 </template>
41</test-fixture>
42
43<script>
Kasper Nilsson659a44d2017-05-15 16:52:50 -070044 suite('gr-select tests', () => {
45 let element;
Wyatt Allen8fee90b2016-06-04 18:21:01 -070046
Kasper Nilsson659a44d2017-05-15 16:52:50 -070047 setup(() => {
Wyatt Allen8fee90b2016-06-04 18:21:01 -070048 element = fixture('basic');
49 });
50
Becky Siegelaae6d6702017-12-05 17:07:26 -080051 test('value of 0 should still trigger value updates', () => {
52 element.bindValue = 0;
53 assert.equal(element.nativeSelect.value, 0);
54 });
55
Kasper Nilsson659a44d2017-05-15 16:52:50 -070056 test('bidirectional binding property-to-attribute', () => {
57 const changeStub = sinon.stub();
Wyatt Allen8fee90b2016-06-04 18:21:01 -070058 element.addEventListener('bind-value-changed', changeStub);
59
60 // The selected element should be the first one by default.
Becky Siegel8e174ab2017-07-05 14:12:44 -070061 assert.equal(element.nativeSelect.value, '1');
Wyatt Allen8fee90b2016-06-04 18:21:01 -070062 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 Siegel8e174ab2017-07-05 14:12:44 -070069 assert.equal(element.nativeSelect.value, '2');
Wyatt Allen8fee90b2016-06-04 18:21:01 -070070 assert.equal(element.bindValue, '2');
71 assert.isTrue(changeStub.called);
72 });
73
Kasper Nilsson659a44d2017-05-15 16:52:50 -070074 test('bidirectional binding attribute-to-property', () => {
75 const changeStub = sinon.stub();
Wyatt Allen8fee90b2016-06-04 18:21:01 -070076 element.addEventListener('bind-value-changed', changeStub);
77
78 // The selected element should be the first one by default.
Becky Siegel8e174ab2017-07-05 14:12:44 -070079 assert.equal(element.nativeSelect.value, '1');
Wyatt Allen8fee90b2016-06-04 18:21:01 -070080 assert.equal(element.bindValue, '1');
81 assert.isFalse(changeStub.called);
82
83 // Now change the value.
Becky Siegel8e174ab2017-07-05 14:12:44 -070084 element.nativeSelect.value = '3';
Wyatt Allen8fee90b2016-06-04 18:21:01 -070085 element.fire('change');
86
87 // It should be updated.
Becky Siegel8e174ab2017-07-05 14:12:44 -070088 assert.equal(element.nativeSelect.value, '3');
Wyatt Allen8fee90b2016-06-04 18:21:01 -070089 assert.equal(element.bindValue, '3');
90 assert.isTrue(changeStub.called);
91 });
92 });
93</script>