| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | @license |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 4 | Copyright (C) 2020 The Android Open Source Project |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 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" |
| 20 | content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 21 | <meta charset="utf-8"> |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 22 | <title>gr-simple-submit-rules-repo-config</title> |
| 23 | |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 24 | <script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script> |
| 25 | <script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script> |
| 26 | <script src="../bower_components/web-component-tester/browser.js"></script> |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 27 | |
| 28 | <test-fixture id="basic"> |
| 29 | <template> |
| 30 | <gr-simple-submit-rules-repo-config repo-name="test-repo"></gr-simple-submit-rules-repo-config> |
| 31 | </template> |
| 32 | </test-fixture> |
| 33 | |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 34 | <script type="module"> |
| 35 | import '../test/common-test-setup.js'; |
| 36 | import '../test/gr-select.js'; |
| 37 | import "./gr-simple-submit-rules-repo-config.js"; |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 38 | suite('gr-simple-submit-rules-repo-config tests', () => { |
| 39 | let element; |
| 40 | let sandbox; |
| 41 | let unresolvedCommentsEl; |
| 42 | |
| 43 | setup(() => { |
| 44 | sandbox = sinon.sandbox.create(); |
| 45 | |
| 46 | stub('gr-simple-submit-rules-repo-config', { |
| 47 | _pluginRestApi() { |
| 48 | return { |
| 49 | get(url) { |
| 50 | return Promise.resolve({ |
| 51 | comments: { |
| 52 | block_if_unresolved_comments: false, |
| 53 | }, |
| Maxime Guerreiro | e1842a0 | 2018-07-26 13:52:00 +0000 | [diff] [blame] | 54 | labels: {}, |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 55 | }); |
| 56 | }, |
| 57 | getLoggedIn() { return Promise.resolve(true); }, |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 58 | }; |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 59 | }, |
| 60 | |
| 61 | _getRepoAccess(repoName) { |
| 62 | return Promise.resolve({ |
| 63 | 'test-repo': { |
| 64 | is_owner: true, |
| 65 | }, |
| 66 | }); |
| 67 | }, |
| 68 | |
| 69 | }); |
| 70 | |
| 71 | element = fixture('basic'); |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 72 | unresolvedCommentsEl = element.shadowRoot.querySelector('#unresolved_comments select'); |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 73 | return element._loadRepo(); |
| 74 | }); |
| 75 | |
| 76 | teardown(() => { |
| 77 | sandbox.restore(); |
| 78 | }); |
| 79 | |
| 80 | test('unresolved comments option exists', () => { |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 81 | const unresolvedCommentsEl = element.shadowRoot.querySelector('#unresolved_comments'); |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 82 | assert.ok(unresolvedCommentsEl); |
| 83 | }); |
| 84 | |
| 85 | test('readOnly disables fields', () => { |
| 86 | element._readOnly = false; |
| 87 | assert.equal(unresolvedCommentsEl.disabled, false); |
| 88 | |
| 89 | element._readOnly = true; |
| 90 | assert.equal(unresolvedCommentsEl.disabled, true); |
| 91 | }); |
| 92 | |
| Maxime Guerreiro | e1842a0 | 2018-07-26 13:52:00 +0000 | [diff] [blame] | 93 | test('adds a label element', done => { |
| 94 | element.set(['_repoConfig', 'labels', 'Verified'], { |
| 95 | function: 'MaxNoBlock', |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 96 | copy_scores: [], |
| Maxime Guerreiro | e1842a0 | 2018-07-26 13:52:00 +0000 | [diff] [blame] | 97 | }); |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 98 | flush(() => { |
| 99 | const labelItems = element.shadowRoot.querySelectorAll('gr-simple-submit-rules-label-config'); |
| Maxime Guerreiro | e1842a0 | 2018-07-26 13:52:00 +0000 | [diff] [blame] | 100 | assert.ok(labelItems); |
| 101 | assert.equal(labelItems.length, 1); |
| 102 | |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 103 | const labelEl = labelItems[0]; |
| Maxime Guerreiro | e1842a0 | 2018-07-26 13:52:00 +0000 | [diff] [blame] | 104 | assert.ok(labelEl); |
| 105 | assert.equal(labelEl.labelName, 'Verified'); |
| 106 | assert.equal(labelEl.readOnly, false); |
| 107 | done(); |
| 108 | }); |
| 109 | }); |
| 110 | |
| 111 | test('adds two labels elements', done => { |
| 112 | element.set(['_repoConfig', 'labels', 'Verified'], { |
| 113 | function: 'MaxNoBlock', |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 114 | copy_scores: [], |
| Maxime Guerreiro | e1842a0 | 2018-07-26 13:52:00 +0000 | [diff] [blame] | 115 | }); |
| 116 | |
| 117 | element.set(['_repoConfig', 'labels', 'Code-Review'], { |
| 118 | function: 'MaxNoBlock', |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 119 | copy_scores: [], |
| Maxime Guerreiro | e1842a0 | 2018-07-26 13:52:00 +0000 | [diff] [blame] | 120 | }); |
| 121 | |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 122 | flush(() => { |
| 123 | const labelItems = element.shadowRoot.querySelectorAll('gr-simple-submit-rules-label-config'); |
| Maxime Guerreiro | e1842a0 | 2018-07-26 13:52:00 +0000 | [diff] [blame] | 124 | assert.equal(labelItems.length, 2); |
| 125 | done(); |
| 126 | }); |
| 127 | }); |
| 128 | |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 129 | test('unresolved comment uses the repoConfig value (false)', done => { |
| 130 | element.set('_repoConfig.comments.block_if_unresolved_comments', false); |
| 131 | |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 132 | flush(() => { |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 133 | assert.equal(unresolvedCommentsEl.value, 'false'); |
| 134 | done(); |
| 135 | }); |
| 136 | }); |
| 137 | |
| 138 | test('unresolved comment uses the repoConfig value (true)', done => { |
| 139 | element.set('_repoConfig.comments.block_if_unresolved_comments', true); |
| 140 | |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 141 | flush(() => { |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 142 | assert.equal(unresolvedCommentsEl.value, 'true'); |
| 143 | done(); |
| 144 | }); |
| 145 | }); |
| 146 | |
| 147 | test('unresolved comment sets the repoConfig value (true)', done => { |
| 148 | unresolvedCommentsEl.value = 'true'; |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 149 | element.shadowRoot.querySelector('#blockOnUnresolvedComments').dispatchEvent(new Event('change')); |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 150 | |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 151 | flush(() => { |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 152 | assert.equal(element._repoConfig.comments.block_if_unresolved_comments, 'true'); |
| 153 | done(); |
| 154 | }); |
| 155 | }); |
| 156 | |
| 157 | test('unresolved comment sets the repoConfig value (false)', done => { |
| 158 | unresolvedCommentsEl.value = 'false'; |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 159 | element.shadowRoot.querySelector('#blockOnUnresolvedComments').dispatchEvent(new Event('change')); |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 160 | |
| Tao Zhou | ae9c87a | 2020-06-15 19:16:56 +0200 | [diff] [blame] | 161 | flush(() => { |
| Maxime Guerreiro | 0916fe5 | 2018-05-30 14:23:43 +0000 | [diff] [blame] | 162 | assert.equal(element._repoConfig.comments.block_if_unresolved_comments, 'false'); |
| 163 | done(); |
| 164 | }); |
| 165 | }); |
| 166 | }); |
| 167 | </script> |