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