blob: 92d1ff2bd23cb095299ff9f86c85dfed514805f6 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright 2017 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>tricium-view</title>
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script src="../bower_components/web-component-tester/browser.js"></script>
<script src="../src/main/resources/static/promises.js"></script>
<script src="../src/main/resources/static/auth.js"></script>
<script src="../src/main/resources/static/tricium-client.js"></script>
<link rel="import" href="../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="../src/main/resources/static/tricium-view.html">
<test-fixture id="tricium-view-fixture">
<template>
<tricium-view></tricium-view>
</template>
</test-fixture>
<script>
suite('<tricium-view>', () => {
let element;
let sandbox;
setup(() => {
element = fixture('tricium-view-fixture');
sandbox = sinon.sandbox.create();
sandbox.stub(window.tricium, 'getAccessToken', async () => 'accessToken');
});
teardown(() => {
sandbox.restore();
});
test('merged CL sets revision to last before merge on attached', async () => {
element.change = {
change_id: 'Iabc12345def123451234',
_number: 12345,
status: 'MERGED',
revisions: {
'1badc0ffee': {
kind: 'REWORK',
_number: 1,
ref: 'refs/changes/45/12345/1',
},
'2ba5eba110': {
kind: 'REWORK',
_number: 2,
ref: 'refs/changes/45/12345/2',
},
},
};
element.revision = {
kind: 'REWORK',
_number: 2,
ref: 'refs/changes/45/12345/2',
};
element.attached();
assert.deepEqual(element.revision, {
kind: 'REWORK',
_number: 1,
ref: 'refs/changes/45/12345/1',
});
}),
test('_update clears timeout when after trying for max time', async () => {
// Set the start time to some time a long time ago.
element._startTime = new Date('2018-06-01');
sandbox.stub(
window.tricium.TriciumV1Client.prototype, 'getProgress',
() => Promise.resolve([{name: 'MyLinter', state: 'PENDING'}]));
await element._update();
// We shall not try to update again, if it still appears to be "pending",
// since the start time was long ago. So, no update timeout is set.
assert.isNotOk(element._updateTimeoutID);
});
test('_update clears timeout when finished', async () => {
assert.isNotOk(element._updateTimeoutID);
sandbox.stub(
window.tricium.TriciumV1Client.prototype, 'getProgress',
() => Promise.resolve({runId: '1324', state: 'SUCCESS'}));
await element._update();
assert.isNotOk(element._updateTimeoutID);
});
test('_update uses exponential back-off on error', async () => {
assert.isNotOk(element._updateTimeoutID);
sandbox.stub(
window.tricium.TriciumV1Client.prototype, 'getProgress',
() => Promise.reject('simulated getProgress error (expected)'));
const initialTimeoutMs = element._updateIntervalMs;
await element._update();
assert.isTrue(element._updateIntervalMs > 2 * initialTimeoutMs);
assert.isOk(element._updateTimeoutID);
});
test('_computeTitleText with null response', () => {
assert.equal('No Tricium Results', element._computeTitleText(null));
});
test('_computeTitleText with non-null response', () => {
assert.equal('Tricium', element._computeTitleText({}));
});
test('_isDone returns false with null response', () => {
element._response = null;
assert.isFalse(element._isDone());
});
test('_isDone returns false with an empty response', () => {
element._response = {};
assert.isFalse(element._isDone());
element._response = {runId: 0};
assert.isFalse(element._isDone());
});
test('_isDone returns true when there is a run ID', () => {
element._response = {runId: 123, state: 'SUCCESS'};
assert.isTrue(element._isDone());
element._response = {runId: 123, state: 'FAILURE'};
assert.isTrue(element._isDone());
element._response = {runId: 123};
assert.isTrue(element._isDone());
});
});
</script>