| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | @license |
| 4 | Copyright (C) 2020 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 | <meta name="viewport" |
| 19 | content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> |
| 20 | <meta charset="utf-8"> |
| 21 | <title>gr-simple-submit-rules-label-config</title> |
| 22 | |
| 23 | <script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script> |
| 24 | <script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script> |
| 25 | <script src="../bower_components/web-component-tester/browser.js"></script> |
| 26 | |
| 27 | <test-fixture id="basic"> |
| 28 | <template> |
| 29 | <gr-simple-submit-rules-label-config label-name="Verified" |
| 30 | repo-config='{"labels": {"Verified": {"function": "MaxNoBlock", "copy_scores": []}}}' |
| 31 | readOnly="false"> |
| 32 | </gr-simple-submit-rules-label-config> |
| 33 | </template> |
| 34 | </test-fixture> |
| 35 | |
| 36 | <script type="module"> |
| 37 | import '../test/common-test-setup.js'; |
| 38 | import '../test/gr-select.js'; |
| 39 | import "./gr-simple-submit-rules-label-config.js"; |
| 40 | const COPY_SCORES = [ |
| 41 | 'copyMinScore', |
| 42 | 'copyMaxScore', |
| 43 | 'copyAllScoresOnTrivialRebase', |
| 44 | 'copyAllScoresIfNoCodeChange', |
| 45 | 'copyAllScoresIfNoChange', |
| 46 | 'copyAllScoresOnMergeFirstParentUpdate', |
| 47 | ]; |
| 48 | |
| 49 | suite('gr-simple-submit-rules-label-config tests', () => { |
| 50 | let element; |
| 51 | let sandbox; |
| 52 | |
| 53 | setup(() => { |
| 54 | sandbox = sinon.sandbox.create(); |
| 55 | |
| 56 | element = fixture('basic'); |
| 57 | }); |
| 58 | |
| 59 | teardown(() => { |
| 60 | sandbox.restore(); |
| 61 | }); |
| 62 | |
| 63 | test('section title is correct', () => { |
| 64 | assert.equal(element.shadowRoot.querySelector('#options').innerText.indexOf('Label Verified'), 0); |
| 65 | }); |
| 66 | |
| 67 | // The following tests check that changing the function name (from the REST API) |
| 68 | // has an impact on the displayed settings |
| 69 | test('function "MaxWithBlock" is properly mapped to UI', done => { |
| 70 | element.set('_labelConfig.function', 'MaxWithBlock'); |
| 71 | |
| 72 | flush(() => { |
| 73 | assert.ok(element.shadowRoot.querySelector('#negativeBlocks').checked); |
| 74 | assert.ok(element.shadowRoot.querySelector('#maxVoteRequired').checked); |
| 75 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'MaxWithBlock'); |
| 76 | done(); |
| 77 | }); |
| 78 | }); |
| 79 | |
| 80 | test('function "MaxNoBlock" is properly mapped to UI', done => { |
| 81 | element.set('_labelConfig.function', 'MaxNoBlock'); |
| 82 | |
| 83 | flush(() => { |
| 84 | assert.equal(element.shadowRoot.querySelector('#negativeBlocks').checked, false); |
| 85 | assert.ok(element.shadowRoot.querySelector('#maxVoteRequired').checked); |
| 86 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'MaxNoBlock'); |
| 87 | done(); |
| 88 | }); |
| 89 | }); |
| 90 | |
| 91 | test('function "NoBlock" is properly mapped to UI', done => { |
| 92 | element.set('_labelConfig.function', 'NoBlock'); |
| 93 | |
| 94 | flush(() => { |
| 95 | assert.equal(element.shadowRoot.querySelector('#negativeBlocks').checked, false); |
| 96 | assert.equal(element.shadowRoot.querySelector('#maxVoteRequired').checked, false); |
| 97 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'NoBlock'); |
| 98 | done(); |
| 99 | }); |
| 100 | }); |
| 101 | |
| 102 | test('function "AnyWithBlock" is properly mapped to UI', done => { |
| 103 | element.set('_labelConfig.function', 'AnyWithBlock'); |
| 104 | |
| 105 | flush(() => { |
| 106 | assert.ok(element.shadowRoot.querySelector('#negativeBlocks').checked); |
| 107 | assert.equal(element.shadowRoot.querySelector('#maxVoteRequired').checked, false); |
| 108 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'AnyWithBlock'); |
| 109 | done(); |
| 110 | }); |
| 111 | }); |
| 112 | |
| 113 | // The following tests check that changing the function from the UI has a |
| 114 | // visible impact on the easy checkboxes options, while keeping the function |
| 115 | // name intact. |
| 116 | test('picking function "MaxWithBlock" correctly updates the UI', done => { |
| 117 | element.shadowRoot.querySelector('#functionName select').value = 'MaxWithBlock'; |
| 118 | element.shadowRoot.querySelector('#functionName').dispatchEvent(new Event('change')); |
| 119 | |
| 120 | flush(() => { |
| 121 | assert.ok(element.shadowRoot.querySelector('#negativeBlocks').checked); |
| 122 | assert.ok(element.shadowRoot.querySelector('#maxVoteRequired').checked); |
| 123 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'MaxWithBlock'); |
| 124 | done(); |
| 125 | }); |
| 126 | }); |
| 127 | |
| 128 | test('picking function "NoBlock" correctly updates the UI', done => { |
| 129 | element.shadowRoot.querySelector('#functionName select').value = 'NoBlock'; |
| 130 | element.shadowRoot.querySelector('#functionName').dispatchEvent(new Event('change')); |
| 131 | |
| 132 | flush(() => { |
| 133 | assert.equal(element.shadowRoot.querySelector('#negativeBlocks').checked, false); |
| 134 | assert.equal(element.shadowRoot.querySelector('#maxVoteRequired').checked, false); |
| 135 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'NoBlock'); |
| 136 | done(); |
| 137 | }); |
| 138 | }); |
| 139 | |
| 140 | test('picking function "AnyWithBlock" correctly updates the UI', done => { |
| 141 | element.shadowRoot.querySelector('#functionName select').value = 'AnyWithBlock'; |
| 142 | element.shadowRoot.querySelector('#functionName').dispatchEvent(new Event('change')); |
| 143 | |
| 144 | flush(() => { |
| 145 | assert.ok(element.shadowRoot.querySelector('#negativeBlocks').checked); |
| 146 | assert.equal(element.shadowRoot.querySelector('#maxVoteRequired').checked, false); |
| 147 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'AnyWithBlock'); |
| 148 | done(); |
| 149 | }); |
| 150 | }); |
| 151 | |
| 152 | test('picking function "MaxNoBlock" correctly updates the UI', done => { |
| 153 | element.shadowRoot.querySelector('#functionName select').value = 'MaxNoBlock'; |
| 154 | element.shadowRoot.querySelector('#functionName').dispatchEvent(new Event('change')); |
| 155 | |
| 156 | flush(() => { |
| 157 | assert.equal(element.shadowRoot.querySelector('#negativeBlocks').checked, false); |
| 158 | assert.ok(element.shadowRoot.querySelector('#maxVoteRequired').checked); |
| 159 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'MaxNoBlock'); |
| 160 | done(); |
| 161 | }); |
| 162 | }); |
| 163 | |
| 164 | // The following tests check that the easy way to define the function |
| 165 | // ("negative blocks?" and "max vote required?") maps to the right function, |
| 166 | // without impacting the user choices. |
| 167 | test('function "MaxWithBlock" is properly suggested from UI', done => { |
| 168 | element.shadowRoot.querySelector('#negativeBlocks').checked = true; |
| 169 | element.shadowRoot.querySelector('#negativeBlocks').dispatchEvent(new Event('change')); |
| 170 | |
| 171 | element.shadowRoot.querySelector('#maxVoteRequired').checked = 'true'; |
| 172 | element.shadowRoot.querySelector('#maxVoteRequired').dispatchEvent(new Event('change')); |
| 173 | |
| 174 | flush(() => { |
| 175 | assert.ok(element.shadowRoot.querySelector('#negativeBlocks').checked); |
| 176 | assert.ok(element.shadowRoot.querySelector('#maxVoteRequired').checked); |
| 177 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'MaxWithBlock'); |
| 178 | done(); |
| 179 | }); |
| 180 | }); |
| 181 | |
| 182 | test('function "NoBlock" is properly suggested from UI', done => { |
| 183 | element.shadowRoot.querySelector('#negativeBlocks').checked = false; |
| 184 | element.shadowRoot.querySelector('#negativeBlocks').dispatchEvent(new Event('change')); |
| 185 | |
| 186 | element.shadowRoot.querySelector('#maxVoteRequired').checked = false; |
| 187 | element.shadowRoot.querySelector('#maxVoteRequired').dispatchEvent(new Event('change')); |
| 188 | |
| 189 | flush(() => { |
| 190 | assert.equal(element.shadowRoot.querySelector('#negativeBlocks').checked, false); |
| 191 | assert.equal(element.shadowRoot.querySelector('#maxVoteRequired').checked, false); |
| 192 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'NoBlock'); |
| 193 | done(); |
| 194 | }); |
| 195 | }); |
| 196 | |
| 197 | test('function "AnyWithBlock" is properly suggested from UI', done => { |
| 198 | element.shadowRoot.querySelector('#negativeBlocks').checked = true; |
| 199 | element.shadowRoot.querySelector('#negativeBlocks').dispatchEvent(new Event('change')); |
| 200 | |
| 201 | element.shadowRoot.querySelector('#maxVoteRequired').checked = false; |
| 202 | element.shadowRoot.querySelector('#maxVoteRequired').dispatchEvent(new Event('change')); |
| 203 | |
| 204 | flush(() => { |
| 205 | assert.ok(element.shadowRoot.querySelector('#negativeBlocks').checked); |
| 206 | assert.equal(element.shadowRoot.querySelector('#maxVoteRequired').checked, false); |
| 207 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'AnyWithBlock'); |
| 208 | done(); |
| 209 | }); |
| 210 | }); |
| 211 | |
| 212 | test('function "MaxNoBlock" is properly suggested from UI', done => { |
| 213 | element.shadowRoot.querySelector('#negativeBlocks').checked = false; |
| 214 | |
| 215 | element.shadowRoot.querySelector('#maxVoteRequired').checked = 'true'; |
| 216 | element.shadowRoot.querySelector('#maxVoteRequired').dispatchEvent(new Event('change')); |
| 217 | |
| 218 | flush(() => { |
| 219 | assert.equal(element.shadowRoot.querySelector('#negativeBlocks').checked, false); |
| 220 | assert.ok(element.shadowRoot.querySelector('#maxVoteRequired').checked); |
| 221 | assert.equal(element.shadowRoot.querySelector('#functionName select').value, 'MaxNoBlock'); |
| 222 | done(); |
| 223 | }); |
| 224 | }); |
| 225 | |
| 226 | // The following tests check that "copy scores" are correctly mapped *to* and |
| 227 | // *from* the UI, for the two possible boolean values. |
| 228 | for (const copyScoreName of COPY_SCORES) { |
| 229 | const elName = '#' + copyScoreName; |
| 230 | |
| 231 | test('copyScore.' + copyScoreName + ' [false] is reflected *in* the UI', () => { |
| 232 | assert.equal(element.shadowRoot.querySelector(elName).checked, false); |
| 233 | }); |
| 234 | |
| 235 | test('copyScore.' + copyScoreName + ' [true] is reflected in the UI', done => { |
| 236 | element.set('_labelConfig.copy_score_rules', [copyScoreName]); |
| 237 | |
| 238 | flush(() => { |
| 239 | assert.ok(element.shadowRoot.querySelector(elName).checked); |
| 240 | done(); |
| 241 | }); |
| 242 | }); |
| 243 | } |
| 244 | |
| 245 | for (const copyScoreName of COPY_SCORES) { |
| 246 | const elName = '#' + copyScoreName; |
| 247 | |
| 248 | test('copyScore.' + copyScoreName + ' is reflected *from* the UI', done => { |
| 249 | element.shadowRoot.querySelector(elName).checked = 'true'; |
| 250 | element.shadowRoot.querySelector(elName).dispatchEvent(new Event('change')); |
| 251 | |
| 252 | flush(() => { |
| 253 | assert.isTrue( |
| 254 | element.repoConfig.labels.Verified.copy_score_rules.includes(copyScoreName) |
| 255 | ); |
| 256 | done(); |
| 257 | }); |
| 258 | }); |
| 259 | } |
| 260 | }); |
| 261 | </script> |