Files
gerrit/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences_test.html
Thomas Draebing 6ff72df1ce Downport "Update eslint version and eslint rules"
Legacy indent rules doesn't handle all cases. As a result there are
different indents in .js files. This commit update eslint rules and add
autofix for incorrect indents. It is expected that fix should be run
after converting to class-based elements.

Change-Id: I844132280d3fcc6203777425316d8fb348e126c0
2019-12-27 11:56:58 +01:00

124 lines
4.3 KiB
HTML

<!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-diff-preferences</title>
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
<link rel="import" href="gr-diff-preferences.html">
<script>void(0);</script>
<test-fixture id="basic">
<template>
<gr-diff-preferences></gr-diff-preferences>
</template>
</test-fixture>
<script>
suite('gr-diff-preferences tests', () => {
let element;
let sandbox;
let diffPreferences;
function valueOf(title, fieldsetid) {
const sections = element.$[fieldsetid].querySelectorAll('section');
let titleEl;
for (let i = 0; i < sections.length; i++) {
titleEl = sections[i].querySelector('.title');
if (titleEl.textContent.trim() === title) {
return sections[i].querySelector('.value');
}
}
}
setup(() => {
diffPreferences = {
context: 10,
line_wrapping: false,
line_length: 100,
tab_size: 8,
font_size: 12,
show_tabs: true,
show_whitespace_errors: true,
syntax_highlighting: true,
manual_review: false,
ignore_whitespace: 'IGNORE_NONE',
};
stub('gr-rest-api-interface', {
getDiffPreferences() {
return Promise.resolve(diffPreferences);
},
});
element = fixture('basic');
sandbox = sinon.sandbox.create();
return element.loadData();
});
teardown(() => { sandbox.restore(); });
test('renders', () => {
// Rendered with the expected preferences selected.
assert.equal(valueOf('Context', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.context);
assert.equal(valueOf('Fit to screen', 'diffPreferences')
.firstElementChild.checked, diffPreferences.line_wrapping);
assert.equal(valueOf('Diff width', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.line_length);
assert.equal(valueOf('Tab width', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.tab_size);
assert.equal(valueOf('Font size', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.font_size);
assert.equal(valueOf('Show tabs', 'diffPreferences')
.firstElementChild.checked, diffPreferences.show_tabs);
assert.equal(valueOf('Show trailing whitespace', 'diffPreferences')
.firstElementChild.checked, diffPreferences.show_whitespace_errors);
assert.equal(valueOf('Syntax highlighting', 'diffPreferences')
.firstElementChild.checked, diffPreferences.syntax_highlighting);
assert.equal(
valueOf('Automatically mark viewed files reviewed', 'diffPreferences')
.firstElementChild.checked, !diffPreferences.manual_review);
assert.equal(valueOf('Ignore Whitespace', 'diffPreferences')
.firstElementChild.bindValue, diffPreferences.ignore_whitespace);
assert.isFalse(element.hasUnsavedChanges);
});
test('save changes', () => {
sandbox.stub(element.$.restAPI, 'saveDiffPreferences')
.returns(Promise.resolve());
const showTrailingWhitespaceCheckbox =
valueOf('Show trailing whitespace', 'diffPreferences')
.firstElementChild;
showTrailingWhitespaceCheckbox.checked = false;
element._handleShowTrailingWhitespaceTap();
assert.isTrue(element.hasUnsavedChanges);
// Save the change.
return element.save().then(() => {
assert.isFalse(element.hasUnsavedChanges);
});
});
});
</script>