Commit 167a7e21 authored by mfluharty's avatar mfluharty

Show recent failures count on widget and per suite

Count recent failures when reports are loaded
Store counts in report summaries
Display counts in the widget
parent b5e66b4b
...@@ -11,7 +11,12 @@ import Modal from './modal.vue'; ...@@ -11,7 +11,12 @@ import Modal from './modal.vue';
import createStore from '../store'; import createStore from '../store';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { summaryTextBuilder, reportTextBuilder, statusIcon } from '../store/utils'; import {
summaryTextBuilder,
reportTextBuilder,
statusIcon,
recentFailuresTextBuilder,
} from '../store/utils';
export default { export default {
name: 'GroupedTestReportsApp', name: 'GroupedTestReportsApp',
...@@ -86,6 +91,12 @@ export default { ...@@ -86,6 +91,12 @@ export default {
return reportTextBuilder(name, summary); return reportTextBuilder(name, summary);
}, },
hasRecentFailures(summary) {
return summary?.recentlyFailed > 0;
},
getRecentFailuresText(summary) {
return recentFailuresTextBuilder(summary);
},
getReportIcon(report) { getReportIcon(report) {
return statusIcon(report.status); return statusIcon(report.status);
}, },
...@@ -134,14 +145,22 @@ export default { ...@@ -134,14 +145,22 @@ export default {
{{ s__('ciReport|View full report') }} {{ s__('ciReport|View full report') }}
</gl-button> </gl-button>
</template> </template>
<template v-if="hasRecentFailures(summary)" #subHeading>
{{ getRecentFailuresText(summary) }}
</template>
<template #body> <template #body>
<div class="mr-widget-grouped-section report-block"> <div class="mr-widget-grouped-section report-block">
<template v-for="(report, i) in reports"> <template v-for="(report, i) in reports">
<summary-row <summary-row :key="`summary-row-${i}`" :status-icon="getReportIcon(report)">
:key="`summary-row-${i}`" <template #summary>
:summary="reportText(report)" <div class="gl-display-inline-flex gl-flex-direction-column">
:status-icon="getReportIcon(report)" <div>{{ reportText(report) }}</div>
/> <div v-if="hasRecentFailures(report.summary)">
{{ getRecentFailuresText(report.summary) }}
</div>
</div>
</template>
</summary-row>
<issues-list <issues-list
v-if="shouldRenderIssuesList(report)" v-if="shouldRenderIssuesList(report)"
:key="`issues-list-${i}`" :key="`issues-list-${i}`"
......
import * as types from './mutation_types'; import * as types from './mutation_types';
import { countRecentlyFailedTests } from './utils';
export default { export default {
[types.SET_ENDPOINT](state, endpoint) { [types.SET_ENDPOINT](state, endpoint) {
...@@ -16,9 +17,15 @@ export default { ...@@ -16,9 +17,15 @@ export default {
state.summary.resolved = response.summary.resolved; state.summary.resolved = response.summary.resolved;
state.summary.failed = response.summary.failed; state.summary.failed = response.summary.failed;
state.summary.errored = response.summary.errored; state.summary.errored = response.summary.errored;
state.summary.recentlyFailed = countRecentlyFailedTests(response.suites);
state.status = response.status; state.status = response.status;
state.reports = response.suites; state.reports = response.suites;
state.reports.forEach((report, i) => {
if (!state.reports[i].summary) return;
state.reports[i].summary.recentlyFailed = countRecentlyFailedTests(report);
});
}, },
[types.RECEIVE_REPORTS_ERROR](state) { [types.RECEIVE_REPORTS_ERROR](state) {
state.isLoading = false; state.isLoading = false;
...@@ -30,6 +37,7 @@ export default { ...@@ -30,6 +37,7 @@ export default {
resolved: 0, resolved: 0,
failed: 0, failed: 0,
errored: 0, errored: 0,
recentlyFailed: 0,
}; };
state.status = null; state.status = null;
}, },
......
...@@ -48,6 +48,38 @@ export const reportTextBuilder = (name = '', results = {}) => { ...@@ -48,6 +48,38 @@ export const reportTextBuilder = (name = '', results = {}) => {
return sprintf(__('%{name} found %{resultsString}'), { name, resultsString }); return sprintf(__('%{name} found %{resultsString}'), { name, resultsString });
}; };
export const recentFailuresTextBuilder = (summary = {}) => {
const { failed, recentlyFailed } = summary;
if (!failed || !recentlyFailed) return '';
const failedString = n__('%d failed test', '%d failed tests', failed);
const recentOutOfFailedString = n__(
sprintf('%d out of %{failedString} has failed', { failedString }),
sprintf('%d out of %{failedString} have failed', { failedString }),
recentlyFailed,
);
return sprintf(s__(`Reports|%{recentOutOfFailedString} more than once in the last 14 days`), {
recentOutOfFailedString,
});
};
export const countRecentlyFailedTests = subject => {
// handle either a single report or an array of reports
const reports = !subject.length ? [subject] : subject;
return reports
.map(report => {
return (
[report.new_failures, report.existing_failures, report.resolved_failures]
// only count tests which have failed more than once
.map(failureArray => failureArray.filter(failure => failure.recent_failures > 1).length)
.reduce((total, count) => total + count, 0)
);
})
.reduce((total, count) => total + count, 0);
};
export const statusIcon = status => { export const statusIcon = status => {
if (status === STATUS_FAILED) { if (status === STATUS_FAILED) {
return ICON_WARNING; return ICON_WARNING;
......
...@@ -195,6 +195,11 @@ msgid_plural "%d failed security jobs" ...@@ -195,6 +195,11 @@ msgid_plural "%d failed security jobs"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
msgid "%d failed test"
msgid_plural "%d failed tests"
msgstr[0] ""
msgstr[1] ""
msgid "%d fixed test result" msgid "%d fixed test result"
msgid_plural "%d fixed test results" msgid_plural "%d fixed test results"
msgstr[0] "" msgstr[0] ""
...@@ -11208,6 +11213,11 @@ msgstr "" ...@@ -11208,6 +11213,11 @@ msgstr ""
msgid "Failed" msgid "Failed"
msgstr "" msgstr ""
msgid "Failed %d time in the last 14 days"
msgid_plural "Failed %d times in the last 14 days"
msgstr[0] ""
msgstr[1] ""
msgid "Failed Jobs" msgid "Failed Jobs"
msgstr "" msgstr ""
...@@ -22688,6 +22698,9 @@ msgstr "" ...@@ -22688,6 +22698,9 @@ msgstr ""
msgid "Reports|%{combinedString} and %{resolvedString}" msgid "Reports|%{combinedString} and %{resolvedString}"
msgstr "" msgstr ""
msgid "Reports|%{recentOutOfFailedString} more than once in the last 14 days"
msgstr ""
msgid "Reports|Accessibility scanning detected %d issue for the source branch only" msgid "Reports|Accessibility scanning detected %d issue for the source branch only"
msgid_plural "Reports|Accessibility scanning detected %d issues for the source branch only" msgid_plural "Reports|Accessibility scanning detected %d issues for the source branch only"
msgstr[0] "" msgstr[0] ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment