
This is a partial roll-forward of c/106190 This replaces all loads of iron-test-helpers with a load of a file that wraps it, and adds that file to test files that do not currently load iron-test-helpers. A future CL will also install polymer-resin via common-test-helpers.html. I tested by running $ WCT_ARGS="-l chrome" ./polygerrit-ui/app/run_test.sh Change-Id: Ifb3cd2c8db13d724f57e56e7e78045470d103a43
215 lines
6.8 KiB
HTML
215 lines
6.8 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="../../../test/common-test-setup.html"/>
|
|
<link rel="import" href="gr-change-list-view.html">
|
|
|
|
<script>void(0);</script>
|
|
|
|
<test-fixture id="basic">
|
|
<template>
|
|
<gr-change-list-view></gr-change-list-view>
|
|
</template>
|
|
</test-fixture>
|
|
|
|
<script>
|
|
const CHANGE_ID = 'IcA3dAB3edAB9f60B8dcdA6ef71A75980e4B7127';
|
|
const COMMIT_HASH = '12345678';
|
|
|
|
suite('gr-change-list-view tests', () => {
|
|
let element;
|
|
let sandbox;
|
|
|
|
setup(() => {
|
|
stub('gr-rest-api-interface', {
|
|
getLoggedIn() { return Promise.resolve(false); },
|
|
getChanges(num, query) {
|
|
return Promise.resolve([]);
|
|
},
|
|
});
|
|
element = fixture('basic');
|
|
sandbox = sinon.sandbox.create();
|
|
});
|
|
|
|
teardown(done => {
|
|
flush(() => {
|
|
sandbox.restore();
|
|
done();
|
|
});
|
|
});
|
|
|
|
test('url is properly encoded', () => {
|
|
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', () => {
|
|
const query = 'status:open';
|
|
let offset = 0;
|
|
let direction = 1;
|
|
const 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('_computeNavLink with path', () => {
|
|
window.CANONICAL_PATH = '/r';
|
|
const query = 'status:open';
|
|
let offset = 0;
|
|
let direction = 1;
|
|
const changesPerPage = 5;
|
|
assert.equal(
|
|
element._computeNavLink(query, offset, direction, changesPerPage),
|
|
'/r/q/status:open,5');
|
|
direction = -1;
|
|
assert.equal(
|
|
element._computeNavLink(query, offset, direction, changesPerPage),
|
|
'/r/q/status:open');
|
|
offset = 5;
|
|
direction = 1;
|
|
assert.equal(
|
|
element._computeNavLink(query, offset, direction, changesPerPage),
|
|
'/r/q/status:open,10');
|
|
});
|
|
|
|
test('_hidePrevArrow', () => {
|
|
let offset = 0;
|
|
assert.isTrue(element._hidePrevArrow(offset));
|
|
offset = 5;
|
|
assert.isFalse(element._hidePrevArrow(offset));
|
|
});
|
|
|
|
test('_hideNextArrow', () => {
|
|
let loading = true;
|
|
assert.isTrue(element._hideNextArrow(loading));
|
|
loading = false;
|
|
assert.isTrue(element._hideNextArrow(loading));
|
|
element._changes = [];
|
|
assert.isTrue(element._hideNextArrow(loading));
|
|
element._changes =
|
|
Array(...Array(5)).map(Object.prototype.valueOf, {});
|
|
assert.isTrue(element._hideNextArrow(loading));
|
|
element._changes =
|
|
Array(...Array(25)).map(Object.prototype.valueOf,
|
|
{_more_changes: true});
|
|
assert.isFalse(element._hideNextArrow(loading));
|
|
element._changes =
|
|
Array(...Array(25)).map(Object.prototype.valueOf, {});
|
|
assert.isTrue(element._hideNextArrow(loading));
|
|
});
|
|
|
|
test('_handleNextPage', () => {
|
|
const 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', () => {
|
|
const 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);
|
|
});
|
|
|
|
suite('query based navigation', () => {
|
|
test('Searching for a change ID redirects to change', done => {
|
|
sandbox.stub(element, '_getChanges')
|
|
.returns(Promise.resolve([{_number: 1}]));
|
|
sandbox.stub(page, 'show', url => {
|
|
assert.equal(url, '/c/1');
|
|
done();
|
|
});
|
|
|
|
element.params = {view: 'gr-change-list-view', query: CHANGE_ID};
|
|
});
|
|
|
|
test('Searching for a change num redirects to change', done => {
|
|
sandbox.stub(element, '_getChanges')
|
|
.returns(Promise.resolve([{_number: 1}]));
|
|
sandbox.stub(page, 'show', url => {
|
|
assert.equal(url, '/c/1');
|
|
done();
|
|
});
|
|
|
|
element.params = {view: 'gr-change-list-view', query: '1'};
|
|
});
|
|
|
|
test('Commit hash redirects to change', done => {
|
|
sandbox.stub(element, '_getChanges')
|
|
.returns(Promise.resolve([{_number: 1}]));
|
|
sandbox.stub(page, 'show', url => {
|
|
assert.equal(url, '/c/1');
|
|
done();
|
|
});
|
|
|
|
element.params = {view: 'gr-change-list-view', query: COMMIT_HASH};
|
|
});
|
|
|
|
test('Searching for an invalid change ID searches', () => {
|
|
sandbox.stub(element, '_getChanges')
|
|
.returns(Promise.resolve([]));
|
|
const stub = sandbox.stub(page, 'show');
|
|
|
|
element.params = {view: 'gr-change-list-view', query: CHANGE_ID};
|
|
flushAsynchronousOperations();
|
|
|
|
assert.isFalse(stub.called);
|
|
});
|
|
|
|
test('Change ID with multiple search results searches', () => {
|
|
sandbox.stub(element, '_getChanges')
|
|
.returns(Promise.resolve([{}, {}]));
|
|
const stub = sandbox.stub(page, 'show');
|
|
|
|
element.params = {view: 'gr-change-list-view', query: CHANGE_ID};
|
|
flushAsynchronousOperations();
|
|
|
|
assert.isFalse(stub.called);
|
|
});
|
|
});
|
|
});
|
|
</script>
|