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