blob: 0097a50a2414728f5cf6dbdbb4f2dadca5380077 [file] [log] [blame]
Kasper Nilssonf99ce6e2016-09-23 15:14:59 -07001<!DOCTYPE html>
2<!--
3Copyright (C) 2016 The Android Open Source Project
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16-->
17
18<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
19<title>gr-change-list-view</title>
20
Becky Siegeld405bba2017-02-22 17:24:58 -080021<script src="../../../bower_components/page/page.js"></script>
Kasper Nilssonf99ce6e2016-09-23 15:14:59 -070022<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
23<script src="../../../bower_components/web-component-tester/browser.js"></script>
24
Kasper Nilssona81a8a32017-03-13 14:46:44 -070025<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
Kasper Nilssonf99ce6e2016-09-23 15:14:59 -070026<link rel="import" href="gr-change-list-view.html">
27
Viktar Donich29e1ce52017-03-28 17:02:44 -070028<script>void(0);</script>
29
Kasper Nilssonf99ce6e2016-09-23 15:14:59 -070030<test-fixture id="basic">
31 <template>
32 <gr-change-list-view></gr-change-list-view>
33 </template>
34</test-fixture>
35
36<script>
Kasper Nilssona81a8a32017-03-13 14:46:44 -070037 var CHANGE_ID = 'IcA3dAB3edAB9f60B8dcdA6ef71A75980e4B7127';
38 var COMMIT_HASH = '12345678';
39
Kasper Nilssonf99ce6e2016-09-23 15:14:59 -070040 suite('gr-change-list-view tests', function() {
41 var element;
Becky Siegeld405bba2017-02-22 17:24:58 -080042 var sandbox;
Kasper Nilssonf99ce6e2016-09-23 15:14:59 -070043
44 setup(function() {
Andrew Bonventrefd434af2016-10-15 20:22:00 -070045 stub('gr-rest-api-interface', {
46 getLoggedIn: function() { return Promise.resolve(false); },
Kasper Nilssona81a8a32017-03-13 14:46:44 -070047 getChanges: function(num, query) {
48 return Promise.resolve([]);
49 },
Andrew Bonventrefd434af2016-10-15 20:22:00 -070050 });
Kasper Nilssonf99ce6e2016-09-23 15:14:59 -070051 element = fixture('basic');
Becky Siegeld405bba2017-02-22 17:24:58 -080052 sandbox = sinon.sandbox.create();
53 });
54
Viktar Donich29e1ce52017-03-28 17:02:44 -070055 teardown(function(done) {
56 flush(function() {
57 sandbox.restore();
58 done();
59 });
Kasper Nilssonf99ce6e2016-09-23 15:14:59 -070060 });
61
62 test('url is properly encoded', function() {
63 assert.equal(element._computeNavLink(
64 'status:open project:platform/frameworks/base', 0, -1, 25),
65 '/q/status:open+project:platform%252Fframeworks%252Fbase'
66 );
67 assert.equal(element._computeNavLink(
68 'status:open project:platform/frameworks/base', 0, 1, 25),
69 '/q/status:open+project:platform%252Fframeworks%252Fbase,25'
70 );
71 });
Becky Siegeld405bba2017-02-22 17:24:58 -080072
73 test('_computeNavLink', function() {
74 var query = 'status:open';
75 var offset = 0;
76 var direction = 1;
77 var changesPerPage = 5;
78 assert.equal(
79 element._computeNavLink(query, offset, direction, changesPerPage),
80 '/q/status:open,5');
81 direction = -1;
82 assert.equal(
83 element._computeNavLink(query, offset, direction, changesPerPage),
84 '/q/status:open');
85 offset = 5;
86 direction = 1;
87 assert.equal(
88 element._computeNavLink(query, offset, direction, changesPerPage),
89 '/q/status:open,10');
90 });
91
92 test('_hidePrevArrow', function() {
93 var offset = 0;
94 assert.isTrue(element._hidePrevArrow(offset));
95 offset = 5;
96 assert.isFalse(element._hidePrevArrow(offset));
97 });
98
99 test('_hideNextArrow', function() {
100 var loading = true;
Becky Siegel4491ff12017-02-23 13:15:34 -0800101 assert.isTrue(element._hideNextArrow(loading));
Becky Siegeld405bba2017-02-22 17:24:58 -0800102 loading = false;
Becky Siegel4491ff12017-02-23 13:15:34 -0800103 assert.isTrue(element._hideNextArrow(loading));
104 element._changes = [];
105 assert.isTrue(element._hideNextArrow(loading));
Becky Siegeld405bba2017-02-22 17:24:58 -0800106 element._changes =
Becky Siegel4491ff12017-02-23 13:15:34 -0800107 Array.apply(null, Array(5)).map(Object.prototype.valueOf, {});
108 assert.isTrue(element._hideNextArrow(loading));
Becky Siegeld405bba2017-02-22 17:24:58 -0800109 element._changes =
Becky Siegel4491ff12017-02-23 13:15:34 -0800110 Array.apply(null, Array(25)).map(Object.prototype.valueOf,
111 {_more_changes: true});
112 assert.isFalse(element._hideNextArrow(loading));
113 element._changes =
114 Array.apply(null, Array(25)).map(Object.prototype.valueOf, {});
115 assert.isTrue(element._hideNextArrow(loading));
Becky Siegeld405bba2017-02-22 17:24:58 -0800116 });
117
118 test('_handleNextPage', function() {
119 var showStub = sandbox.stub(page, 'show');
120 element.$.nextArrow.hidden = true;
121 element._handleNextPage();
122 assert.isFalse(showStub.called);
123 element.$.nextArrow.hidden = false;
124 element._handleNextPage();
125 assert.isTrue(showStub.called);
126 });
127
128 test('_handlePreviousPage', function() {
129 var showStub = sandbox.stub(page, 'show');
130 element.$.prevArrow.hidden = true;
131 element._handlePreviousPage();
132 assert.isFalse(showStub.called);
133 element.$.prevArrow.hidden = false;
134 element._handlePreviousPage();
135 assert.isTrue(showStub.called);
136 });
Kasper Nilssona81a8a32017-03-13 14:46:44 -0700137
138 suite('query based navigation', function() {
139 test('Searching for a change ID redirects to change', function(done) {
140 sandbox.stub(element, '_getChanges')
141 .returns(Promise.resolve([{_number: 1}]));
142 sandbox.stub(page, 'show', function(url) {
143 assert.equal(url, '/c/1');
144 done();
145 });
146
147 element.params = {view: 'gr-change-list-view', query: CHANGE_ID};
148 });
149
150 test('Searching for a change num redirects to change', function(done) {
151 sandbox.stub(element, '_getChanges')
152 .returns(Promise.resolve([{_number: 1}]));
153 sandbox.stub(page, 'show', function(url) {
154 assert.equal(url, '/c/1');
155 done();
156 });
157
158 element.params = {view: 'gr-change-list-view', query: '1'};
159 });
160
161 test('Commit hash redirects to change', function(done) {
162 sandbox.stub(element, '_getChanges')
163 .returns(Promise.resolve([{_number: 1}]));
164 sandbox.stub(page, 'show', function(url) {
165 assert.equal(url, '/c/1');
166 done();
167 });
168
169 element.params = {view: 'gr-change-list-view', query: COMMIT_HASH};
170 });
171
172 test('Searching for an invalid change ID searches', function() {
173 sandbox.stub(element, '_getChanges')
174 .returns(Promise.resolve([]));
175 var stub = sandbox.stub(page, 'show');
176
177 element.params = {view: 'gr-change-list-view', query: CHANGE_ID};
Kasper Nilsson38e8fbb2017-03-30 15:54:21 -0700178 flushAsynchronousOperations();
Kasper Nilssona81a8a32017-03-13 14:46:44 -0700179
180 assert.isFalse(stub.called);
181 });
182
183 test('Change ID with multiple search results searches', function() {
184 sandbox.stub(element, '_getChanges')
185 .returns(Promise.resolve([{}, {}]));
186 var stub = sandbox.stub(page, 'show');
187
188 element.params = {view: 'gr-change-list-view', query: CHANGE_ID};
Kasper Nilsson38e8fbb2017-03-30 15:54:21 -0700189 flushAsynchronousOperations();
Kasper Nilssona81a8a32017-03-13 14:46:44 -0700190
191 assert.isFalse(stub.called);
192 });
193 });
Kasper Nilssonf99ce6e2016-09-23 15:14:59 -0700194 });
195</script>