blob: 37da30200f3fad7f556d707510d917a5ea8aa2dc [file] [log] [blame] [edit]
<!DOCTYPE html>
<!--
@license
Copyright (C) 2020 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<meta name="viewport"
content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<meta charset="utf-8">
<title>gr-simple-submit-rules-repo-config</title>
<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
<script src="../bower_components/web-component-tester/browser.js"></script>
<test-fixture id="basic">
<template>
<gr-simple-submit-rules-repo-config repo-name="test-repo"></gr-simple-submit-rules-repo-config>
</template>
</test-fixture>
<script type="module">
import '../test/common-test-setup.js';
import '../test/gr-select.js';
import "./gr-simple-submit-rules-repo-config.js";
suite('gr-simple-submit-rules-repo-config tests', () => {
let element;
let sandbox;
let unresolvedCommentsEl;
setup(() => {
sandbox = sinon.sandbox.create();
stub('gr-simple-submit-rules-repo-config', {
_pluginRestApi() {
return {
get(url) {
return Promise.resolve({
comments: {
block_if_unresolved_comments: false,
},
labels: {},
});
},
getLoggedIn() { return Promise.resolve(true); },
};
},
_getRepoAccess(repoName) {
return Promise.resolve({
'test-repo': {
is_owner: true,
},
});
},
});
element = fixture('basic');
unresolvedCommentsEl = element.shadowRoot.querySelector('#unresolved_comments select');
return element._loadRepo();
});
teardown(() => {
sandbox.restore();
});
test('unresolved comments option exists', () => {
const unresolvedCommentsEl = element.shadowRoot.querySelector('#unresolved_comments');
assert.ok(unresolvedCommentsEl);
});
test('readOnly disables fields', () => {
element._readOnly = false;
assert.equal(unresolvedCommentsEl.disabled, false);
element._readOnly = true;
assert.equal(unresolvedCommentsEl.disabled, true);
});
test('adds a label element', done => {
element.set(['_repoConfig', 'labels', 'Verified'], {
function: 'MaxNoBlock',
copy_scores: [],
});
flush(() => {
const labelItems = element.shadowRoot.querySelectorAll('gr-simple-submit-rules-label-config');
assert.ok(labelItems);
assert.equal(labelItems.length, 1);
const labelEl = labelItems[0];
assert.ok(labelEl);
assert.equal(labelEl.labelName, 'Verified');
assert.equal(labelEl.readOnly, false);
done();
});
});
test('adds two labels elements', done => {
element.set(['_repoConfig', 'labels', 'Verified'], {
function: 'MaxNoBlock',
copy_scores: [],
});
element.set(['_repoConfig', 'labels', 'Code-Review'], {
function: 'MaxNoBlock',
copy_scores: [],
});
flush(() => {
const labelItems = element.shadowRoot.querySelectorAll('gr-simple-submit-rules-label-config');
assert.equal(labelItems.length, 2);
done();
});
});
test('unresolved comment uses the repoConfig value (false)', done => {
element.set('_repoConfig.comments.block_if_unresolved_comments', false);
flush(() => {
assert.equal(unresolvedCommentsEl.value, 'false');
done();
});
});
test('unresolved comment uses the repoConfig value (true)', done => {
element.set('_repoConfig.comments.block_if_unresolved_comments', true);
flush(() => {
assert.equal(unresolvedCommentsEl.value, 'true');
done();
});
});
test('unresolved comment sets the repoConfig value (true)', done => {
unresolvedCommentsEl.value = 'true';
element.shadowRoot.querySelector('#blockOnUnresolvedComments').dispatchEvent(new Event('change'));
flush(() => {
assert.equal(element._repoConfig.comments.block_if_unresolved_comments, 'true');
done();
});
});
test('unresolved comment sets the repoConfig value (false)', done => {
unresolvedCommentsEl.value = 'false';
element.shadowRoot.querySelector('#blockOnUnresolvedComments').dispatchEvent(new Event('change'));
flush(() => {
assert.equal(element._repoConfig.comments.block_if_unresolved_comments, 'false');
done();
});
});
});
</script>