Files
gerrit/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view_test.html
Becky Siegel 56fbb55325 Consolidate list-view code
Throughout the admin section, there are (at least) three distinct list
views that behave very similarly. This change helps share code between
them:

Create a list-view element that handles the filtering and navigation,
and styles <content></content>,  which is the same among lists.

Change-Id: I1037c43df7be58aa00843d29cae50495e089826d
2017-06-05 17:24:15 -07:00

113 lines
3.3 KiB
HTML

<!DOCTYPE html>
<!--
Copyright (C) 2017 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-list-view</title>
<script src="../../../bower_components/page/page.js"></script>
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.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-list-view.html">
<script>void(0);</script>
<test-fixture id="basic">
<template>
<gr-list-view></gr-list-view>
</template>
</test-fixture>
<script>
suite('gr-list-view tests', () => {
let element;
let sandbox;
setup(() => {
sandbox = sinon.sandbox.create();
element = fixture('basic');
});
teardown(() => {
sandbox.restore();
});
test('_computeNavLink', () => {
const offset = 25;
const projectsPerPage = 25;
const filter = 'test';
element.path = '/admin/projects';
sandbox.stub(element, 'getBaseUrl', () => '');
assert.equal(
element._computeNavLink(offset, 1, projectsPerPage, filter),
'/admin/projects/q/filter:test,50');
assert.equal(
element._computeNavLink(offset, -1, projectsPerPage, filter),
'/admin/projects/q/filter:test');
assert.equal(
element._computeNavLink(offset, 1, projectsPerPage, null),
'/admin/projects,50');
assert.equal(
element._computeNavLink(offset, -1, projectsPerPage, null),
'/admin/projects');
});
test('_onValueChange', done => {
element.path = '/admin/projects';
sandbox.stub(page, 'show', url => {
assert.equal(url, '/admin/projects/q/filter:test');
done();
});
const e = {target: {value: 'test'}};
element._onValueChange(e);
});
test('next button', done => {
element.itemsPerPage = 25;
projects = new Array(26);
flush(() => {
let loading;
assert.isFalse(element._hideNextArrow(loading, projects));
loading = true;
assert.isTrue(element._hideNextArrow(loading, projects));
loading = false;
assert.isFalse(element._hideNextArrow(loading, projects));
element._projects = [];
assert.isTrue(element._hideNextArrow(loading, element._projects));
projects = new Array(4);
assert.isTrue(element._hideNextArrow(loading, projects));
done();
});
});
test('prev button', () => {
flush(() => {
let offset = 0;
assert.isTrue(element._hidePrevArrow(offset));
offset = 5;
assert.isFalse(element._hidePrevArrow(offset));
});
});
});
</script>