blob: 3f96aacbaf5df76fb0baca1f61555df2b52d0c06 [file] [log] [blame]
<!DOCTYPE html>
<!--
@license
Copyright (C) 2016 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">
<title>gr-simple-submit-rules-repo-config</title>
<script src="../../../polygerrit-ui/app/bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../polygerrit-ui/app/bower_components/web-component-tester/browser.js"></script>
<link rel="import"
href="../../../polygerrit-ui/app/test/common-test-setup.html" />
<!-- TODO(maximeg) find if there is a better way to do this, like .. not in tests -->
<link rel="import"
href="../../../polygerrit-ui/app/elements/shared/gr-select/gr-select.html" />
<link rel="import"
href="../../../polygerrit-ui/app/styles/shared-styles.html" />
<link rel="import"
href="../../../polygerrit-ui/app/styles/gr-form-styles.html" />
<link rel="import"
href="gr-simple-submit-rules-repo-config.html">
<script>void (0);</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>
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.$$('#unresolved_comments select');
return element._loadRepo();
});
teardown(() => {
sandbox.restore();
});
test('unresolved comments option exists', () => {
const unresolvedCommentsEl = element.$$('#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(function () {
let labelItems = element.querySelectorAll('gr-simple-submit-rules-label-config');
assert.ok(labelItems);
assert.equal(labelItems.length, 1);
let 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(function () {
let labelItems = element.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(function () {
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(function () {
assert.equal(unresolvedCommentsEl.value, 'true');
done();
});
});
test('unresolved comment sets the repoConfig value (true)', done => {
unresolvedCommentsEl.value = 'true';
element.$$('#blockOnUnresolvedComments').dispatchEvent(new Event('change'));
flush(function () {
assert.equal(element._repoConfig.comments.block_if_unresolved_comments, 'true');
done();
});
});
test('unresolved comment sets the repoConfig value (false)', done => {
unresolvedCommentsEl.value = 'false';
element.$$('#blockOnUnresolvedComments').dispatchEvent(new Event('change'));
flush(function () {
assert.equal(element._repoConfig.comments.block_if_unresolved_comments, 'false');
done();
});
});
});
</script>