2019-07-31 22:56:46 +05:30
|
|
|
import { sprintf, n__, s__, __ } from '~/locale';
|
2018-11-18 11:00:15 +05:30
|
|
|
import {
|
|
|
|
STATUS_FAILED,
|
|
|
|
STATUS_SUCCESS,
|
|
|
|
ICON_WARNING,
|
|
|
|
ICON_SUCCESS,
|
|
|
|
ICON_NOTFOUND,
|
|
|
|
} from '../constants';
|
|
|
|
|
|
|
|
const textBuilder = results => {
|
2020-03-13 15:44:24 +05:30
|
|
|
const { failed, errored, resolved, total } = results;
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
const failedOrErrored = (failed || 0) + (errored || 0);
|
2020-04-08 14:13:33 +05:30
|
|
|
const failedString = failed ? n__('%d failed', '%d failed', failed) : null;
|
|
|
|
const erroredString = errored ? n__('%d error', '%d errors', errored) : null;
|
|
|
|
const combinedString =
|
|
|
|
failed && errored ? `${failedString}, ${erroredString}` : failedString || erroredString;
|
2018-11-18 11:00:15 +05:30
|
|
|
const resolvedString = resolved
|
|
|
|
? n__('%d fixed test result', '%d fixed test results', resolved)
|
|
|
|
: null;
|
|
|
|
const totalString = total ? n__('out of %d total test', 'out of %d total tests', total) : null;
|
|
|
|
|
|
|
|
let resultsString = s__('Reports|no changed test results');
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
if (failedOrErrored) {
|
2018-11-18 11:00:15 +05:30
|
|
|
if (resolved) {
|
2020-04-08 14:13:33 +05:30
|
|
|
resultsString = sprintf(s__('Reports|%{combinedString} and %{resolvedString}'), {
|
|
|
|
combinedString,
|
2018-11-18 11:00:15 +05:30
|
|
|
resolvedString,
|
|
|
|
});
|
|
|
|
} else {
|
2020-04-08 14:13:33 +05:30
|
|
|
resultsString = combinedString;
|
2018-11-18 11:00:15 +05:30
|
|
|
}
|
|
|
|
} else if (resolved) {
|
|
|
|
resultsString = resolvedString;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${resultsString} ${totalString}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const summaryTextBuilder = (name = '', results = {}) => {
|
|
|
|
const resultsString = textBuilder(results);
|
2019-07-31 22:56:46 +05:30
|
|
|
return sprintf(__('%{name} contained %{resultsString}'), { name, resultsString });
|
2018-11-18 11:00:15 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
export const reportTextBuilder = (name = '', results = {}) => {
|
|
|
|
const resultsString = textBuilder(results);
|
2019-07-31 22:56:46 +05:30
|
|
|
return sprintf(__('%{name} found %{resultsString}'), { name, resultsString });
|
2018-11-18 11:00:15 +05:30
|
|
|
};
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
export const recentFailuresTextBuilder = (summary = {}) => {
|
|
|
|
const { failed, recentlyFailed } = summary;
|
|
|
|
if (!failed || !recentlyFailed) return '';
|
|
|
|
|
|
|
|
if (failed < 2) {
|
|
|
|
return sprintf(
|
|
|
|
s__(
|
|
|
|
'Reports|%{recentlyFailed} out of %{failed} failed test has failed more than once in the last 14 days',
|
|
|
|
),
|
|
|
|
{ recentlyFailed, failed },
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return sprintf(
|
|
|
|
n__(
|
2021-02-22 17:27:13 +05:30
|
|
|
'Reports|%{recentlyFailed} out of %{failed} failed tests has failed more than once in the last 14 days',
|
|
|
|
'Reports|%{recentlyFailed} out of %{failed} failed tests have failed more than once in the last 14 days',
|
2021-01-29 00:20:46 +05:30
|
|
|
recentlyFailed,
|
|
|
|
),
|
|
|
|
{ recentlyFailed, failed },
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2021-02-22 17:27:13 +05:30
|
|
|
.map(
|
|
|
|
failureArray =>
|
|
|
|
failureArray.filter(failure => failure.recent_failures?.count > 1).length,
|
|
|
|
)
|
2021-01-29 00:20:46 +05:30
|
|
|
.reduce((total, count) => total + count, 0)
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.reduce((total, count) => total + count, 0);
|
|
|
|
};
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
export const statusIcon = status => {
|
|
|
|
if (status === STATUS_FAILED) {
|
|
|
|
return ICON_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status === STATUS_SUCCESS) {
|
|
|
|
return ICON_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ICON_NOTFOUND;
|
|
|
|
};
|