Commit 013d8af3 authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch '241759-recent-failures-count-and-base-branch' into 'master'

Interpret recent_failures as object, not integer

See merge request gitlab-org/gitlab!48066
parents fd48a29d 7b3b46ac
<script>
import { mapActions } from 'vuex';
import { GlBadge } from '@gitlab/ui';
import { n__ } from '~/locale';
import { GlBadge, GlSprintf } from '@gitlab/ui';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
export default {
name: 'TestIssueBody',
components: {
GlBadge,
GlSprintf,
},
mixins: [glFeatureFlagsMixin()],
props: {
......@@ -28,18 +28,15 @@ export default {
},
computed: {
showRecentFailures() {
return this.glFeatures.testFailureHistory && this.issue.recent_failures;
return (
this.glFeatures.testFailureHistory &&
this.issue.recent_failures?.count &&
this.issue.recent_failures?.base_branch
);
},
},
methods: {
...mapActions(['openModal']),
recentFailuresText(count) {
return n__(
'Failed %d time in the last 14 days',
'Failed %d times in the last 14 days',
count,
);
},
},
};
</script>
......@@ -53,7 +50,18 @@ export default {
>
<gl-badge v-if="isNew" variant="danger" class="gl-mr-2">{{ s__('New') }}</gl-badge>
<gl-badge v-if="showRecentFailures" variant="warning" class="gl-mr-2">
{{ recentFailuresText(issue.recent_failures) }}
<gl-sprintf
:message="
n__(
'Reports|Failed %{count} time in %{base_branch} in the last 14 days',
'Reports|Failed %{count} times in %{base_branch} in the last 14 days',
issue.recent_failures.count,
)
"
>
<template #count>{{ issue.recent_failures.count }}</template>
<template #base_branch>{{ issue.recent_failures.base_branch }}</template>
</gl-sprintf>
</gl-badge>
{{ issue.name }}
</button>
......
......@@ -62,12 +62,8 @@ export const recentFailuresTextBuilder = (summary = {}) => {
}
return sprintf(
n__(
s__(
'Reports|%{recentlyFailed} out of %{failed} failed tests has failed more than once in the last 14 days',
),
s__(
'Reports|%{recentlyFailed} out of %{failed} failed tests have failed more than once in the last 14 days',
),
'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',
recentlyFailed,
),
{ recentlyFailed, failed },
......@@ -83,7 +79,10 @@ export const countRecentlyFailedTests = subject => {
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)
.map(
failureArray =>
failureArray.filter(failure => failure.recent_failures?.count > 1).length,
)
.reduce((total, count) => total + count, 0)
);
})
......
......@@ -11375,11 +11375,6 @@ msgstr ""
msgid "Failed"
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"
msgstr ""
......@@ -22939,10 +22934,9 @@ msgid "Reports|%{recentlyFailed} out of %{failed} failed test has failed more th
msgstr ""
msgid "Reports|%{recentlyFailed} out of %{failed} failed tests has failed more than once in the last 14 days"
msgstr ""
msgid "Reports|%{recentlyFailed} out of %{failed} failed tests have failed more than once in the last 14 days"
msgstr ""
msgid_plural "Reports|%{recentlyFailed} out of %{failed} failed tests have failed more than once in the last 14 days"
msgstr[0] ""
msgstr[1] ""
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"
......@@ -22976,6 +22970,11 @@ msgstr ""
msgid "Reports|Execution time"
msgstr ""
msgid "Reports|Failed %{count} time in %{base_branch} in the last 14 days"
msgid_plural "Reports|Failed %{count} times in %{base_branch} in the last 14 days"
msgstr[0] ""
msgstr[1] ""
msgid "Reports|Failure"
msgstr ""
......
......@@ -264,7 +264,9 @@ describe('Grouped test reports app', () => {
});
it('renders the recent failures count on the test case', () => {
expect(findIssueDescription().text()).toContain('Failed 8 times in the last 14 days');
expect(findIssueDescription().text()).toContain(
'Failed 8 times in master in the last 14 days',
);
});
});
......
......@@ -10,7 +10,10 @@
"name": "Test#sum when a is 1 and b is 2 returns summary",
"execution_time": 0.009411,
"system_output": "Failure/Error: is_expected.to eq(3)\n\n expected: 3\n got: -1\n\n (compared using ==)\n./spec/test_spec.rb:12:in `block (4 levels) in <top (required)>'",
"recent_failures": 8
"recent_failures": {
"count": 8,
"base_branch": "master"
}
},
{
"result": "failure",
......@@ -33,7 +36,10 @@
"result": "failure",
"name": "Test#sum when a is 100 and b is 200 returns summary",
"execution_time": 0.000562,
"recent_failures": 3
"recent_failures": {
"count": 3,
"base_branch": "master"
}
}
],
"resolved_failures": [],
......
......@@ -46,7 +46,10 @@ describe('Reports Store Mutations', () => {
name: 'StringHelper#concatenate when a is git and b is lab returns summary',
execution_time: 0.0092435,
system_output: "Failure/Error: is_expected.to eq('gitlab')",
recent_failures: 4,
recent_failures: {
count: 4,
base_branch: 'master',
},
},
],
resolved_failures: [
......
......@@ -188,9 +188,9 @@ describe('Reports store utils', () => {
describe('countRecentlyFailedTests', () => {
it('counts tests with more than one recent failure in a report', () => {
const report = {
new_failures: [{ recent_failures: 2 }],
existing_failures: [{ recent_failures: 1 }],
resolved_failures: [{ recent_failures: 20 }, { recent_failures: 5 }],
new_failures: [{ recent_failures: { count: 2 } }],
existing_failures: [{ recent_failures: { count: 1 } }],
resolved_failures: [{ recent_failures: { count: 20 } }, { recent_failures: { count: 5 } }],
};
const result = utils.countRecentlyFailedTests(report);
......@@ -200,14 +200,17 @@ describe('Reports store utils', () => {
it('counts tests with more than one recent failure in an array of reports', () => {
const reports = [
{
new_failures: [{ recent_failures: 2 }],
existing_failures: [{ recent_failures: 20 }, { recent_failures: 5 }],
resolved_failures: [{ recent_failures: 2 }],
new_failures: [{ recent_failures: { count: 2 } }],
existing_failures: [
{ recent_failures: { count: 20 } },
{ recent_failures: { count: 5 } },
],
resolved_failures: [{ recent_failures: { count: 2 } }],
},
{
new_failures: [{ recent_failures: 8 }, { recent_failures: 14 }],
existing_failures: [{ recent_failures: 1 }],
resolved_failures: [{ recent_failures: 7 }, { recent_failures: 5 }],
new_failures: [{ recent_failures: { count: 8 } }, { recent_failures: { count: 14 } }],
existing_failures: [{ recent_failures: { count: 1 } }],
resolved_failures: [{ recent_failures: { count: 7 } }, { recent_failures: { count: 5 } }],
},
];
const result = utils.countRecentlyFailedTests(reports);
......
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