Becky Siegel | f5d2e88 | 2016-11-16 12:59:59 -0800 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 3 | @license |
Becky Siegel | f5d2e88 | 2016-11-16 12:59:59 -0800 | [diff] [blame] | 4 | Copyright (C) 2016 The Android Open Source Project |
| 5 | |
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | you may not use this file except in compliance with the License. |
| 8 | You may obtain a copy of the License at |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 12 | Unless required by applicable law or agreed to in writing, software |
| 13 | distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | See the License for the specific language governing permissions and |
| 16 | limitations under the License. |
| 17 | --> |
| 18 | |
| 19 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> |
Tao Zhou | d90e7f4 | 2020-04-29 17:07:14 +0200 | [diff] [blame] | 20 | <meta charset="utf-8"> |
Becky Siegel | f5d2e88 | 2016-11-16 12:59:59 -0800 | [diff] [blame] | 21 | <title>gr-confirm-cherrypick-dialog</title> |
Tao Zhou | 8ef16f7 | 2019-11-18 14:14:36 -0800 | [diff] [blame] | 22 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 23 | <script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script> |
Becky Siegel | f5d2e88 | 2016-11-16 12:59:59 -0800 | [diff] [blame] | 24 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 25 | <script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script> |
| 26 | <script src="/components/wct-browser-legacy/browser.js"></script> |
Viktar Donich | 29e1ce5 | 2017-03-28 17:02:44 -0700 | [diff] [blame] | 27 | |
Becky Siegel | f5d2e88 | 2016-11-16 12:59:59 -0800 | [diff] [blame] | 28 | <test-fixture id="basic"> |
| 29 | <template> |
| 30 | <gr-confirm-cherrypick-dialog></gr-confirm-cherrypick-dialog> |
| 31 | </template> |
| 32 | </test-fixture> |
| 33 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 34 | <script type="module"> |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 35 | import '../../../test/common-test-setup.js'; |
| 36 | import './gr-confirm-cherrypick-dialog.js'; |
Dhruv Srivastava | bab00cf | 2020-03-19 12:11:50 +0100 | [diff] [blame] | 37 | |
| 38 | const CHERRY_PICK_TYPES = { |
| 39 | SINGLE_CHANGE: 1, |
| 40 | TOPIC: 2, |
| 41 | }; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 42 | suite('gr-confirm-cherrypick-dialog tests', () => { |
| 43 | let element; |
| 44 | let sandbox; |
Becky Siegel | f5d2e88 | 2016-11-16 12:59:59 -0800 | [diff] [blame] | 45 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 46 | setup(() => { |
| 47 | sandbox = sinon.sandbox.create(); |
| 48 | stub('gr-rest-api-interface', { |
| 49 | getRepoBranches(input) { |
| 50 | if (input.startsWith('test')) { |
| 51 | return Promise.resolve([ |
| 52 | { |
| 53 | ref: 'refs/heads/test-branch', |
| 54 | revision: '67ebf73496383c6777035e374d2d664009e2aa5c', |
| 55 | can_delete: true, |
| 56 | }, |
| 57 | ]); |
| 58 | } else { |
| 59 | return Promise.resolve({}); |
| 60 | } |
| 61 | }, |
Becky Siegel | f5d2e88 | 2016-11-16 12:59:59 -0800 | [diff] [blame] | 62 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 63 | element = fixture('basic'); |
| 64 | element.project = 'test-project'; |
| 65 | }); |
Becky Siegel | f5d2e88 | 2016-11-16 12:59:59 -0800 | [diff] [blame] | 66 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 67 | teardown(() => { sandbox.restore(); }); |
Kasper Nilsson | f927042 | 2017-10-16 16:39:35 -0700 | [diff] [blame] | 68 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 69 | test('with merged change', () => { |
| 70 | element.changeStatus = 'MERGED'; |
| 71 | element.commitMessage = 'message\n'; |
| 72 | element.commitNum = '123'; |
| 73 | element.branch = 'master'; |
| 74 | flushAsynchronousOperations(); |
| 75 | const expectedMessage = 'message\n(cherry picked from commit 123)'; |
| 76 | assert.equal(element.message, expectedMessage); |
| 77 | }); |
Becky Siegel | f5d2e88 | 2016-11-16 12:59:59 -0800 | [diff] [blame] | 78 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 79 | test('with unmerged change', () => { |
| 80 | element.changeStatus = 'OPEN'; |
| 81 | element.commitMessage = 'message\n'; |
| 82 | element.commitNum = '123'; |
| 83 | element.branch = 'master'; |
| 84 | flushAsynchronousOperations(); |
| 85 | const expectedMessage = 'message\n'; |
| 86 | assert.equal(element.message, expectedMessage); |
| 87 | }); |
Becky Siegel | 013648f | 2017-03-10 14:19:08 -0800 | [diff] [blame] | 88 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 89 | test('with updated commit message', () => { |
| 90 | element.changeStatus = 'OPEN'; |
| 91 | element.commitMessage = 'message\n'; |
| 92 | element.commitNum = '123'; |
| 93 | element.branch = 'master'; |
| 94 | const myNewMessage = 'updated commit message'; |
| 95 | element.message = myNewMessage; |
| 96 | flushAsynchronousOperations(); |
| 97 | assert.equal(element.message, myNewMessage); |
| 98 | }); |
Paladox none | 4fb2347 | 2017-07-11 23:05:25 +0000 | [diff] [blame] | 99 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 100 | test('_getProjectBranchesSuggestions empty', done => { |
| 101 | element._getProjectBranchesSuggestions('nonexistent').then(branches => { |
| 102 | assert.equal(branches.length, 0); |
| 103 | done(); |
Paladox none | 4fb2347 | 2017-07-11 23:05:25 +0000 | [diff] [blame] | 104 | }); |
Becky Siegel | f5d2e88 | 2016-11-16 12:59:59 -0800 | [diff] [blame] | 105 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 106 | |
Dhruv Srivastava | bab00cf | 2020-03-19 12:11:50 +0100 | [diff] [blame] | 107 | suite('cherry pick topic', () => { |
| 108 | const changes = [ |
| 109 | { |
| 110 | change_id: '12345678901234', topic: 'T', subject: 'random', |
| 111 | project: 'A', |
| 112 | _number: 1, |
| 113 | revisions: { |
| 114 | a: {_number: 1}, |
| 115 | }, |
| 116 | current_revision: 'a', |
| 117 | }, |
| 118 | { |
| 119 | change_id: '23456', topic: 'T', subject: 'a'.repeat(100), |
| 120 | project: 'B', |
| 121 | _number: 2, |
| 122 | revisions: { |
| 123 | a: {_number: 1}, |
| 124 | }, |
| 125 | current_revision: 'a', |
| 126 | }, |
| 127 | ]; |
| 128 | setup(() => { |
| 129 | element.updateChanges(changes); |
| 130 | element._cherryPickType = CHERRY_PICK_TYPES.TOPIC; |
| 131 | }); |
| 132 | |
| 133 | test('cherry pick topic submit', done => { |
| 134 | element.branch = 'master'; |
| 135 | const executeChangeActionStub = sandbox.stub(element.$.restAPI, |
| 136 | 'executeChangeAction').returns(Promise.resolve([])); |
| 137 | MockInteractions.tap(element.shadowRoot. |
| 138 | querySelector('gr-dialog').$.confirm); |
| 139 | flush(() => { |
| 140 | const args = executeChangeActionStub.args[0]; |
| 141 | assert.equal(args[0], 1); |
| 142 | assert.equal(args[1], 'POST'); |
| 143 | assert.equal(args[2], '/cherrypick'); |
| 144 | assert.equal(args[4].destination, 'master'); |
| 145 | assert.isTrue(args[4].allow_conflicts); |
Dhruv Srivastava | 45b1ff8 | 2020-04-08 13:41:27 +0200 | [diff] [blame] | 146 | assert.isTrue(args[4].allow_empty); |
Dhruv Srivastava | bab00cf | 2020-03-19 12:11:50 +0100 | [diff] [blame] | 147 | done(); |
| 148 | }); |
| 149 | }); |
| 150 | |
Dhruv Srivastava | e81b909 | 2020-04-07 11:57:52 +0200 | [diff] [blame] | 151 | test('_computeStatusClass', () => { |
| 152 | assert.equal(element._computeStatusClass({id: 1}, {1: {status: 'RUNNING'}, |
| 153 | }), ''); |
| 154 | assert.equal(element._computeStatusClass({id: 1}, {1: {status: 'FAILED'}} |
| 155 | ), 'error'); |
| 156 | }); |
| 157 | |
Dhruv Srivastava | bab00cf | 2020-03-19 12:11:50 +0100 | [diff] [blame] | 158 | test('submit button is blocked while cherry picks is running', done => { |
| 159 | console.log(element); |
| 160 | const confirmButton = element.shadowRoot.querySelector('gr-dialog').$ |
| 161 | .confirm; |
| 162 | assert.isFalse(confirmButton.hasAttribute('disabled')); |
| 163 | element.updateStatus(changes[0], {status: 'RUNNING'}); |
| 164 | flush(() => { |
| 165 | assert.isTrue(confirmButton.hasAttribute('disabled')); |
| 166 | done(); |
| 167 | }); |
| 168 | }); |
| 169 | }); |
| 170 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 171 | test('resetFocus', () => { |
| 172 | const focusStub = sandbox.stub(element.$.branchInput, 'focus'); |
| 173 | element.resetFocus(); |
| 174 | assert.isTrue(focusStub.called); |
| 175 | }); |
| 176 | |
| 177 | test('_getProjectBranchesSuggestions non-empty', done => { |
| 178 | element._getProjectBranchesSuggestions('test-branch').then(branches => { |
| 179 | assert.equal(branches.length, 1); |
| 180 | assert.equal(branches[0].name, 'test-branch'); |
| 181 | done(); |
| 182 | }); |
| 183 | }); |
| 184 | }); |
Becky Siegel | f5d2e88 | 2016-11-16 12:59:59 -0800 | [diff] [blame] | 185 | </script> |