Files
gerrit/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view_test.html
Becky Siegel ae9648bcc8 Fix prev/next links in list-view to depend on path
Since branches and tags depend on the same view, when the path was
updated, the next/prev links were not. Make 'path' an explicit
parameter, so it is observed by the prev/next link's calculating
function.

Change-Id: I79288ebe5837e7ad6bc678ffde98f313935bc1be
2017-07-19 13:45:08 -07:00

143 lines
4.4 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="../../../test/common-test-setup.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';
const path = '/admin/projects';
sandbox.stub(element, 'getBaseUrl', () => '');
assert.equal(
element._computeNavLink(offset, 1, projectsPerPage, filter, path),
'/admin/projects/q/filter:test,50');
assert.equal(
element._computeNavLink(offset, -1, projectsPerPage, filter, path),
'/admin/projects/q/filter:test');
assert.equal(
element._computeNavLink(offset, 1, projectsPerPage, null, path),
'/admin/projects,50');
assert.equal(
element._computeNavLink(offset, -1, projectsPerPage, null, path),
'/admin/projects');
});
test('_onValueChange', done => {
element.path = '/admin/projects';
sandbox.stub(page, 'show', url => {
assert.equal(url, '/admin/projects/q/filter:test');
done();
});
element._filterChanged('test');
});
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));
});
});
test('createNew link appears correctly', () => {
assert.isFalse(element.$$('#createNewContainer').classList
.contains('show'));
element.createNew = true;
flushAsynchronousOperations();
assert.isTrue(element.$$('#createNewContainer').classList
.contains('show'));
});
test('fires create clicked event when button tapped', () => {
const clickHandler = sandbox.stub();
element.addEventListener('create-clicked', clickHandler);
element.createNew = true;
flushAsynchronousOperations();
MockInteractions.tap(element.$$('#createNew'));
assert.isTrue(clickHandler.called);
});
test('next/prev links change when path changes', () => {
const BRANCHES_PATH = '/path/to/branches';
const TAGS_PATH = '/path/to/tags';
sandbox.stub(element, '_computeNavLink');
element.offset = 0;
element.itemsPerPage = 25;
element.filter = '';
element.path = BRANCHES_PATH;
assert.equal(element._computeNavLink.lastCall.args[4], BRANCHES_PATH);
element.path = TAGS_PATH;
assert.equal(element._computeNavLink.lastCall.args[4], TAGS_PATH);
});
});
</script>