First round cleanup of network requests & errors from tests

+ These were slowing down tests in cases where it would actually hit a
  live server, potentially adding the latency from the network to the
  test.
+ Other fixes involve removing unused imports of util.js amongst other
  small tweaks/fixes.

Bug: Issue 4016
Change-Id: I442deefebeffc6a701e4922faccfe1c74b3a35b6
This commit is contained in:
Andrew Bonventre
2016-10-15 20:22:00 -07:00
parent 29978b4bbb
commit fd434afe59
21 changed files with 95 additions and 53 deletions

View File

@@ -35,6 +35,10 @@ limitations under the License.
var element;
setup(function() {
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
getLoggedIn: function() { return Promise.resolve(false); },
});
element = fixture('basic');
});

View File

@@ -34,6 +34,9 @@ limitations under the License.
var element;
setup(function() {
stub('gr-rest-api-interface', {
getLoggedIn: function() { return Promise.resolve(false); },
});
element = fixture('basic');
});

View File

@@ -21,7 +21,6 @@ limitations under the License.
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<script src="../../../bower_components/page/page.js"></script>
<script src="../../../scripts/util.js"></script>
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-change-list.html">

View File

@@ -20,7 +20,6 @@ limitations under the License.
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<script src="../../../scripts/util.js"></script>
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-account-list.html">
@@ -59,14 +58,11 @@ limitations under the License.
existingReviewer1 = makeAccount();
existingReviewer2 = makeAccount();
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
});
element = fixture('basic');
element.accounts = [existingReviewer1, existingReviewer2];
stub('gr-rest-api-interface', {
getConfig: function() {
return Promise.resolve({});
},
});
});
test('account entry only appears when editable', function() {

View File

@@ -36,6 +36,7 @@ limitations under the License.
setup(function() {
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
getLoggedIn: function() { return Promise.resolve(false); },
});

View File

@@ -357,12 +357,11 @@
// a linked message is performed after related changes is fully loaded.
this.$.relatedChanges.reload().then(function() {
this.async(function() {
if (!history.state.scrollTop) {
this._maybeScrollToMessage();
} else {
if (history.state && history.state.scrollTop) {
document.documentElement.scrollTop =
document.body.scrollTop = history.state.scrollTop;
} else {
this._maybeScrollToMessage();
}
}, 1);
}.bind(this));

View File

@@ -21,7 +21,6 @@ limitations under the License.
<script src="../../../bower_components/webcomponentsjs/webcomponents.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<script src="../../../bower_components/page/page.js"></script>
<script src="../../../scripts/util.js"></script>
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-change-view.html">
@@ -39,6 +38,7 @@ limitations under the License.
setup(function() {
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
getAccount: function() { return Promise.resolve(null); },
});
element = fixture('basic');

View File

@@ -53,6 +53,9 @@ limitations under the License.
stub('gr-date-formatter', {
_loadTimeFormat: function() { return Promise.resolve(''); }
});
stub('gr-diff', {
reload: function() { return Promise.resolve(); },
});
element = fixture('basic');
});
@@ -362,14 +365,11 @@ limitations under the License.
flushAsynchronousOperations();
var fileRows =
Polymer.dom(element.root).querySelectorAll('.row:not(.header)');
// Prevent diff from making API call.
var diffStub = sandbox.stub(element.diffs[0], 'reload');
var showHideCheck = fileRows[0].querySelector(
'input.show-hide[type="checkbox"]');
assert.isTrue(showHideCheck.checked);
MockInteractions.tap(showHideCheck);
assert.isFalse(element.diffs[0].hidden);
diffStub.restore();
});
test('path should be properly escaped', function() {

View File

@@ -20,7 +20,6 @@ limitations under the License.
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<script src="../../../scripts/util.js"></script>
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-message.html">
@@ -36,8 +35,10 @@ limitations under the License.
var element;
setup(function() {
stub('gr-rest-api-interface', {
getLoggedIn: function() { return Promise.resolve(false); },
});
element = fixture('basic');
sinon.stub(element.$.restAPI, 'getLoggedIn').returns(true);
});
test('reply event', function(done) {

View File

@@ -20,7 +20,6 @@ limitations under the License.
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<script src="../../../scripts/util.js"></script>
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-messages-list.html">
@@ -36,6 +35,10 @@ limitations under the License.
var element;
setup(function() {
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
getLoggedIn: function() { return Promise.resolve(false); },
});
element = fixture('basic');
element.messages = [
{

View File

@@ -20,7 +20,6 @@ limitations under the License.
<script src="../../../bower_components/webcomponentsjs/webcomponents.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<script src="../../../scripts/util.js"></script>
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-reply-dialog.html">
@@ -49,6 +48,7 @@ limitations under the License.
patchNum = 1;
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
getAccount: function() { return Promise.resolve({}); },
});

View File

@@ -20,7 +20,6 @@ limitations under the License.
<script src="../../../bower_components/webcomponentsjs/webcomponents.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<script src="../../../scripts/util.js"></script>
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-reviewer-list.html">
@@ -40,6 +39,7 @@ limitations under the License.
element = fixture('basic');
sandbox = sinon.sandbox.create();
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
removeChangeReviewer: function() {
return Promise.resolve({ok: true});
},

View File

@@ -35,6 +35,9 @@ limitations under the License.
var element;
setup(function() {
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
});
element = fixture('basic');
});

View File

@@ -35,6 +35,9 @@ limitations under the License.
var element;
setup(function() {
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
});
stub('gr-main-header', {
_loadAccount: function() {},
});

View File

@@ -57,6 +57,9 @@ limitations under the License.
var builder;
setup(function() {
stub('gr-rest-api-interface', {
getLoggedIn: function() { return Promise.resolve(false); },
});
var prefs = {
line_length: 10,
show_tabs: true,
@@ -534,7 +537,8 @@ limitations under the License.
line_length: 10,
show_tabs: true,
tab_size: 4,
context: -1
context: -1,
syntax_highlighting: true,
};
content = [
{
@@ -554,9 +558,11 @@ limitations under the License.
});
element = fixture('basic');
outputEl = element.queryEffectiveChildren('#diffTable');
element.addEventListener('render', function() {
var renderHandler = function() {
element.removeEventListener('render', renderHandler);
done();
});
};
element.addEventListener('render', renderHandler);
sinon.stub(element, '_getDiffBuilder', function() {
var builder = new GrDiffBuilder(
{content: content}, {left: [], right: []}, prefs, outputEl);
@@ -614,7 +620,7 @@ limitations under the License.
assert.strictEqual(sections[1], section[1]);
});
test('render-start and render are fired', function() {
test('render-start and render are fired', function(done) {
var fireStub = sinon.stub(element, 'fire');
element.render({left: [], right: []}, {});
flush(function() {
@@ -625,18 +631,24 @@ limitations under the License.
});
test('rendering normal-sized diff does not disable syntax', function() {
flush(function() {
assert.isTrue(element.$.syntaxLayer.enabled);
});
assert.isTrue(element.$.syntaxLayer.enabled);
});
test('rendering large diff disables syntax', function() {
test('rendering large diff disables syntax', function(done) {
// Before it renders, set the first diff line to 500 '*' characters.
element.diff.content[0].a = new Array(501).join('*');
flush(function() {
element.diff.content[0].a = [new Array(501).join('*')];
element.addEventListener('render', function() {
assert.isFalse(element.$.syntaxLayer.enabled);
done();
});
var prefs = {
line_length: 10,
show_tabs: true,
tab_size: 4,
context: -1,
syntax_highlighting: true,
};
element.render({left: [], right: []}, prefs);
});
});

View File

@@ -36,7 +36,6 @@ limitations under the License.
var element;
suite('not logged in', function() {
setup(function() {
stub('gr-rest-api-interface', {
getLoggedIn: function() { return Promise.resolve(false); },
@@ -340,10 +339,12 @@ limitations under the License.
});
suite('logged in', function() {
setup(function() {
stub('gr-rest-api-interface', {
getLoggedIn: function() { return Promise.resolve(true); },
getPreferences: function() {
return Promise.resolve({time_format: 'HHMM_12'});
},
});
element = fixture('basic');
});

View File

@@ -39,17 +39,21 @@ limitations under the License.
stub('gr-reporting', {
appStarted: sandbox.stub(),
});
var config = {
gerrit: {web_uis: ['GWT', 'POLYGERRIT']},
plugin: {js_resource_paths: []},
};
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve(config); },
getAccount: function() { return Promise.resolve(null); },
getConfig: function() {
return Promise.resolve({
gerrit: {web_uis: ['GWT', 'POLYGERRIT']},
plugin: {js_resource_paths: []},
});
},
getVersion: function() { return Promise.resolve(42); },
});
element = fixture('basic');
flush(done);
});
teardown(function() {
sandbox.restore();
});
@@ -58,28 +62,31 @@ limitations under the License.
assert.isTrue(element.$.reporting.appStarted.calledOnce);
});
test('location change updates gwt footer', function() {
test('location change updates gwt footer', function(done) {
element._path = '/test/path';
var gwtLink = element.$$('#gwtLink');
assert.equal(gwtLink.href,
'http://' + location.host + '/?polygerrit=0#/test/path');
flush(function() {
var gwtLink = element.$$('#gwtLink');
assert.equal(gwtLink.href,
'http://' + location.host + '/?polygerrit=0#/test/path');
done();
});
});
test('_handleLocationChange handles hashes', function() {
test('_handleLocationChange handles hashes', function(done) {
var curLocation = {
pathname: '/c/1/1/testfile.txt',
hash: '#2',
host: location.host,
};
sandbox.stub(element, '_handleSearchPageChange');
element._handleLocationChange({detail: curLocation});
var event = {detail: curLocation};
var gwtLink = element.$$('#gwtLink');
sinon.stub(element, '_handleSearchPageChange');
element._handleLocationChange(event);
assert.equal(gwtLink.href,
'http://' + location.host + '/?polygerrit=0#/c/1/1/testfile.txt@2');
flush(function() {
var gwtLink = element.$$('#gwtLink');
assert.equal(gwtLink.href,
'http://' + location.host + '/?polygerrit=0#/c/1/1/testfile.txt@2');
done();
})
});
test('sets plugins count', function() {

View File

@@ -35,6 +35,10 @@ limitations under the License.
var element;
setup(function() {
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
getLoggedIn: function() { return Promise.resolve(false); },
});
element = fixture('basic');
});

View File

@@ -20,7 +20,6 @@ limitations under the License.
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<script src="../../../scripts/util.js"></script>
<link rel="import" href="gr-account-link.html">
@@ -35,6 +34,9 @@ limitations under the License.
var element;
setup(function() {
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
});
element = fixture('basic');
});

View File

@@ -34,6 +34,9 @@ limitations under the License.
var element;
setup(function() {
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
});
element = fixture('basic');
});

View File

@@ -42,6 +42,7 @@ breaking changes to gr-reply-dialog wont be noticed.
setup(function() {
stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); },
getAccount: function() { return Promise.resolve(null); },
});
element = fixture('basic');