Files
gerrit/polygerrit-ui/app/elements/admin/gr-plugin-config-array-editor/gr-plugin-config-array-editor_test.html
Ole Rehmsen 31640747ec Use bower paths relative to the domain
This is shorter, and makes it easier to move test files around.

Change-Id: Ife3dcdd66b66a698d71b0fce2bce457410a4dd73
2019-05-23 17:02:27 +02:00

143 lines
4.5 KiB
HTML

<!DOCTYPE html>
<!--
@license
Copyright (C) 2018 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-plugin-config-array-editor</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-plugin-config-array-editor.html">
<script>void(0);</script>
<test-fixture id="basic">
<template>
<gr-plugin-config-array-editor></gr-plugin-config-array-editor>
</template>
</test-fixture>
<script>
suite('gr-plugin-config-array-editor tests', () => {
let element;
let sandbox;
let dispatchStub;
const getAll = str => Polymer.dom(element.root).querySelectorAll(str);
setup(() => {
sandbox = sinon.sandbox.create();
element = fixture('basic');
element.pluginOption = {
_key: 'test-key',
info: {
values: [],
},
};
});
teardown(() => sandbox.restore());
test('_computeShowInputRow', () => {
assert.equal(element._computeShowInputRow(true), 'hide');
assert.equal(element._computeShowInputRow(false), '');
});
test('_computeDisabled', () => {
assert.isTrue(element._computeDisabled({}));
assert.isTrue(element._computeDisabled({base: {}}));
assert.isTrue(element._computeDisabled({base: {info: {}}}));
assert.isTrue(
element._computeDisabled({base: {info: {editable: false}}}));
assert.isFalse(
element._computeDisabled({base: {info: {editable: true}}}));
});
suite('adding', () => {
setup(() => {
dispatchStub = sandbox.stub(element, '_dispatchChanged');
});
test('with enter', () => {
element._newValue = '';
MockInteractions.pressAndReleaseKeyOn(element.$.input, 13); // Enter
flushAsynchronousOperations();
assert.isFalse(dispatchStub.called);
element._newValue = 'test';
MockInteractions.pressAndReleaseKeyOn(element.$.input, 13); // Enter
flushAsynchronousOperations();
assert.isTrue(dispatchStub.called);
assert.equal(dispatchStub.lastCall.args[0], 'test');
assert.equal(element._newValue, '');
});
test('with add btn', () => {
element._newValue = '';
MockInteractions.tap(element.$.addButton);
flushAsynchronousOperations();
assert.isFalse(dispatchStub.called);
element._newValue = 'test';
MockInteractions.tap(element.$.addButton);
flushAsynchronousOperations();
assert.isTrue(dispatchStub.called);
assert.equal(dispatchStub.lastCall.args[0], 'test');
assert.equal(element._newValue, '');
});
});
test('deleting', () => {
dispatchStub = sandbox.stub(element, '_dispatchChanged');
element.pluginOption = {info: {values: ['test', 'test2']}};
flushAsynchronousOperations();
const rows = getAll('.existingItems .row');
assert.equal(rows.length, 2);
const button = rows[0].querySelector('gr-button');
MockInteractions.tap(button);
flushAsynchronousOperations();
assert.isFalse(dispatchStub.called);
element.pluginOption.info.editable = true;
element.notifyPath('pluginOption.info.editable');
flushAsynchronousOperations();
MockInteractions.tap(button);
flushAsynchronousOperations();
assert.isTrue(dispatchStub.called);
assert.deepEqual(dispatchStub.lastCall.args[0], ['test2']);
});
test('_dispatchChanged', () => {
const eventStub = sandbox.stub(element, 'dispatchEvent');
element._dispatchChanged(['new-test-value']);
assert.isTrue(eventStub.called);
const {detail} = eventStub.lastCall.args[0];
assert.equal(detail._key, 'test-key');
assert.deepEqual(detail.info, {values: ['new-test-value']});
assert.equal(detail.notifyPath, 'test-key.values');
});
});
</script>