blob: 37da30200f3fad7f556d707510d917a5ea8aa2dc [file] [log] [blame]
Maxime Guerreiro0916fe52018-05-30 14:23:43 +00001<!DOCTYPE html>
2<!--
3@license
Tao Zhouae9c87a2020-06-15 19:16:56 +02004Copyright (C) 2020 The Android Open Source Project
Maxime Guerreiro0916fe52018-05-30 14:23:43 +00005
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"
20 content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
Tao Zhouae9c87a2020-06-15 19:16:56 +020021<meta charset="utf-8">
Maxime Guerreiro0916fe52018-05-30 14:23:43 +000022<title>gr-simple-submit-rules-repo-config</title>
23
Tao Zhouae9c87a2020-06-15 19:16:56 +020024<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
25<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
26<script src="../bower_components/web-component-tester/browser.js"></script>
Maxime Guerreiro0916fe52018-05-30 14:23:43 +000027
28<test-fixture id="basic">
29 <template>
30 <gr-simple-submit-rules-repo-config repo-name="test-repo"></gr-simple-submit-rules-repo-config>
31 </template>
32</test-fixture>
33
Tao Zhouae9c87a2020-06-15 19:16:56 +020034<script type="module">
35 import '../test/common-test-setup.js';
36 import '../test/gr-select.js';
37 import "./gr-simple-submit-rules-repo-config.js";
Maxime Guerreiro0916fe52018-05-30 14:23:43 +000038 suite('gr-simple-submit-rules-repo-config tests', () => {
39 let element;
40 let sandbox;
41 let unresolvedCommentsEl;
42
43 setup(() => {
44 sandbox = sinon.sandbox.create();
45
46 stub('gr-simple-submit-rules-repo-config', {
47 _pluginRestApi() {
48 return {
49 get(url) {
50 return Promise.resolve({
51 comments: {
52 block_if_unresolved_comments: false,
53 },
Maxime Guerreiroe1842a02018-07-26 13:52:00 +000054 labels: {},
Maxime Guerreiro0916fe52018-05-30 14:23:43 +000055 });
56 },
57 getLoggedIn() { return Promise.resolve(true); },
Tao Zhouae9c87a2020-06-15 19:16:56 +020058 };
Maxime Guerreiro0916fe52018-05-30 14:23:43 +000059 },
60
61 _getRepoAccess(repoName) {
62 return Promise.resolve({
63 'test-repo': {
64 is_owner: true,
65 },
66 });
67 },
68
69 });
70
71 element = fixture('basic');
Tao Zhouae9c87a2020-06-15 19:16:56 +020072 unresolvedCommentsEl = element.shadowRoot.querySelector('#unresolved_comments select');
Maxime Guerreiro0916fe52018-05-30 14:23:43 +000073 return element._loadRepo();
74 });
75
76 teardown(() => {
77 sandbox.restore();
78 });
79
80 test('unresolved comments option exists', () => {
Tao Zhouae9c87a2020-06-15 19:16:56 +020081 const unresolvedCommentsEl = element.shadowRoot.querySelector('#unresolved_comments');
Maxime Guerreiro0916fe52018-05-30 14:23:43 +000082 assert.ok(unresolvedCommentsEl);
83 });
84
85 test('readOnly disables fields', () => {
86 element._readOnly = false;
87 assert.equal(unresolvedCommentsEl.disabled, false);
88
89 element._readOnly = true;
90 assert.equal(unresolvedCommentsEl.disabled, true);
91 });
92
Maxime Guerreiroe1842a02018-07-26 13:52:00 +000093 test('adds a label element', done => {
94 element.set(['_repoConfig', 'labels', 'Verified'], {
95 function: 'MaxNoBlock',
Tao Zhouae9c87a2020-06-15 19:16:56 +020096 copy_scores: [],
Maxime Guerreiroe1842a02018-07-26 13:52:00 +000097 });
Tao Zhouae9c87a2020-06-15 19:16:56 +020098 flush(() => {
99 const labelItems = element.shadowRoot.querySelectorAll('gr-simple-submit-rules-label-config');
Maxime Guerreiroe1842a02018-07-26 13:52:00 +0000100 assert.ok(labelItems);
101 assert.equal(labelItems.length, 1);
102
Tao Zhouae9c87a2020-06-15 19:16:56 +0200103 const labelEl = labelItems[0];
Maxime Guerreiroe1842a02018-07-26 13:52:00 +0000104 assert.ok(labelEl);
105 assert.equal(labelEl.labelName, 'Verified');
106 assert.equal(labelEl.readOnly, false);
107 done();
108 });
109 });
110
111 test('adds two labels elements', done => {
112 element.set(['_repoConfig', 'labels', 'Verified'], {
113 function: 'MaxNoBlock',
Tao Zhouae9c87a2020-06-15 19:16:56 +0200114 copy_scores: [],
Maxime Guerreiroe1842a02018-07-26 13:52:00 +0000115 });
116
117 element.set(['_repoConfig', 'labels', 'Code-Review'], {
118 function: 'MaxNoBlock',
Tao Zhouae9c87a2020-06-15 19:16:56 +0200119 copy_scores: [],
Maxime Guerreiroe1842a02018-07-26 13:52:00 +0000120 });
121
Tao Zhouae9c87a2020-06-15 19:16:56 +0200122 flush(() => {
123 const labelItems = element.shadowRoot.querySelectorAll('gr-simple-submit-rules-label-config');
Maxime Guerreiroe1842a02018-07-26 13:52:00 +0000124 assert.equal(labelItems.length, 2);
125 done();
126 });
127 });
128
Maxime Guerreiro0916fe52018-05-30 14:23:43 +0000129 test('unresolved comment uses the repoConfig value (false)', done => {
130 element.set('_repoConfig.comments.block_if_unresolved_comments', false);
131
Tao Zhouae9c87a2020-06-15 19:16:56 +0200132 flush(() => {
Maxime Guerreiro0916fe52018-05-30 14:23:43 +0000133 assert.equal(unresolvedCommentsEl.value, 'false');
134 done();
135 });
136 });
137
138 test('unresolved comment uses the repoConfig value (true)', done => {
139 element.set('_repoConfig.comments.block_if_unresolved_comments', true);
140
Tao Zhouae9c87a2020-06-15 19:16:56 +0200141 flush(() => {
Maxime Guerreiro0916fe52018-05-30 14:23:43 +0000142 assert.equal(unresolvedCommentsEl.value, 'true');
143 done();
144 });
145 });
146
147 test('unresolved comment sets the repoConfig value (true)', done => {
148 unresolvedCommentsEl.value = 'true';
Tao Zhouae9c87a2020-06-15 19:16:56 +0200149 element.shadowRoot.querySelector('#blockOnUnresolvedComments').dispatchEvent(new Event('change'));
Maxime Guerreiro0916fe52018-05-30 14:23:43 +0000150
Tao Zhouae9c87a2020-06-15 19:16:56 +0200151 flush(() => {
Maxime Guerreiro0916fe52018-05-30 14:23:43 +0000152 assert.equal(element._repoConfig.comments.block_if_unresolved_comments, 'true');
153 done();
154 });
155 });
156
157 test('unresolved comment sets the repoConfig value (false)', done => {
158 unresolvedCommentsEl.value = 'false';
Tao Zhouae9c87a2020-06-15 19:16:56 +0200159 element.shadowRoot.querySelector('#blockOnUnresolvedComments').dispatchEvent(new Event('change'));
Maxime Guerreiro0916fe52018-05-30 14:23:43 +0000160
Tao Zhouae9c87a2020-06-15 19:16:56 +0200161 flush(() => {
Maxime Guerreiro0916fe52018-05-30 14:23:43 +0000162 assert.equal(element._repoConfig.comments.block_if_unresolved_comments, 'false');
163 done();
164 });
165 });
166 });
167</script>