Andrew Bonventre | 09c8c24 | 2016-02-23 17:28:50 -0500 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | Copyright (C) 2015 The Android Open Source Project |
| 4 | |
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | you may not use this file except in compliance with the License. |
| 7 | You may obtain a copy of the License at |
| 8 | |
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, software |
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | See the License for the specific language governing permissions and |
| 15 | limitations under the License. |
| 16 | --> |
| 17 | |
| 18 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> |
| 19 | <title>gr-change-metadata</title> |
| 20 | |
Viktar Donich | 29e1ce5 | 2017-03-28 17:02:44 -0700 | [diff] [blame] | 21 | <script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script> |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 22 | <script src="../../../bower_components/web-component-tester/browser.js"></script> |
Andrew Bonventre | 09c8c24 | 2016-02-23 17:28:50 -0500 | [diff] [blame] | 23 | |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 24 | <link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html"> |
| 25 | <link rel="import" href="gr-change-metadata.html"> |
Andrew Bonventre | 09c8c24 | 2016-02-23 17:28:50 -0500 | [diff] [blame] | 26 | |
Viktar Donich | 29e1ce5 | 2017-03-28 17:02:44 -0700 | [diff] [blame] | 27 | <script>void(0);</script> |
| 28 | |
Andrew Bonventre | 09c8c24 | 2016-02-23 17:28:50 -0500 | [diff] [blame] | 29 | <test-fixture id="basic"> |
| 30 | <template> |
| 31 | <gr-change-metadata></gr-change-metadata> |
| 32 | </template> |
| 33 | </test-fixture> |
| 34 | |
| 35 | <script> |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 36 | suite('gr-change-metadata tests', () => { |
| 37 | let element; |
| 38 | let sandbox; |
Andrew Bonventre | 09c8c24 | 2016-02-23 17:28:50 -0500 | [diff] [blame] | 39 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 40 | setup(() => { |
Becky Siegel | 1f0ca99 | 2017-01-20 15:41:52 -0800 | [diff] [blame] | 41 | sandbox = sinon.sandbox.create(); |
Wyatt Allen | 5623757 | 2016-05-31 14:06:03 -0700 | [diff] [blame] | 42 | stub('gr-rest-api-interface', { |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 43 | getConfig() { return Promise.resolve({}); }, |
| 44 | getLoggedIn() { return Promise.resolve(false); }, |
Wyatt Allen | 5623757 | 2016-05-31 14:06:03 -0700 | [diff] [blame] | 45 | }); |
| 46 | |
Andrew Bonventre | 09c8c24 | 2016-02-23 17:28:50 -0500 | [diff] [blame] | 47 | element = fixture('basic'); |
| 48 | }); |
| 49 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 50 | teardown(() => { |
Becky Siegel | 1f0ca99 | 2017-01-20 15:41:52 -0800 | [diff] [blame] | 51 | sandbox.restore(); |
| 52 | }); |
| 53 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 54 | test('computed fields', () => { |
Andrew Bonventre | 09c8c24 | 2016-02-23 17:28:50 -0500 | [diff] [blame] | 55 | assert.isFalse(element._computeHideStrategy({status: 'NEW'})); |
| 56 | assert.isFalse(element._computeHideStrategy({status: 'DRAFT'})); |
| 57 | assert.isTrue(element._computeHideStrategy({status: 'MERGED'})); |
| 58 | assert.isTrue(element._computeHideStrategy({status: 'ABANDONED'})); |
| 59 | assert.equal(element._computeStrategy({submit_type: 'CHERRY_PICK'}), |
| 60 | 'Cherry Pick'); |
| 61 | }); |
| 62 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 63 | test('show strategy for open change', () => { |
Urs Wolfer | cdbba5a | 2016-02-27 10:47:25 +0100 | [diff] [blame] | 64 | element.change = {status: 'NEW', submit_type: 'CHERRY_PICK', labels: {}}; |
| 65 | flushAsynchronousOperations(); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 66 | const strategy = element.$$('.strategy'); |
Urs Wolfer | cdbba5a | 2016-02-27 10:47:25 +0100 | [diff] [blame] | 67 | assert.ok(strategy); |
| 68 | assert.isFalse(strategy.hasAttribute('hidden')); |
| 69 | assert.equal(strategy.children[1].innerHTML, 'Cherry Pick'); |
| 70 | }); |
| 71 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 72 | test('hide strategy for closed change', () => { |
Urs Wolfer | cdbba5a | 2016-02-27 10:47:25 +0100 | [diff] [blame] | 73 | element.change = {status: 'MERGED', labels: {}}; |
| 74 | flushAsynchronousOperations(); |
| 75 | assert.isTrue(element.$$('.strategy').hasAttribute('hidden')); |
| 76 | }); |
| 77 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 78 | test('show CC section when NoteDb enabled', () => { |
Logan Hanks | a75fb05 | 2016-08-01 13:23:38 -0700 | [diff] [blame] | 79 | function hasCc() { |
| 80 | return element._showReviewersByState; |
| 81 | } |
| 82 | |
| 83 | element.serverConfig = {}; |
| 84 | assert.isFalse(hasCc()); |
| 85 | |
| 86 | element.serverConfig = {note_db_enabled: true}; |
| 87 | assert.isTrue(hasCc()); |
| 88 | }); |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 89 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 90 | test('computes submit status', () => { |
| 91 | let showMissingLabels = false; |
| 92 | sandbox.stub(element, '_showMissingLabels', () => { |
Logan Hanks | dc65dde | 2017-04-27 11:45:23 +0200 | [diff] [blame] | 93 | return showMissingLabels; |
| 94 | }); |
| 95 | assert.isFalse(element._showMissingRequirements(null, false)); |
| 96 | assert.isTrue(element._showMissingRequirements(null, true)); |
| 97 | showMissingLabels = true; |
| 98 | assert.isTrue(element._showMissingRequirements(null, false)); |
| 99 | }); |
| 100 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 101 | test('show missing labels', () => { |
| 102 | let labels = {}; |
Wyatt Allen | 9432320 | 2017-04-13 10:06:14 -0700 | [diff] [blame] | 103 | assert.isFalse(element._showMissingLabels(labels)); |
Andrew Bonventre | 77fcd28 | 2016-10-14 12:05:39 -0700 | [diff] [blame] | 104 | labels = {test: {}}; |
Wyatt Allen | 9432320 | 2017-04-13 10:06:14 -0700 | [diff] [blame] | 105 | assert.isTrue(element._showMissingLabels(labels)); |
| 106 | assert.deepEqual(element._computeMissingLabels(labels), ['test']); |
Kasper Nilsson | 92039854 | 2016-10-10 14:03:24 -0700 | [diff] [blame] | 107 | labels.test.approved = true; |
Wyatt Allen | 9432320 | 2017-04-13 10:06:14 -0700 | [diff] [blame] | 108 | assert.isFalse(element._showMissingLabels(labels)); |
Kasper Nilsson | 92039854 | 2016-10-10 14:03:24 -0700 | [diff] [blame] | 109 | labels.test.approved = false; |
| 110 | labels.test.optional = true; |
Wyatt Allen | 9432320 | 2017-04-13 10:06:14 -0700 | [diff] [blame] | 111 | assert.isFalse(element._showMissingLabels(labels)); |
Kasper Nilsson | 92039854 | 2016-10-10 14:03:24 -0700 | [diff] [blame] | 112 | labels.test.optional = false; |
| 113 | labels.test2 = {}; |
Wyatt Allen | 9432320 | 2017-04-13 10:06:14 -0700 | [diff] [blame] | 114 | assert.isTrue(element._showMissingLabels(labels)); |
| 115 | assert.deepEqual(element._computeMissingLabels(labels), |
| 116 | ['test', 'test2']); |
Kasper Nilsson | 92039854 | 2016-10-10 14:03:24 -0700 | [diff] [blame] | 117 | }); |
| 118 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 119 | test('weblinks hidden when no weblinks', () => { |
Becky Siegel | 896a03f | 2017-01-19 10:49:00 -0800 | [diff] [blame] | 120 | element.commitInfo = {}; |
| 121 | flushAsynchronousOperations(); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 122 | const webLinks = element.$.webLinks; |
Becky Siegel | 896a03f | 2017-01-19 10:49:00 -0800 | [diff] [blame] | 123 | assert.isTrue(webLinks.hasAttribute('hidden')); |
| 124 | }); |
| 125 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 126 | test('weblinks hidden when only gitiles weblink', () => { |
Becky Siegel | 896a03f | 2017-01-19 10:49:00 -0800 | [diff] [blame] | 127 | element.commitInfo = {web_links: [{name: 'gitiles', url: '#'}]}; |
| 128 | flushAsynchronousOperations(); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 129 | const webLinks = element.$.webLinks; |
Becky Siegel | 896a03f | 2017-01-19 10:49:00 -0800 | [diff] [blame] | 130 | assert.isTrue(webLinks.hasAttribute('hidden')); |
| 131 | assert.equal(element._computeWebLinks(element.commitInfo), null); |
| 132 | }); |
| 133 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 134 | test('weblinks are visible when other weblinks', () => { |
Becky Siegel | 896a03f | 2017-01-19 10:49:00 -0800 | [diff] [blame] | 135 | element.commitInfo = {web_links: [{name: 'test', url: '#'}]}; |
| 136 | flushAsynchronousOperations(); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 137 | const webLinks = element.$.webLinks; |
Becky Siegel | 896a03f | 2017-01-19 10:49:00 -0800 | [diff] [blame] | 138 | assert.isFalse(webLinks.hasAttribute('hidden')); |
| 139 | assert.equal(element._computeWebLinks(element.commitInfo).length, 1); |
| 140 | // With two non-gitiles weblinks, there are two returned. |
| 141 | element.commitInfo = { |
| 142 | web_links: [{name: 'test', url: '#'}, {name: 'test2', url: '#'}]}; |
| 143 | assert.equal(element._computeWebLinks(element.commitInfo).length, 2); |
| 144 | }); |
| 145 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 146 | test('weblinks are visible when gitiles and other weblinks', () => { |
Becky Siegel | 896a03f | 2017-01-19 10:49:00 -0800 | [diff] [blame] | 147 | element.commitInfo = { |
| 148 | web_links: [{name: 'test', url: '#'}, {name: 'gitiles', url: '#'}]}; |
| 149 | flushAsynchronousOperations(); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 150 | const webLinks = element.$.webLinks; |
Becky Siegel | 896a03f | 2017-01-19 10:49:00 -0800 | [diff] [blame] | 151 | assert.isFalse(webLinks.hasAttribute('hidden')); |
| 152 | // Only the non-gitiles weblink is returned. |
| 153 | assert.equal(element._computeWebLinks(element.commitInfo).length, 1); |
| 154 | }); |
| 155 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 156 | test('determines whether to show "Ready to Submit" label', () => { |
| 157 | const showMissingSpy = sandbox.spy(element, '_showMissingRequirements'); |
Wyatt Allen | 5b94161 | 2017-05-12 09:50:48 -0700 | [diff] [blame] | 158 | element.change = {status: 'NEW', submit_type: 'CHERRY_PICK', labels: { |
| 159 | test: { |
| 160 | all: [{_account_id: 1, name: 'bojack', value: 1}], |
| 161 | default_value: 0, |
| 162 | values: [], |
| 163 | }, |
| 164 | }}; |
| 165 | flushAsynchronousOperations(); |
| 166 | assert.isTrue(showMissingSpy.called); |
| 167 | }); |
| 168 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 169 | suite('Topic removal', () => { |
| 170 | let change; |
| 171 | setup(() => { |
Becky Siegel | 1f0ca99 | 2017-01-20 15:41:52 -0800 | [diff] [blame] | 172 | change = { |
| 173 | _number: 'the number', |
| 174 | actions: { |
| 175 | topic: {enabled: false}, |
| 176 | }, |
| 177 | change_id: 'the id', |
| 178 | topic: 'the topic', |
| 179 | status: 'NEW', |
| 180 | submit_type: 'CHERRY_PICK', |
| 181 | labels: { |
| 182 | test: { |
| 183 | all: [{_account_id: 1, name: 'bojack', value: 1}], |
| 184 | default_value: 0, |
| 185 | values: [], |
| 186 | }, |
| 187 | }, |
| 188 | removable_reviewers: [], |
| 189 | }; |
| 190 | }); |
| 191 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 192 | test('_computeTopicReadOnly', () => { |
| 193 | let mutable = false; |
Becky Siegel | 1f0ca99 | 2017-01-20 15:41:52 -0800 | [diff] [blame] | 194 | assert.isTrue(element._computeTopicReadOnly(mutable, change)); |
| 195 | mutable = true; |
| 196 | assert.isTrue(element._computeTopicReadOnly(mutable, change)); |
| 197 | change.actions.topic.enabled = true; |
| 198 | assert.isFalse(element._computeTopicReadOnly(mutable, change)); |
| 199 | mutable = false; |
| 200 | assert.isTrue(element._computeTopicReadOnly(mutable, change)); |
| 201 | }); |
| 202 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 203 | test('topic read only hides delete button', () => { |
Becky Siegel | 1f0ca99 | 2017-01-20 15:41:52 -0800 | [diff] [blame] | 204 | element.mutable = false; |
| 205 | element.change = change; |
| 206 | flushAsynchronousOperations(); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 207 | const button = element.$$('gr-linked-chip').$$('gr-button'); |
Becky Siegel | 1f0ca99 | 2017-01-20 15:41:52 -0800 | [diff] [blame] | 208 | assert.isTrue(button.hasAttribute('hidden')); |
| 209 | }); |
| 210 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 211 | test('topic not read only does not hide delete button', () => { |
Becky Siegel | 1f0ca99 | 2017-01-20 15:41:52 -0800 | [diff] [blame] | 212 | element.mutable = true; |
| 213 | change.actions.topic.enabled = true; |
| 214 | element.change = change; |
| 215 | flushAsynchronousOperations(); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 216 | const button = element.$$('gr-linked-chip').$$('gr-button'); |
Becky Siegel | 1f0ca99 | 2017-01-20 15:41:52 -0800 | [diff] [blame] | 217 | assert.isFalse(button.hasAttribute('hidden')); |
| 218 | }); |
| 219 | }); |
| 220 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 221 | suite('remove reviewer votes', () => { |
| 222 | setup(() => { |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 223 | sandbox.stub(element, '_computeValueTooltip').returns(''); |
| 224 | sandbox.stub(element, '_computeTopicReadOnly').returns(true); |
| 225 | element.change = { |
Becky Siegel | 53d7509 | 2017-01-13 14:50:13 -0800 | [diff] [blame] | 226 | _number: 'the number', |
Wyatt Allen | 2f2a3a5 | 2016-10-10 14:04:20 -0700 | [diff] [blame] | 227 | change_id: 'the id', |
Kasper Nilsson | 486b0aa | 2017-04-12 12:52:00 -0700 | [diff] [blame] | 228 | actions: [], |
Wyatt Allen | 2f2a3a5 | 2016-10-10 14:04:20 -0700 | [diff] [blame] | 229 | topic: 'the topic', |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 230 | status: 'NEW', |
| 231 | submit_type: 'CHERRY_PICK', |
| 232 | labels: { |
| 233 | test: { |
| 234 | all: [{_account_id: 1, name: 'bojack', value: 1}], |
| 235 | default_value: 0, |
Andrew Bonventre | d9acaab | 2016-10-14 12:17:25 -0700 | [diff] [blame] | 236 | values: [], |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 237 | }, |
| 238 | }, |
| 239 | removable_reviewers: [], |
| 240 | }; |
| 241 | }); |
| 242 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 243 | test('_computeCanDeleteVote hides delete button', () => { |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 244 | flushAsynchronousOperations(); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 245 | const button = element.$$('gr-account-chip').$$('gr-button'); |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 246 | assert.isTrue(button.hasAttribute('hidden')); |
| 247 | element.mutable = true; |
| 248 | assert.isTrue(button.hasAttribute('hidden')); |
| 249 | }); |
| 250 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 251 | test('_computeCanDeleteVote shows delete button', () => { |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 252 | element.change.removable_reviewers = [ |
| 253 | { |
| 254 | _account_id: 1, |
| 255 | name: 'bojack', |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 256 | }, |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 257 | ]; |
| 258 | element.mutable = true; |
| 259 | flushAsynchronousOperations(); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 260 | const button = element.$$('gr-account-chip').$$('gr-button'); |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 261 | assert.isFalse(button.hasAttribute('hidden')); |
| 262 | }); |
| 263 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 264 | test('deletes votes', done => { |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 265 | sandbox.stub(element.$.restAPI, 'deleteVote') |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 266 | .returns(Promise.resolve({ok: true})); |
| 267 | const spliceStub = sandbox.stub(element, 'splice', (path, index, |
| 268 | length) => { |
| 269 | assert.deepEqual(path, ['change.labels', 'test', 'all']); |
| 270 | assert.equal(index, 0); |
| 271 | assert.equal(length, 1); |
| 272 | assert.notOk(element.change.labels.test.recommended); |
| 273 | spliceStub.restore(); |
| 274 | done(); |
| 275 | }); |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 276 | element.change.removable_reviewers = [ |
| 277 | { |
| 278 | _account_id: 1, |
| 279 | name: 'bojack', |
Kasper Nilsson | 7cc56f8 | 2017-04-19 18:05:38 -0700 | [diff] [blame] | 280 | }, |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 281 | ]; |
Kasper Nilsson | 7cc56f8 | 2017-04-19 18:05:38 -0700 | [diff] [blame] | 282 | element.change.labels.test.recommended = {_account_id: 1}; |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 283 | element.mutable = true; |
| 284 | flushAsynchronousOperations(); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 285 | const button = element.$$('gr-account-chip').$$('gr-button'); |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 286 | MockInteractions.tap(button); |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 287 | }); |
Wyatt Allen | 2f2a3a5 | 2016-10-10 14:04:20 -0700 | [diff] [blame] | 288 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 289 | test('changing topic calls setChangeTopic', () => { |
| 290 | const topicStub = sandbox.stub(element.$.restAPI, 'setChangeTopic', |
| 291 | () => {}); |
Wyatt Allen | 2f2a3a5 | 2016-10-10 14:04:20 -0700 | [diff] [blame] | 292 | element._handleTopicChanged({}, 'the new topic'); |
Becky Siegel | 53d7509 | 2017-01-13 14:50:13 -0800 | [diff] [blame] | 293 | assert.isTrue(topicStub.calledWith('the number', 'the new topic')); |
Wyatt Allen | 2f2a3a5 | 2016-10-10 14:04:20 -0700 | [diff] [blame] | 294 | }); |
Kasper Nilsson | 42b1af4 | 2016-11-18 13:49:05 -0800 | [diff] [blame] | 295 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 296 | test('topic href has quotes', () => { |
| 297 | const hrefArr = element._computeTopicURL('test') |
Kasper Nilsson | 08d0be5 | 2017-02-22 10:57:46 -0800 | [diff] [blame] | 298 | .split('%2522'); // Double-escaped quote. |
| 299 | assert.equal(hrefArr[1], 'test'); |
| 300 | }); |
| 301 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 302 | test('clicking x on topic chip removes topic', () => { |
| 303 | const topicStub = sandbox.stub(element.$.restAPI, 'setChangeTopic'); |
Kasper Nilsson | 42b1af4 | 2016-11-18 13:49:05 -0800 | [diff] [blame] | 304 | flushAsynchronousOperations(); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 305 | const remove = element.$$('gr-linked-chip').$.remove; |
Kasper Nilsson | 42b1af4 | 2016-11-18 13:49:05 -0800 | [diff] [blame] | 306 | MockInteractions.tap(remove); |
| 307 | assert.equal(element.change.topic, ''); |
Kasper Nilsson | 6ebeaac | 2016-12-02 11:16:36 -0800 | [diff] [blame] | 308 | assert.isTrue(topicStub.called); |
Kasper Nilsson | 42b1af4 | 2016-11-18 13:49:05 -0800 | [diff] [blame] | 309 | }); |
Kasper Nilsson | 9bbd47c | 2017-01-09 10:14:36 -0800 | [diff] [blame] | 310 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 311 | suite('assignee field', () => { |
| 312 | const dummyAccount = { |
Kasper Nilsson | 9bbd47c | 2017-01-09 10:14:36 -0800 | [diff] [blame] | 313 | _account_id: 1, |
| 314 | name: 'bojack', |
| 315 | }; |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 316 | const change = { |
Kasper Nilsson | 486b0aa | 2017-04-12 12:52:00 -0700 | [diff] [blame] | 317 | actions: { |
| 318 | assignee: {enabled: false}, |
| 319 | }, |
| 320 | assignee: dummyAccount, |
| 321 | }; |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 322 | let deleteStub; |
| 323 | let setStub; |
Kasper Nilsson | 486b0aa | 2017-04-12 12:52:00 -0700 | [diff] [blame] | 324 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 325 | setup(() => { |
Kasper Nilsson | 9bbd47c | 2017-01-09 10:14:36 -0800 | [diff] [blame] | 326 | deleteStub = sandbox.stub(element.$.restAPI, 'deleteAssignee'); |
| 327 | setStub = sandbox.stub(element.$.restAPI, 'setAssignee'); |
| 328 | }); |
| 329 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 330 | test('changing change recomputes _assignee', () => { |
Kasper Nilsson | 9bbd47c | 2017-01-09 10:14:36 -0800 | [diff] [blame] | 331 | assert.isFalse(!!element._assignee.length); |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 332 | const change = element.change; |
Kasper Nilsson | 9bbd47c | 2017-01-09 10:14:36 -0800 | [diff] [blame] | 333 | change.assignee = dummyAccount; |
| 334 | element._changeChanged(change); |
| 335 | assert.deepEqual(element._assignee[0], dummyAccount); |
| 336 | }); |
| 337 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 338 | test('modifying _assignee calls API', () => { |
Kasper Nilsson | 9bbd47c | 2017-01-09 10:14:36 -0800 | [diff] [blame] | 339 | assert.isFalse(!!element._assignee.length); |
| 340 | element.set('_assignee', [dummyAccount]); |
| 341 | assert.isTrue(setStub.calledOnce); |
| 342 | assert.deepEqual(element.change.assignee, dummyAccount); |
| 343 | element.set('_assignee', [dummyAccount]); |
| 344 | assert.isTrue(setStub.calledOnce); |
| 345 | element.set('_assignee', []); |
| 346 | assert.isTrue(deleteStub.calledOnce); |
| 347 | assert.equal(element.change.assignee, undefined); |
| 348 | element.set('_assignee', []); |
| 349 | assert.isTrue(deleteStub.calledOnce); |
| 350 | }); |
Kasper Nilsson | 486b0aa | 2017-04-12 12:52:00 -0700 | [diff] [blame] | 351 | |
Kasper Nilsson | 5514e0b | 2017-05-16 12:45:21 -0700 | [diff] [blame^] | 352 | test('_computeAssigneeReadOnly', () => { |
| 353 | let mutable = false; |
Kasper Nilsson | 486b0aa | 2017-04-12 12:52:00 -0700 | [diff] [blame] | 354 | assert.isTrue(element._computeAssigneeReadOnly(mutable, change)); |
| 355 | mutable = true; |
| 356 | assert.isTrue(element._computeAssigneeReadOnly(mutable, change)); |
| 357 | change.actions.assignee.enabled = true; |
| 358 | assert.isFalse(element._computeAssigneeReadOnly(mutable, change)); |
| 359 | mutable = false; |
| 360 | assert.isTrue(element._computeAssigneeReadOnly(mutable, change)); |
| 361 | }); |
Kasper Nilsson | 9bbd47c | 2017-01-09 10:14:36 -0800 | [diff] [blame] | 362 | }); |
Kasper Nilsson | f0f5740 | 2016-09-28 14:56:06 -0700 | [diff] [blame] | 363 | }); |
Andrew Bonventre | 09c8c24 | 2016-02-23 17:28:50 -0500 | [diff] [blame] | 364 | }); |
| 365 | </script> |