From a5155e15efa978828e3a11005727f9c810037323 Mon Sep 17 00:00:00 2001 From: Ralf Ueberfuhr Date: Fri, 6 Sep 2024 07:17:34 +0200 Subject: [PATCH] Hide tags column when JUnit tags are not used --- .../dev-ui/qwc/qwc-continuous-testing.js | 144 +++++++++--------- 1 file changed, 75 insertions(+), 69 deletions(-) diff --git a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-continuous-testing.js b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-continuous-testing.js index ce4bfedec57cd..8dea8c9e6acc1 100644 --- a/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-continuous-testing.js +++ b/extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-continuous-testing.js @@ -80,7 +80,8 @@ export class QwcContinuousTesting extends QwcHotReloadElement { _state: {state: true}, _results: {state: true}, _busy: {state: true}, - _detailsOpenedItem: {state: true, type: Array} + _detailsOpenedItem: {state: true, type: Array}, + _displayTags: {state: true, type: Boolean}, }; constructor() { @@ -136,14 +137,56 @@ export class QwcContinuousTesting extends QwcHotReloadElement { } render() { + let results = this._prepareResultsToRender(); return html` - ${this._renderMenuBar()} - ${this._renderResultSet()} - ${this._renderBarChart()} + ${this._renderMenuBar(results)} + ${this._renderResults(results)} + ${this._renderBarChart(results)} `; } - _renderMenuBar(){ + _prepareResultsToRender() { + if(this._state && this._state.running && this._results && this._results.results) { + let itemsByState = { + passing: [], + failing: [], + skipped: [], + } + Object + .values(this._results.results) + .forEach(item => { + itemsByState.passing.push(...item.passing.filter( obj => obj.test === true )); + itemsByState.failing.push(...item.failing.filter( obj => obj.test === true )); + itemsByState.skipped.push(...item.skipped.filter( obj => obj.test === true )); + }); + let items = itemsByState.failing.concat( + itemsByState.passing, + itemsByState.skipped + ); + let hasTags = items.find( item => item.tags && item.tags.length > 0 ); + return { + items: items, + meta: { + hasTags: hasTags, + failing: itemsByState.failing.length, + passing: itemsByState.passing.length, + skipped: itemsByState.skipped.length, + }, + } + } else { + return { + items: [], + meta: { + hasTags: false, + failing: 0, + passing: 0, + skipped: 0, + }, + }; + } + } + + _renderMenuBar(results){ if(this._state){ return html``; @@ -162,9 +205,9 @@ export class QwcContinuousTesting extends QwcHotReloadElement { } } - _renderBarChart(){ - if(this._state && this._state.running && this._state.run > 0){ - let values = [this._state.passed, this._state.failed, this._state.skipped]; + _renderBarChart(results){ + if(this._state && this._state.running && results.items.length > 0){ + let values = [results.meta.passing, results.meta.failing, results.meta.skipped]; return html` 0){ - - let items = []; - - for (let i = 0; i < results.length; i++) { - let result = results[i]; - - let failingResult = result.failing.filter(function( obj ) { - return obj.test === true; - }); - let passingResult = result.passing.filter(function( obj ) { - return obj.test === true; - }); - let skippedResult = result.skipped.filter(function( obj ) { - return obj.test === true; - }); + if(results.items.length > 0){ + + return html` + + ${ + this._displayTags && results.meta.hasTags + ? html` this._tagsRenderer(prop), [])}>` + : '' + } + this._testRenderer(prop), [])}> + this._nameRenderer(prop), [])}> + this._timeRenderer(prop), [])}>> + `; - items.push.apply(items, failingResult); - items.push.apply(items, passingResult); - items.push.apply(items, skippedResult); - } - - if(items.length>0){ - return html` - - ${this._displayTags ? html` - this._tagsRenderer(prop), [])}> - `: ''} - this._testRenderer(prop), [])}> - this._nameRenderer(prop), [])}> - this._timeRenderer(prop), [])}>> - `; - }else{ - return html`No tests`; - } - }else{ return html`No tests`; } @@ -402,13 +409,13 @@ export class QwcContinuousTesting extends QwcHotReloadElement { } } - _renderToggleDisplayTags() { + _renderToggleDisplayTags(results) { if(this._state && this._state.running){ return html` + ?disabled=${this._state.inProgress || this._busy || !results.meta.hasTags} + label="Display tags (if available)"> `; } } @@ -454,7 +461,6 @@ export class QwcContinuousTesting extends QwcHotReloadElement { _toggleDisplayTags(){ this._displayTags = !this._displayTags; - this.hotReload(); } } customElements.define('qwc-continuous-testing', QwcContinuousTesting); \ No newline at end of file