| <!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> |
| |
| <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(); |
| }); |
| |
| teardown(() => { |
| sandbox.restore(); |
| }); |
| |
| test('_loggedIn initial state', () => { |
| assert.isFalse(element._loggedIn); |
| }); |
| |
| test('_loggedIn after _handleAuthChange', () => { |
| element._handleAuthChange({detail: {loggedIn: true}}); |
| assert.isTrue(element._loggedIn); |
| element._handleAuthChange({detail: {}}); |
| assert.isFalse(element._loggedIn); |
| }); |
| |
| 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 sets timeout when not finished', async () => { |
| assert.isNotOk(element._updateTimeoutID); |
| sandbox.stub(element.$.client, 'getOAuthToken', () => Promise.resolve()); |
| sandbox.stub( |
| element.$.client, 'getProgress', |
| () => Promise.resolve([{name: 'MyLinter', state: 'PENDING'}])); |
| await element._update(); |
| assert.isDefined(element._updateTimeoutID); |
| }); |
| |
| test('_update clears timeout when finished', async () => { |
| assert.isNotOk(element._updateTimeoutID); |
| sandbox.stub(element.$.client, 'getOAuthToken', () => Promise.resolve()); |
| sandbox.stub( |
| element.$.client, 'getProgress', |
| () => Promise.resolve([{name: 'MyLinter', state: 'SUCCESS'}])); |
| await element._update(); |
| assert.isNotOk(element._updateTimeoutID); |
| }); |
| |
| test('_update uses exponential back-off on error', async () => { |
| assert.isNotOk(element._updateTimeoutID); |
| sandbox.stub(element.$.client, 'getOAuthToken', () => Promise.resolve()); |
| sandbox.stub( |
| element.$.client, '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 empty list', () => { |
| assert.equal('No Tricium Results', element._computeTitleText([])); |
| }); |
| |
| test('_computeTitleText with non-empty list', () => { |
| assert.equal('Tricium Results', element._computeTitleText([{name: 'Hi'}])); |
| }); |
| |
| test('_getFunctionClass with valid states', () => { |
| assert.equal('pending', element._getFunctionClass({state: 'PENDING'})); |
| assert.equal('running', element._getFunctionClass({state: 'RUNNING'})); |
| assert.equal('success', element._getFunctionClass({state: 'SUCCESS'})); |
| assert.equal('failure', element._getFunctionClass({state: 'FAILURE'})); |
| }); |
| |
| test('_getFunctionClass with an invalid state', () => { |
| assert.equal('', element._getFunctionClass({state: 'BOGUS'})); |
| }); |
| |
| test('_getFunctionClass with no state', () => { |
| assert.equal('pending', element._getFunctionClass({})); |
| }); |
| |
| test('_computePatchsetDescription with patchset', () => { |
| assert.equal( |
| 'Showing results for patchset 3.', |
| element._computePatchsetDescription({ |
| description: 'Update from feedback', |
| kind: 'REWORK', |
| _number: 3, |
| ref: 'refs/changes/14/702314/3', |
| })); |
| }); |
| |
| test('_computePatchsetDescription without patchset', () => { |
| assert.equal('', element._computePatchsetDescription({})); |
| }); |
| |
| test('_isDone returns false with empty results', () => { |
| element._results = []; |
| assert.isFalse(element._isDone()); |
| }); |
| |
| test('_isDone returns false with unfinished result', () => { |
| element._results = [ |
| { |
| name: 'NotStarted', |
| state: 'PENDING', |
| }, |
| ]; |
| assert.isFalse(element._isDone()); |
| element._results = [ |
| { |
| name: 'NotFinished', |
| swarmingUrl: 'http://example.com', |
| swarmingTaskId: '2', |
| state: 'RUNNING', |
| }, |
| ]; |
| assert.isFalse(element._isDone()); |
| }); |
| |
| test('_isDone returns false with unfinished result', () => { |
| element._results = [ |
| { |
| name: 'NotStarted', |
| state: 'PENDING', |
| }, |
| ]; |
| assert.isFalse(element._isDone()); |
| element._results = [ |
| { |
| name: 'NotFinished', |
| swarmingUrl: 'http://example.com', |
| swarmingTaskId: '2', |
| state: 'RUNNING', |
| }, |
| ]; |
| assert.isFalse(element._isDone()); |
| }); |
| |
| test('_isDone returns true with only finished results', () => { |
| element._results = [ |
| { |
| name: 'MyLinter', |
| swarmingUrl: 'http://example.com', |
| swarmingTaskId: '6', |
| state: 'SUCCESS', |
| numComments: 3, |
| }, |
| { |
| name: 'MyBrokenLinter', |
| swarmingUrl: 'http://example.com', |
| swarmingTaskId: '6', |
| state: 'FAILURE', |
| numComments: 0, |
| }, |
| ]; |
| assert.isTrue(element._isDone()); |
| }); |
| }); |
| </script> |