Files
gerrit/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete_test.html
Wyatt Allen bd47217b1b Adds "Watched Projects"/Notifications section to PolyGerrit settings
Gives the PolyGerrit settings view a new section for Notifications which
replicates the "Watched Projects" screen in the GWT settings UI. Users
can add, remove and update which projects they receive email
notifications for.

Introduces the gr-watched-projects-editor element, which is given the
user's watched projects data and is able to display and modify the info.
In the same way that the GWT UI includes an autocomplete input for adding
new projects to watch, this implementation uses gr-autocomplete.

The gr-watched-projects-editor is added to the gr-settings-view, which
manages the loading, saving and deleting of the user's watched-project
data.

Other changes:

- Tidies the layout of gr-settings-view to permit larger tables such as
  gr-watched-projects-editor without disrupting the look.

- Tweaks functionality of gr-autocomplete use in the watched projects
  editor. Specifically, it does not take on a value until the user
  "commits" to a suggestion, and it does not clear the input when
  committed unless a flag is enabled. Also now supports placeholder
  text.

- Fixes some gr-settings-view unit-test failures in Safari.

- Fixes the markup of some table headers and footers.

- Lots of new unit tests.

Bug: Issue 3911
Change-Id: I4667c29aa3addcd9b6676bc8763d8e3deb327539
2016-06-13 20:40:07 -07:00

213 lines
6.1 KiB
HTML

<!DOCTYPE html>
<!--
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-reviewer-list</title>
<script src="../../../bower_components/webcomponentsjs/webcomponents.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-autocomplete.html">
<test-fixture id="basic">
<template>
<gr-autocomplete></gr-autocomplete>
</template>
</test-fixture>
<script>
suite('gr-autocomplete tests', function() {
var element;
setup(function() {
element = fixture('basic');
});
test('renders', function(done) {
var promise;
var queryStub = sinon.spy(function(input) {
return promise = Promise.resolve([
{name: input + ' 0', value: 0},
{name: input + ' 1', value: 1},
{name: input + ' 2', value: 2},
{name: input + ' 3', value: 3},
{name: input + ' 4', value: 4},
]);
});
element.query = queryStub;
assert.isTrue(element.$.suggestions.hasAttribute('hidden'));
assert.equal(element.$.cursor.index, -1);
element.text = 'blah';
assert.isTrue(queryStub.called);
promise.then(function() {
assert.isFalse(element.$.suggestions.hasAttribute('hidden'));
var suggestions = element.$.suggestions.querySelectorAll('li');
assert.equal(suggestions.length, 5);
for (var i = 0; i < 5; i++) {
assert.equal(suggestions[i].textContent, 'blah ' + i);
}
assert.notEqual(element.$.cursor.index, -1);
done();
});
});
test('emits cancel', function(done) {
var promise;
var queryStub = sinon.spy(function() {
return promise = Promise.resolve([
{name: 'blah', value: 123},
]);
});
element.query = queryStub;
assert.isTrue(element.$.suggestions.hasAttribute('hidden'));
element.text = 'blah';
promise.then(function() {
assert.isFalse(element.$.suggestions.hasAttribute('hidden'));
var cancelHandler = sinon.spy();
element.addEventListener('cancel', cancelHandler);
MockInteractions.pressAndReleaseKeyOn(element.$.input, 27); // Esc
assert.isTrue(cancelHandler.called);
assert.isTrue(element.$.suggestions.hasAttribute('hidden'));
done();
});
});
test('emits commit and handles cursor movement', function(done) {
var promise;
var queryStub = sinon.spy(function(input) {
return promise = Promise.resolve([
{name: input + ' 0', value: 0},
{name: input + ' 1', value: 1},
{name: input + ' 2', value: 2},
{name: input + ' 3', value: 3},
{name: input + ' 4', value: 4},
]);
});
element.query = queryStub;
assert.isTrue(element.$.suggestions.hasAttribute('hidden'));
assert.equal(element.$.cursor.index, -1);
element.text = 'blah';
promise.then(function() {
assert.isFalse(element.$.suggestions.hasAttribute('hidden'));
var commitHandler = sinon.spy();
element.addEventListener('commit', commitHandler);
assert.equal(element.$.cursor.index, 0);
MockInteractions.pressAndReleaseKeyOn(element.$.input, 40); // Down
assert.equal(element.$.cursor.index, 1);
MockInteractions.pressAndReleaseKeyOn(element.$.input, 40); // Down
assert.equal(element.$.cursor.index, 2);
MockInteractions.pressAndReleaseKeyOn(element.$.input, 38); // Up
assert.equal(element.$.cursor.index, 1);
MockInteractions.pressAndReleaseKeyOn(element.$.input, 13); // Enter
assert.equal(element.value, 1);
assert.isTrue(commitHandler.called);
assert.equal(commitHandler.getCall(0).args[0].detail.value, 1);
assert.isTrue(element.$.suggestions.hasAttribute('hidden'));
done();
});
});
test('clear-on-commit behavior (off)', function(done) {
var promise;
var queryStub = sinon.spy(function() {
return promise = Promise.resolve([{name: 'suggestion', value: 0}]);
});
element.query = queryStub;
element.text = 'blah';
promise.then(function() {
var commitHandler = sinon.spy();
element.addEventListener('commit', commitHandler);
MockInteractions.pressAndReleaseKeyOn(element.$.input, 13); // Enter
assert.isTrue(commitHandler.called);
assert.equal(element.text, 'suggestion');
done();
});
});
test('clear-on-commit behavior (on)', function(done) {
var promise;
var queryStub = sinon.spy(function() {
return promise = Promise.resolve([{name: 'suggestion', value: 0}]);
});
element.query = queryStub;
element.text = 'blah';
element.clearOnCommit = true;
promise.then(function() {
var commitHandler = sinon.spy();
element.addEventListener('commit', commitHandler);
MockInteractions.pressAndReleaseKeyOn(element.$.input, 13); // Enter
assert.isTrue(commitHandler.called);
assert.equal(element.text, '');
done();
});
});
test('threshold guards the query', function() {
var queryStub = sinon.spy(function() {
return Promise.resolve([]);
});
element.query = queryStub;
element.threshold = 2;
element.text = 'a';
assert.isFalse(queryStub.called);
element.text = 'ab';
assert.isTrue(queryStub.called);
});
});
</script>