Remove old obsolete Checks UI
Keep the dialog for checker configuration. Will add this as a top-level
action to the new Checks UI.
Change-Id: If77cb2615ba9a0838a39f478aa225df8f608a074
diff --git a/gr-checks/gr-checks-all-statuses.js b/gr-checks/gr-checks-all-statuses.js
deleted file mode 100644
index 2aaed0b..0000000
--- a/gr-checks/gr-checks-all-statuses.js
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 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.
- */
-
-/** All statuses */
-export const Statuses = {
- // non-terminal statuses
- NOT_STARTED: 'NOT_STARTED',
- SCHEDULED: 'SCHEDULED',
- RUNNING: 'RUNNING',
-
- // terminal statuses
- SUCCESSFUL: 'SUCCESSFUL',
- FAILED: 'FAILED',
- NOT_RELEVANT: 'NOT_RELEVANT',
-
- STATUS_UNKNOWN: 'UNKNOWN',
-};
-
-/**
- * @param {string} status
- * @param {Array<string>} includedStatuses
- * @returns {boolean}
- */
-function isStatus(status, includedStatuses) {
- return includedStatuses.includes(status);
-}
-
-/**
- * @param {string} status
- * @returns {boolean} if status is Unevaluated.
- */
-export function isUnevaluated(status) {
- return isStatus(status, [Statuses.NOT_STARTED]);
-}
-
-/**
- * @param {string} status
- * @returns {boolean} if status is Not Relevant
- */
-export function isNotRelevant(status) {
- return isStatus(status, [Statuses.NOT_RELEVANT]);
-}
-
-/**
- * @param {string} status
- * @returns {boolean} if status is Scheduled.
- */
-export function isScheduled(status) {
- return isStatus(status, [Statuses.SCHEDULED]);
-}
-
-/**
- * @param {string} status
- * @returns {boolean} if status is Running. */
-export function isRunning(status) {
- return isStatus(status, [Statuses.RUNNING]);
-}
-
-/**
- * @param {string} status
- * @returns {boolean} if status is InProgress.
- */
-export function isInProgress(status) {
- return isStatus(status, [Statuses.SCHEDULED, Statuses.RUNNING]);
-}
-
-/**
- * @param {string} status
- * @returns {boolean} if status is Successful.
- */
-export function isSuccessful(status) {
- return isStatus(status, [Statuses.SUCCESSFUL]);
-}
-
-/**
- * @param {string} status
- * @returns {boolean} if status is Failed.
- */
-export function isFailed(status) {
- return isStatus(status, [Statuses.FAILED]);
-}
-
-/**
- * @param {string} status
- * @returns {string} class of given status.
- */
-export function statusClass(status) {
- if (isUnevaluated(status)) {
- return 'unevaluated';
- }
- if (isInProgress(status)) {
- return 'in-progress';
- }
- if (isSuccessful(status)) {
- return 'successful';
- }
- if (isFailed(status)) {
- return 'failed';
- }
- return 'unevaluated';
-}
\ No newline at end of file
diff --git a/gr-checks/gr-checks-change-list-header-view.js b/gr-checks/gr-checks-change-list-header-view.js
deleted file mode 100644
index 09d60c0..0000000
--- a/gr-checks/gr-checks-change-list-header-view.js
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 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.
- */
-class GrChecksChangeListHeaderView extends Polymer.GestureEventListeners(
- Polymer.LegacyElementMixin(
- Polymer.Element)) {
- /** @returns {string} name of the component */
- static get is() { return 'gr-checks-change-list-header-view'; }
-
- /** @returns {?} template for this component */
- static get template() {
- return Polymer.html`
- <style>
- :host {
- display: table-cell;
- padding: 0 3px;
- }
- </style>
- Checks
- `;
- }
-}
-
-customElements.define(GrChecksChangeListHeaderView.is,
- GrChecksChangeListHeaderView);
\ No newline at end of file
diff --git a/gr-checks/gr-checks-change-list-header-view_test.html b/gr-checks/gr-checks-change-list-header-view_test.html
deleted file mode 100644
index f4e964d..0000000
--- a/gr-checks/gr-checks-change-list-header-view_test.html
+++ /dev/null
@@ -1,35 +0,0 @@
-<!DOCTYPE html>
-<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
-<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
-<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
-<script src="../bower_components/web-component-tester/browser.js"></script>
-
-<title>gr-checks-change-list-header-view</title>
-
-<test-fixture id="basic">
- <template>
- <gr-checks-change-list-header-view></gr-checks-change-list-header-view>
- </template>
-</test-fixture>
-
-<script type="module">
- import '../test/common-test-setup.js';
- import './gr-checks-change-list-header-view.js';
- suite('gr-checks-change-list-header-view tests', () => {
- let element;
- let sandbox;
-
- setup(done => {
- sandbox = sinon.sandbox.create();
-
- element = fixture('basic');
- flush(done);
- });
-
- teardown(() => { sandbox.restore(); });
-
- test('renders the header', () => {
- assert.include(element.shadowRoot.textContent, 'Checks');
- });
- });
-</script>
diff --git a/gr-checks/gr-checks-change-list-item-cell-view.js b/gr-checks/gr-checks-change-list-item-cell-view.js
deleted file mode 100644
index 98a75aa..0000000
--- a/gr-checks/gr-checks-change-list-item-cell-view.js
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 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.
- */
-class GrChecksChangeListItemCellView extends Polymer.GestureEventListeners(
- Polymer.LegacyElementMixin(
- Polymer.Element)) {
- /** @returns {string} name of the component */
- static get is() { return 'gr-checks-change-list-item-cell-view'; }
-
- /** @returns {?} template for this component */
- static get template() {
- return Polymer.html`
- <style>
- :host {
- display: inline-block;
- text-align: center;
- width: 100%;
- }
- </style>
- `;
- }
-
- /**
- * Defines properties of the component
- *
- * @returns {?}
- */
- static get properties() {
- return {
- change: Object,
- };
- }
-}
-
-customElements.define(GrChecksChangeListItemCellView.is,
- GrChecksChangeListItemCellView);
\ No newline at end of file
diff --git a/gr-checks/gr-checks-change-list-item-cell-view_test.html b/gr-checks/gr-checks-change-list-item-cell-view_test.html
deleted file mode 100644
index a8b5779..0000000
--- a/gr-checks/gr-checks-change-list-item-cell-view_test.html
+++ /dev/null
@@ -1,43 +0,0 @@
-<!DOCTYPE html>
-<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
-<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
-<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
-<script src="../bower_components/web-component-tester/browser.js"></script>
-
-<title>gr-checks-change-list-item-cell-view</title>
-
-<test-fixture id="basic">
- <template>
- <gr-checks-change-list-item-cell-view></gr-checks-change-list-item-cell-view>
- </template>
-</test-fixture>
-
-<script type="module">
- import '../test/common-test-setup.js';
- import './gr-checks-change-list-item-cell-view.js';
-
- suite('gr-checks-change-list-item-cell-view tests', () => {
- let element;
- let sandbox;
-
- setup(done => {
- sandbox = sinon.sandbox.create();
-
- element = fixture('basic');
- element.change = {
- project: 'test-repository',
- revisions: {
- 'first-sha': 'test-revision',
- 'second-sha': 'test-revision2',
- },
- };
- flush(done);
- });
-
- teardown(() => { sandbox.restore(); });
-
- test('renders the element', () => {
- assert.isOk(element);
- });
- });
-</script>
diff --git a/gr-checks/gr-checks-change-view-tab-header-view.js b/gr-checks/gr-checks-change-view-tab-header-view.js
deleted file mode 100644
index 4c1a022..0000000
--- a/gr-checks/gr-checks-change-view-tab-header-view.js
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 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.
- */
-
-class GrChecksChangeViewTabHeaderView extends Polymer.GestureEventListeners(
- Polymer.LegacyElementMixin(
- Polymer.Element)) {
- /** @returns {string} name of the component */
- static get is() { return 'gr-checks-change-view-tab-header-view'; }
-
- /** @returns {?} template for this component */
- static get template() {
- return Polymer.html`Checks`;
- }
-}
-
-customElements.define(GrChecksChangeViewTabHeaderView.is,
- GrChecksChangeViewTabHeaderView);
\ No newline at end of file
diff --git a/gr-checks/gr-checks-change-view-tab-header-view_test.html b/gr-checks/gr-checks-change-view-tab-header-view_test.html
deleted file mode 100644
index cee3780..0000000
--- a/gr-checks/gr-checks-change-view-tab-header-view_test.html
+++ /dev/null
@@ -1,36 +0,0 @@
-<!DOCTYPE html>
-<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
-
-<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
-<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
-<script src="../bower_components/web-component-tester/browser.js"></script>
-
-<title>gr-checks-change-view-tab-header-view</title>
-
-<test-fixture id="basic">
- <template>
- <gr-checks-change-view-tab-header-view></gr-checks-change-view-tab-header-view>
- </template>
-</test-fixture>
-
-<script type="module">
- import '../test/common-test-setup.js';
- import './gr-checks-change-view-tab-header-view.js';
- suite('gr-checks-change-view-tab-header-view tests', () => {
- let element;
- let sandbox;
-
- setup(done => {
- sandbox = sinon.sandbox.create();
-
- element = fixture('basic');
- flush(done);
- });
-
- teardown(() => { sandbox.restore(); });
-
- test('renders the header', () => {
- assert.include(element.shadowRoot.textContent.trim(), 'Checks');
- });
- });
-</script>
diff --git a/gr-checks/gr-checks-chip-view.js b/gr-checks/gr-checks-chip-view.js
deleted file mode 100644
index 3415844..0000000
--- a/gr-checks/gr-checks-chip-view.js
+++ /dev/null
@@ -1,290 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 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.
- */
-import './gr-checks-status.js';
-import {statusClass, Statuses} from './gr-checks-all-statuses.js';
-
-const StatusPriorityOrder = [
- Statuses.FAILED,
- Statuses.SCHEDULED,
- Statuses.RUNNING,
- Statuses.SUCCESSFUL,
- Statuses.NOT_STARTED,
- Statuses.NOT_RELEVANT,
-];
-
-const HumanizedStatuses = {
- // non-terminal statuses
- NOT_STARTED: 'in progress',
- NOT_RELEVANT: 'not relevant',
- SCHEDULED: 'in progress',
- RUNNING: 'in progress',
-
- // terminal statuses
- SUCCESSFUL: 'successful',
- FAILED: 'failed',
-};
-
-const CHECKS_POLL_INTERVAL_MS = 60 * 1000;
-
-const Defs = {};
-/**
- * @typedef {{
- * _number: number,
- * }}
- */
-Defs.Change;
-/**
- * @typedef {{
- * _number: number,
- * }}
- */
-Defs.Revision;
-
-/**
- * @param {Array<Object>} checks
- * @returns {Object}
- */
-function computeCheckStatuses(checks) {
- return checks.reduce((accum, check) => {
- accum[check.state] || (accum[check.state] = 0);
- accum[check.state]++;
- return accum;
- }, {total: checks.length});
-}
-
-/**
- * @param {Array<Object>} checks
- * @returns {string}
- */
-function downgradeFailureToWarning(checks) {
- const hasFailedCheck = checks.some(
- check => {
- return check.state == Statuses.FAILED;
- }
- );
- if (!hasFailedCheck) return '';
- const hasRequiredFailedCheck = checks.some(
- check => {
- return check.state == Statuses.FAILED &&
- check.blocking && check.blocking.length > 0;
- }
- );
- return hasRequiredFailedCheck ? '' : 'set';
-}
-
-class GrChecksChipView extends Polymer.GestureEventListeners(
- Polymer.LegacyElementMixin(
- Polymer.Element)) {
- /** @returns {string} name of the component */
- static get is() { return 'gr-checks-chip-view'; }
-
- /** @returns {?} template for this component */
- static get template() {
- return Polymer.html`<style>
-
- :host {
- display: inline-block;
- cursor: pointer;
- }
-
- .chip {
- border-color: #D0D0D0;
- border-radius: 4px;
- border-style: solid;
- border-width: 1px;
- padding: 4px 8px;
- }
- .chip.failed {
- border-color: #DA4236;
- }
- </style>
- <template is="dom-if" if="[[_hasChecks]]">
- Checks:
- <span
- class$="[[_chipClasses]]"
- role="button"
- aria-label="Open checks tab"
- >
- <gr-checks-status
- status="[[_status]]"
- downgrade-failure-to-warning="[[_downgradeFailureToWarning]]">
- </gr-checks-status>
- [[_statusString]]
- </span>
- </template>`;
- }
-
- /**
- * Defines properties of the component
- *
- * @returns {?}
- */
- static get properties() {
- return {
- revision: Object,
- change: Object,
- /** @type {function(number, number): !Promise<!Object>} */
- getChecks: Function,
- _checkStatuses: Object,
- _hasChecks: Boolean,
- _failedRequiredChecksCount: Number,
- _status: {type: String, computed: '_computeStatus(_checkStatuses)'},
- _statusString: {
- type: String,
- computed: '_computeStatusString(_status, _checkStatuses,' +
- '_failedRequiredChecksCount)',
- },
- _chipClasses: {type: String, computed: '_computeChipClass(_status)'},
- // Type is set as string so that it reflects on changes
- // Polymer does not support reflecting changes in Boolean property
- _downgradeFailureToWarning: {
- type: String,
- value: '',
- },
- pollChecksInterval: Object,
- visibilityChangeListenerAdded: {
- type: Boolean,
- value: false,
- },
- };
- }
-
- created() {
- super.created();
- this.addEventListener('click',
- () => this.showChecksTable());
- }
-
- detached() {
- super.detached();
- clearInterval(this.pollChecksInterval);
- this.unlisten(document, 'visibilitychange', '_onVisibililityChange');
- }
-
- static get observers() {
- return [
- '_pollChecksRegularly(change, getChecks)',
- ];
- }
-
- showChecksTable() {
- this.dispatchEvent(
- new CustomEvent(
- 'show-checks-table',
- {
- bubbles: true,
- composed: true,
- detail: {
- tab: 'change-view-tab-header-checks',
- scrollIntoView: true,
- },
- })
- );
- }
-
- /**
- * @param {!Defs.Change} change
- * @param {function(number, number): !Promise<!Object>} getChecks
- */
- _fetchChecks(change, getChecks) {
- if (!getChecks || !change) return;
-
- // change.current_revision always points to latest patchset
- getChecks(change._number, change.revisions[change.current_revision]
- ._number).then(checks => {
- this.set('_hasChecks', checks.length > 0);
- if (checks.length > 0) {
- this._downgradeFailureToWarning =
- downgradeFailureToWarning(checks);
- this._failedRequiredChecksCount =
- this.computeFailedRequiredChecksCount(checks);
- this._checkStatuses = computeCheckStatuses(checks);
- }
- }, error => {
- this.set('_hasChecks', false);
- console.error(error);
- });
- }
-
- _onVisibililityChange() {
- if (document.hidden) {
- clearInterval(this.pollChecksInterval);
- return;
- }
- this._pollChecksRegularly(this.change, this.getChecks);
- }
-
- _pollChecksRegularly(change, getChecks) {
- if (this.pollChecksInterval) {
- clearInterval(this.pollChecksInterval);
- }
- const poll = () => this._fetchChecks(change, getChecks);
- poll();
- this.pollChecksInterval = setInterval(poll, CHECKS_POLL_INTERVAL_MS);
- if (!this.visibilityChangeListenerAdded) {
- this.visibilityChangeListenerAdded = true;
- this.listen(document, 'visibilitychange', '_onVisibililityChange');
- }
- }
-
- /**
- * @param {!Object} checkStatuses The number of checks in each status.
- * @return {string}
- */
- _computeStatus(checkStatuses) {
- return StatusPriorityOrder.find(
- status => checkStatuses[status] > 0) ||
- Statuses.STATUS_UNKNOWN;
- }
-
- computeFailedRequiredChecksCount(checks) {
- const failedRequiredChecks = checks.filter(
- check => {
- return check.state == Statuses.FAILED &&
- check.blocking && check.blocking.length > 0;
- }
- );
- return failedRequiredChecks.length;
- }
-
- /**
- * @param {string} status The overall status of the checks.
- * @param {!Object} checkStatuses The number of checks in each status.
- * @param {number} failedRequiredChecksCount The number of failed required checks.
- * @return {string}
- */
- _computeStatusString(status, checkStatuses, failedRequiredChecksCount) {
- if (!checkStatuses) return;
- if (checkStatuses.total === 0) return 'No checks';
- let statusString = `${checkStatuses[status]} of ${
- checkStatuses.total} checks ${HumanizedStatuses[status]}`;
- if (status === Statuses.FAILED && failedRequiredChecksCount > 0) {
- statusString += ` (${failedRequiredChecksCount} required)`;
- }
- return statusString;
- }
-
- /**
- * @param {string} status The overall status of the checks.
- * @return {string}
- */
- _computeChipClass(status) {
- return `chip ${statusClass(status)}`;
- }
-}
-
-customElements.define(GrChecksChipView.is, GrChecksChipView);
\ No newline at end of file
diff --git a/gr-checks/gr-checks-chip-view_test.html b/gr-checks/gr-checks-chip-view_test.html
deleted file mode 100644
index f5a02b3..0000000
--- a/gr-checks/gr-checks-chip-view_test.html
+++ /dev/null
@@ -1,88 +0,0 @@
-<!DOCTYPE html>
-<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
-<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
-<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
-<script src="../bower_components/web-component-tester/browser.js"></script>
-
-<title>gr-checks-chip-view</title>
-
-<test-fixture id="basic">
- <template>
- <gr-checks-chip-view></gr-checks-chip-view>
- </template>
-</test-fixture>
-
-<script type="module">
- import '../test/common-test-setup.js';
- import './gr-checks-chip-view.js';
- const CHECK1 = {
- checkId: 'test-check-id',
- log: 'http://example.com/test-log-url',
- started: '2019-02-06T22:25:19.269Z',
- finished: '2019-02-06T22:25:44.574Z',
- state: 'SUCCESSFUL',
- };
-
- const CHECK2 = {
- checkId: 'test-check-id-2',
- log: 'http://example.com/test-log-url',
- started: '2019-02-06T22:25:19.269Z',
- finished: '2019-02-06T22:25:44.574Z',
- state: 'FAILED',
- };
-
- suite('gr-checks-chip-view tests', () => {
- let element;
- let sandbox;
- let getChecksSpy;
-
- setup(done => {
- sandbox = sinon.sandbox.create();
-
- getChecksSpy = sinon.stub();
- getChecksSpy.returns(Promise.resolve([CHECK1, CHECK2, CHECK1]));
-
- element = fixture('basic');
- element.getChecks = getChecksSpy;
- element.change = {
- _number: 314,
- current_revision: 'abcd',
- revisions: {
- abcd: {
- _number: 271,
- },
- },
- };
- element.revision = {
- _number: 271,
- };
- flush(done);
- });
-
- teardown(() => { sandbox.restore(); });
-
- test('renders the checks prefix', () => {
- assert.include(element.shadowRoot.textContent.trim(), 'Checks:');
- });
-
- test('updating revision does not update getChecks call', done => {
- element.revision = {_number: 272};
- flush(() => {
- assert.isFalse(getChecksSpy.calledWith(314, 272));
- done();
- });
- });
-
- suite('builds chip contents', () => {
- test('queries the checks', () => {
- assert.isTrue(getChecksSpy.called);
- assert.isTrue(getChecksSpy.calledWith(314, 271));
- });
-
- test('renders the text of failed checks', () => {
- const chip = element.$$('.chip');
- assert.equal(chip.textContent.trim(), '1 of 3 checks failed');
- });
- });
- });
-</script>
diff --git a/gr-checks/gr-checks-item.js b/gr-checks/gr-checks-item.js
deleted file mode 100644
index 40c4d77..0000000
--- a/gr-checks/gr-checks-item.js
+++ /dev/null
@@ -1,258 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 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.
- */
-import './gr-checks-status.js';
-
-const Defs = {};
-/**
- * @typedef {{
- * project: string,
- * change_number: number,
- * patch_set_id: number,
- * checker_uuid: string,
- * state: string,
- * url: string,
- * started: string,
- * finished: string,
- * created: string,
- * updated: string,
- * checker_name: string,
- * checker_status: string,
- * blocking: Array<Object>,
- * }}
- */
-Defs.Check;
-
-class GrChecksItem extends Polymer.GestureEventListeners(
- Polymer.LegacyElementMixin(
- Polymer.Element)) {
- /** @returns {string} name of the component */
- static get is() { return 'gr-checks-item'; }
-
- /** @returns {?} template for this component */
- static get template() {
- return Polymer.html`
- <style>
- :host {
- border-top: 1px solid var(--border-color);
- }
-
- td:first-child {
- padding-left: 1rem;
- }
-
- td {
- padding: 1px 32px 1px 0;
- white-space: nowrap;
- }
-
- a.log {
- margin-right: 16px;
- display: inline-block;
- }
- .nav-icon {
- cursor: pointer;
- }
- .duration {
- text-align: center;
- }
- </style>
- <td>
- <template is="dom-if" if="[[check.message]]">
- <iron-icon
- class="nav-icon expand-message"
- on-click="_toggleMessageShown"
- icon="[[_computeExpandIcon(showCheckMessage)]]">
- </iron-icon>
- </template>
- </td>
- <td>[[check.checker_name]]</td>
- <td>[[_requiredForMerge]]</td>
- <td>
- <gr-checks-status
- show-text
- status="[[check.state]]"
- downgrade-failure-to-warning="[[false]]">
- </gr-checks-status>
- </td>
- <td>
- <gr-date-formatter
- has-tooltip
- show-date-and-time
- date-str="[[_startTime]]">
- </gr-date-formatter>
- </td>
- <td class="duration">[[_duration]]</td>
- <td>
- <a href$="[[check.url]]" target="_blank" class="log">
- <gr-button link no-uppercase disabled="[[!check.url]]">
- Details
- </gr-button>
- </a>
- </td>
- <td>
- <gr-button
- link
- no-uppercase
- on-click="_handleReRunClicked">
- Re-run
- </gr-button>
- </td>
- <td>[[check.checker_description]]</td>
- `;
- }
-
- /**
- * Defines properties of the component
- *
- * @returns {?}
- */
- static get properties() {
- return {
- /** @type {Defs.Check} */
- check: Object,
- /** @type {function(string): !Promise<!Object>} */
- _startTime: {
- type: String,
- computed: '_computeStartTime(check)',
- },
- _duration: {
- type: String,
- computed: '_computeDuration(check)',
- },
- _requiredForMerge: {
- type: String,
- computed: '_computeRequiredForMerge(check)',
- },
- showCheckMessage: {
- type: Boolean,
- value: false,
- },
- };
- }
-
- /**
- * Fired when the retry check button is pressed.
- *
- * @event retry-check
- */
-
- /**
- * @param {!Defs.Check} check
- * @return {string}
- */
- _computeStartTime(check) {
- if (!check.started) return '-';
- return check.started;
- }
-
- _toggleMessageShown() {
- this.showCheckMessage = !this.showCheckMessage;
- this.dispatchEvent(new CustomEvent('toggle-check-message',
- {
- detail: {uuid: this.check.checker_uuid},
- bubbles: true,
- composed: true,
- }));
- }
-
- _computeExpandIcon(showCheckMessage) {
- return showCheckMessage ? 'gr-icons:expand-less': 'gr-icons:expand-more';
- }
-
- /**
- * @param {!Defs.Check} check
- * @return {string}
- */
- _computeDuration(check) {
- if (!check.started || !check.finished) {
- return '-';
- }
- const startTime = new Date(check.started);
- const finishTime = check.finished ? new Date(check.finished) : new Date();
- return generateDurationString(startTime, finishTime);
- }
-
- /**
- * @param {!Defs.Check} check
- * @return {string}
- */
- _computeRequiredForMerge(check) {
- return (check.blocking && check.blocking.length === 0) ? 'Optional' :
- 'Required';
- }
-
- _handleReRunClicked() {
- this.dispatchEvent(new CustomEvent('retry-check',
- {
- detail: {uuid: this.check.checker_uuid},
- bubbles: false,
- composed: true,
- }));
- }
-}
-
-customElements.define(GrChecksItem.is, GrChecksItem);
-
-const ZERO_SECONDS = '0 sec';
-
-/**
- * @param {Date} startTime
- * @param {Date} endTime
- * @return {string}
- */
-function generateDurationString(startTime, endTime) {
- const secondsAgo = Math.round((endTime - startTime) / 1000);
-
- if (secondsAgo === 0) {
- return ZERO_SECONDS;
- }
-
- const durationSegments = [];
- if (secondsAgo % 60 !== 0) {
- durationSegments.push(`${secondsAgo % 60} sec`);
- }
- const minutesAgo = Math.floor(secondsAgo / 60);
- if (minutesAgo % 60 !== 0) {
- durationSegments.push(`${minutesAgo % 60} min`);
- }
- const hoursAgo = Math.floor(minutesAgo / 60);
- if (hoursAgo % 24 !== 0) {
- const hours = pluralize(hoursAgo % 24, 'hour', 'hours');
- durationSegments.push(`${hoursAgo % 24} ${hours}`);
- }
- const daysAgo = Math.floor(hoursAgo / 24);
- if (daysAgo % 30 !== 0) {
- const days = pluralize(daysAgo % 30, 'day', 'days');
- durationSegments.push(`${daysAgo % 30} ${days}`);
- }
- const monthsAgo = Math.floor(daysAgo / 30);
- if (monthsAgo > 0) {
- const months = pluralize(monthsAgo, 'month', 'months');
- durationSegments.push(`${monthsAgo} ${months}`);
- }
- return durationSegments.reverse().slice(0, 2).join(' ');
-}
-
-/**
- * @param {number} unit
- * @param {string} singular
- * @param {string} plural
- * @return {string}
- */
-function pluralize(unit, singular, plural) {
- return unit === 1 ? singular : plural;
-}
diff --git a/gr-checks/gr-checks-item_test.html b/gr-checks/gr-checks-item_test.html
deleted file mode 100644
index 305d965..0000000
--- a/gr-checks/gr-checks-item_test.html
+++ /dev/null
@@ -1,129 +0,0 @@
-<!DOCTYPE html>
-<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
-<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
-<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
-<script src="../bower_components/web-component-tester/browser.js"></script>
-
-<title>gr-checks-item</title>
-
-<test-fixture id="basic">
- <template>
- <gr-checks-item></gr-checks-item>
- </template>
-</test-fixture>
-
-<script type="module">
- import '../test/common-test-setup.js';
- import './gr-checks-item.js';
- const CHECKS_ITEM = {
- MESSAGE: 1,
- NAME: 2,
- BLOCKING: 3,
- STATUS: 4,
- START_TIME: 5,
- DURATION: 6,
- DETAILS: 7,
- RERUN: 8,
- DESCRIPTION: 9,
- };
- suite('gr-checks-item tests', () => {
- let element;
- let sandbox;
- let retryCheckSpy;
-
- setup(done => {
- sandbox = sinon.sandbox.create();
- retryCheckSpy = sinon.stub();
- retryCheckSpy.returns(Promise.resolve());
-
- element = fixture('basic');
- element.retryCheck = retryCheckSpy;
- element.check = {
- checkId: 'test-check-id',
- url: 'http://example.com/test-log-url',
- started: '2019-02-06T22:25:19.269Z',
- finished: '2019-02-06T22:25:44.574Z',
- };
- flush(done);
- });
-
- teardown(() => { sandbox.restore(); });
-
- test('renders the status', () => {
- const idx = CHECKS_ITEM.STATUS;
- const status = element.shadowRoot
- .querySelector(`td:nth-of-type(${idx}) > gr-checks-status`);
- assert.isOk(status);
- });
-
- test('renders the start time', () => {
- assert.equal(element._startTime, '2019-02-06T22:25:19.269Z');
- });
-
- suite('duration', () => {
- test('renders the run duration', () => {
- const idx = CHECKS_ITEM.DURATION;
- const name = element.$$(`td:nth-of-type(${idx})`);
- assert.equal(name.textContent.trim(), '25 sec');
- });
-
- test('renders 0 sec when the start and end time are the same', () => {
- element.check = {
- checkId: 'test-check-id',
- url: 'http://example.com/test-log-url',
- started: '2019-02-06T22:25:19.269Z',
- finished: '2019-02-06T22:25:19.269Z',
- };
- const idx = CHECKS_ITEM.DURATION;
- const name = element.shadowRoot
- .querySelector(`td:nth-of-type(${idx})`);
- assert.equal(name.textContent.trim(), '0 sec');
- });
-
- test('renders > 1m correctly', () => {
- element.check = {
- checkId: 'test-check-id',
- started: '2019-02-06T22:25:19.269Z',
- finished: '2019-02-06T22:45:29.269Z',
- };
- const idx = CHECKS_ITEM.DURATION;
- const name = element.shadowRoot
- .querySelector(`td:nth-of-type(${idx})`);
- assert.equal(name.textContent.trim(), '20 min 10 sec');
- });
-
- test('renders > 1h correctly', () => {
- element.check = {
- checkId: 'test-check-id',
- started: '2019-02-06T22:25:19.269Z',
- finished: '2019-02-06T23:45:29.269Z',
- };
- const idx = CHECKS_ITEM.DURATION;
- const name = element.shadowRoot
- .querySelector(`td:nth-of-type(${idx})`);
- assert.equal(name.textContent.trim(), '1 hour 20 min');
- });
-
- test('renders > 1d correctly', () => {
- element.check = {
- checkId: 'test-check-id',
- started: '2019-02-06T22:25:19.269Z',
- finished: '2019-02-07T23:45:29.269Z',
- };
- const idx = CHECKS_ITEM.DURATION;
- const name = element.shadowRoot
- .querySelector(`td:nth-of-type(${idx})`);
- assert.equal(name.textContent.trim(), '1 day 1 hour');
- });
- });
-
- test('renders a link to the log', () => {
- const idx = CHECKS_ITEM.DETAILS;
- const logLink = element.shadowRoot
- .querySelector(`td:nth-of-type(${idx}) > a`);
- assert.equal(logLink.getAttribute('href'),
- 'http://example.com/test-log-url');
- assert.equal(logLink.textContent.trim(), 'Details');
- });
- });
-</script>
diff --git a/gr-checks/gr-checks-status.js b/gr-checks/gr-checks-status.js
deleted file mode 100644
index 557e81c..0000000
--- a/gr-checks/gr-checks-status.js
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 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.
- */
-import {htmlTemplate} from './gr-checks-status_html.js';
-import {isNotRelevant, isUnevaluated, isInProgress, isRunning, isScheduled, isSuccessful, isFailed} from './gr-checks-all-statuses.js';
-
-class GrChecksStatus extends Polymer.GestureEventListeners(
- Polymer.LegacyElementMixin(
- Polymer.Element)) {
- /** @returns {string} name of the component */
- static get is() { return 'gr-checks-status'; }
-
- /** @returns {?} template for this component */
- static get template() { return htmlTemplate; }
-
- /**
- * Defines properties of the component
- *
- * @returns {?}
- */
- static get properties() {
- return {
- showText: {
- type: Boolean,
- value: false,
- reflectToAttribute: true,
- },
- status: String,
- downgradeFailureToWarning: String,
- };
- }
-
- _isNotRelevant(status) {
- return isNotRelevant(status);
- }
-
- _isUnevaluated(status) {
- return isUnevaluated(status);
- }
-
- _isInProgress(status) {
- return isInProgress(status);
- }
-
- _isRunning(status) {
- return isRunning(status);
- }
-
- _isScheduled(status) {
- return isScheduled(status);
- }
-
- _isSuccessful(status) {
- return isSuccessful(status);
- }
-
- _isFailed(status) {
- return !this.downgradeFailureToWarning &&
- isFailed(status);
- }
-
- _isWarning(status) {
- return this.downgradeFailureToWarning &&
- isFailed(status);
- }
-}
-
-customElements.define(GrChecksStatus.is, GrChecksStatus);
\ No newline at end of file
diff --git a/gr-checks/gr-checks-status_html.js b/gr-checks/gr-checks-status_html.js
deleted file mode 100644
index 5cca639..0000000
--- a/gr-checks/gr-checks-status_html.js
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 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.
- */
-
-export const htmlTemplate = Polymer.html`
- <style>
- :host {
- display: inline-block;
- }
- i {
- border-radius: 50%;
- color: white;
- display: inline-block;
- font-style: normal;
- height: 16px;
- margin-right: 4px;
- text-align: center;
- width: 16px;
- }
- svg {
- display: inline-block;
- vertical-align: middle;
- }
- </style>
- <span>
- <template is="dom-if" if="[[_isNotRelevant(status)]]">
- <svg width="18" height="18" xmlns="http://www.w3.org/2000/svg">
- <g fill="none" fill-rule="evenodd">
- <path d="M0 0h18v18H0z"/>
- <path d="M9 11.8a2.8 2.8 0 1 1 0-5.6 2.8 2.8 0 0 1 0 5.6M9 2a7 7 0 1 0 0 14A7 7 0 0 0 9 2" fill="#9E9E9E"/>
- </g>
- </svg>
- <template is="dom-if" if="[[showText]]">
- <span>
- Not relevant
- </span>
- </template>
- </template>
- <template is="dom-if" if="[[_isUnevaluated(status)]]">
- <svg width="18" height="18" xmlns="http://www.w3.org/2000/svg">
- <g fill="none" fill-rule="evenodd">
- <path d="M0 0h18v18H0z"/>
- <path d="M9 11.8a2.8 2.8 0 1 1 0-5.6 2.8 2.8 0 0 1 0 5.6M9 2a7 7 0 1 0 0 14A7 7 0 0 0 9 2" fill="#9E9E9E"/>
- </g>
- </svg>
- <template is="dom-if" if="[[showText]]">
- <span>
- Unevaluated
- </span>
- </template>
- </template>
- <template is="dom-if" if="[[_isScheduled(status)]]">
- <svg width="18" height="18" xmlns="http://www.w3.org/2000/svg">
- <g fill="none" fill-rule="evenodd">
- <path d="M12.184 9.293c-.86 0-1.641-.39-2.15-.976L9.8 9.489l.82.78V13.2h-.78v-2.344l-.821-.781-.39 1.719-2.736-.547.157-.782 1.914.391.625-3.164-.703.273v1.328h-.782V7.457l2.032-.86c.117 0 .196-.039.313-.039.273 0 .508.157.664.391l.39.625c.313.547.939.938 1.68.938v.781zM10.034 4.8c.43 0 .782.352.782.782 0 .43-.352.781-.781.781a.783.783 0 0 1-.782-.781c0-.43.352-.782.782-.782zM9 2a7 7 0 1 0 .002 14.002A7 7 0 0 0 9 2z" fill="#9C27B0"/>
- <path d="M0 0h18v18H0z"/>
- </g>
- </svg>
- <template is="dom-if" if="[[showText]]">
- <span>
- Scheduled
- </span>
- </template>
- </template>
- <template is="dom-if" if="[[_isRunning(status)]]">
- <svg width="18" height="18" xmlns="http://www.w3.org/2000/svg">
- <g fill="none" fill-rule="evenodd">
- <path d="M12.184 9.293c-.86 0-1.641-.39-2.15-.976L9.8 9.489l.82.78V13.2h-.78v-2.344l-.821-.781-.39 1.719-2.736-.547.157-.782 1.914.391.625-3.164-.703.273v1.328h-.782V7.457l2.032-.86c.117 0 .196-.039.313-.039.273 0 .508.157.664.391l.39.625c.313.547.939.938 1.68.938v.781zM10.034 4.8c.43 0 .782.352.782.782 0 .43-.352.781-.781.781a.783.783 0 0 1-.782-.781c0-.43.352-.782.782-.782zM9 2a7 7 0 1 0 .002 14.002A7 7 0 0 0 9 2z" fill="#9C27B0"/>
- <path d="M0 0h18v18H0z"/>
- </g>
- </svg>
- <template is="dom-if" if="[[showText]]">
- <span>
- Running
- </span>
- </template>
- </template>
- <template is="dom-if" if="[[_isSuccessful(status)]]">
- <svg width="18" height="18" xmlns="http://www.w3.org/2000/svg">
- <g fill="none" fill-rule="evenodd">
- <path d="M9 2C5.136 2 2 5.136 2 9s3.136 7 7 7 7-3.136 7-7-3.136-7-7-7zM7.6 12.5L4.1 9l.987-.987L7.6 10.519l5.313-5.313.987.994-6.3 6.3z" fill="#00C752"/>
- <path d="M0 0h18v18H0z"/>
- </g>
- </svg>
- <template is="dom-if" if="[[showText]]">
- <span>
- Successful
- </span>
- </template>
- </template>
- <template is="dom-if" if="[[_isFailed(status)]]">
- <svg width="18" height="18" xmlns="http://www.w3.org/2000/svg">
- <g fill="none" fill-rule="evenodd">
- <path d="M9 2a7 7 0 1 0 0 14A7 7 0 0 0 9 2zm-1 8V5h2v5H8zm0 3v-2h2v2H8z" fill="#DA4236"/>
- <path d="M0 0h18v18H0z"/>
- </g>
- </svg>
- <template is="dom-if" if="[[showText]]">
- <span>
- Failed
- </span>
- </template>
- </template>
- <template is="dom-if" if="[[_isWarning(status)]]">
- <svg width="18" height="18" xmlns="http://www.w3.org/2000/svg">
- <g fill="none" fill-rule="evenodd">
- <g transform="translate(2 2)">
- <circle fill="#F29900" cx="6.921" cy="6.921" r="6.921"/>
- <path d="M6.92 1.3l4.686 8.2H2.235L6.92 1.3zm-.584 5.271h1.171V3.643H6.336V6.57zm0 2.258h1.171V7.657H6.336V8.83z" fill="#F8F9FA"/>
- </g>
- <path d="M0 0h18v18H0z"/>
- </g>
- </svg>
- <template is="dom-if" if="[[showText]]">
- <span>
- Failed
- </span>
- </template>
- </template>
- </span>
-`;
\ No newline at end of file
diff --git a/gr-checks/gr-checks-status_test.html b/gr-checks/gr-checks-status_test.html
deleted file mode 100644
index 3963dc4..0000000
--- a/gr-checks/gr-checks-status_test.html
+++ /dev/null
@@ -1,63 +0,0 @@
-<!DOCTYPE html>
-<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
-<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
-<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
-<script src="../bower_components/web-component-tester/browser.js"></script>
-
-<title>gr-checks-item</title>
-
-<test-fixture id="basic">
- <template>
- <gr-checks-status></gr-checks-status>
- </template>
-</test-fixture>
-
-<script type="module">
- import '../test/common-test-setup.js';
- import './gr-checks-status.js';
- suite('gr-checks-status tests', () => {
- let sandbox;
-
- setup(() => {
- sandbox = sinon.sandbox.create();
- });
-
- teardown(() => { sandbox.restore(); });
-
- function testStatus(expectedStatusClass, statusText, statusesToTest) {
- suite(expectedStatusClass, () => {
- for (const statusToTest of statusesToTest) {
- test(`renders ${expectedStatusClass} for ${statusToTest}`, done => {
- const element = fixture('basic');
- element.status = statusToTest;
- element.showText = false;
-
- flush(() => {
- const svg = element.shadowRoot.querySelector(`span svg`);
- assert.isOk(svg);
- done();
- });
- });
- test(`renders ${expectedStatusClass} for ${statusToTest} rendering
- text ${statusText}`, done => {
- const element = fixture('basic');
- element.status = statusToTest;
- element.showText = true;
-
- flush(() => {
- const text = element.shadowRoot.querySelector(`span span`);
- assert.equal(text.textContent.trim(), statusText);
- done();
- });
- });
- }
- });
- }
-
- testStatus('successful', 'Successful', ['SUCCESSFUL']);
- testStatus('failed', 'Failed', ['FAILED']);
- testStatus('running', 'Running', ['RUNNING']);
- testStatus('running', 'Scheduled', ['SCHEDULED']);
- testStatus('unevaluated', 'Unevaluated', ['NOT_STARTED']);
- });
-</script>
diff --git a/gr-checks/gr-checks-view.js b/gr-checks/gr-checks-view.js
deleted file mode 100644
index a398509..0000000
--- a/gr-checks/gr-checks-view.js
+++ /dev/null
@@ -1,411 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 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.
- */
-import './gr-checkers-list.js';
-import './gr-checks-status.js';
-import './gr-checks-item.js';
-
-import {htmlTemplate} from './gr-checks-view_html.js';
-import {Statuses} from './gr-checks-all-statuses.js';
-
-const Defs = {};
-
-const StatusPriorityOrder = [
- Statuses.FAILED,
- Statuses.SCHEDULED,
- Statuses.RUNNING,
- Statuses.SUCCESSFUL,
- Statuses.NOT_STARTED,
- Statuses.NOT_RELEVANT,
-];
-
-const STATE_ALL = 'ALL';
-const CheckStateFilters = [STATE_ALL, ...StatusPriorityOrder];
-
-const CHECKS_POLL_INTERVAL_MS = 60 * 1000;
-const CHECKS_LIMIT = 20;
-
-/**
- * @typedef {{
- * _number: number,
- * }}
- */
-Defs.Change;
-/**
- * @typedef {{
- * _number: number,
- * }}
- */
-Defs.Revision;
-
-const LoadingStatus = {
- LOADING: 0,
- EMPTY: 1,
- RESULTS: 2,
- NOT_CONFIGURED: 3,
-};
-
-class GrChecksView extends Polymer.GestureEventListeners(
- Polymer.LegacyElementMixin(
- Polymer.Element)) {
- /** @returns {string} name of the component */
- static get is() { return 'gr-checks-view'; }
-
- /** @returns {?} template for this component */
- static get template() { return htmlTemplate; }
-
- /**
- * Defines properties of the component
- *
- * @returns {?}
- */
- static get properties() {
- return {
- revision: {
- type: Object,
- observer: '_handleRevisionUpdate',
- },
- change: Object,
- /** @type {function(number, number): !Promise<!Object>} */
- getChecks: Function,
- /** @type {function(string): !Promise<boolean>} */
- isConfigured: Function,
- /** @type {function(string, string): !Promise<!Object>} */
- pluginRestApi: Object,
- _checks: Array,
- _status: {
- type: Object,
- value: LoadingStatus.LOADING,
- },
- _visibleChecks: {
- type: Array,
- },
- _statuses: Array,
- pollChecksInterval: Number,
- visibilityChangeListenerAdded: {
- type: Boolean,
- value: false,
- },
- _createCheckerCapability: {
- type: Boolean,
- value: false,
- },
- _patchSetDropdownItems: {
- type: Array,
- value() { return []; },
- computed: '_computePatchSetDropdownItems(change)',
- },
- _currentPatchSet: {
- type: Number,
- },
- _currentStatus: {
- type: String,
- value: STATE_ALL,
- },
- _showBlockingChecksOnly: {
- type: Boolean,
- value: false,
- },
- _showAllChecks: {
- type: Boolean,
- value: false,
- },
- _filteredChecks: Array,
- _showMoreChecksButton: {
- type: Boolean,
- value: false,
- notify: true,
- },
- };
- }
-
- static get observers() {
- return [
- '_pollChecksRegularly(change, _currentPatchSet, getChecks)',
- '_updateVisibleChecks(_checks.*, _currentStatus, ' +
- '_showBlockingChecksOnly, _showAllChecks)',
- '_pluginReady(plugin)',
- ];
- }
-
- detached() {
- super.detached();
- clearInterval(this.pollChecksInterval);
- this.unlisten(document, 'visibilitychange', '_onVisibililityChange');
- }
-
- _pluginReady(plugin) {
- this.pluginRestApi = plugin.restApi();
- this._statuses = CheckStateFilters.map(state => {
- return {
- text: state,
- value: state,
- };
- });
- this._initCreateCheckerCapability();
- }
-
- _toggleShowChecks() {
- this._showAllChecks = !this._showAllChecks;
- }
-
- _computePatchSetDropdownItems(change) {
- return Object.values(change.revisions)
- .filter(patch => patch._number !== 'edit')
- .map(patch => {
- return {
- text: 'Patchset ' + patch._number,
- value: patch._number,
- };
- })
- .sort((a, b) => b.value - a.value);
- }
-
- _computeShowText(showAllChecks) {
- return showAllChecks ? 'Show Less' : 'Show All';
- }
-
- _updateVisibleChecks(checksRecord, status, showBlockingChecksOnly,
- showAllChecks) {
- const checks = checksRecord.base;
- if (!checks) return [];
- this._filteredChecks = checks.filter(check => {
- if (showBlockingChecksOnly && (!check.blocking ||
- !check.blocking.length)) return false;
- return status === STATE_ALL || check.state === status;
- });
- /* The showCheckMessage property is notified for change because the
- changes to showCheckMessage are not reflected to the dom as the object
- check has the same reference as before
- If not notified, then the message for the check is not displayed after
- clicking the toggle
- */
- this._showMoreChecksButton = this._filteredChecks.length > CHECKS_LIMIT;
- this._visibleChecks = this._filteredChecks.slice(0, showAllChecks ?
- undefined : CHECKS_LIMIT);
- this._visibleChecks.forEach((val, idx) =>
- this.notifyPath(`_visibleChecks.${idx}.showCheckMessage`));
- }
-
- _handleRevisionUpdate(revision) {
- if (!revision) return;
- this._currentPatchSet = revision._number;
- }
-
- _handlePatchSetChanged(e) {
- // gr-dropdown-list returns value of type "String"
- const patchSet = parseInt(e.detail.value);
- if (patchSet === this._currentPatchSet) return;
- this._currentPatchSet = patchSet;
- }
-
- _handleBlockingCheckboxClicked() {
- this._showBlockingChecksOnly = !this._showBlockingChecksOnly;
- }
-
- _handleStatusFilterChanged(e) {
- const status = e.detail.value;
- if (status === this._currentStatus) return;
- this._currentStatus = status;
- }
-
- _handleCheckersListResize() {
- // Force polymer to recalculate position of overlay when length of
- // checkers changes
- this.$.listOverlay.refit();
- }
-
- _initCreateCheckerCapability() {
- return this.pluginRestApi.getAccount().then(account => {
- if (!account) { return; }
- return this.pluginRestApi
- .getAccountCapabilities(['checks-administrateCheckers'])
- .then(capabilities => {
- if (capabilities['checks-administrateCheckers']) {
- this._createCheckerCapability = true;
- }
- });
- });
- }
-
- _handleConfigureClicked() {
- this.$$('gr-checkers-list')._showConfigureOverlay();
- }
-
- _orderChecks(a, b) {
- if (a.state != b.state) {
- const indexA = StatusPriorityOrder.indexOf(a.state);
- const indexB = StatusPriorityOrder.indexOf(b.state);
- if (indexA != -1 && indexB != -1) {
- return indexA - indexB;
- }
- return indexA == -1 ? 1 : -1;
- }
- if (a.state === Statuses.FAILED) {
- if (a.blocking && b.blocking &&
- a.blocking.length !== b.blocking.length) {
- return a.blocking.length == 0 ? 1 : -1;
- }
- }
- return a.checker_name.localeCompare(b.checker_name);
- }
-
- _handleRetryCheck(e) {
- const uuid = e.detail.uuid;
- const retryCheck = (change, revision, uuid) => this.pluginRestApi.post(
- '/changes/' + change + '/revisions/' + revision + '/checks/' + uuid
- + '/rerun'
- );
- retryCheck(this.change._number, this.revision._number, uuid).then(
- res => {
- this._fetchChecks(this.change, this.revision._number,
- this.getChecks);
- }, error => {
- this.dispatchEvent(new CustomEvent('show-error',
- {
- detail: {message: error.message},
- bubbles: true,
- composed: true,
- }));
- }
- );
- }
-
- /**
- * Explicity add showCheckMessage to maintain it
- *
- * Loop over checks to make sure no new checks are missed
- * Remove any check that is not returned the next time
- * Ensure message is updated
- *
- * @param {Array<Object>} checks
- * @returns {Object}
- */
- _updateChecks(checks) {
- return checks.map(
- check => {
- const prevCheck = this._checks.find(
- c => c.checker_uuid === check.checker_uuid
- );
- if (!prevCheck) return Object.assign({}, check);
- return Object.assign({}, check,
- {showCheckMessage: prevCheck.showCheckMessage});
- });
- }
-
- /**
- * @param {!Defs.Change} change
- * @param {!Defs.Revision} revisionNumber
- * @param {function(number, number): !Promise<!Object>} getChecks
- */
- _fetchChecks(change, revisionNumber, getChecks) {
- if (!getChecks || !change || !revisionNumber) return;
-
- getChecks(change._number, revisionNumber).then(checks => {
- if (revisionNumber !== this._currentPatchSet) return;
- if (checks && checks.length) {
- checks.sort((a, b) => this._orderChecks(a, b));
- if (!this._checks) {
- this._checks = checks;
- } else {
- this._checks = this._updateChecks(checks);
- }
- this.set('_status', LoadingStatus.RESULTS);
- } else {
- this._checkConfigured();
- }
- }, error => {
- this._checks = [];
- this.set('_status', LoadingStatus.EMPTY);
- });
- }
-
- _onVisibililityChange() {
- if (document.hidden) {
- clearInterval(this.pollChecksInterval);
- return;
- }
- this._pollChecksRegularly(this.change, this._currentPatchSet,
- this.getChecks);
- }
-
- _toggleCheckMessage(e) {
- const uuid = e.detail.uuid;
- if (!uuid) {
- console.warn('uuid not found');
- return;
- }
- const idx = this._checks.findIndex(check => check.checker_uuid === uuid);
- if (idx == -1) {
- console.warn('check not found');
- return;
- }
- // Update subproperty of _checks[idx] so that it reflects to polymer
- this.set(`_checks.${idx}.showCheckMessage`,
- !this._checks[idx].showCheckMessage);
- }
-
- _pollChecksRegularly(change, revisionNumber, getChecks) {
- if (!change || !revisionNumber || !getChecks) return;
- if (this.pollChecksInterval) {
- clearInterval(this.pollChecksInterval);
- }
- const poll = () => this._fetchChecks(change, revisionNumber, getChecks);
- poll();
- this.pollChecksInterval = setInterval(poll, CHECKS_POLL_INTERVAL_MS);
- if (!this.visibilityChangeListenerAdded) {
- this.visibilityChangeListenerAdded = true;
- this.listen(document, 'visibilitychange', '_onVisibililityChange');
- }
- }
-
- _checkConfigured() {
- const repository = this.change['project'];
- this.isConfigured(repository).then(configured => {
- const status =
- configured ? LoadingStatus.EMPTY : LoadingStatus.NOT_CONFIGURED;
- this.set('_status', status);
- });
- }
-
- _isLoading(status) {
- return status === LoadingStatus.LOADING;
- }
-
- _isEmpty(status) {
- return status === LoadingStatus.EMPTY;
- }
-
- _hasResults(status) {
- return status === LoadingStatus.RESULTS;
- }
-
- _isNotConfigured(status) {
- return status === LoadingStatus.NOT_CONFIGURED;
- }
-
- _computeHeaderClass(currentPatchSet, sortedAllPatchsets) {
- if (!sortedAllPatchsets
- || sortedAllPatchsets.length < 1
- || !currentPatchSet) {
- return '';
- }
- return currentPatchSet === sortedAllPatchsets[0].value ?
- '' : 'oldPatchset';
- }
-}
-
-customElements.define(GrChecksView.is, GrChecksView);
\ No newline at end of file
diff --git a/gr-checks/gr-checks-view_html.js b/gr-checks/gr-checks-view_html.js
deleted file mode 100644
index 22af763..0000000
--- a/gr-checks/gr-checks-view_html.js
+++ /dev/null
@@ -1,263 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 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.
- */
-
-export const htmlTemplate = Polymer.html`
- <style>
- :host {
- display: block;
- width: 100%;
- overflow: auto;
- }
-
- table {
- width: 100%;
- }
-
- gr-checks-item {
- display: table-row;
- }
-
- gr-dropdown-list {
- --trigger-style: {
- color: var(--deemphasized-text-color);
- text-transform: none;
- font-family: var(--font-family);
- }
- --trigger-hover-color: rgba(0,0,0,.6);
- }
- @media screen and (max-width: 50em) {
- gr-dropdown-list {
- --native-select-style: {
- max-width: 5.25em;
- }
- --dropdown-content-stype: {
- max-width: 300px;
- }
- }
- }
-
- .headerRow {
- border-bottom: 1px solid #ddd;
- }
-
- .topHeader {
- padding-right: 32px;
- padding-bottom: 4px;
- text-align: left;
- white-space: nowrap;
- }
-
- th.topHeader:last-child {
- width: 100%;
- }
-
- h2 {
- font-size: 1.17em;
- font-weight: 500;
- }
-
- h3 {
- flex: 1;
- font-size: 1.17em;
- font-weight: 500;
- margin-bottom: 1.5rem;
- }
-
- header {
- display: flex;
- padding: var(--spacing-s) var(--spacing-m);
- }
-
- header.oldPatchset {
- background: var(--emphasis-color);
- }
-
- table {
- margin-bottom: 16px;
- }
-
- th:first-child {
- padding-left: 1rem;
- }
-
- .no-content {
- min-height: 106px;
- padding: 24px 0;
- text-align: center;
- }
-
- /* Add max-width 1px to check-message make sure content doesn't
- expand beyond the table width */
- .check-message {
- padding-left: 1rem;
- background: var(--table-subheader-background-color);
- max-width: 1px;
- }
-
- .message {
- white-space: pre-wrap;
- word-wrap: break-word;
- }
-
- .message-heading {
- font-weight: bold;
- margin-top: 1em;
- }
-
- .check-message-heading {
- padding-left: 1em;
- }
-
- .configure-button-container {
- text-align: right;
- flex: 1;
- }
-
- .filter {
- margin-left: 10px;
- }
-
- #listOverlay {
- width: 75%;
- }
-
- .container {
- display: flex;
- width: 100%;
- }
-
- .blocking-checks-container {
- margin-left: 10px;
- display: flex;
- align-items: center;
- }
-
- .show-more-checks {
- margin: 0 0 var(--spacing-l) var(--spacing-l);
- }
-
- .checks-table {
- border-collapse: collapse;
- }
-
- </style>
-
- <header class$="[[_computeHeaderClass(_currentPatchSet, _patchSetDropdownItems)]]">
- <div class="container">
- <template is="dom-if" if="[[_patchSetDropdownItems.length]]">
- <gr-dropdown-list
- class="patch-set-dropdown"
- items="[[_patchSetDropdownItems]]"
- on-value-change="_handlePatchSetChanged"
- value="[[_currentPatchSet]]">
- </gr-dropdown-list>
- </template>
- <template is="dom-if" if="[[_hasResults(_status)]]">
- <div class="filter">
- <span> Filter By: </span>
- <gr-dropdown-list
- class="check-state-filter"
- items="[[_statuses]]"
- on-value-change="_handleStatusFilterChanged"
- value="[[_currentStatus]]">
- </gr-dropdown-list>
- </div>
- <div class="blocking-checks-container">
- <input type="checkbox"
- name="blocking"
- checked$="[[_showBlockingChecksOnly]]"
- on-click="_handleBlockingCheckboxClicked"
- value="blocking">
- Required for Submit
- </div>
- </template>
- <template is="dom-if" if="[[_createCheckerCapability]]">
- <div class="configure-button-container">
- <gr-button on-click="_handleConfigureClicked"> Configure </gr-button>
- </div>
- </template>
- </div>
- </header>
-
- <template is="dom-if" if="[[_isLoading(_status)]]">
- <div class="no-content">
- <p>Loading...</p>
- </div>
- </template>
-
- <template is="dom-if" if="[[_isEmpty(_status)]]">
- <div class="no-content">
- <h2>No checks ran for this code review</h2>
- <p>Configure checkers to view the results here.</p>
- </div>
- </template>
-
- <template is="dom-if" if="[[_isNotConfigured(_status)]]">
- <div class="no-content">
- <h2>Code review checks not configured</h2>
- <p>Configure checkers to view the results here.</p>
- </div>
- </template>
-
- <template is="dom-if" if="[[_hasResults(_status)]]">
- <table class="checks-table">
- <thead>
- <tr class="headerRow">
- <th class="topHeader"></th>
- <th class="topHeader">Name</th>
- <th class="topHeader">For submit</th>
- <th class="topHeader">Status</th>
- <th class="topHeader">Started</th>
- <th class="topHeader">Duration</th>
- <th class="topHeader"><!-- actions --></th>
- <th class="topHeader"><!-- re-run --></th>
- <th class="topHeader">Description</th>
- </tr>
- </thead>
- <tbody>
- <template is="dom-repeat" items="[[_visibleChecks]]" as="check">
- <tr>
- <gr-checks-item on-retry-check="_handleRetryCheck" on-toggle-check-message="_toggleCheckMessage"
- check="[[check]]">
- </gr-checks-item>
- </tr>
- <template is="dom-if" if="[[check.showCheckMessage]]">
- <tr>
- <td colspan="10" class="check-message-heading">
- <span class="message-heading">
- Message
- </span>
- </td>
- </tr>
- <tr>
- <td colspan="10" class="check-message">
- <span class="message"> [[check.message]] </span>
- </td>
- </tr>
- </template>
- </template>
- </tbody>
- </table>
- <template is="dom-if" if="[[_showMoreChecksButton]]">
- <gr-button class="show-more-checks" on-click="_toggleShowChecks">
- [[_computeShowText(_showAllChecks)]]
- </gr-button>
- </template>
- </template>
-
- <gr-checkers-list on-resize="_handleCheckersListResize" plugin-rest-api="[[pluginRestApi]]"></gr-checkers-list>
- `;
\ No newline at end of file
diff --git a/gr-checks/gr-checks-view_test.html b/gr-checks/gr-checks-view_test.html
deleted file mode 100644
index beeac95..0000000
--- a/gr-checks/gr-checks-view_test.html
+++ /dev/null
@@ -1,559 +0,0 @@
-<!DOCTYPE html>
-<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
-<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
-<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
-<script src="../bower_components/web-component-tester/browser.js"></script>
-
-<title>gr-checks-item</title>
-
-<!-- Gr-overlay does not exist in the test framework
-It is expected to be provided by Gerrit core -->
-
-<script type="module">
- import '../test/common-test-setup.js';
-
- class GrOverlay extends Polymer.Element {
- static get is() { return 'gr-overlay'; }
-
- refit() {}
-
- open() {}
- }
-
- customElements.define(GrOverlay.is, GrOverlay);
-</script>
-
-<test-fixture id="basic">
- <template>
- <gr-checks-view></gr-checks-view>
- </template>
-</test-fixture>
-
-<script type="module">
- import './gr-checks-view.js';
- import {Statuses} from './gr-checks-all-statuses.js';
-
- const CHECK1 = {
- checkId: 'test-check-id',
- logUrl: 'http://example.com/test-log-url',
- startTime: '2019-02-06T22:25:19.269Z',
- finishTime: '2019-02-06T22:25:44.574Z',
- checker_name: 'test checker',
- state: 'RUNNING',
- checker_status: 'ENABLED',
- blocking: [],
- checker_description: 'No-op jobs for testing purposes',
- message: '\n\nChange-Id: I8df212a28ae23cc239afd10ee4f506887e03ab70\n',
- showCheckMessage: undefined,
- checker_uuid: 'codestyle-a6a0e4682515f3521897c5f950d1394f4619d928',
- };
- const CHECK2 = {
- checkId: 'test-check-id2',
- logUrl: 'http://example.com/test-log-url',
- startTime: '2019-02-06T22:25:19.269Z',
- finishTime: '2019-02-06T22:25:44.574Z',
- checker_name: 'test checker2',
- state: 'RUNNING',
- checker_status: 'ENABLED',
- blocking: [],
- checker_description: 'No-op jobs for testing purposes 2',
- message: '\n\nChange-Id: I8df212a28ae23cc239afd10ee4f506887e03ab70\n',
- showCheckMessage: undefined,
- checker_uuid: 'polygerrit-a6a0e4682515f3521897c5f950d1394f4619d928',
- };
- const REVISION = {
- kind: 'REWORK',
- _number: 3,
- created: '2018-05-15 21:56:13.000000000',
- uploader: {
- _account_id: 1000000,
- },
- ref: 'refs/changes/00/1000/1',
- commit: {
- parents: [],
- subject: '',
- message: '\n\nChange-Id: I8df212a28ae23cc239afd10ee4f506887e03ab70\n',
- commit: '1c9a1dfd38ea51dc7880f3ddf669100710f0c91b',
- },
- };
- const REVISION2 = {
- kind: 'REWORK',
- _number: 2,
- created: '2018-05-15 21:56:13.000000000',
- uploader: {
- _account_id: 1000000,
- },
- ref: 'refs/changes/00/1000/2',
- commit: {
- parents: [],
- subject: '',
- message: '\n\nChange-Id: I8df212a28ae23cc239afd10ee4f506887e03ab70\n',
- commit: '1c9a1dfd38ea51dc6880f3ddf669100710f0c91b',
- },
- };
-
- const CHECKS_POLL_INTERVAL_MS = 60 * 1000;
- const STATE_ALL = 'ALL';
- const CHECKS_LIMIT = 20;
-
- suite('gr-checks-view tests', () => {
- let element;
- let sandbox;
- let getChecksSpy;
- let getChecksResolve;
- let retryCheckSpy;
- let isConfiguredSpy;
- let isConfiguredResolve;
- let getAccountSpy;
- let getAccountResolve;
- let fetchJSONSpy;
- let getAccountCapabilitiesSpy;
- let getAccountCapabilitiesResolve;
- let postSpy;
- let postReject;
- setup(done => {
- sandbox = sinon.sandbox.create();
-
- getChecksSpy = sinon.stub();
- const getChecksPromise = new Promise((resolve, reject) => {
- getChecksResolve = resolve;
- });
- getChecksSpy.returns(getChecksPromise);
-
- isConfiguredSpy = sinon.stub();
- const isConfiguredPromise = new Promise((resolve, reject) => {
- isConfiguredResolve = resolve;
- });
- isConfiguredSpy.returns(isConfiguredPromise);
-
- retryCheckSpy = sinon.stub();
- retryCheckSpy.returns(Promise.resolve());
-
- const plugin = {};
- getAccountSpy = sinon.stub();
- const getAccountPromise = new Promise((resolve, reject) => {
- getAccountResolve = resolve;
- });
- getAccountSpy.returns(getAccountPromise);
-
- postSpy = sinon.stub();
- const postPromise = new Promise((resolve, reject) => {
- postReject = reject;
- });
- postSpy.returns(postPromise);
-
- fetchJSONSpy = sinon.stub();
- const fetchJSONPromise = new Promise(() => {});
- fetchJSONSpy.returns(fetchJSONPromise);
-
- getAccountCapabilitiesSpy = sinon.stub();
- const getAccountCapabilitiesPromise = new Promise((resolve, reject) => {
- getAccountCapabilitiesResolve = resolve;
- });
- getAccountCapabilitiesSpy.returns(getAccountCapabilitiesPromise);
-
- plugin.restApi = () => ({
- getAccount: getAccountSpy,
- fetchJSON: fetchJSONSpy,
- getAccountCapabilities: getAccountCapabilitiesSpy,
- post: postSpy,
- });
- element = fixture('basic');
- Object.assign(element, {
- retryCheck: retryCheckSpy,
- getChecks: getChecksSpy,
- isConfigured: isConfiguredSpy,
- change: {
- project: 'test-repository',
- _number: 2,
- revisions: {
- 'first-sha': REVISION2,
- 'second-sha': REVISION,
- },
- },
- plugin,
- revision: REVISION,
- });
- flush(done);
- });
-
- teardown(() => { sandbox.restore(); });
-
- test('renders loading', () => {
- // Element also contains the hidden gr-overlay hence use includes
- assert(element.shadowRoot.textContent.trim().includes('Loading...'));
- });
-
- test('queries the checks', () => {
- assert.isTrue(getChecksSpy.called);
- assert.isTrue(getChecksSpy.calledWith(2, 3));
- });
-
- suite('no checks returned', () => {
- setup(done => {
- getChecksResolve([]);
- flush(done);
- });
-
- test('it calls to check if the checks are configured', () => {
- assert.isTrue(isConfiguredSpy.called);
- assert.isTrue(isConfiguredSpy.calledWith('test-repository'));
- });
-
- test('no configure button renders', () => {
- assert(!element.$$('gr-button'));
- });
-
- suite('not configured', () => {
- setup(done => {
- isConfiguredResolve(false);
- flush(done);
- });
-
- test('renders checks not configured', () => {
- const header = element.$$('h2');
- assert.equal(header.textContent.trim(),
- 'Code review checks not configured');
- });
-
- suite('create checker capability false', () => {
- setup(done => {
- getAccountResolve(true);
- getAccountCapabilitiesResolve({'checks-administrateCheckers': false});
- flush(done);
- });
-
- test('checker button does not render', () => {
- assert(!element.$$('gr-button'));
- });
- });
-
- suite('create checker capability true', () => {
- setup(done => {
- getAccountResolve(true);
- getAccountCapabilitiesResolve({'checks-administrateCheckers': true});
- flush(done);
- });
- test('checker button renders', () => {
- assert(element.$$('gr-button'));
- });
- });
- });
-
- suite('no checks ran', () => {
- setup(done => {
- isConfiguredResolve(true);
- flush(done);
- });
-
- test('renders checks not configured', () => {
- const header = element.shadowRoot.querySelector('h2');
- assert.equal(header.textContent.trim(),
- 'No checks ran for this code review');
- });
- });
- });
-
- suite('checks updated properly', () => {
- setup(done => {
- element._checks = [CHECK1, CHECK2];
- flush(done);
- });
-
- test('message is updated', () => {
- const NEW_CHECKS = [Object.assign({}, CHECK1),
- Object.assign({}, CHECK2)];
- NEW_CHECKS[0].message = 'New message 1';
- NEW_CHECKS[1].message = 'New message 2';
- const EXPECTED_CHECKS = [Object.assign({}, CHECK1),
- Object.assign({}, CHECK2)];
- EXPECTED_CHECKS[0].message = 'New message 1';
- EXPECTED_CHECKS[1].message = 'New message 2';
- const UPDATED_CHECKS = element._updateChecks(NEW_CHECKS);
- assert.equal(UPDATED_CHECKS[0].message, NEW_CHECKS[0].message);
- assert.equal(UPDATED_CHECKS[1].message, NEW_CHECKS[1].message);
- });
-
- test('total checks updated if one is deleted', () => {
- const NEW_CHECKS = [Object.assign({}, CHECK1)];
- const EXPECTED_CHECKS = [Object.assign({}, CHECK1)];
- const UPDATED_CHECKS = element._updateChecks(NEW_CHECKS);
- assert.equal(UPDATED_CHECKS.length, 1);
- assert.deepEqual(UPDATED_CHECKS, EXPECTED_CHECKS);
- });
-
- test('status is updated', () => {
- const NEW_CHECKS = [Object.assign({}, CHECK1),
- Object.assign({}, CHECK2)];
- NEW_CHECKS[0].state = 'SUCCESSFUL';
- NEW_CHECKS[1].state = 'FAILED';
- const UPDATED_CHECKS = element._updateChecks(NEW_CHECKS);
- assert.deepEqual(UPDATED_CHECKS, NEW_CHECKS);
- });
-
- test('showMessage property is retained', () => {
- element._checks[0].showCheckMessage = true;
- element._checks[1].showCheckMessage = false;
-
- const NEW_CHECKS = [Object.assign({}, CHECK1),
- Object.assign({}, CHECK2)];
- const UPDATED_CHECKS = element._updateChecks(NEW_CHECKS);
- assert.equal(UPDATED_CHECKS[0].showCheckMessage,
- CHECK1.showCheckMessage);
- assert.equal(UPDATED_CHECKS[1].showCheckMessage,
- CHECK2.showCheckMessage);
-
- element._checks[0].showCheckMessage = undefined;
- element._checks[1].showCheckMessage = undefined;
- });
-
- test('url is not set if new check has no url', () => {
- const NEW_CHECKS = [Object.assign({}, CHECK1),
- Object.assign({}, CHECK2)];
- delete NEW_CHECKS[0]['url'];
- delete NEW_CHECKS[1]['url'];
- const UPDATED_CHECKS = element._updateChecks(NEW_CHECKS);
- assert.isNotOk(UPDATED_CHECKS[0].url);
- assert.isNotOk(UPDATED_CHECKS[1].url);
- });
-
- test('url is not set if new check has no url', () => {
- const NEW_CHECKS = [Object.assign({}, CHECK1),
- Object.assign({}, CHECK2)];
- delete NEW_CHECKS[0]['url'];
- delete NEW_CHECKS[1]['url'];
- const UPDATED_CHECKS = element._updateChecks(NEW_CHECKS);
- assert.isNotOk(UPDATED_CHECKS[0].url);
- assert.isNotOk(UPDATED_CHECKS[1].url);
- });
-
- test('message is not shown if new check has no message', () => {
- const NEW_CHECKS = [Object.assign({}, CHECK1),
- Object.assign({}, CHECK2)];
- NEW_CHECKS[0].message = '';
- const UPDATED_CHECKS = element._updateChecks(NEW_CHECKS);
- assert.equal(UPDATED_CHECKS[0].message, NEW_CHECKS[0].message);
- });
- });
-
- suite('with checks', () => {
- setup(done => {
- const CHECK3 = Object.assign({}, CHECK1, {state: 'FAILED'});
- const CHECK4 = Object.assign({}, CHECK1, {state: 'FAILED',
- blocking: [1, 2, 3]});
- getChecksResolve([CHECK1, CHECK2, CHECK3, CHECK4]);
- flush(done);
- });
-
- test('it calls to check if the checks are configured', () => {
- assert.isFalse(isConfiguredSpy.called);
- });
-
- test('renders a table of all the checks', () => {
- const tbody = element.$$('table > tbody');
- assert.lengthOf(tbody.querySelectorAll('gr-checks-item'), 4);
- });
-
- test('retry fires show-error event', done => {
- postReject(new Error('random error'));
- const fireStub = sandbox.stub(element, 'dispatchEvent');
- Polymer.dom.flush();
- const checksItem = element.shadowRoot.querySelectorAll(
- 'table > tbody > gr-checks-item'
- )[0];
- const reRun = checksItem.shadowRoot.querySelectorAll('td')[7];
- const reRunButton = reRun.querySelector('gr-button');
- reRunButton.click();
- flush(() => {
- assert.equal(fireStub.firstCall.args[0].type, ('show-error'));
- done();
- });
- });
-
- suite('message is rendered', () => {
- setup(done => {
- element._checks = [CHECK1, CHECK2];
- flush(done);
- });
-
- test('messsage icon is displayed', () => {
- const checkItems = element.shadowRoot
- .querySelectorAll('gr-checks-item');
- const messagesCount = [...checkItems].reduce((count, item) => {
- return count += item.shadowRoot
- .querySelectorAll('.expand-message').length;
- }, 0);
- assert.equal(messagesCount,
- element._visibleChecks.length);
- });
-
- test('message displayed on clicking icon', done => {
- const checkItem = element.shadowRoot.querySelector('gr-checks-item');
- checkItem.shadowRoot
- .querySelector('.expand-message').click();
- flush(() => {
- const msg = element.shadowRoot
- .querySelector('.check-message').innerText
- .trim();
- assert.equal(msg, element._visibleChecks[0].message.trim());
- done();
- });
- });
- });
-
- suite('create checker capability false', () => {
- setup(done => {
- getAccountResolve(true);
- getAccountCapabilitiesResolve({'checks-administrateCheckers': false});
- flush(done);
- });
- test('checker button does not render', () => {
- assert(!element.$$('gr-button'));
- });
- });
-
- test('retry checks', done => {
- const checkItems = element.shadowRoot
- .querySelectorAll('gr-checks-item');
- const retryButton = checkItems[0].shadowRoot
- .querySelectorAll('gr-button')[1];
- MockInteractions.tap(retryButton);
- const expectedUrl = '/changes/2/revisions/3/checks/codestyle-'
- + 'a6a0e4682515f3521897c5f950d1394f4619d928/rerun';
- flush(() => {
- assert.isTrue(postSpy.calledWith(expectedUrl));
- done();
- });
- });
-
- suite('create checker capability true', () => {
- setup(done => {
- getAccountResolve(true);
- getAccountCapabilitiesResolve({
- 'checks-administrateCheckers': true,
- });
- flush(done);
- });
-
- test('checker button renders', () => {
- assert(element.$$('gr-button'));
- });
- });
-
- suite('patchset navigation', () => {
- test('renders the dropdown', () => {
- assert.isNotNull(element.shadowRoot
- .querySelector('.patch-set-dropdown'));
- });
-
- test('when patchset updated it fetches new checks', done => {
- const clock = sinon.useFakeTimers();
- const fetchChecksStub = sandbox.stub(element,
- '_fetchChecks');
- assert.equal(element._currentPatchSet, 3);
- element.revision = REVISION2;
- flush(() => {
- const firstCallArgs = fetchChecksStub.args[0];
- assert.equal(firstCallArgs[1], element._currentPatchSet);
- clock.tick(CHECKS_POLL_INTERVAL_MS + 1000);
- flush(() => {
- assert(fetchChecksStub.callCount === 2);
- const secondCallArgs = fetchChecksStub.args[1];
- assert.equal(secondCallArgs[1], element._currentPatchSet);
- done();
- });
- });
- });
-
- test('update to revision updates currentPatchset', done => {
- assert.equal(element._currentPatchSet, 3);
- element.revision = REVISION2;
- flush(() => {
- assert.equal(element._currentPatchSet, 2);
- done();
- });
- });
- });
-
- suite('check state filter', () => {
- test('renders the filter dropdown', () => {
- assert.isNotNull(element.shadowRoot
- .querySelector('.check-state-filter'));
- });
-
- test('default filter is all', () => {
- assert.equal(element._currentStatus, STATE_ALL);
- });
-
- test('updating filter status filters checks', done => {
- assert.equal(element._visibleChecks.length, 4);
- element._currentStatus = Statuses.RUNNING;
- flush(() => {
- assert.equal(element._visibleChecks.length, 2);
- done();
- });
- });
- });
-
- suite('blocking checkbox', () => {
- test('renders the checkbox', () => {
- assert.isNotNull(element.shadowRoot
- .querySelector('input[name="blocking"]'));
- });
-
- test('default filter is all', () => {
- assert.equal(element.shadowRoot
- .querySelector('input[name="blocking"]').checked,
- false);
- });
-
- test('blocking checkbox filters checks', done => {
- assert.equal(element._visibleChecks.length, 4);
- element.shadowRoot.querySelector('input[name="blocking"]').click();
- flush(() => {
- assert.equal(element._visibleChecks.length, 1);
- done();
- });
- });
- });
- });
-
- suite('with large number of checks', () => {
- setup(done => {
- const CHECK3 = Object.assign({}, CHECK1, {state: 'FAILED'});
- const CHECK4 = Object.assign({}, CHECK1, {state: 'FAILED',
- blocking: [1, 2, 3]});
- const checks = [];
- for (let i = 1; i <= 20; i++) {
- checks.push(...[CHECK1, CHECK2, CHECK3, CHECK4]);
- }
- getChecksResolve(checks);
- flush(done);
- });
-
- test('rendered checks are limited by default', () => {
- assert.equal(element._visibleChecks.length, CHECKS_LIMIT);
- });
-
- test('show more button expands to show all checks', () => {
- const showMoreChecksButton = element.shadowRoot
- .querySelector('.show-more-checks');
- assert.isOk(showMoreChecksButton);
- showMoreChecksButton.click();
- flush(() => {
- assert.equal(element._visibleChecks.length, element._checks.length);
- });
- });
-
- test('show more button hides if checks are below limit', () => {
- element._currentStatus = Statuses.NOT_STARTED;
- flush(() => {
- const showMoreChecksButton = element.querySelector(
- '.show-more-checks');
- assert.equal(showMoreChecksButton.style.display, 'none');
- });
- });
- });
- });
-
-</script>
diff --git a/gr-checks/gr-checks.js b/gr-checks/gr-checks.js
index 39152f5..d72e920 100644
--- a/gr-checks/gr-checks.js
+++ b/gr-checks/gr-checks.js
@@ -14,65 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import './gr-checks-chip-view.js';
-import './gr-checks-view.js';
-import './gr-checks-change-view-tab-header-view.js';
-import './gr-checks-change-list-header-view.js';
-import './gr-checks-change-list-item-cell-view.js';
-import './gr-checks-item.js';
-import './gr-checks-status.js';
import {RebootFetcher} from './gr-checks-reboot.js';
-function installChecksLegacy(plugin) {
- const getChecks = (change, revision) => {
- return plugin.restApi().get(
- '/changes/' + change + '/revisions/' + revision + '/checks?o=CHECKER');
- };
-
- // TODO(brohlfs): Enable this dashboard column when search queries start
- // returning checks.
- // plugin.registerDynamicCustomComponent(
- // 'change-list-header',
- // 'gr-checks-change-list-header-viewgg');
- // plugin.registerDynamicCustomComponent(
- // 'change-list-item-cell',
- // 'gr-checks-change-list-item-cell-view');
- plugin.registerCustomComponent(
- 'commit-container',
- 'gr-checks-chip-view').onAttached(
- view => {
- view['getChecks'] = getChecks;
- }
- );
- plugin.registerDynamicCustomComponent(
- 'change-view-tab-header',
- 'gr-checks-change-view-tab-header-view'
- );
- plugin.registerDynamicCustomComponent(
- 'change-view-tab-content',
- 'gr-checks-view').onAttached(
- view => {
- view['isConfigured'] = repository => Promise.resolve(true);
- view['getChecks'] = getChecks;
- });
-}
-
-function installChecksReboot(plugin) {
+Gerrit.install(plugin => {
const checksApi = plugin.checks();
const fetcher = new RebootFetcher(plugin.restApi());
checksApi.register({
- fetch: (data) => fetcher.fetch(data)
+ fetch: data => fetcher.fetch(data),
});
-}
-
-Gerrit.install(plugin => {
- const experiments = window.ENABLED_EXPERIMENTS || [];
- if (experiments.includes("UiFeature__ci_reboot_checks_checks")) {
- // Until end of 2020 this is only interesting for developing purposes. So
- // no real user is affected for the time being.
- console.log('Installing checks REBOOT plugin.');
- installChecksReboot(plugin);
- } else {
- installChecksLegacy(plugin);
- }
});