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