blob: 000718bcb1f25483325cdf15fcd7c3d9d27b830f [file] [log] [blame]
Becky Siegelf5d2e882016-11-16 12:59:59 -08001<!DOCTYPE html>
2<!--
Dave Borowitz8cdc76b2018-03-26 10:04:27 -04003@license
Becky Siegelf5d2e882016-11-16 12:59:59 -08004Copyright (C) 2016 The Android Open Source Project
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations 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 Zhoud90e7f42020-04-29 17:07:14 +020020<meta charset="utf-8">
Becky Siegelf5d2e882016-11-16 12:59:59 -080021<title>gr-confirm-cherrypick-dialog</title>
Tao Zhou8ef16f72019-11-18 14:14:36 -080022
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010023<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
Becky Siegelf5d2e882016-11-16 12:59:59 -080024
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010025<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
26<script src="/components/wct-browser-legacy/browser.js"></script>
Viktar Donich29e1ce52017-03-28 17:02:44 -070027
Becky Siegelf5d2e882016-11-16 12:59:59 -080028<test-fixture id="basic">
29 <template>
30 <gr-confirm-cherrypick-dialog></gr-confirm-cherrypick-dialog>
31 </template>
32</test-fixture>
33
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010034<script type="module">
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010035import '../../../test/common-test-setup.js';
36import './gr-confirm-cherrypick-dialog.js';
Dhruv Srivastavabab00cf2020-03-19 12:11:50 +010037
38const CHERRY_PICK_TYPES = {
39 SINGLE_CHANGE: 1,
40 TOPIC: 2,
41};
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010042suite('gr-confirm-cherrypick-dialog tests', () => {
43 let element;
44 let sandbox;
Becky Siegelf5d2e882016-11-16 12:59:59 -080045
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010046 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 Siegelf5d2e882016-11-16 12:59:59 -080062 });
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010063 element = fixture('basic');
64 element.project = 'test-project';
65 });
Becky Siegelf5d2e882016-11-16 12:59:59 -080066
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010067 teardown(() => { sandbox.restore(); });
Kasper Nilssonf9270422017-10-16 16:39:35 -070068
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010069 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 Siegelf5d2e882016-11-16 12:59:59 -080078
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010079 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 Siegel013648f2017-03-10 14:19:08 -080088
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010089 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 none4fb23472017-07-11 23:05:25 +000099
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +0100100 test('_getProjectBranchesSuggestions empty', done => {
101 element._getProjectBranchesSuggestions('nonexistent').then(branches => {
102 assert.equal(branches.length, 0);
103 done();
Paladox none4fb23472017-07-11 23:05:25 +0000104 });
Becky Siegelf5d2e882016-11-16 12:59:59 -0800105 });
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +0100106
Dhruv Srivastavabab00cf2020-03-19 12:11:50 +0100107 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 Srivastava45b1ff82020-04-08 13:41:27 +0200146 assert.isTrue(args[4].allow_empty);
Dhruv Srivastavabab00cf2020-03-19 12:11:50 +0100147 done();
148 });
149 });
150
Dhruv Srivastavae81b9092020-04-07 11:57:52 +0200151 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 Srivastavabab00cf2020-03-19 12:11:50 +0100158 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 Filippovdaf0ec92020-03-17 11:27:28 +0100171 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 Siegelf5d2e882016-11-16 12:59:59 -0800185</script>