Files
gerrit/polygerrit-ui/app/elements/change-list/gr-change-list-view/gr-change-list-view_test.html
Becky Siegel 4491ff19a4 Don't show next arrow when there are not more changes on next page
The logic hiding the next arrow on the change list view was incorrect
when there was a full page of results, but no more to dipslay.

The API includes an attribute _more_changes on the last item of the
array to let the client know whether or not there should be another
page. This change uses _more_changes instead of comparing to
_changesPerPage to take this edge case into account.

Bug: Issue 5622
Change-Id: I17dba2c807d152485494405fb412a502ba666df6
2017-02-23 13:15:34 -08:00

127 lines
4.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-change-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="gr-change-list-view.html">
<test-fixture id="basic">
<template>
<gr-change-list-view></gr-change-list-view>
</template>
</test-fixture>
<script>
suite('gr-change-list-view tests', function() {
var element;
var sandbox;
setup(function() {
stub('gr-rest-api-interface', {
getLoggedIn: function() { return Promise.resolve(false); },
});
element = fixture('basic');
sandbox = sinon.sandbox.create();
});
teardown(function() {
sandbox.restore();
});
test('url is properly encoded', function() {
assert.equal(element._computeNavLink(
'status:open project:platform/frameworks/base', 0, -1, 25),
'/q/status:open+project:platform%252Fframeworks%252Fbase'
);
assert.equal(element._computeNavLink(
'status:open project:platform/frameworks/base', 0, 1, 25),
'/q/status:open+project:platform%252Fframeworks%252Fbase,25'
);
});
test('_computeNavLink', function() {
var query = 'status:open';
var offset = 0;
var direction = 1;
var changesPerPage = 5;
assert.equal(
element._computeNavLink(query, offset, direction, changesPerPage),
'/q/status:open,5');
direction = -1;
assert.equal(
element._computeNavLink(query, offset, direction, changesPerPage),
'/q/status:open');
offset = 5;
direction = 1;
assert.equal(
element._computeNavLink(query, offset, direction, changesPerPage),
'/q/status:open,10');
});
test('_hidePrevArrow', function() {
var offset = 0;
assert.isTrue(element._hidePrevArrow(offset));
offset = 5;
assert.isFalse(element._hidePrevArrow(offset));
});
test('_hideNextArrow', function() {
var loading = true;
assert.isTrue(element._hideNextArrow(loading));
loading = false;
assert.isTrue(element._hideNextArrow(loading));
element._changes = [];
assert.isTrue(element._hideNextArrow(loading));
element._changes =
Array.apply(null, Array(5)).map(Object.prototype.valueOf, {});
assert.isTrue(element._hideNextArrow(loading));
element._changes =
Array.apply(null, Array(25)).map(Object.prototype.valueOf,
{_more_changes: true});
assert.isFalse(element._hideNextArrow(loading));
element._changes =
Array.apply(null, Array(25)).map(Object.prototype.valueOf, {});
assert.isTrue(element._hideNextArrow(loading));
});
test('_handleNextPage', function() {
var showStub = sandbox.stub(page, 'show');
element.$.nextArrow.hidden = true;
element._handleNextPage();
assert.isFalse(showStub.called);
element.$.nextArrow.hidden = false;
element._handleNextPage();
assert.isTrue(showStub.called);
});
test('_handlePreviousPage', function() {
var showStub = sandbox.stub(page, 'show');
element.$.prevArrow.hidden = true;
element._handlePreviousPage();
assert.isFalse(showStub.called);
element.$.prevArrow.hidden = false;
element._handlePreviousPage();
assert.isTrue(showStub.called);
});
});
</script>