Files
gerrit/polygerrit-ui/app/elements/shared/gr-editable-label/gr-editable-label_test.html
Wyatt Allen f1d7d87d6f Allows topic editing in the change view
Adds an editable text label to the gr-change-metadata for modifying the
topic of a change.  Introduces the gr-editable-label as a UI element for
editable text labels.  Editing the topic is only allowed if the user is
logged in and has the topic-edit permission.

This is a redo of change 78110, which had been rebased wrong and had to
be reverted. https://gerrit-review.googlesource.com/c/78110/

Bug: Issue 4102
Change-Id: Ia7bb7b803a9fdd15a5f9f0f8eecf77bdd3ee4ba7
2016-05-31 19:13:42 +00:00

131 lines
3.5 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-editable-label</title>
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<script src="../../../bower_components/iron-test-helpers/mock-interactions.js"></script>
<link rel="import" href="gr-editable-label.html">
<test-fixture id="basic">
<template>
<gr-editable-label
value="value text"
placeholder="label text"></gr-editable-label>
</template>
</test-fixture>
<test-fixture id="read-only">
<template>
<gr-editable-label
read-only
value="value text"
placeholder="label text"></gr-editable-label>
</template>
</test-fixture>
<script>
suite('gr-linked-text tests', function() {
var element;
var input;
var label;
setup(function() {
element = fixture('basic');
input = element.$$('input');
label = element.$$('label');
});
test('element render', function() {
// The input is hidden and the label is visible:
assert.isNotNull(input.getAttribute('hidden'));
assert.isNull(label.getAttribute('hidden'));
assert.isTrue(label.classList.contains('editable'));
assert.equal(label.textContent, 'value text');
MockInteractions.tap(label);
Polymer.dom.flush();
// The input is visible and the label is hidden:
assert.isNull(input.getAttribute('hidden'));
assert.isNotNull(label.getAttribute('hidden'));
assert.equal(input.value, 'value text');
});
test('edit value', function(done) {
var editedStub = sinon.stub();
element.addEventListener('changed', editedStub);
MockInteractions.tap(label);
Polymer.dom.flush();
element._inputText = 'new text';
assert.isFalse(editedStub.called);
element.async(function() {
assert.isTrue(editedStub.called);
assert.equal(input.value, 'new text');
done();
});
// Press enter:
MockInteractions.keyDownOn(input, 13);
});
});
suite('gr-linked-text tests', function() {
var element;
var input;
var label;
setup(function() {
element = fixture('read-only');
input = element.$$('input');
label = element.$$('label');
});
test('disallows edit when read-only', function() {
// The input is hidden and the label is visible:
assert.isNotNull(input.getAttribute('hidden'));
assert.isNull(label.getAttribute('hidden'));
MockInteractions.tap(label);
Polymer.dom.flush();
// The input is still hidden and the label is still visible:
assert.isNotNull(input.getAttribute('hidden'));
assert.isNull(label.getAttribute('hidden'));
});
test('label is not marked as editable', function() {
assert.isFalse(label.classList.contains('editable'));
});
});
</script>