Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | Copyright (C) 2016 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-actions</title> |
| 20 | |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 21 | <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 Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 24 | |
Andrew Bonventre | 78792e8 | 2016-03-04 17:48:22 -0500 | [diff] [blame] | 25 | <link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html"> |
| 26 | <link rel="import" href="gr-change-actions.html"> |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 27 | |
Viktar Donich | 29e1ce5 | 2017-03-28 17:02:44 -0700 | [diff] [blame] | 28 | <script>void(0);</script> |
| 29 | |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 30 | <test-fixture id="basic"> |
| 31 | <template> |
| 32 | <gr-change-actions></gr-change-actions> |
| 33 | </template> |
| 34 | </test-fixture> |
| 35 | |
| 36 | <script> |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 37 | suite('gr-change-actions tests', () => { |
| 38 | let element; |
| 39 | let sandbox; |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 40 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 41 | setup(() => { |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 42 | stub('gr-rest-api-interface', { |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 43 | getChangeRevisionActions() { |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 44 | return Promise.resolve({ |
Andrew Bonventre | e073fa9 | 2016-09-20 16:50:33 -0400 | [diff] [blame] | 45 | '/': { |
| 46 | method: 'DELETE', |
| 47 | label: 'Delete', |
| 48 | title: 'Delete draft revision 2', |
Andrew Bonventre | 43e35b9 | 2016-09-21 15:18:28 -0400 | [diff] [blame] | 49 | enabled: true, |
Andrew Bonventre | e073fa9 | 2016-09-20 16:50:33 -0400 | [diff] [blame] | 50 | }, |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 51 | 'cherrypick': { |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 52 | method: 'POST', |
| 53 | label: 'Cherry Pick', |
| 54 | title: 'Cherry pick change to a different branch', |
Andrew Bonventre | 43e35b9 | 2016-09-21 15:18:28 -0400 | [diff] [blame] | 55 | enabled: true, |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 56 | }, |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 57 | 'rebase': { |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 58 | method: 'POST', |
| 59 | label: 'Rebase', |
Andrew Bonventre | 43e35b9 | 2016-09-21 15:18:28 -0400 | [diff] [blame] | 60 | title: 'Rebase onto tip of branch or parent change', |
| 61 | enabled: true, |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 62 | }, |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 63 | 'submit': { |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 64 | method: 'POST', |
| 65 | label: 'Submit', |
Andrew Bonventre | e073fa9 | 2016-09-20 16:50:33 -0400 | [diff] [blame] | 66 | title: 'Submit patch set 2 into master', |
Andrew Bonventre | 43e35b9 | 2016-09-21 15:18:28 -0400 | [diff] [blame] | 67 | enabled: true, |
Andrew Bonventre | e073fa9 | 2016-09-20 16:50:33 -0400 | [diff] [blame] | 68 | }, |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 69 | }); |
| 70 | }, |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 71 | send(method, url, payload) { |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 72 | if (method !== 'POST') { return Promise.reject('bad method'); } |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 73 | |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 74 | if (url === '/changes/42/revisions/2/submit') { |
| 75 | return Promise.resolve({ |
| 76 | ok: true, |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 77 | text() { return Promise.resolve(')]}\'\n{}'); }, |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 78 | }); |
| 79 | } else if (url === '/changes/42/revisions/2/rebase') { |
| 80 | return Promise.resolve({ |
| 81 | ok: true, |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 82 | text() { return Promise.resolve(')]}\'\n{}'); }, |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 83 | }); |
| 84 | } |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 85 | |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 86 | return Promise.reject('bad url'); |
| 87 | }, |
Urs Wolfer | f531d0a | 2016-03-12 12:48:10 +0100 | [diff] [blame] | 88 | }); |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 89 | |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 90 | element = fixture('basic'); |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 91 | element.change = {}; |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 92 | element.changeNum = '42'; |
| 93 | element.patchNum = '2'; |
Andrew Bonventre | e073fa9 | 2016-09-20 16:50:33 -0400 | [diff] [blame] | 94 | element.actions = { |
| 95 | '/': { |
| 96 | method: 'DELETE', |
| 97 | label: 'Delete', |
| 98 | title: 'Delete draft change 42', |
Kasper Nilsson | df696b4 | 2017-01-19 13:15:12 -0800 | [diff] [blame] | 99 | enabled: true, |
Andrew Bonventre | e073fa9 | 2016-09-20 16:50:33 -0400 | [diff] [blame] | 100 | }, |
| 101 | }; |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 102 | sandbox = sinon.sandbox.create(); |
| 103 | |
Viktar Donich | 853e142 | 2016-04-25 11:30:42 -0700 | [diff] [blame] | 104 | return element.reload(); |
Andrew Bonventre | 57fbfa8 | 2016-03-14 20:38:56 -0400 | [diff] [blame] | 105 | }); |
| 106 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 107 | teardown(() => { |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 108 | sandbox.restore(); |
| 109 | }); |
| 110 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 111 | test('_shouldHideActions', () => { |
Wyatt Allen | a9807e4 | 2017-01-25 11:29:35 -0800 | [diff] [blame] | 112 | assert.isTrue(element._shouldHideActions(undefined, true)); |
| 113 | assert.isTrue(element._shouldHideActions({base: {}}, false)); |
| 114 | assert.isFalse(element._shouldHideActions({base: ['test']}, false)); |
Kasper Nilsson | df696b4 | 2017-01-19 13:15:12 -0800 | [diff] [blame] | 115 | }); |
| 116 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 117 | test('hide revision action', done => { |
| 118 | flush(() => { |
| 119 | const buttonEl = element.$$('[data-action-key="submit"]'); |
Andrew Bonventre | c4249c3 | 2016-10-12 14:22:25 -0700 | [diff] [blame] | 120 | assert.isOk(buttonEl); |
Andrew Bonventre | c4249c3 | 2016-10-12 14:22:25 -0700 | [diff] [blame] | 121 | assert.throws(element.setActionHidden.bind(element, 'invalid type')); |
| 122 | element.setActionHidden(element.ActionType.REVISION, |
| 123 | element.RevisionActions.SUBMIT, true); |
Wyatt Allen | a9807e4 | 2017-01-25 11:29:35 -0800 | [diff] [blame] | 124 | assert.lengthOf(element._hiddenActions, 1); |
Andrew Bonventre | c4249c3 | 2016-10-12 14:22:25 -0700 | [diff] [blame] | 125 | element.setActionHidden(element.ActionType.REVISION, |
| 126 | element.RevisionActions.SUBMIT, true); |
Wyatt Allen | a9807e4 | 2017-01-25 11:29:35 -0800 | [diff] [blame] | 127 | assert.lengthOf(element._hiddenActions, 1); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 128 | flush(() => { |
| 129 | const buttonEl = element.$$('[data-action-key="submit"]'); |
Wyatt Allen | 89842ab | 2017-01-30 12:34:14 -0800 | [diff] [blame] | 130 | assert.isNotOk(buttonEl); |
Andrew Bonventre | c4249c3 | 2016-10-12 14:22:25 -0700 | [diff] [blame] | 131 | |
| 132 | element.setActionHidden(element.ActionType.REVISION, |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 133 | element.RevisionActions.SUBMIT, false); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 134 | flush(() => { |
| 135 | const buttonEl = element.$$('[data-action-key="submit"]'); |
Andrew Bonventre | c4249c3 | 2016-10-12 14:22:25 -0700 | [diff] [blame] | 136 | assert.isOk(buttonEl); |
| 137 | assert.isFalse(buttonEl.hasAttribute('hidden')); |
| 138 | done(); |
| 139 | }); |
| 140 | }); |
| 141 | }); |
| 142 | }); |
| 143 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 144 | test('hide menu action', done => { |
| 145 | flush(() => { |
| 146 | const buttonEl = |
Viktar Donich | 44e2ccd | 2017-04-17 10:58:12 -0700 | [diff] [blame] | 147 | element.$.moreActions.$$('span[data-id="delete-revision"]'); |
Andrew Bonventre | c4249c3 | 2016-10-12 14:22:25 -0700 | [diff] [blame] | 148 | assert.isOk(buttonEl); |
Andrew Bonventre | c4249c3 | 2016-10-12 14:22:25 -0700 | [diff] [blame] | 149 | assert.throws(element.setActionHidden.bind(element, 'invalid type')); |
| 150 | element.setActionHidden(element.ActionType.CHANGE, |
| 151 | element.ChangeActions.DELETE, true); |
Wyatt Allen | a9807e4 | 2017-01-25 11:29:35 -0800 | [diff] [blame] | 152 | assert.lengthOf(element._hiddenActions, 1); |
Andrew Bonventre | c4249c3 | 2016-10-12 14:22:25 -0700 | [diff] [blame] | 153 | element.setActionHidden(element.ActionType.CHANGE, |
| 154 | element.ChangeActions.DELETE, true); |
Wyatt Allen | a9807e4 | 2017-01-25 11:29:35 -0800 | [diff] [blame] | 155 | assert.lengthOf(element._hiddenActions, 1); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 156 | flush(() => { |
| 157 | const buttonEl = |
Viktar Donich | 44e2ccd | 2017-04-17 10:58:12 -0700 | [diff] [blame] | 158 | element.$.moreActions.$$('span[data-id="delete-revision"]'); |
Wyatt Allen | 5ccad3a | 2017-01-25 12:08:59 -0800 | [diff] [blame] | 159 | assert.isNotOk(buttonEl); |
Andrew Bonventre | c4249c3 | 2016-10-12 14:22:25 -0700 | [diff] [blame] | 160 | |
| 161 | element.setActionHidden(element.ActionType.CHANGE, |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 162 | element.RevisionActions.DELETE, false); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 163 | flush(() => { |
| 164 | const buttonEl = |
Viktar Donich | 44e2ccd | 2017-04-17 10:58:12 -0700 | [diff] [blame] | 165 | element.$.moreActions.$$('span[data-id="delete-revision"]'); |
Andrew Bonventre | c4249c3 | 2016-10-12 14:22:25 -0700 | [diff] [blame] | 166 | assert.isOk(buttonEl); |
Andrew Bonventre | c4249c3 | 2016-10-12 14:22:25 -0700 | [diff] [blame] | 167 | done(); |
| 168 | }); |
| 169 | }); |
| 170 | }); |
| 171 | }); |
| 172 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 173 | test('buttons exist', done => { |
Kasper Nilsson | df696b4 | 2017-01-19 13:15:12 -0800 | [diff] [blame] | 174 | element._loading = false; |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 175 | flush(() => { |
| 176 | const buttonEls = Polymer.dom(element.root) |
Kasper Nilsson | df696b4 | 2017-01-19 13:15:12 -0800 | [diff] [blame] | 177 | .querySelectorAll('gr-button'); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 178 | const menuItems = element.$.moreActions.items; |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 179 | assert.equal(buttonEls.length + menuItems.length, 7); |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 180 | assert.isFalse(element.hidden); |
| 181 | done(); |
Urs Wolfer | b603694 | 2016-03-06 14:57:02 +0100 | [diff] [blame] | 182 | }); |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 183 | }); |
| 184 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 185 | test('delete buttons have explicit labels', done => { |
| 186 | flush(() => { |
| 187 | const deleteItems = element.$.moreActions.items.filter(item => { |
| 188 | return item.id.startsWith('delete'); |
Wyatt Allen | 5ccad3a | 2017-01-25 12:08:59 -0800 | [diff] [blame] | 189 | }); |
| 190 | assert.equal(deleteItems.length, 2); |
Wyatt Allen | 89842ab | 2017-01-30 12:34:14 -0800 | [diff] [blame] | 191 | assert.notEqual(deleteItems[0].name, deleteItems[1].name); |
Andrew Bonventre | e073fa9 | 2016-09-20 16:50:33 -0400 | [diff] [blame] | 192 | assert.isTrue( |
Wyatt Allen | 5ccad3a | 2017-01-25 12:08:59 -0800 | [diff] [blame] | 193 | deleteItems[0].name === 'Delete Revision' || |
| 194 | deleteItems[0].name === 'Delete Change' |
Andrew Bonventre | e073fa9 | 2016-09-20 16:50:33 -0400 | [diff] [blame] | 195 | ); |
| 196 | assert.isTrue( |
Wyatt Allen | 5ccad3a | 2017-01-25 12:08:59 -0800 | [diff] [blame] | 197 | deleteItems[1].name === 'Delete Revision' || |
| 198 | deleteItems[1].name === 'Delete Change' |
Andrew Bonventre | e073fa9 | 2016-09-20 16:50:33 -0400 | [diff] [blame] | 199 | ); |
| 200 | done(); |
| 201 | }); |
| 202 | }); |
| 203 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 204 | test('get revision object from change', () => { |
| 205 | const revObj = {_number: 2, foo: 'bar'}; |
| 206 | const change = { |
Andrew Bonventre | a5ee85c | 2016-10-05 10:47:40 -0700 | [diff] [blame] | 207 | revisions: { |
| 208 | rev1: {_number: 1}, |
| 209 | rev2: revObj, |
| 210 | }, |
| 211 | }; |
| 212 | assert.deepEqual(element._getRevision(change, '2'), revObj); |
| 213 | }); |
| 214 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 215 | test('_actionComparator sort order', () => { |
| 216 | const actions = [ |
Wyatt Allen | 9a70d98 | 2017-01-27 12:02:10 -0800 | [diff] [blame] | 217 | {label: '123', __type: 'change', __key: 'review'}, |
Viktar Donich | 7f412ae | 2017-04-18 16:08:13 -0700 | [diff] [blame] | 218 | {label: 'abc-ro', __type: 'revision'}, |
Wyatt Allen | 9a70d98 | 2017-01-27 12:02:10 -0800 | [diff] [blame] | 219 | {label: 'abc', __type: 'change'}, |
| 220 | {label: 'def', __type: 'change'}, |
Viktar Donich | 7f412ae | 2017-04-18 16:08:13 -0700 | [diff] [blame] | 221 | {label: 'def-p', __type: 'change', __primary: true}, |
Wyatt Allen | a9807e4 | 2017-01-25 11:29:35 -0800 | [diff] [blame] | 222 | ]; |
Wyatt Allen | 9a70d98 | 2017-01-27 12:02:10 -0800 | [diff] [blame] | 223 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 224 | const result = actions.slice(); |
Wyatt Allen | 9a70d98 | 2017-01-27 12:02:10 -0800 | [diff] [blame] | 225 | result.reverse(); |
Viktar Donich | 7f412ae | 2017-04-18 16:08:13 -0700 | [diff] [blame] | 226 | result.sort(element._actionComparator.bind(element)); |
Wyatt Allen | a9807e4 | 2017-01-25 11:29:35 -0800 | [diff] [blame] | 227 | assert.deepEqual(result, actions); |
| 228 | }); |
| 229 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 230 | test('submit change', done => { |
Wyatt Allen | 6cf5875 | 2017-04-24 16:59:07 +0200 | [diff] [blame] | 231 | sandbox.stub(element, 'fetchIsLatestKnown', |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 232 | () => { return Promise.resolve(true); }); |
Andrew Bonventre | a5ee85c | 2016-10-05 10:47:40 -0700 | [diff] [blame] | 233 | element.change = { |
| 234 | revisions: { |
| 235 | rev1: {_number: 1}, |
| 236 | rev2: {_number: 2}, |
| 237 | }, |
| 238 | }; |
| 239 | element.patchNum = '2'; |
| 240 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 241 | flush(() => { |
| 242 | const submitButton = element.$$('gr-button[data-action-key="submit"]'); |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 243 | assert.ok(submitButton); |
| 244 | MockInteractions.tap(submitButton); |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 245 | |
| 246 | // Upon success it should fire the reload-change event. |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 247 | element.addEventListener('reload-change', () => { |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 248 | done(); |
| 249 | }); |
Urs Wolfer | b603694 | 2016-03-06 14:57:02 +0100 | [diff] [blame] | 250 | }); |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 251 | }); |
Andrew Bonventre | 81170c6 | 2016-02-10 11:48:37 -0500 | [diff] [blame] | 252 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 253 | test('submit change with plugin hook', done => { |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 254 | sandbox.stub(element, '_canSubmitChange', |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 255 | () => { return false; }); |
| 256 | const fireActionStub = sandbox.stub(element, '_fireAction'); |
| 257 | flush(() => { |
| 258 | const submitButton = element.$$('gr-button[data-action-key="submit"]'); |
Andrew Bonventre | d2b9043 | 2016-03-29 14:12:33 -0400 | [diff] [blame] | 259 | assert.ok(submitButton); |
| 260 | MockInteractions.tap(submitButton); |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 261 | assert.equal(fireActionStub.callCount, 0); |
Andrew Bonventre | d2b9043 | 2016-03-29 14:12:33 -0400 | [diff] [blame] | 262 | |
Andrew Bonventre | d2b9043 | 2016-03-29 14:12:33 -0400 | [diff] [blame] | 263 | done(); |
| 264 | }); |
| 265 | }); |
| 266 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 267 | test('chain state', () => { |
Becky Siegel | 61ecc0c | 2017-02-15 11:32:21 -0800 | [diff] [blame] | 268 | assert.equal(element._hasKnownChainState, false); |
| 269 | element.hasParent = true; |
| 270 | assert.equal(element._hasKnownChainState, true); |
| 271 | element.hasParent = false; |
| 272 | }); |
| 273 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 274 | test('_calculateDisabled', () => { |
| 275 | let hasKnownChainState = false; |
| 276 | const action = {__key: 'rebase', enabled: true}; |
Becky Siegel | 61ecc0c | 2017-02-15 11:32:21 -0800 | [diff] [blame] | 277 | 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 Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 294 | test('rebase change', done => { |
| 295 | const fireActionStub = sandbox.stub(element, '_fireAction'); |
| 296 | flush(() => { |
| 297 | const rebaseButton = element.$$('gr-button[data-action-key="rebase"]'); |
Andrew Bonventre | 81170c6 | 2016-02-10 11:48:37 -0500 | [diff] [blame] | 298 | MockInteractions.tap(rebaseButton); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 299 | const rebaseAction = { |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 300 | __key: 'rebase', |
| 301 | __type: 'revision', |
Andrew Bonventre | 4117ea4 | 2016-06-15 14:35:55 -0700 | [diff] [blame] | 302 | __primary: false, |
Andrew Bonventre | 43e35b9 | 2016-09-21 15:18:28 -0400 | [diff] [blame] | 303 | enabled: true, |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 304 | label: 'Rebase', |
| 305 | method: 'POST', |
| 306 | title: 'Rebase onto tip of branch or parent change', |
| 307 | }; |
Becky Siegel | 61ecc0c | 2017-02-15 11:32:21 -0800 | [diff] [blame] | 308 | // rebase on other |
Andrew Bonventre | 81170c6 | 2016-02-10 11:48:37 -0500 | [diff] [blame] | 309 | element.$.confirmRebase.base = '1234'; |
| 310 | element._handleRebaseConfirm(); |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 311 | assert.deepEqual(fireActionStub.lastCall.args, |
| 312 | ['/rebase', rebaseAction, true, {base: '1234'}]); |
Andrew Bonventre | 81170c6 | 2016-02-10 11:48:37 -0500 | [diff] [blame] | 313 | |
Becky Siegel | 61ecc0c | 2017-02-15 11:32:21 -0800 | [diff] [blame] | 314 | // rebase on parent |
| 315 | element.$.confirmRebase.base = null; |
Andrew Bonventre | 81170c6 | 2016-02-10 11:48:37 -0500 | [diff] [blame] | 316 | element._handleRebaseConfirm(); |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 317 | assert.deepEqual(fireActionStub.lastCall.args, |
Becky Siegel | 61ecc0c | 2017-02-15 11:32:21 -0800 | [diff] [blame] | 318 | ['/rebase', rebaseAction, true, {base: null}]); |
Andrew Bonventre | 81170c6 | 2016-02-10 11:48:37 -0500 | [diff] [blame] | 319 | |
Becky Siegel | 61ecc0c | 2017-02-15 11:32:21 -0800 | [diff] [blame] | 320 | // rebase on tip |
| 321 | element.$.confirmRebase.base = ''; |
Andrew Bonventre | 81170c6 | 2016-02-10 11:48:37 -0500 | [diff] [blame] | 322 | element._handleRebaseConfirm(); |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 323 | assert.deepEqual(fireActionStub.lastCall.args, |
| 324 | ['/rebase', rebaseAction, true, {base: ''}]); |
Andrew Bonventre | 81170c6 | 2016-02-10 11:48:37 -0500 | [diff] [blame] | 325 | |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 326 | done(); |
Urs Wolfer | b603694 | 2016-03-06 14:57:02 +0100 | [diff] [blame] | 327 | }); |
Andrew Bonventre | 81170c6 | 2016-02-10 11:48:37 -0500 | [diff] [blame] | 328 | }); |
| 329 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 330 | test('two dialogs are not shown at the same time', done => { |
Becky Siegel | 61ecc0c | 2017-02-15 11:32:21 -0800 | [diff] [blame] | 331 | element._hasKnownChainState = true; |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 332 | flush(() => { |
| 333 | const rebaseButton = element.$$('gr-button[data-action-key="rebase"]'); |
Andrew Bonventre | 43e35b9 | 2016-09-21 15:18:28 -0400 | [diff] [blame] | 334 | assert.ok(rebaseButton); |
| 335 | MockInteractions.tap(rebaseButton); |
| 336 | flushAsynchronousOperations(); |
| 337 | assert.isFalse(element.$.confirmRebase.hidden); |
| 338 | |
Wyatt Allen | 5ccad3a | 2017-01-25 12:08:59 -0800 | [diff] [blame] | 339 | element._handleCherrypickTap(); |
Andrew Bonventre | 43e35b9 | 2016-09-21 15:18:28 -0400 | [diff] [blame] | 340 | flushAsynchronousOperations(); |
| 341 | assert.isTrue(element.$.confirmRebase.hidden); |
| 342 | assert.isFalse(element.$.confirmCherrypick.hidden); |
| 343 | done(); |
| 344 | }); |
| 345 | }); |
| 346 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 347 | suite('cherry-pick', () => { |
| 348 | let fireActionStub; |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 349 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 350 | setup(() => { |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 351 | fireActionStub = sandbox.stub(element, '_fireAction'); |
| 352 | sandbox.stub(window, 'alert'); |
Viktar Donich | 853e142 | 2016-04-25 11:30:42 -0700 | [diff] [blame] | 353 | }); |
| 354 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 355 | test('works', () => { |
Wyatt Allen | 5ccad3a | 2017-01-25 12:08:59 -0800 | [diff] [blame] | 356 | element._handleCherrypickTap(); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 357 | const action = { |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 358 | __key: 'cherrypick', |
| 359 | __type: 'revision', |
Andrew Bonventre | 4117ea4 | 2016-06-15 14:35:55 -0700 | [diff] [blame] | 360 | __primary: false, |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 361 | 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 Siegel | 4872199 | 2016-11-30 15:33:19 -0800 | [diff] [blame] | 374 | // 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 Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 379 | element._handleCherrypickConfirm(); |
| 380 | |
Becky Siegel | 4872199 | 2016-11-30 15:33:19 -0800 | [diff] [blame] | 381 | assert.equal(element.$.confirmCherrypick.$.messageInput.value, |
Viktar Donich | c503679 | 2016-12-02 15:38:19 -0800 | [diff] [blame] | 382 | 'foo message'); |
Becky Siegel | 4872199 | 2016-11-30 15:33:19 -0800 | [diff] [blame] | 383 | |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 384 | assert.deepEqual(fireActionStub.lastCall.args, [ |
| 385 | '/cherrypick', action, true, { |
| 386 | destination: 'master', |
| 387 | message: 'foo message', |
Kasper Nilsson | df696b4 | 2017-01-19 13:15:12 -0800 | [diff] [blame] | 388 | }, |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 389 | ]); |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 390 | }); |
Becky Siegel | 5755ef9 | 2016-10-03 11:43:18 -0700 | [diff] [blame] | 391 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 392 | test('branch name cleared when re-open cherrypick', () => { |
| 393 | const emptyBranchName = ''; |
Becky Siegel | 5755ef9 | 2016-10-03 11:43:18 -0700 | [diff] [blame] | 394 | element.$.confirmCherrypick.branch = 'master'; |
| 395 | |
Wyatt Allen | 5ccad3a | 2017-01-25 12:08:59 -0800 | [diff] [blame] | 396 | element._handleCherrypickTap(); |
Becky Siegel | 5755ef9 | 2016-10-03 11:43:18 -0700 | [diff] [blame] | 397 | assert.equal(element.$.confirmCherrypick.branch, emptyBranchName); |
| 398 | }); |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 399 | }); |
| 400 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 401 | test('custom actions', done => { |
Andrew Bonventre | cd73e96 | 2016-06-22 17:52:56 -0400 | [diff] [blame] | 402 | // Add a button with the same key as a server-based one to ensure |
| 403 | // collisions are taken care of. |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 404 | const key = element.addActionButton(element.ActionType.REVISION, 'Bork!'); |
| 405 | element.addEventListener(key + '-tap', e => { |
Andrew Bonventre | cd73e96 | 2016-06-22 17:52:56 -0400 | [diff] [blame] | 406 | assert.equal(e.detail.node.getAttribute('data-action-key'), key); |
| 407 | element.removeActionButton(key); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 408 | flush(() => { |
Andrew Bonventre | cd73e96 | 2016-06-22 17:52:56 -0400 | [diff] [blame] | 409 | assert.notOk(element.$$('[data-action-key="' + key + '"]')); |
| 410 | done(); |
| 411 | }); |
| 412 | }); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 413 | flush(() => { |
Andrew Bonventre | cd73e96 | 2016-06-22 17:52:56 -0400 | [diff] [blame] | 414 | MockInteractions.tap(element.$$('[data-action-key="' + key + '"]')); |
| 415 | }); |
| 416 | }); |
| 417 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 418 | test('_setLoadingOnButtonWithKey top-level', () => { |
| 419 | const key = 'rebase'; |
| 420 | const type = 'revision'; |
| 421 | const cleanup = element._setLoadingOnButtonWithKey(type, key); |
Wyatt Allen | 89842ab | 2017-01-30 12:34:14 -0800 | [diff] [blame] | 422 | assert.equal(element._actionLoadingMessage, 'Rebasing...'); |
Wyatt Allen | cf44a38 | 2017-01-27 13:53:58 -0800 | [diff] [blame] | 423 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 424 | const button = element.$$('[data-action-key="' + key + '"]'); |
Wyatt Allen | cf44a38 | 2017-01-27 13:53:58 -0800 | [diff] [blame] | 425 | 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 Allen | 89842ab | 2017-01-30 12:34:14 -0800 | [diff] [blame] | 434 | assert.isNotOk(element._actionLoadingMessage); |
Wyatt Allen | cf44a38 | 2017-01-27 13:53:58 -0800 | [diff] [blame] | 435 | }); |
| 436 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 437 | test('_setLoadingOnButtonWithKey overflow menu', () => { |
| 438 | const key = 'cherrypick'; |
| 439 | const type = 'revision'; |
| 440 | const cleanup = element._setLoadingOnButtonWithKey(type, key); |
Wyatt Allen | dee92f7 | 2017-02-08 14:25:04 -0800 | [diff] [blame] | 441 | assert.equal(element._actionLoadingMessage, 'Cherry-Picking...'); |
| 442 | assert.include(element._disabledMenuActions, 'cherrypick'); |
Wyatt Allen | cf44a38 | 2017-01-27 13:53:58 -0800 | [diff] [blame] | 443 | assert.isFunction(cleanup); |
Wyatt Allen | dee92f7 | 2017-02-08 14:25:04 -0800 | [diff] [blame] | 444 | |
| 445 | cleanup(); |
| 446 | |
| 447 | assert.notOk(element._actionLoadingMessage); |
| 448 | assert.notInclude(element._disabledMenuActions, 'cherrypick'); |
Wyatt Allen | cf44a38 | 2017-01-27 13:53:58 -0800 | [diff] [blame] | 449 | }); |
| 450 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 451 | suite('revert change', () => { |
| 452 | let alertStub; |
| 453 | let fireActionStub; |
Andrew Bonventre | 1508cac | 2016-04-02 21:37:15 -0400 | [diff] [blame] | 454 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 455 | setup(() => { |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 456 | fireActionStub = sandbox.stub(element, '_fireAction'); |
| 457 | alertStub = sandbox.stub(window, 'alert'); |
Viktar Donich | 853e142 | 2016-04-25 11:30:42 -0700 | [diff] [blame] | 458 | element.actions = { |
| 459 | revert: { |
| 460 | method: 'POST', |
| 461 | label: 'Revert', |
| 462 | title: 'Revert the change', |
Kasper Nilsson | df696b4 | 2017-01-19 13:15:12 -0800 | [diff] [blame] | 463 | enabled: true, |
| 464 | }, |
Viktar Donich | 853e142 | 2016-04-25 11:30:42 -0700 | [diff] [blame] | 465 | }; |
| 466 | return element.reload(); |
| 467 | }); |
| 468 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 469 | test('revert change with plugin hook', done => { |
Ravi Mistry | 95b96f8 | 2016-10-10 14:04:17 -0400 | [diff] [blame] | 470 | element.change = { |
| 471 | current_revision: 'abc1234', |
| 472 | }; |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 473 | const newRevertMsg = 'Modified revert msg'; |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 474 | sandbox.stub(element, '_modifyRevertMsg', |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 475 | () => { return newRevertMsg; }); |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 476 | sandbox.stub(element.$.confirmRevertDialog, 'populateRevertMessage', |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 477 | () => { return 'original msg'; }); |
| 478 | flush(() => { |
| 479 | const revertButton = |
| 480 | element.$$('gr-button[data-action-key="revert"]'); |
Ravi Mistry | 7d64e78 | 2016-08-02 07:48:45 -0400 | [diff] [blame] | 481 | MockInteractions.tap(revertButton); |
| 482 | |
| 483 | assert.equal(element.$.confirmRevertDialog.message, newRevertMsg); |
Ravi Mistry | 7d64e78 | 2016-08-02 07:48:45 -0400 | [diff] [blame] | 484 | done(); |
| 485 | }); |
| 486 | }); |
| 487 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 488 | test('works', () => { |
Ravi Mistry | 95b96f8 | 2016-10-10 14:04:17 -0400 | [diff] [blame] | 489 | element.change = { |
| 490 | current_revision: 'abc1234', |
| 491 | }; |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 492 | sandbox.stub(element.$.confirmRevertDialog, 'populateRevertMessage', |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 493 | () => { return 'original msg'; }); |
| 494 | const revertButton = element.$$('gr-button[data-action-key="revert"]'); |
Viktar Donich | 853e142 | 2016-04-25 11:30:42 -0700 | [diff] [blame] | 495 | MockInteractions.tap(revertButton); |
| 496 | |
| 497 | element.$.confirmRevertDialog.message = 'foo message'; |
| 498 | element._handleRevertDialogConfirm(); |
| 499 | assert.notOk(alertStub.called); |
| 500 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 501 | const action = { |
Viktar Donich | 853e142 | 2016-04-25 11:30:42 -0700 | [diff] [blame] | 502 | __key: 'revert', |
| 503 | __type: 'change', |
Andrew Bonventre | 4117ea4 | 2016-06-15 14:35:55 -0700 | [diff] [blame] | 504 | __primary: false, |
Viktar Donich | 853e142 | 2016-04-25 11:30:42 -0700 | [diff] [blame] | 505 | 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 Donich | bcd44b1 | 2016-11-07 15:50:11 -0800 | [diff] [blame] | 516 | |
Paladox none | 1f6008b | 2017-04-19 21:42:54 +0000 | [diff] [blame] | 517 | 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 Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 611 | suite('delete change', () => { |
| 612 | let fireActionStub; |
| 613 | let deleteAction; |
Viktar Donich | bcd44b1 | 2016-11-07 15:50:11 -0800 | [diff] [blame] | 614 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 615 | setup(() => { |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 616 | fireActionStub = sandbox.stub(element, '_fireAction'); |
Viktar Donich | bcd44b1 | 2016-11-07 15:50:11 -0800 | [diff] [blame] | 617 | 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 Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 631 | test('does not delete on action', () => { |
Wyatt Allen | 5ccad3a | 2017-01-25 12:08:59 -0800 | [diff] [blame] | 632 | element._handleDeleteTap(); |
Viktar Donich | bcd44b1 | 2016-11-07 15:50:11 -0800 | [diff] [blame] | 633 | assert.isFalse(fireActionStub.called); |
| 634 | }); |
| 635 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 636 | test('shows confirm dialog', () => { |
Wyatt Allen | 5ccad3a | 2017-01-25 12:08:59 -0800 | [diff] [blame] | 637 | element._handleDeleteTap(); |
Viktar Donich | bcd44b1 | 2016-11-07 15:50:11 -0800 | [diff] [blame] | 638 | 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 Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 645 | test('hides delete confirm on cancel', () => { |
Wyatt Allen | 5ccad3a | 2017-01-25 12:08:59 -0800 | [diff] [blame] | 646 | element._handleDeleteTap(); |
Viktar Donich | bcd44b1 | 2016-11-07 15:50:11 -0800 | [diff] [blame] | 647 | 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 Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 654 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 655 | suite('ignore change', () => { |
| 656 | setup(done => { |
| 657 | sandbox.stub(element, '_fireAction'); |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 658 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 659 | const IgnoreAction = { |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 660 | __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 Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 676 | element.reload().then(() => {flush(done);}); |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 677 | }); |
| 678 | |
| 679 | test('make sure the ignore button is not outside of the overflow menu', |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 680 | () => { |
| 681 | assert.isNotOk(element.$$('[data-action-key="ignore"]')); |
| 682 | }); |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 683 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 684 | test('ignoring change', () => { |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 685 | 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 Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 694 | suite('unignore change', () => { |
| 695 | setup(done => { |
| 696 | sandbox.stub(element, '_fireAction'); |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 697 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 698 | const UnignoreAction = { |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 699 | __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 Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 715 | element.reload().then(() => {flush(done);}); |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 716 | }); |
| 717 | |
| 718 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 719 | test('unignore button is not outside of the overflow menu', () => { |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 720 | assert.isNotOk(element.$$('[data-action-key="unignore"]')); |
| 721 | }); |
| 722 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 723 | test('unignoring change', () => { |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 724 | assert.isOk( |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 725 | element.$.moreActions.$$('span[data-id="unignore-change"]')); |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 726 | element.setActionOverflow('change', 'unignore', false); |
| 727 | flushAsynchronousOperations(); |
| 728 | assert.isOk(element.$$('[data-action-key="unignore"]')); |
| 729 | assert.isNotOk( |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 730 | element.$.moreActions.$$('span[data-id="unignore-change"]')); |
Paladox none | 92ac519 | 2017-04-29 14:19:48 +0000 | [diff] [blame] | 731 | }); |
| 732 | }); |
| 733 | |
Paladox none | 288f57c | 2017-05-11 14:46:39 +0000 | [diff] [blame] | 734 | 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 Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 813 | suite('quick approve', () => { |
| 814 | setup(() => { |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 815 | element.change = { |
| 816 | current_revision: 'abc1234', |
| 817 | }; |
| 818 | element.change = { |
| 819 | current_revision: 'abc1234', |
| 820 | labels: { |
Viktar Donich | 0713056 | 2016-12-06 11:21:39 -0800 | [diff] [blame] | 821 | foo: { |
| 822 | values: { |
| 823 | '-1': '', |
| 824 | ' 0': '', |
| 825 | '+1': '', |
| 826 | }, |
| 827 | }, |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 828 | }, |
| 829 | permitted_labels: { |
Viktar Donich | 0713056 | 2016-12-06 11:21:39 -0800 | [diff] [blame] | 830 | foo: ['-1', ' 0', '+1'], |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 831 | }, |
| 832 | }; |
| 833 | flushAsynchronousOperations(); |
| 834 | }); |
| 835 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 836 | test('added when can approve', () => { |
| 837 | const approveButton = |
| 838 | element.$$('gr-button[data-action-key=\'review\']'); |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 839 | assert.isNotNull(approveButton); |
| 840 | }); |
| 841 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 842 | test('is first in list of actions', () => { |
| 843 | const approveButton = element.$$('gr-button'); |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 844 | assert.equal(approveButton.getAttribute('data-label'), 'foo+1'); |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 845 | }); |
| 846 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 847 | test('not added when already approved', () => { |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 848 | element.change = { |
| 849 | current_revision: 'abc1234', |
| 850 | labels: { |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 851 | foo: { |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 852 | approved: {}, |
Viktar Donich | 0713056 | 2016-12-06 11:21:39 -0800 | [diff] [blame] | 853 | values: {}, |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 854 | }, |
| 855 | }, |
| 856 | permitted_labels: { |
Viktar Donich | 0713056 | 2016-12-06 11:21:39 -0800 | [diff] [blame] | 857 | foo: [' 0', '+1'], |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 858 | }, |
| 859 | }; |
| 860 | flushAsynchronousOperations(); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 861 | const approveButton = |
| 862 | element.$$('gr-button[data-action-key=\'review\']'); |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 863 | assert.isNull(approveButton); |
| 864 | }); |
| 865 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 866 | test('not added when label not permitted', () => { |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 867 | element.change = { |
| 868 | current_revision: 'abc1234', |
| 869 | labels: { |
Viktar Donich | 0713056 | 2016-12-06 11:21:39 -0800 | [diff] [blame] | 870 | foo: {values: {}}, |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 871 | }, |
| 872 | permitted_labels: { |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 873 | bar: [], |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 874 | }, |
| 875 | }; |
| 876 | flushAsynchronousOperations(); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 877 | const approveButton = |
| 878 | element.$$('gr-button[data-action-key=\'review\']'); |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 879 | assert.isNull(approveButton); |
| 880 | }); |
| 881 | |
Paladox none | 288f57c | 2017-05-11 14:46:39 +0000 | [diff] [blame] | 882 | test('approves when tapped', () => { |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 883 | const fireActionStub = sandbox.stub(element, '_fireAction'); |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 884 | MockInteractions.tap( |
| 885 | element.$$('gr-button[data-action-key=\'review\']')); |
| 886 | flushAsynchronousOperations(); |
| 887 | assert.isTrue(fireActionStub.called); |
| 888 | assert.isTrue(fireActionStub.calledWith('/review')); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 889 | const payload = fireActionStub.lastCall.args[3]; |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 890 | assert.deepEqual(payload.labels, {foo: '+1'}); |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 891 | }); |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 892 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 893 | test('not added when multiple labels are required', () => { |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 894 | element.change = { |
| 895 | current_revision: 'abc1234', |
| 896 | labels: { |
Viktar Donich | 0713056 | 2016-12-06 11:21:39 -0800 | [diff] [blame] | 897 | foo: {values: {}}, |
| 898 | bar: {values: {}}, |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 899 | }, |
| 900 | permitted_labels: { |
| 901 | foo: [' 0', '+1'], |
| 902 | bar: [' 0', '+1', '+2'], |
| 903 | }, |
| 904 | }; |
| 905 | flushAsynchronousOperations(); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 906 | const approveButton = |
| 907 | element.$$('gr-button[data-action-key=\'review\']'); |
Viktar Donich | 0713056 | 2016-12-06 11:21:39 -0800 | [diff] [blame] | 908 | assert.isNull(approveButton); |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 909 | }); |
| 910 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 911 | test('button label for missing approval', () => { |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 912 | element.change = { |
| 913 | current_revision: 'abc1234', |
| 914 | labels: { |
Viktar Donich | 0713056 | 2016-12-06 11:21:39 -0800 | [diff] [blame] | 915 | foo: { |
| 916 | values: { |
| 917 | ' 0': '', |
| 918 | '+1': '', |
| 919 | }, |
| 920 | }, |
| 921 | bar: {approved: {}, values: {}}, |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 922 | }, |
| 923 | permitted_labels: { |
| 924 | foo: [' 0', '+1'], |
| 925 | bar: [' 0', '+1', '+2'], |
| 926 | }, |
| 927 | }; |
| 928 | flushAsynchronousOperations(); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 929 | const approveButton = |
| 930 | element.$$('gr-button[data-action-key=\'review\']'); |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 931 | assert.equal(approveButton.getAttribute('data-label'), 'foo+1'); |
| 932 | }); |
| 933 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 934 | test('no quick approve if score is not maximal for a label', () => { |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 935 | element.change = { |
| 936 | current_revision: 'abc1234', |
| 937 | labels: { |
Viktar Donich | 0713056 | 2016-12-06 11:21:39 -0800 | [diff] [blame] | 938 | bar: { |
| 939 | value: 1, |
| 940 | values: { |
| 941 | ' 0': '', |
| 942 | '+1': '', |
| 943 | '+2': '', |
| 944 | }, |
| 945 | }, |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 946 | }, |
| 947 | permitted_labels: { |
| 948 | bar: [' 0', '+1'], |
| 949 | }, |
| 950 | }; |
| 951 | flushAsynchronousOperations(); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 952 | const approveButton = |
| 953 | element.$$('gr-button[data-action-key=\'review\']'); |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 954 | assert.isNull(approveButton); |
| 955 | }); |
| 956 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 957 | test('approving label with a non-max score', () => { |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 958 | element.change = { |
| 959 | current_revision: 'abc1234', |
| 960 | labels: { |
Viktar Donich | 0713056 | 2016-12-06 11:21:39 -0800 | [diff] [blame] | 961 | bar: { |
| 962 | value: 1, |
| 963 | values: { |
| 964 | ' 0': '', |
| 965 | '+1': '', |
| 966 | '+2': '', |
| 967 | }, |
| 968 | }, |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 969 | }, |
| 970 | permitted_labels: { |
| 971 | bar: [' 0', '+1', '+2'], |
| 972 | }, |
| 973 | }; |
| 974 | flushAsynchronousOperations(); |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 975 | const approveButton = |
| 976 | element.$$('gr-button[data-action-key=\'review\']'); |
Viktar Donich | eadec2e | 2016-11-29 15:46:17 -0800 | [diff] [blame] | 977 | assert.equal(approveButton.getAttribute('data-label'), 'bar+2'); |
| 978 | }); |
Viktar Donich | 50e2c00 | 2016-11-11 14:41:24 -0800 | [diff] [blame] | 979 | }); |
Viktar Donich | 44e2ccd | 2017-04-17 10:58:12 -0700 | [diff] [blame] | 980 | |
Kasper Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 981 | test('adds download revision action', () => { |
| 982 | const handler = sandbox.stub(); |
Kasper Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 983 | 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 Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 991 | suite('setActionOverflow', () => { |
| 992 | test('move action from overflow', () => { |
Viktar Donich | 44e2ccd | 2017-04-17 10:58:12 -0700 | [diff] [blame] | 993 | 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 Nilsson | 414ba69 | 2017-05-16 11:03:22 -0700 | [diff] [blame] | 1003 | test('move action to overflow', () => { |
Viktar Donich | 44e2ccd | 2017-04-17 10:58:12 -0700 | [diff] [blame] | 1004 | 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 Nilsson | f6c0b50 | 2017-04-25 10:45:28 +0200 | [diff] [blame] | 1009 | element.$.moreActions.items[4].id, 'submit-revision'); |
Viktar Donich | 44e2ccd | 2017-04-17 10:58:12 -0700 | [diff] [blame] | 1010 | }); |
| 1011 | }); |
Andrew Bonventre | 8f46e03 | 2016-01-07 16:38:37 -0500 | [diff] [blame] | 1012 | }); |
| 1013 | </script> |