blob: 8aa6bab1df6b6631efa4ab964cfba8349c565b60 [file] [log] [blame]
Andrew Bonventre8f46e032016-01-07 16:38:37 -05001<!DOCTYPE html>
2<!--
3Copyright (C) 2016 The Android Open Source Project
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations 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-actions</title>
20
Andrew Bonventre78792e82016-03-04 17:48:22 -050021<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
22<script src="../../../bower_components/web-component-tester/browser.js"></script>
23<script src="../../../scripts/util.js"></script>
Andrew Bonventre8f46e032016-01-07 16:38:37 -050024
Andrew Bonventre78792e82016-03-04 17:48:22 -050025<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
26<link rel="import" href="gr-change-actions.html">
Andrew Bonventre8f46e032016-01-07 16:38:37 -050027
Viktar Donich29e1ce52017-03-28 17:02:44 -070028<script>void(0);</script>
29
Andrew Bonventre8f46e032016-01-07 16:38:37 -050030<test-fixture id="basic">
31 <template>
32 <gr-change-actions></gr-change-actions>
33 </template>
34</test-fixture>
35
36<script>
Kasper Nilsson414ba692017-05-16 11:03:22 -070037 suite('gr-change-actions tests', () => {
38 let element;
39 let sandbox;
Kasper Nilssonf6c0b502017-04-25 10:45:28 +020040
Kasper Nilsson414ba692017-05-16 11:03:22 -070041 setup(() => {
Andrew Bonventre1508cac2016-04-02 21:37:15 -040042 stub('gr-rest-api-interface', {
Kasper Nilsson414ba692017-05-16 11:03:22 -070043 getChangeRevisionActions() {
Andrew Bonventre1508cac2016-04-02 21:37:15 -040044 return Promise.resolve({
Andrew Bonventree073fa92016-09-20 16:50:33 -040045 '/': {
46 method: 'DELETE',
47 label: 'Delete',
48 title: 'Delete draft revision 2',
Andrew Bonventre43e35b92016-09-21 15:18:28 -040049 enabled: true,
Andrew Bonventree073fa92016-09-20 16:50:33 -040050 },
Kasper Nilsson414ba692017-05-16 11:03:22 -070051 'cherrypick': {
Andrew Bonventre8f46e032016-01-07 16:38:37 -050052 method: 'POST',
53 label: 'Cherry Pick',
54 title: 'Cherry pick change to a different branch',
Andrew Bonventre43e35b92016-09-21 15:18:28 -040055 enabled: true,
Andrew Bonventre8f46e032016-01-07 16:38:37 -050056 },
Kasper Nilsson414ba692017-05-16 11:03:22 -070057 'rebase': {
Andrew Bonventre8f46e032016-01-07 16:38:37 -050058 method: 'POST',
59 label: 'Rebase',
Andrew Bonventre43e35b92016-09-21 15:18:28 -040060 title: 'Rebase onto tip of branch or parent change',
61 enabled: true,
Andrew Bonventre8f46e032016-01-07 16:38:37 -050062 },
Kasper Nilsson414ba692017-05-16 11:03:22 -070063 'submit': {
Andrew Bonventre8f46e032016-01-07 16:38:37 -050064 method: 'POST',
65 label: 'Submit',
Andrew Bonventree073fa92016-09-20 16:50:33 -040066 title: 'Submit patch set 2 into master',
Andrew Bonventre43e35b92016-09-21 15:18:28 -040067 enabled: true,
Andrew Bonventree073fa92016-09-20 16:50:33 -040068 },
Andrew Bonventre1508cac2016-04-02 21:37:15 -040069 });
70 },
Kasper Nilsson414ba692017-05-16 11:03:22 -070071 send(method, url, payload) {
Andrew Bonventre1508cac2016-04-02 21:37:15 -040072 if (method !== 'POST') { return Promise.reject('bad method'); }
Andrew Bonventre8f46e032016-01-07 16:38:37 -050073
Andrew Bonventre1508cac2016-04-02 21:37:15 -040074 if (url === '/changes/42/revisions/2/submit') {
75 return Promise.resolve({
76 ok: true,
Kasper Nilsson414ba692017-05-16 11:03:22 -070077 text() { return Promise.resolve(')]}\'\n{}'); },
Andrew Bonventre1508cac2016-04-02 21:37:15 -040078 });
79 } else if (url === '/changes/42/revisions/2/rebase') {
80 return Promise.resolve({
81 ok: true,
Kasper Nilsson414ba692017-05-16 11:03:22 -070082 text() { return Promise.resolve(')]}\'\n{}'); },
Andrew Bonventre1508cac2016-04-02 21:37:15 -040083 });
84 }
Andrew Bonventre8f46e032016-01-07 16:38:37 -050085
Andrew Bonventre1508cac2016-04-02 21:37:15 -040086 return Promise.reject('bad url');
87 },
Urs Wolferf531d0a2016-03-12 12:48:10 +010088 });
Andrew Bonventre8f46e032016-01-07 16:38:37 -050089
Andrew Bonventre1508cac2016-04-02 21:37:15 -040090 element = fixture('basic');
Viktar Donich50e2c002016-11-11 14:41:24 -080091 element.change = {};
Andrew Bonventre1508cac2016-04-02 21:37:15 -040092 element.changeNum = '42';
93 element.patchNum = '2';
Andrew Bonventree073fa92016-09-20 16:50:33 -040094 element.actions = {
95 '/': {
96 method: 'DELETE',
97 label: 'Delete',
98 title: 'Delete draft change 42',
Kasper Nilssondf696b42017-01-19 13:15:12 -080099 enabled: true,
Andrew Bonventree073fa92016-09-20 16:50:33 -0400100 },
101 };
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200102 sandbox = sinon.sandbox.create();
103
Viktar Donich853e1422016-04-25 11:30:42 -0700104 return element.reload();
Andrew Bonventre57fbfa82016-03-14 20:38:56 -0400105 });
106
Kasper Nilsson414ba692017-05-16 11:03:22 -0700107 teardown(() => {
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200108 sandbox.restore();
109 });
110
Kasper Nilsson414ba692017-05-16 11:03:22 -0700111 test('_shouldHideActions', () => {
Wyatt Allena9807e42017-01-25 11:29:35 -0800112 assert.isTrue(element._shouldHideActions(undefined, true));
113 assert.isTrue(element._shouldHideActions({base: {}}, false));
114 assert.isFalse(element._shouldHideActions({base: ['test']}, false));
Kasper Nilssondf696b42017-01-19 13:15:12 -0800115 });
116
Kasper Nilsson414ba692017-05-16 11:03:22 -0700117 test('hide revision action', done => {
118 flush(() => {
119 const buttonEl = element.$$('[data-action-key="submit"]');
Andrew Bonventrec4249c32016-10-12 14:22:25 -0700120 assert.isOk(buttonEl);
Andrew Bonventrec4249c32016-10-12 14:22:25 -0700121 assert.throws(element.setActionHidden.bind(element, 'invalid type'));
122 element.setActionHidden(element.ActionType.REVISION,
123 element.RevisionActions.SUBMIT, true);
Wyatt Allena9807e42017-01-25 11:29:35 -0800124 assert.lengthOf(element._hiddenActions, 1);
Andrew Bonventrec4249c32016-10-12 14:22:25 -0700125 element.setActionHidden(element.ActionType.REVISION,
126 element.RevisionActions.SUBMIT, true);
Wyatt Allena9807e42017-01-25 11:29:35 -0800127 assert.lengthOf(element._hiddenActions, 1);
Kasper Nilsson414ba692017-05-16 11:03:22 -0700128 flush(() => {
129 const buttonEl = element.$$('[data-action-key="submit"]');
Wyatt Allen89842ab2017-01-30 12:34:14 -0800130 assert.isNotOk(buttonEl);
Andrew Bonventrec4249c32016-10-12 14:22:25 -0700131
132 element.setActionHidden(element.ActionType.REVISION,
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200133 element.RevisionActions.SUBMIT, false);
Kasper Nilsson414ba692017-05-16 11:03:22 -0700134 flush(() => {
135 const buttonEl = element.$$('[data-action-key="submit"]');
Andrew Bonventrec4249c32016-10-12 14:22:25 -0700136 assert.isOk(buttonEl);
137 assert.isFalse(buttonEl.hasAttribute('hidden'));
138 done();
139 });
140 });
141 });
142 });
143
Kasper Nilsson414ba692017-05-16 11:03:22 -0700144 test('hide menu action', done => {
145 flush(() => {
146 const buttonEl =
Viktar Donich44e2ccd2017-04-17 10:58:12 -0700147 element.$.moreActions.$$('span[data-id="delete-revision"]');
Andrew Bonventrec4249c32016-10-12 14:22:25 -0700148 assert.isOk(buttonEl);
Andrew Bonventrec4249c32016-10-12 14:22:25 -0700149 assert.throws(element.setActionHidden.bind(element, 'invalid type'));
150 element.setActionHidden(element.ActionType.CHANGE,
151 element.ChangeActions.DELETE, true);
Wyatt Allena9807e42017-01-25 11:29:35 -0800152 assert.lengthOf(element._hiddenActions, 1);
Andrew Bonventrec4249c32016-10-12 14:22:25 -0700153 element.setActionHidden(element.ActionType.CHANGE,
154 element.ChangeActions.DELETE, true);
Wyatt Allena9807e42017-01-25 11:29:35 -0800155 assert.lengthOf(element._hiddenActions, 1);
Kasper Nilsson414ba692017-05-16 11:03:22 -0700156 flush(() => {
157 const buttonEl =
Viktar Donich44e2ccd2017-04-17 10:58:12 -0700158 element.$.moreActions.$$('span[data-id="delete-revision"]');
Wyatt Allen5ccad3a2017-01-25 12:08:59 -0800159 assert.isNotOk(buttonEl);
Andrew Bonventrec4249c32016-10-12 14:22:25 -0700160
161 element.setActionHidden(element.ActionType.CHANGE,
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200162 element.RevisionActions.DELETE, false);
Kasper Nilsson414ba692017-05-16 11:03:22 -0700163 flush(() => {
164 const buttonEl =
Viktar Donich44e2ccd2017-04-17 10:58:12 -0700165 element.$.moreActions.$$('span[data-id="delete-revision"]');
Andrew Bonventrec4249c32016-10-12 14:22:25 -0700166 assert.isOk(buttonEl);
Andrew Bonventrec4249c32016-10-12 14:22:25 -0700167 done();
168 });
169 });
170 });
171 });
172
Kasper Nilsson414ba692017-05-16 11:03:22 -0700173 test('buttons exist', done => {
Kasper Nilssondf696b42017-01-19 13:15:12 -0800174 element._loading = false;
Kasper Nilsson414ba692017-05-16 11:03:22 -0700175 flush(() => {
176 const buttonEls = Polymer.dom(element.root)
Kasper Nilssondf696b42017-01-19 13:15:12 -0800177 .querySelectorAll('gr-button');
Kasper Nilsson414ba692017-05-16 11:03:22 -0700178 const menuItems = element.$.moreActions.items;
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200179 assert.equal(buttonEls.length + menuItems.length, 7);
Andrew Bonventre8f46e032016-01-07 16:38:37 -0500180 assert.isFalse(element.hidden);
181 done();
Urs Wolferb6036942016-03-06 14:57:02 +0100182 });
Andrew Bonventre8f46e032016-01-07 16:38:37 -0500183 });
184
Kasper Nilsson414ba692017-05-16 11:03:22 -0700185 test('delete buttons have explicit labels', done => {
186 flush(() => {
187 const deleteItems = element.$.moreActions.items.filter(item => {
188 return item.id.startsWith('delete');
Wyatt Allen5ccad3a2017-01-25 12:08:59 -0800189 });
190 assert.equal(deleteItems.length, 2);
Wyatt Allen89842ab2017-01-30 12:34:14 -0800191 assert.notEqual(deleteItems[0].name, deleteItems[1].name);
Andrew Bonventree073fa92016-09-20 16:50:33 -0400192 assert.isTrue(
Wyatt Allen5ccad3a2017-01-25 12:08:59 -0800193 deleteItems[0].name === 'Delete Revision' ||
194 deleteItems[0].name === 'Delete Change'
Andrew Bonventree073fa92016-09-20 16:50:33 -0400195 );
196 assert.isTrue(
Wyatt Allen5ccad3a2017-01-25 12:08:59 -0800197 deleteItems[1].name === 'Delete Revision' ||
198 deleteItems[1].name === 'Delete Change'
Andrew Bonventree073fa92016-09-20 16:50:33 -0400199 );
200 done();
201 });
202 });
203
Kasper Nilsson414ba692017-05-16 11:03:22 -0700204 test('get revision object from change', () => {
205 const revObj = {_number: 2, foo: 'bar'};
206 const change = {
Andrew Bonventrea5ee85c2016-10-05 10:47:40 -0700207 revisions: {
208 rev1: {_number: 1},
209 rev2: revObj,
210 },
211 };
212 assert.deepEqual(element._getRevision(change, '2'), revObj);
213 });
214
Kasper Nilsson414ba692017-05-16 11:03:22 -0700215 test('_actionComparator sort order', () => {
216 const actions = [
Wyatt Allen9a70d982017-01-27 12:02:10 -0800217 {label: '123', __type: 'change', __key: 'review'},
Viktar Donich7f412ae2017-04-18 16:08:13 -0700218 {label: 'abc-ro', __type: 'revision'},
Wyatt Allen9a70d982017-01-27 12:02:10 -0800219 {label: 'abc', __type: 'change'},
220 {label: 'def', __type: 'change'},
Viktar Donich7f412ae2017-04-18 16:08:13 -0700221 {label: 'def-p', __type: 'change', __primary: true},
Wyatt Allena9807e42017-01-25 11:29:35 -0800222 ];
Wyatt Allen9a70d982017-01-27 12:02:10 -0800223
Kasper Nilsson414ba692017-05-16 11:03:22 -0700224 const result = actions.slice();
Wyatt Allen9a70d982017-01-27 12:02:10 -0800225 result.reverse();
Viktar Donich7f412ae2017-04-18 16:08:13 -0700226 result.sort(element._actionComparator.bind(element));
Wyatt Allena9807e42017-01-25 11:29:35 -0800227 assert.deepEqual(result, actions);
228 });
229
Kasper Nilsson414ba692017-05-16 11:03:22 -0700230 test('submit change', done => {
Wyatt Allen6cf58752017-04-24 16:59:07 +0200231 sandbox.stub(element, 'fetchIsLatestKnown',
Kasper Nilsson414ba692017-05-16 11:03:22 -0700232 () => { return Promise.resolve(true); });
Andrew Bonventrea5ee85c2016-10-05 10:47:40 -0700233 element.change = {
234 revisions: {
235 rev1: {_number: 1},
236 rev2: {_number: 2},
237 },
238 };
239 element.patchNum = '2';
240
Kasper Nilsson414ba692017-05-16 11:03:22 -0700241 flush(() => {
242 const submitButton = element.$$('gr-button[data-action-key="submit"]');
Andrew Bonventre8f46e032016-01-07 16:38:37 -0500243 assert.ok(submitButton);
244 MockInteractions.tap(submitButton);
Andrew Bonventre8f46e032016-01-07 16:38:37 -0500245
246 // Upon success it should fire the reload-change event.
Kasper Nilsson414ba692017-05-16 11:03:22 -0700247 element.addEventListener('reload-change', () => {
Andrew Bonventre8f46e032016-01-07 16:38:37 -0500248 done();
249 });
Urs Wolferb6036942016-03-06 14:57:02 +0100250 });
Andrew Bonventre8f46e032016-01-07 16:38:37 -0500251 });
Andrew Bonventre81170c62016-02-10 11:48:37 -0500252
Kasper Nilsson414ba692017-05-16 11:03:22 -0700253 test('submit change with plugin hook', done => {
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200254 sandbox.stub(element, '_canSubmitChange',
Kasper Nilsson414ba692017-05-16 11:03:22 -0700255 () => { return false; });
256 const fireActionStub = sandbox.stub(element, '_fireAction');
257 flush(() => {
258 const submitButton = element.$$('gr-button[data-action-key="submit"]');
Andrew Bonventred2b90432016-03-29 14:12:33 -0400259 assert.ok(submitButton);
260 MockInteractions.tap(submitButton);
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400261 assert.equal(fireActionStub.callCount, 0);
Andrew Bonventred2b90432016-03-29 14:12:33 -0400262
Andrew Bonventred2b90432016-03-29 14:12:33 -0400263 done();
264 });
265 });
266
Kasper Nilsson414ba692017-05-16 11:03:22 -0700267 test('chain state', () => {
Becky Siegel61ecc0c2017-02-15 11:32:21 -0800268 assert.equal(element._hasKnownChainState, false);
269 element.hasParent = true;
270 assert.equal(element._hasKnownChainState, true);
271 element.hasParent = false;
272 });
273
Kasper Nilsson414ba692017-05-16 11:03:22 -0700274 test('_calculateDisabled', () => {
275 let hasKnownChainState = false;
276 const action = {__key: 'rebase', enabled: true};
Becky Siegel61ecc0c2017-02-15 11:32:21 -0800277 assert.equal(
278 element._calculateDisabled(action, hasKnownChainState), true);
279
280 action.__key = 'delete';
281 assert.equal(
282 element._calculateDisabled(action, hasKnownChainState), false);
283
284 action.__key = 'rebase';
285 hasKnownChainState = true;
286 assert.equal(
287 element._calculateDisabled(action, hasKnownChainState), false);
288
289 action.enabled = false;
290 assert.equal(
291 element._calculateDisabled(action, hasKnownChainState), true);
292 });
293
Kasper Nilsson414ba692017-05-16 11:03:22 -0700294 test('rebase change', done => {
295 const fireActionStub = sandbox.stub(element, '_fireAction');
296 flush(() => {
297 const rebaseButton = element.$$('gr-button[data-action-key="rebase"]');
Andrew Bonventre81170c62016-02-10 11:48:37 -0500298 MockInteractions.tap(rebaseButton);
Kasper Nilsson414ba692017-05-16 11:03:22 -0700299 const rebaseAction = {
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400300 __key: 'rebase',
301 __type: 'revision',
Andrew Bonventre4117ea42016-06-15 14:35:55 -0700302 __primary: false,
Andrew Bonventre43e35b92016-09-21 15:18:28 -0400303 enabled: true,
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400304 label: 'Rebase',
305 method: 'POST',
306 title: 'Rebase onto tip of branch or parent change',
307 };
Becky Siegel61ecc0c2017-02-15 11:32:21 -0800308 // rebase on other
Andrew Bonventre81170c62016-02-10 11:48:37 -0500309 element.$.confirmRebase.base = '1234';
310 element._handleRebaseConfirm();
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400311 assert.deepEqual(fireActionStub.lastCall.args,
312 ['/rebase', rebaseAction, true, {base: '1234'}]);
Andrew Bonventre81170c62016-02-10 11:48:37 -0500313
Becky Siegel61ecc0c2017-02-15 11:32:21 -0800314 // rebase on parent
315 element.$.confirmRebase.base = null;
Andrew Bonventre81170c62016-02-10 11:48:37 -0500316 element._handleRebaseConfirm();
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400317 assert.deepEqual(fireActionStub.lastCall.args,
Becky Siegel61ecc0c2017-02-15 11:32:21 -0800318 ['/rebase', rebaseAction, true, {base: null}]);
Andrew Bonventre81170c62016-02-10 11:48:37 -0500319
Becky Siegel61ecc0c2017-02-15 11:32:21 -0800320 // rebase on tip
321 element.$.confirmRebase.base = '';
Andrew Bonventre81170c62016-02-10 11:48:37 -0500322 element._handleRebaseConfirm();
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400323 assert.deepEqual(fireActionStub.lastCall.args,
324 ['/rebase', rebaseAction, true, {base: ''}]);
Andrew Bonventre81170c62016-02-10 11:48:37 -0500325
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400326 done();
Urs Wolferb6036942016-03-06 14:57:02 +0100327 });
Andrew Bonventre81170c62016-02-10 11:48:37 -0500328 });
329
Kasper Nilsson414ba692017-05-16 11:03:22 -0700330 test('two dialogs are not shown at the same time', done => {
Becky Siegel61ecc0c2017-02-15 11:32:21 -0800331 element._hasKnownChainState = true;
Kasper Nilsson414ba692017-05-16 11:03:22 -0700332 flush(() => {
333 const rebaseButton = element.$$('gr-button[data-action-key="rebase"]');
Andrew Bonventre43e35b92016-09-21 15:18:28 -0400334 assert.ok(rebaseButton);
335 MockInteractions.tap(rebaseButton);
336 flushAsynchronousOperations();
337 assert.isFalse(element.$.confirmRebase.hidden);
338
Wyatt Allen5ccad3a2017-01-25 12:08:59 -0800339 element._handleCherrypickTap();
Andrew Bonventre43e35b92016-09-21 15:18:28 -0400340 flushAsynchronousOperations();
341 assert.isTrue(element.$.confirmRebase.hidden);
342 assert.isFalse(element.$.confirmCherrypick.hidden);
343 done();
344 });
345 });
346
Kasper Nilsson414ba692017-05-16 11:03:22 -0700347 suite('cherry-pick', () => {
348 let fireActionStub;
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400349
Kasper Nilsson414ba692017-05-16 11:03:22 -0700350 setup(() => {
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200351 fireActionStub = sandbox.stub(element, '_fireAction');
352 sandbox.stub(window, 'alert');
Viktar Donich853e1422016-04-25 11:30:42 -0700353 });
354
Kasper Nilsson414ba692017-05-16 11:03:22 -0700355 test('works', () => {
Wyatt Allen5ccad3a2017-01-25 12:08:59 -0800356 element._handleCherrypickTap();
Kasper Nilsson414ba692017-05-16 11:03:22 -0700357 const action = {
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400358 __key: 'cherrypick',
359 __type: 'revision',
Andrew Bonventre4117ea42016-06-15 14:35:55 -0700360 __primary: false,
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400361 enabled: true,
362 label: 'Cherry Pick',
363 method: 'POST',
364 title: 'Cherry pick change to a different branch',
365 };
366
367 element._handleCherrypickConfirm();
368 assert.equal(fireActionStub.callCount, 0);
369
370 element.$.confirmCherrypick.branch = 'master';
371 element._handleCherrypickConfirm();
372 assert.equal(fireActionStub.callCount, 0); // Still needs a message.
373
Becky Siegel48721992016-11-30 15:33:19 -0800374 // Add attributes that are used to determine the message.
375 element.$.confirmCherrypick.commitMessage = 'foo message';
376 element.$.confirmCherrypick.changeStatus = 'OPEN';
377 element.$.confirmCherrypick.commitNum = '123';
378
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400379 element._handleCherrypickConfirm();
380
Becky Siegel48721992016-11-30 15:33:19 -0800381 assert.equal(element.$.confirmCherrypick.$.messageInput.value,
Viktar Donichc5036792016-12-02 15:38:19 -0800382 'foo message');
Becky Siegel48721992016-11-30 15:33:19 -0800383
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400384 assert.deepEqual(fireActionStub.lastCall.args, [
385 '/cherrypick', action, true, {
386 destination: 'master',
387 message: 'foo message',
Kasper Nilssondf696b42017-01-19 13:15:12 -0800388 },
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400389 ]);
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400390 });
Becky Siegel5755ef92016-10-03 11:43:18 -0700391
Kasper Nilsson414ba692017-05-16 11:03:22 -0700392 test('branch name cleared when re-open cherrypick', () => {
393 const emptyBranchName = '';
Becky Siegel5755ef92016-10-03 11:43:18 -0700394 element.$.confirmCherrypick.branch = 'master';
395
Wyatt Allen5ccad3a2017-01-25 12:08:59 -0800396 element._handleCherrypickTap();
Becky Siegel5755ef92016-10-03 11:43:18 -0700397 assert.equal(element.$.confirmCherrypick.branch, emptyBranchName);
398 });
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400399 });
400
Kasper Nilsson414ba692017-05-16 11:03:22 -0700401 test('custom actions', done => {
Andrew Bonventrecd73e962016-06-22 17:52:56 -0400402 // Add a button with the same key as a server-based one to ensure
403 // collisions are taken care of.
Kasper Nilsson414ba692017-05-16 11:03:22 -0700404 const key = element.addActionButton(element.ActionType.REVISION, 'Bork!');
405 element.addEventListener(key + '-tap', e => {
Andrew Bonventrecd73e962016-06-22 17:52:56 -0400406 assert.equal(e.detail.node.getAttribute('data-action-key'), key);
407 element.removeActionButton(key);
Kasper Nilsson414ba692017-05-16 11:03:22 -0700408 flush(() => {
Andrew Bonventrecd73e962016-06-22 17:52:56 -0400409 assert.notOk(element.$$('[data-action-key="' + key + '"]'));
410 done();
411 });
412 });
Kasper Nilsson414ba692017-05-16 11:03:22 -0700413 flush(() => {
Andrew Bonventrecd73e962016-06-22 17:52:56 -0400414 MockInteractions.tap(element.$$('[data-action-key="' + key + '"]'));
415 });
416 });
417
Kasper Nilsson414ba692017-05-16 11:03:22 -0700418 test('_setLoadingOnButtonWithKey top-level', () => {
419 const key = 'rebase';
420 const type = 'revision';
421 const cleanup = element._setLoadingOnButtonWithKey(type, key);
Wyatt Allen89842ab2017-01-30 12:34:14 -0800422 assert.equal(element._actionLoadingMessage, 'Rebasing...');
Wyatt Allencf44a382017-01-27 13:53:58 -0800423
Kasper Nilsson414ba692017-05-16 11:03:22 -0700424 const button = element.$$('[data-action-key="' + key + '"]');
Wyatt Allencf44a382017-01-27 13:53:58 -0800425 assert.isTrue(button.hasAttribute('loading'));
426 assert.isTrue(button.disabled);
427
428 assert.isOk(cleanup);
429 assert.isFunction(cleanup);
430 cleanup();
431
432 assert.isFalse(button.hasAttribute('loading'));
433 assert.isFalse(button.disabled);
Wyatt Allen89842ab2017-01-30 12:34:14 -0800434 assert.isNotOk(element._actionLoadingMessage);
Wyatt Allencf44a382017-01-27 13:53:58 -0800435 });
436
Kasper Nilsson414ba692017-05-16 11:03:22 -0700437 test('_setLoadingOnButtonWithKey overflow menu', () => {
438 const key = 'cherrypick';
439 const type = 'revision';
440 const cleanup = element._setLoadingOnButtonWithKey(type, key);
Wyatt Allendee92f72017-02-08 14:25:04 -0800441 assert.equal(element._actionLoadingMessage, 'Cherry-Picking...');
442 assert.include(element._disabledMenuActions, 'cherrypick');
Wyatt Allencf44a382017-01-27 13:53:58 -0800443 assert.isFunction(cleanup);
Wyatt Allendee92f72017-02-08 14:25:04 -0800444
445 cleanup();
446
447 assert.notOk(element._actionLoadingMessage);
448 assert.notInclude(element._disabledMenuActions, 'cherrypick');
Wyatt Allencf44a382017-01-27 13:53:58 -0800449 });
450
Kasper Nilsson414ba692017-05-16 11:03:22 -0700451 suite('revert change', () => {
452 let alertStub;
453 let fireActionStub;
Andrew Bonventre1508cac2016-04-02 21:37:15 -0400454
Kasper Nilsson414ba692017-05-16 11:03:22 -0700455 setup(() => {
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200456 fireActionStub = sandbox.stub(element, '_fireAction');
457 alertStub = sandbox.stub(window, 'alert');
Viktar Donich853e1422016-04-25 11:30:42 -0700458 element.actions = {
459 revert: {
460 method: 'POST',
461 label: 'Revert',
462 title: 'Revert the change',
Kasper Nilssondf696b42017-01-19 13:15:12 -0800463 enabled: true,
464 },
Viktar Donich853e1422016-04-25 11:30:42 -0700465 };
466 return element.reload();
467 });
468
Kasper Nilsson414ba692017-05-16 11:03:22 -0700469 test('revert change with plugin hook', done => {
Ravi Mistry95b96f82016-10-10 14:04:17 -0400470 element.change = {
471 current_revision: 'abc1234',
472 };
Kasper Nilsson414ba692017-05-16 11:03:22 -0700473 const newRevertMsg = 'Modified revert msg';
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200474 sandbox.stub(element, '_modifyRevertMsg',
Kasper Nilsson414ba692017-05-16 11:03:22 -0700475 () => { return newRevertMsg; });
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200476 sandbox.stub(element.$.confirmRevertDialog, 'populateRevertMessage',
Kasper Nilsson414ba692017-05-16 11:03:22 -0700477 () => { return 'original msg'; });
478 flush(() => {
479 const revertButton =
480 element.$$('gr-button[data-action-key="revert"]');
Ravi Mistry7d64e782016-08-02 07:48:45 -0400481 MockInteractions.tap(revertButton);
482
483 assert.equal(element.$.confirmRevertDialog.message, newRevertMsg);
Ravi Mistry7d64e782016-08-02 07:48:45 -0400484 done();
485 });
486 });
487
Kasper Nilsson414ba692017-05-16 11:03:22 -0700488 test('works', () => {
Ravi Mistry95b96f82016-10-10 14:04:17 -0400489 element.change = {
490 current_revision: 'abc1234',
491 };
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200492 sandbox.stub(element.$.confirmRevertDialog, 'populateRevertMessage',
Kasper Nilsson414ba692017-05-16 11:03:22 -0700493 () => { return 'original msg'; });
494 const revertButton = element.$$('gr-button[data-action-key="revert"]');
Viktar Donich853e1422016-04-25 11:30:42 -0700495 MockInteractions.tap(revertButton);
496
497 element.$.confirmRevertDialog.message = 'foo message';
498 element._handleRevertDialogConfirm();
499 assert.notOk(alertStub.called);
500
Kasper Nilsson414ba692017-05-16 11:03:22 -0700501 const action = {
Viktar Donich853e1422016-04-25 11:30:42 -0700502 __key: 'revert',
503 __type: 'change',
Andrew Bonventre4117ea42016-06-15 14:35:55 -0700504 __primary: false,
Viktar Donich853e1422016-04-25 11:30:42 -0700505 enabled: true,
506 label: 'Revert',
507 method: 'POST',
508 title: 'Revert the change',
509 };
510 assert.deepEqual(fireActionStub.lastCall.args, [
511 '/revert', action, false, {
512 message: 'foo message',
513 }]);
514 });
515 });
Viktar Donichbcd44b12016-11-07 15:50:11 -0800516
Paladox none1f6008b2017-04-19 21:42:54 +0000517 suite('mark change private', () => {
518 setup(() => {
519 const privateAction = {
520 __key: 'private',
521 __type: 'change',
522 __primary: false,
523 method: 'POST',
524 label: 'Mark private',
525 title: 'Working...',
526 enabled: true,
527 };
528
529 element.actions = {
530 private: privateAction,
531 };
532
533 element.change.is_private = false;
534
535 element.changeNum = '2';
536 element.patchNum = '2';
537
538 return element.reload();
539 });
540
541 test('make sure the mark private change button is not outside of the ' +
542 'overflow menu', done => {
543 flush(() => {
544 assert.isNotOk(element.$$('[data-action-key="private"]'));
545 done();
546 });
547 });
548
549 test('private change', done => {
550 flush(() => {
551 assert.isOk(
552 element.$.moreActions.$$('span[data-id="private-change"]'));
553 element.setActionOverflow('change', 'private', false);
554 flushAsynchronousOperations();
555 assert.isOk(element.$$('[data-action-key="private"]'));
556 assert.isNotOk(
557 element.$.moreActions.$$('span[data-id="private-change"]'));
558 done();
559 });
560 });
561 });
562
563 suite('unmark private change', () => {
564 setup(() => {
565 const unmarkPrivateAction = {
566 __key: 'private.delete',
567 __type: 'change',
568 __primary: false,
569 method: 'POST',
570 label: 'Unmark private',
571 title: 'Working...',
572 enabled: true,
573 };
574
575 element.actions = {
576 'private.delete': unmarkPrivateAction,
577 };
578
579 element.change.is_private = true;
580
581 element.changeNum = '2';
582 element.patchNum = '2';
583
584 return element.reload();
585 });
586
587 test('make sure the unmark private change button is not outside of the ' +
588 'overflow menu', done => {
589 flush(() => {
590 assert.isNotOk(element.$$('[data-action-key="private.delete"]'));
591 done();
592 });
593 });
594
595 test('unmark the private change', done => {
596 flush(() => {
597 assert.isOk(
598 element.$.moreActions.$$('span[data-id="private.delete-change"]')
599 );
600 element.setActionOverflow('change', 'private.delete', false);
601 flushAsynchronousOperations();
602 assert.isOk(element.$$('[data-action-key="private.delete"]'));
603 assert.isNotOk(
604 element.$.moreActions.$$('span[data-id="private.delete-change"]')
605 );
606 done();
607 });
608 });
609 });
610
Kasper Nilsson414ba692017-05-16 11:03:22 -0700611 suite('delete change', () => {
612 let fireActionStub;
613 let deleteAction;
Viktar Donichbcd44b12016-11-07 15:50:11 -0800614
Kasper Nilsson414ba692017-05-16 11:03:22 -0700615 setup(() => {
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200616 fireActionStub = sandbox.stub(element, '_fireAction');
Viktar Donichbcd44b12016-11-07 15:50:11 -0800617 element.change = {
618 current_revision: 'abc1234',
619 };
620 deleteAction = {
621 method: 'DELETE',
622 label: 'Delete Change',
623 title: 'Delete change X_X',
624 enabled: true,
625 };
626 element.actions = {
627 '/': deleteAction,
628 };
629 });
630
Kasper Nilsson414ba692017-05-16 11:03:22 -0700631 test('does not delete on action', () => {
Wyatt Allen5ccad3a2017-01-25 12:08:59 -0800632 element._handleDeleteTap();
Viktar Donichbcd44b12016-11-07 15:50:11 -0800633 assert.isFalse(fireActionStub.called);
634 });
635
Kasper Nilsson414ba692017-05-16 11:03:22 -0700636 test('shows confirm dialog', () => {
Wyatt Allen5ccad3a2017-01-25 12:08:59 -0800637 element._handleDeleteTap();
Viktar Donichbcd44b12016-11-07 15:50:11 -0800638 assert.isFalse(element.$$('#confirmDeleteDialog').hidden);
639 MockInteractions.tap(
640 element.$$('#confirmDeleteDialog').$$('gr-button[primary]'));
641 flushAsynchronousOperations();
642 assert.isTrue(fireActionStub.calledWith('/', deleteAction, false));
643 });
644
Kasper Nilsson414ba692017-05-16 11:03:22 -0700645 test('hides delete confirm on cancel', () => {
Wyatt Allen5ccad3a2017-01-25 12:08:59 -0800646 element._handleDeleteTap();
Viktar Donichbcd44b12016-11-07 15:50:11 -0800647 MockInteractions.tap(
648 element.$$('#confirmDeleteDialog').$$('gr-button:not([primary])'));
649 flushAsynchronousOperations();
650 assert.isTrue(element.$$('#confirmDeleteDialog').hidden);
651 assert.isFalse(fireActionStub.called);
652 });
653 });
Viktar Donich50e2c002016-11-11 14:41:24 -0800654
Kasper Nilsson414ba692017-05-16 11:03:22 -0700655 suite('ignore change', () => {
656 setup(done => {
657 sandbox.stub(element, '_fireAction');
Paladox none92ac5192017-04-29 14:19:48 +0000658
Kasper Nilsson414ba692017-05-16 11:03:22 -0700659 const IgnoreAction = {
Paladox none92ac5192017-04-29 14:19:48 +0000660 __key: 'ignore',
661 __type: 'change',
662 __primary: false,
663 method: 'PUT',
664 label: 'Ignore',
665 title: 'Working...',
666 enabled: true,
667 };
668
669 element.actions = {
670 ignore: IgnoreAction,
671 };
672
673 element.changeNum = '2';
674 element.patchNum = '2';
675
Kasper Nilsson414ba692017-05-16 11:03:22 -0700676 element.reload().then(() => {flush(done);});
Paladox none92ac5192017-04-29 14:19:48 +0000677 });
678
679 test('make sure the ignore button is not outside of the overflow menu',
Kasper Nilsson414ba692017-05-16 11:03:22 -0700680 () => {
681 assert.isNotOk(element.$$('[data-action-key="ignore"]'));
682 });
Paladox none92ac5192017-04-29 14:19:48 +0000683
Kasper Nilsson414ba692017-05-16 11:03:22 -0700684 test('ignoring change', () => {
Paladox none92ac5192017-04-29 14:19:48 +0000685 assert.isOk(element.$.moreActions.$$('span[data-id="ignore-change"]'));
686 element.setActionOverflow('change', 'ignore', false);
687 flushAsynchronousOperations();
688 assert.isOk(element.$$('[data-action-key="ignore"]'));
689 assert.isNotOk(
690 element.$.moreActions.$$('span[data-id="ignore-change"]'));
691 });
692 });
693
Kasper Nilsson414ba692017-05-16 11:03:22 -0700694 suite('unignore change', () => {
695 setup(done => {
696 sandbox.stub(element, '_fireAction');
Paladox none92ac5192017-04-29 14:19:48 +0000697
Kasper Nilsson414ba692017-05-16 11:03:22 -0700698 const UnignoreAction = {
Paladox none92ac5192017-04-29 14:19:48 +0000699 __key: 'unignore',
700 __type: 'change',
701 __primary: false,
702 method: 'PUT',
703 label: 'Unignore',
704 title: 'Working...',
705 enabled: true,
706 };
707
708 element.actions = {
709 unignore: UnignoreAction,
710 };
711
712 element.changeNum = '2';
713 element.patchNum = '2';
714
Kasper Nilsson414ba692017-05-16 11:03:22 -0700715 element.reload().then(() => {flush(done);});
Paladox none92ac5192017-04-29 14:19:48 +0000716 });
717
718
Kasper Nilsson414ba692017-05-16 11:03:22 -0700719 test('unignore button is not outside of the overflow menu', () => {
Paladox none92ac5192017-04-29 14:19:48 +0000720 assert.isNotOk(element.$$('[data-action-key="unignore"]'));
721 });
722
Kasper Nilsson414ba692017-05-16 11:03:22 -0700723 test('unignoring change', () => {
Paladox none92ac5192017-04-29 14:19:48 +0000724 assert.isOk(
Kasper Nilsson414ba692017-05-16 11:03:22 -0700725 element.$.moreActions.$$('span[data-id="unignore-change"]'));
Paladox none92ac5192017-04-29 14:19:48 +0000726 element.setActionOverflow('change', 'unignore', false);
727 flushAsynchronousOperations();
728 assert.isOk(element.$$('[data-action-key="unignore"]'));
729 assert.isNotOk(
Kasper Nilsson414ba692017-05-16 11:03:22 -0700730 element.$.moreActions.$$('span[data-id="unignore-change"]'));
Paladox none92ac5192017-04-29 14:19:48 +0000731 });
732 });
733
Paladox none288f57c2017-05-11 14:46:39 +0000734 suite('mute change', () => {
735 setup(done => {
736 sandbox.stub(element, '_fireAction');
737
738 const MuteAction = {
739 __key: 'mute',
740 __type: 'change',
741 __primary: false,
742 method: 'PUT',
743 label: 'Mute',
744 title: 'Working...',
745 enabled: true,
746 };
747
748 element.actions = {
749 mute: MuteAction,
750 };
751
752 element.changeNum = '2';
753 element.patchNum = '2';
754
755 element.reload().then(() => {flush(done);});
756 });
757
758 test('make sure the mute button is not outside of the overflow menu',
759 () => {
760 assert.isNotOk(element.$$('[data-action-key="mute"]'));
761 });
762
763 test('muting change', () => {
764 assert.isOk(element.$.moreActions.$$('span[data-id="mute-change"]'));
765 element.setActionOverflow('change', 'mute', false);
766 flushAsynchronousOperations();
767 assert.isOk(element.$$('[data-action-key="mute"]'));
768 assert.isNotOk(
769 element.$.moreActions.$$('span[data-id="mute-change"]'));
770 });
771 });
772
773 suite('unmute change', () => {
774 setup(done => {
775 sandbox.stub(element, '_fireAction');
776
777 const UnmuteAction = {
778 __key: 'unmute',
779 __type: 'change',
780 __primary: false,
781 method: 'PUT',
782 label: 'Unmute',
783 title: 'Working...',
784 enabled: true,
785 };
786
787 element.actions = {
788 unmute: UnmuteAction,
789 };
790
791 element.changeNum = '2';
792 element.patchNum = '2';
793
794 element.reload().then(() => {flush(done);});
795 });
796
797
798 test('unmute button not outside of the overflow menu', () => {
799 assert.isNotOk(element.$$('[data-action-key="unmute"]'));
800 });
801
802 test('unmuting change', () => {
803 assert.isOk(
804 element.$.moreActions.$$('span[data-id="unmute-change"]'));
805 element.setActionOverflow('change', 'unmute', false);
806 flushAsynchronousOperations();
807 assert.isOk(element.$$('[data-action-key="unmute"]'));
808 assert.isNotOk(
809 element.$.moreActions.$$('span[data-id="unmute-change"]'));
810 });
811 });
812
Kasper Nilsson414ba692017-05-16 11:03:22 -0700813 suite('quick approve', () => {
814 setup(() => {
Viktar Donich50e2c002016-11-11 14:41:24 -0800815 element.change = {
816 current_revision: 'abc1234',
817 };
818 element.change = {
819 current_revision: 'abc1234',
820 labels: {
Viktar Donich07130562016-12-06 11:21:39 -0800821 foo: {
822 values: {
823 '-1': '',
824 ' 0': '',
825 '+1': '',
826 },
827 },
Viktar Donich50e2c002016-11-11 14:41:24 -0800828 },
829 permitted_labels: {
Viktar Donich07130562016-12-06 11:21:39 -0800830 foo: ['-1', ' 0', '+1'],
Viktar Donich50e2c002016-11-11 14:41:24 -0800831 },
832 };
833 flushAsynchronousOperations();
834 });
835
Kasper Nilsson414ba692017-05-16 11:03:22 -0700836 test('added when can approve', () => {
837 const approveButton =
838 element.$$('gr-button[data-action-key=\'review\']');
Viktar Donich50e2c002016-11-11 14:41:24 -0800839 assert.isNotNull(approveButton);
840 });
841
Kasper Nilsson414ba692017-05-16 11:03:22 -0700842 test('is first in list of actions', () => {
843 const approveButton = element.$$('gr-button');
Viktar Donicheadec2e2016-11-29 15:46:17 -0800844 assert.equal(approveButton.getAttribute('data-label'), 'foo+1');
Viktar Donich50e2c002016-11-11 14:41:24 -0800845 });
846
Kasper Nilsson414ba692017-05-16 11:03:22 -0700847 test('not added when already approved', () => {
Viktar Donich50e2c002016-11-11 14:41:24 -0800848 element.change = {
849 current_revision: 'abc1234',
850 labels: {
Viktar Donicheadec2e2016-11-29 15:46:17 -0800851 foo: {
Viktar Donich50e2c002016-11-11 14:41:24 -0800852 approved: {},
Viktar Donich07130562016-12-06 11:21:39 -0800853 values: {},
Viktar Donich50e2c002016-11-11 14:41:24 -0800854 },
855 },
856 permitted_labels: {
Viktar Donich07130562016-12-06 11:21:39 -0800857 foo: [' 0', '+1'],
Viktar Donich50e2c002016-11-11 14:41:24 -0800858 },
859 };
860 flushAsynchronousOperations();
Kasper Nilsson414ba692017-05-16 11:03:22 -0700861 const approveButton =
862 element.$$('gr-button[data-action-key=\'review\']');
Viktar Donich50e2c002016-11-11 14:41:24 -0800863 assert.isNull(approveButton);
864 });
865
Kasper Nilsson414ba692017-05-16 11:03:22 -0700866 test('not added when label not permitted', () => {
Viktar Donich50e2c002016-11-11 14:41:24 -0800867 element.change = {
868 current_revision: 'abc1234',
869 labels: {
Viktar Donich07130562016-12-06 11:21:39 -0800870 foo: {values: {}},
Viktar Donich50e2c002016-11-11 14:41:24 -0800871 },
872 permitted_labels: {
Viktar Donicheadec2e2016-11-29 15:46:17 -0800873 bar: [],
Viktar Donich50e2c002016-11-11 14:41:24 -0800874 },
875 };
876 flushAsynchronousOperations();
Kasper Nilsson414ba692017-05-16 11:03:22 -0700877 const approveButton =
878 element.$$('gr-button[data-action-key=\'review\']');
Viktar Donich50e2c002016-11-11 14:41:24 -0800879 assert.isNull(approveButton);
880 });
881
Paladox none288f57c2017-05-11 14:46:39 +0000882 test('approves when tapped', () => {
Kasper Nilsson414ba692017-05-16 11:03:22 -0700883 const fireActionStub = sandbox.stub(element, '_fireAction');
Viktar Donich50e2c002016-11-11 14:41:24 -0800884 MockInteractions.tap(
885 element.$$('gr-button[data-action-key=\'review\']'));
886 flushAsynchronousOperations();
887 assert.isTrue(fireActionStub.called);
888 assert.isTrue(fireActionStub.calledWith('/review'));
Kasper Nilsson414ba692017-05-16 11:03:22 -0700889 const payload = fireActionStub.lastCall.args[3];
Viktar Donich50e2c002016-11-11 14:41:24 -0800890 assert.deepEqual(payload.labels, {foo: '+1'});
Viktar Donich50e2c002016-11-11 14:41:24 -0800891 });
Viktar Donicheadec2e2016-11-29 15:46:17 -0800892
Kasper Nilsson414ba692017-05-16 11:03:22 -0700893 test('not added when multiple labels are required', () => {
Viktar Donicheadec2e2016-11-29 15:46:17 -0800894 element.change = {
895 current_revision: 'abc1234',
896 labels: {
Viktar Donich07130562016-12-06 11:21:39 -0800897 foo: {values: {}},
898 bar: {values: {}},
Viktar Donicheadec2e2016-11-29 15:46:17 -0800899 },
900 permitted_labels: {
901 foo: [' 0', '+1'],
902 bar: [' 0', '+1', '+2'],
903 },
904 };
905 flushAsynchronousOperations();
Kasper Nilsson414ba692017-05-16 11:03:22 -0700906 const approveButton =
907 element.$$('gr-button[data-action-key=\'review\']');
Viktar Donich07130562016-12-06 11:21:39 -0800908 assert.isNull(approveButton);
Viktar Donicheadec2e2016-11-29 15:46:17 -0800909 });
910
Kasper Nilsson414ba692017-05-16 11:03:22 -0700911 test('button label for missing approval', () => {
Viktar Donicheadec2e2016-11-29 15:46:17 -0800912 element.change = {
913 current_revision: 'abc1234',
914 labels: {
Viktar Donich07130562016-12-06 11:21:39 -0800915 foo: {
916 values: {
917 ' 0': '',
918 '+1': '',
919 },
920 },
921 bar: {approved: {}, values: {}},
Viktar Donicheadec2e2016-11-29 15:46:17 -0800922 },
923 permitted_labels: {
924 foo: [' 0', '+1'],
925 bar: [' 0', '+1', '+2'],
926 },
927 };
928 flushAsynchronousOperations();
Kasper Nilsson414ba692017-05-16 11:03:22 -0700929 const approveButton =
930 element.$$('gr-button[data-action-key=\'review\']');
Viktar Donicheadec2e2016-11-29 15:46:17 -0800931 assert.equal(approveButton.getAttribute('data-label'), 'foo+1');
932 });
933
Kasper Nilsson414ba692017-05-16 11:03:22 -0700934 test('no quick approve if score is not maximal for a label', () => {
Viktar Donicheadec2e2016-11-29 15:46:17 -0800935 element.change = {
936 current_revision: 'abc1234',
937 labels: {
Viktar Donich07130562016-12-06 11:21:39 -0800938 bar: {
939 value: 1,
940 values: {
941 ' 0': '',
942 '+1': '',
943 '+2': '',
944 },
945 },
Viktar Donicheadec2e2016-11-29 15:46:17 -0800946 },
947 permitted_labels: {
948 bar: [' 0', '+1'],
949 },
950 };
951 flushAsynchronousOperations();
Kasper Nilsson414ba692017-05-16 11:03:22 -0700952 const approveButton =
953 element.$$('gr-button[data-action-key=\'review\']');
Viktar Donicheadec2e2016-11-29 15:46:17 -0800954 assert.isNull(approveButton);
955 });
956
Kasper Nilsson414ba692017-05-16 11:03:22 -0700957 test('approving label with a non-max score', () => {
Viktar Donicheadec2e2016-11-29 15:46:17 -0800958 element.change = {
959 current_revision: 'abc1234',
960 labels: {
Viktar Donich07130562016-12-06 11:21:39 -0800961 bar: {
962 value: 1,
963 values: {
964 ' 0': '',
965 '+1': '',
966 '+2': '',
967 },
968 },
Viktar Donicheadec2e2016-11-29 15:46:17 -0800969 },
970 permitted_labels: {
971 bar: [' 0', '+1', '+2'],
972 },
973 };
974 flushAsynchronousOperations();
Kasper Nilsson414ba692017-05-16 11:03:22 -0700975 const approveButton =
976 element.$$('gr-button[data-action-key=\'review\']');
Viktar Donicheadec2e2016-11-29 15:46:17 -0800977 assert.equal(approveButton.getAttribute('data-label'), 'bar+2');
978 });
Viktar Donich50e2c002016-11-11 14:41:24 -0800979 });
Viktar Donich44e2ccd2017-04-17 10:58:12 -0700980
Kasper Nilsson414ba692017-05-16 11:03:22 -0700981 test('adds download revision action', () => {
982 const handler = sandbox.stub();
Kasper Nilssonf6c0b502017-04-25 10:45:28 +0200983 element.addEventListener('download-tap', handler);
984 assert.ok(element.revisionActions.download);
985 element._handleDownloadTap();
986 flushAsynchronousOperations();
987
988 assert.isTrue(handler.called);
989 });
990
Kasper Nilsson414ba692017-05-16 11:03:22 -0700991 suite('setActionOverflow', () => {
992 test('move action from overflow', () => {
Viktar Donich44e2ccd2017-04-17 10:58:12 -0700993 assert.isNotOk(element.$$('[data-action-key="cherrypick"]'));
994 assert.strictEqual(
995 element.$.moreActions.items[0].id, 'cherrypick-revision');
996 element.setActionOverflow('revision', 'cherrypick', false);
997 flushAsynchronousOperations();
998 assert.isOk(element.$$('[data-action-key="cherrypick"]'));
999 assert.notEqual(
1000 element.$.moreActions.items[0].id, 'cherrypick-revision');
1001 });
1002
Kasper Nilsson414ba692017-05-16 11:03:22 -07001003 test('move action to overflow', () => {
Viktar Donich44e2ccd2017-04-17 10:58:12 -07001004 assert.isOk(element.$$('[data-action-key="submit"]'));
1005 element.setActionOverflow('revision', 'submit', true);
1006 flushAsynchronousOperations();
1007 assert.isNotOk(element.$$('[data-action-key="submit"]'));
1008 assert.strictEqual(
Kasper Nilssonf6c0b502017-04-25 10:45:28 +02001009 element.$.moreActions.items[4].id, 'submit-revision');
Viktar Donich44e2ccd2017-04-17 10:58:12 -07001010 });
1011 });
Andrew Bonventre8f46e032016-01-07 16:38:37 -05001012 });
1013</script>