blob: 37f43f47a1f550df771974b8d1757bed7f6bdc0e [file] [log] [blame]
Kasper Nilssonfb5b7112018-11-15 11:46:17 -08001<!DOCTYPE html>
2<!--
3@license
4Copyright (C) 2018 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-repo-plugin-config</title>
21
22<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
23<script src="../../../bower_components/web-component-tester/browser.js"></script>
24<link rel="import" href="../../../test/common-test-setup.html"/>
25<link rel="import" href="gr-repo-plugin-config.html">
26
27<script>void(0);</script>
28
29<test-fixture id="basic">
30 <template>
31 <gr-repo-plugin-config></gr-repo-plugin-config>
32 </template>
33</test-fixture>
34
35<script>
36 suite('gr-repo-plugin-config tests', () => {
37 let element;
38 let sandbox;
39
40 setup(() => {
41 sandbox = sinon.sandbox.create();
42 element = fixture('basic');
43 });
44
45 teardown(() => sandbox.restore());
46
47 test('_computePluginConfigOptions', () => {
48 assert.deepEqual(element._computePluginConfigOptions(), []);
49 assert.deepEqual(element._computePluginConfigOptions({}), []);
50 assert.deepEqual(element._computePluginConfigOptions({base: {}}), []);
51 assert.deepEqual(element._computePluginConfigOptions(
52 {base: {config: {}}}), []);
53 assert.deepEqual(element._computePluginConfigOptions(
54 {base: {config: {testKey: 'testInfo'}}}),
55 [{_key: 'testKey', info: 'testInfo'}]);
56 });
57
58 test('_computeDisabled', () => {
59 assert.isFalse(element._computeDisabled('true'));
60 assert.isTrue(element._computeDisabled('false'));
61 });
62
63 test('_handleChange', () => {
64 const eventStub = sandbox.stub(element, 'dispatchEvent');
65 element.pluginData = {
66 name: 'testName',
67 config: {plugin: {value: 'test'}},
68 };
69 element._handleChange({
70 _key: 'plugin',
71 info: {value: 'newTest'},
72 notifyPath: 'plugin.value',
73 });
74
75 assert.isTrue(eventStub.called);
76
77 const {detail} = eventStub.lastCall.args[0];
78 assert.equal(detail.name, 'testName');
79 assert.deepEqual(detail.config, {plugin: {value: 'newTest'}});
80 assert.equal(detail.notifyPath, 'testName.plugin.value');
81 });
82
83 suite('option types', () => {
84 let changeStub;
85 let buildStub;
86
87 setup(() => {
88 changeStub = sandbox.stub(element, '_handleChange');
89 buildStub = sandbox.stub(element, '_buildConfigChangeInfo');
90 });
91
92 test('ARRAY type option', () => {
93 element.pluginData = {
94 name: 'testName',
95 config: {plugin: {value: 'test', type: 'ARRAY'}},
96 };
97 flushAsynchronousOperations();
98
99 const editor = element.$$('gr-plugin-config-array-editor');
100 assert.ok(editor);
101 element._handleArrayChange({detail: 'test'});
102 assert.isTrue(changeStub.called);
103 assert.equal(changeStub.lastCall.args[0], 'test');
104 });
105
106 test('BOOLEAN type option', () => {
107 element.pluginData = {
108 name: 'testName',
109 config: {plugin: {value: 'true', type: 'BOOLEAN'}},
110 };
111 flushAsynchronousOperations();
112
113 const toggle = element.$$('paper-toggle-button');
114 assert.ok(toggle);
115 toggle.click();
116 flushAsynchronousOperations();
117
118 assert.isTrue(buildStub.called);
119 assert.deepEqual(buildStub.lastCall.args, ['false', 'plugin']);
120
121 assert.isTrue(changeStub.called);
122 });
123
124 test('INT/LONG/STRING type option', () => {
125 element.pluginData = {
126 name: 'testName',
127 config: {plugin: {value: 'test', type: 'STRING'}},
128 };
129 flushAsynchronousOperations();
130
131 const input = element.$$('input');
132 assert.ok(input);
133 input.value = 'newTest';
134 input.dispatchEvent(new Event('input'));
135 flushAsynchronousOperations();
136
137 assert.isTrue(buildStub.called);
138 assert.deepEqual(buildStub.lastCall.args, ['newTest', 'plugin']);
139
140 assert.isTrue(changeStub.called);
141 });
142
143 test('LIST type option', () => {
144 const permitted_values = ['test', 'newTest'];
145 element.pluginData = {
146 name: 'testName',
147 config: {plugin: {value: 'test', type: 'LIST', permitted_values}},
148 };
149 flushAsynchronousOperations();
150
151 const select = element.$$('select');
152 assert.ok(select);
153 select.value = 'newTest';
Ole Rehmsenc82baba2019-05-16 14:43:01 +0200154 select.dispatchEvent(new Event(
155 'change', {bubbles: true, composed: true}));
Kasper Nilssonfb5b7112018-11-15 11:46:17 -0800156 flushAsynchronousOperations();
157
158 assert.isTrue(buildStub.called);
159 assert.deepEqual(buildStub.lastCall.args, ['newTest', 'plugin']);
160
161 assert.isTrue(changeStub.called);
162 });
163 });
164
165 test('_buildConfigChangeInfo', () => {
166 element.pluginData = {
167 name: 'testName',
168 config: {plugin: {value: 'test'}},
169 };
170 const detail = element._buildConfigChangeInfo('newTest', 'plugin');
171 assert.equal(detail._key, 'plugin');
172 assert.deepEqual(detail.info, {value: 'newTest'});
173 assert.equal(detail.notifyPath, 'plugin.value');
174 });
175 });
176</script>