Skip to content

Commit

Permalink
Small improvements to the test history tab
Browse files Browse the repository at this point in the history
  • Loading branch information
john-dupuy authored and jjaquish committed Aug 9, 2022
1 parent c5d4a77 commit abd1793
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 19 deletions.
4 changes: 3 additions & 1 deletion frontend/src/components/classify-failures.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ export class ClassifyFailuresTable extends React.Component {
let result = rows[rowIndex].result;
let hideSummary=true;
let hideTestObject=true;
let defaultTab="test-history";
if (result.result === "skipped") {
hideSummary=false;
hideTestObject=false;
defaultTab="summary";
}
rows[rowIndex + 1].cells = [{
title: <ResultView hideTestHistory={false} hideSummary={hideSummary} hideTestObject={hideTestObject} testResult={rows[rowIndex].result}/>
title: <ResultView defaultTab={defaultTab} hideTestHistory={false} hideSummary={hideSummary} hideTestObject={hideTestObject} testResult={rows[rowIndex].result}/>
}]
}
rows[rowIndex].isOpen = isOpen;
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/components/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class ResultView extends React.Component {
static propTypes = {
testResult: PropTypes.object,
resultId: PropTypes.string,
defaultTab: PropTypes.string,
hideSummary: PropTypes.bool,
hideTestObject: PropTypes.bool,
hideTestHistory: PropTypes.bool,
Expand All @@ -85,7 +86,10 @@ export class ResultView extends React.Component {
}

getDefaultTab() {
if (!this.props.hideSummary) {
if (this.props.defaultTab) {
return this.props.defaultTab;
}
else if (!this.props.hideSummary) {
return 'summary';
}
else if (!!this.state && this.state.artifactTabs.length > 0) {
Expand Down Expand Up @@ -205,6 +209,9 @@ export class ResultView extends React.Component {

componentDidMount() {
this.getResult();
if (this.state.activeTab === "test-history") {
this.getTestHistoryTable();
}
}

componentWillUnmount() {
Expand Down
65 changes: 48 additions & 17 deletions frontend/src/components/test-history.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import {
Badge,
Button,
Card,
CardHeader,
Expand All @@ -19,6 +19,7 @@ import {
TableVariant,
expandable
} from '@patternfly/react-table';
import { Link } from 'react-router-dom';

import { HttpClient } from '../services/http';
import { Settings } from '../settings';
Expand Down Expand Up @@ -60,6 +61,7 @@ export class TestHistoryTable extends React.Component {
onlyFailures: false,
historySummary: null,
dropdownSelection: '1 Week',
lastPassedDate: 'n/a',
filters: Object.assign({
'result': {op: 'in', val: "passed;skipped;failed;error;xpassed;xfailed"},
'test_id': {op: 'eq', val: props.testResult.test_id},
Expand All @@ -73,7 +75,7 @@ export class TestHistoryTable extends React.Component {
}

refreshResults = () => {
this.getResultsForTable();
this.getHistorySummary();
}

onCollapse(event, rowIndex, isOpen) {
Expand All @@ -84,7 +86,7 @@ export class TestHistoryTable extends React.Component {
let result = rows[rowIndex].result;
let hideSummary=true;
let hideTestObject=true;
if (["passed", "skipped"].includes(result.result)) {
if (["passed", "skipped", "xfailed"].includes(result.result)) {
hideSummary=false;
hideTestObject=false;
}
Expand Down Expand Up @@ -192,14 +194,43 @@ export class TestHistoryTable extends React.Component {
data.forEach(item => {
summary[dataToSummary[item['_id']]] = item['count']
})
this.setState({historySummary: summary})
this.setState({historySummary: summary}, this.getResultsForTable)
})
}

getLastPassed(){
// get the passed/failed/etc test summary
let filters = {... this.state.filters};
// disregard result filter so we can filter on last passed
delete filters["result"];
delete filters["start_time"];
filters["result"] = {"op": "eq", "val": "passed"}
let params = buildParams(filters);
params['filter'] = toAPIFilter(filters);
params['pageSize'] = 1;
params['page'] = 1;

HttpClient.get([Settings.serverUrl, 'result'], params)
.then(response => HttpClient.handleResponse(response))
.then(data => this.setState({
lastPassedDate:
<React.Fragment>
<Link target="_blank" rel="noopener noreferrer" to={`/results/${data.results[0].id}`}>
<Badge isRead>
{new Date(data.results[0].start_time).toLocaleString()}
</Badge>
</Link>
</React.Fragment>
}))
.catch((error) => {
console.error('Error fetching result data:', error);
this.setState({lastPassedDate: <Badge isRead>{'n/a'}</Badge>});
});
}

getResultsForTable() {
const filters = this.state.filters;
this.setState({rows: [getSpinnerRow(4)], isEmpty: false, isError: false});
// get only failed results
let params = buildParams(filters);
params['filter'] = toAPIFilter(filters);
params['pageSize'] = this.state.pageSize;
Expand All @@ -216,15 +247,16 @@ export class TestHistoryTable extends React.Component {
totalItems: data.pagination.totalItems,
totalPages: data.pagination.totalPages,
isEmpty: data.pagination.totalItems === 0,
}, this.getHistorySummary))
}))
.catch((error) => {
console.error('Error fetching result data:', error);
this.setState({rows: [], isEmpty: false, isError: true});
});
}

componentDidMount() {
this.getResultsForTable();
this.getHistorySummary();
this.getLastPassed();
}

render() {
Expand Down Expand Up @@ -268,16 +300,6 @@ export class TestHistoryTable extends React.Component {
</Text>
</TextContent>
</FlexItem>
<FlexItem>
<TextContent>
<Text component="h3">
Summary:&nbsp;
{historySummary &&
<RunSummary summary={historySummary}/>
}
</Text>
</TextContent>
</FlexItem>
<FlexItem>
<TextContent>
<Checkbox id="only-failures" label="Only show failures/errors" isChecked={onlyFailures} aria-label="only-failures-checkbox" onChange={this.onFailuresCheck}/>
Expand Down Expand Up @@ -309,6 +331,15 @@ export class TestHistoryTable extends React.Component {
canSelectAll={false}
variant={TableVariant.compact}
activeFilters={this.state.filters}
filters={[
<Text key="summary" component="h4">
Summary:&nbsp;
{historySummary &&
<RunSummary summary={historySummary}/>
}
</Text>,
<Text key="last-passed" component="h4">Last passed:&nbsp;{this.state.lastPassedDate}</Text>,
]}
onRemoveFilter={this.removeFilter}
hideFilters={["project_id", "result", "test_id"]}
/>
Expand Down

0 comments on commit abd1793

Please sign in to comment.