Skip to content

Commit

Permalink
Hide tags column when JUnit tags are not used
Browse files Browse the repository at this point in the history
  • Loading branch information
ueberfuhr committed Sep 6, 2024
1 parent 132ee7a commit a5155e1
Showing 1 changed file with 75 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -136,22 +137,64 @@ 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`<div class="menubar">
<div>
${this._renderStopStartButton()}
${this._renderRunAllButton()}
${this._renderRunFailedButton()}
${this._renderToggleBrokenOnly()}
${this._renderToggleDisplayTags()}
${this._renderToggleDisplayTags(results)}
</div>
${this._renderBusyIndicator()}
</div>`;
Expand All @@ -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`<echarts-horizontal-stacked-bar name = "Tests"
sectionTitles="${this._chartTitles.toString()}"
sectionValues="${values.toString()}"
Expand Down Expand Up @@ -195,64 +238,28 @@ export class QwcContinuousTesting extends QwcHotReloadElement {

}

_renderResultSet(){
if(this._state && this._state.running && this._results && this._results.results) {

let failingResults = this._results.failing;
let passingResults = this._results.passing;
let skippedResults = this._results.skipped;

var allResults = failingResults.concat(passingResults, skippedResults);

return html`${this._renderResults(allResults)}`;
}

}

_renderResults(results){
if(results.length > 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`
<vaadin-grid .items="${results.items}" class="resultTable" theme="no-border"
.detailsOpenedItems="${this._detailsOpenedItem}"
@active-item-changed="${(event) => {
const prop = event.detail.value;
this._detailsOpenedItem = prop ? [prop] : [];
}}"
${gridRowDetailsRenderer(this._descriptionRenderer, [])}
>
${
this._displayTags && results.meta.hasTags
? html`<vaadin-grid-sort-column path="tags" header="Tags" ${columnBodyRenderer((prop) => this._tagsRenderer(prop), [])}></vaadin-grid-sort-column>`
: ''
}
<vaadin-grid-sort-column path="testClass" header="Test Class" ${columnBodyRenderer((prop) => this._testRenderer(prop), [])}></vaadin-grid-sort-column>
<vaadin-grid-sort-column path="displayName" header="Name" ${columnBodyRenderer((prop) => this._nameRenderer(prop), [])}></vaadin-grid-sort-column>
<vaadin-grid-sort-column path="time" header="Time" ${columnBodyRenderer((prop) => this._timeRenderer(prop), [])}>></vaadin-grid-sort-column>
</vaadin-grid>`;

items.push.apply(items, failingResult);
items.push.apply(items, passingResult);
items.push.apply(items, skippedResult);
}

if(items.length>0){
return html`
<vaadin-grid .items="${items}" class="resultTable" theme="no-border"
.detailsOpenedItems="${this._detailsOpenedItem}"
@active-item-changed="${(event) => {
const prop = event.detail.value;
this._detailsOpenedItem = prop ? [prop] : [];
}}"
${gridRowDetailsRenderer(this._descriptionRenderer, [])}
>
${this._displayTags ? html`
<vaadin-grid-sort-column path="tags" header="Tags" ${columnBodyRenderer((prop) => this._tagsRenderer(prop), [])}></vaadin-grid-sort-column>
`: ''}
<vaadin-grid-sort-column path="testClass" header="Test Class" ${columnBodyRenderer((prop) => this._testRenderer(prop), [])}></vaadin-grid-sort-column>
<vaadin-grid-sort-column path="displayName" header="Name" ${columnBodyRenderer((prop) => this._nameRenderer(prop), [])}></vaadin-grid-sort-column>
<vaadin-grid-sort-column path="time" header="Time" ${columnBodyRenderer((prop) => this._timeRenderer(prop), [])}>></vaadin-grid-sort-column>
</vaadin-grid>`;
}else{
return html`No tests`;
}

}else{
return html`No tests`;
}
Expand Down Expand Up @@ -402,13 +409,13 @@ export class QwcContinuousTesting extends QwcHotReloadElement {
}
}

_renderToggleDisplayTags() {
_renderToggleDisplayTags(results) {
if(this._state && this._state.running){
return html`<vaadin-checkbox id="display-tags-cnt-testing-chk" theme="small"
@change="${this._toggleDisplayTags}"
?checked=${this._displayTags}
?disabled=${this._state.inProgress || this._busy}
label="Display tags">
?disabled=${this._state.inProgress || this._busy || !results.meta.hasTags}
label="Display tags (if available)">
</vaadin-checkbox>`;
}
}
Expand Down Expand Up @@ -454,7 +461,6 @@ export class QwcContinuousTesting extends QwcHotReloadElement {

_toggleDisplayTags(){
this._displayTags = !this._displayTags;
this.hotReload();
}
}
customElements.define('qwc-continuous-testing', QwcContinuousTesting);

0 comments on commit a5155e1

Please sign in to comment.