Commit fdbac6f6 authored by Clement Ho's avatar Clement Ho

Merge branch 'add-support-metrics-smaller' into 'master'

Support metrics where smaller is better

Closes #4367

See merge request gitlab-org/gitlab-ee!3891
parents 29c23e4b 1f14b4d9
---
title: Add support within Browser Performance Testing for metrics where smaller is
better
merge_request: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/3891
author: joshlambert
type: added
...@@ -89,6 +89,12 @@ ...@@ -89,6 +89,12 @@
modalIdTarget(index) { modalIdTarget(index) {
return `#${this.getmodalId(index)}`; return `#${this.getmodalId(index)}`;
}, },
formatScore(value) {
if (Math.floor(value) !== value) {
return parseFloat(value).toFixed(2);
}
return value;
},
openDastModal(issue, index) { openDastModal(issue, index) {
this.modalId = this.getmodalId(index); this.modalId = this.getmodalId(index);
this.modalTitle = `${issue.priority}: ${issue.name}`; this.modalTitle = `${issue.priority}: ${issue.name}`;
...@@ -156,11 +162,12 @@ ...@@ -156,11 +162,12 @@
</button> </button>
</template> </template>
<template v-else> <template v-else>
{{ issue.name }}<template v-if="issue.score">: <strong>{{ issue.score }}</strong></template> {{ issue.name }}<template v-if="issue.score">:
<strong>{{ formatScore(issue.score) }}</strong></template>
</template> </template>
<template v-if="isTypePerformance && issue.delta != null"> <template v-if="isTypePerformance && issue.delta != null">
({{ issue.delta >= 0 ? '+' : '' }}{{ issue.delta }}) ({{ issue.delta >= 0 ? '+' : '' }}{{ formatScore(issue.delta) }})
</template> </template>
<template v-if="issue.path"> <template v-if="issue.path">
......
...@@ -204,6 +204,7 @@ export default class MergeRequestStore extends CEMergeRequestStore { ...@@ -204,6 +204,7 @@ export default class MergeRequestStore extends CEMergeRequestStore {
if (baseMetricsIndexed[subject] && baseMetricsIndexed[subject][metric]) { if (baseMetricsIndexed[subject] && baseMetricsIndexed[subject][metric]) {
const baseMetricData = baseMetricsIndexed[subject][metric]; const baseMetricData = baseMetricsIndexed[subject][metric];
const metricDirection = 'desiredSize' in headMetricData && headMetricData.desiredSize === 'smaller' ? -1 : 1;
const metricData = { const metricData = {
name: metric, name: metric,
path: subject, path: subject,
...@@ -211,12 +212,12 @@ export default class MergeRequestStore extends CEMergeRequestStore { ...@@ -211,12 +212,12 @@ export default class MergeRequestStore extends CEMergeRequestStore {
delta: headMetricData.value - baseMetricData.value, delta: headMetricData.value - baseMetricData.value,
}; };
if (headMetricData.value > baseMetricData.value) { if (metricData.delta === 0) {
neutral.push(metricData);
} else if (metricData.delta * metricDirection > 0) {
improved.push(metricData); improved.push(metricData);
} else if (headMetricData.value < baseMetricData.value) {
degraded.push(metricData);
} else { } else {
neutral.push(metricData); degraded.push(metricData);
} }
} else { } else {
neutral.push({ neutral.push({
......
...@@ -291,7 +291,7 @@ describe('ee merge request widget options', () => { ...@@ -291,7 +291,7 @@ describe('ee merge request widget options', () => {
setTimeout(() => { setTimeout(() => {
expect( expect(
vm.$el.querySelector('.js-performance-widget .js-code-text').textContent.trim(), vm.$el.querySelector('.js-performance-widget .js-code-text').textContent.trim(),
).toEqual('Performance metrics improved on 1 point and degraded on 1 point'); ).toEqual('Performance metrics improved on 2 points and degraded on 1 point');
done(); done();
}, 0); }, 0);
}); });
...@@ -304,7 +304,7 @@ describe('ee merge request widget options', () => { ...@@ -304,7 +304,7 @@ describe('ee merge request widget options', () => {
Vue.nextTick(() => { Vue.nextTick(() => {
expect( expect(
vm.$el.querySelector('.js-performance-widget .js-code-text').textContent.trim(), vm.$el.querySelector('.js-performance-widget .js-code-text').textContent.trim(),
).toEqual('Performance metrics improved on 1 point'); ).toEqual('Performance metrics improved on 2 points');
done(); done();
}); });
}, 0); }, 0);
......
...@@ -326,6 +326,12 @@ export const headPerformance = [ ...@@ -326,6 +326,12 @@ export const headPerformance = [
{ {
name: 'Sitespeed Score', name: 'Sitespeed Score',
value: 79, value: 79,
desiredSize: 'larger',
},
{
name: 'Requests',
value: 3,
desiredSize: 'smaller',
}, },
], ],
}, },
...@@ -338,6 +344,7 @@ export const headPerformance = [ ...@@ -338,6 +344,7 @@ export const headPerformance = [
}, },
], ],
}, },
]; ];
export const basePerformance = [ export const basePerformance = [
...@@ -356,6 +363,12 @@ export const basePerformance = [ ...@@ -356,6 +363,12 @@ export const basePerformance = [
{ {
name: 'Sitespeed Score', name: 'Sitespeed Score',
value: 80, value: 80,
desiredSize: 'larger',
},
{
name: 'Requests',
value: 4,
desiredSize: 'smaller',
}, },
], ],
}, },
...@@ -643,4 +656,4 @@ export const parsedDast = [{ ...@@ -643,4 +656,4 @@ export const parsedDast = [{
method: 'GET', method: 'GET',
param: 'X-Content-Type-Options' param: 'X-Content-Type-Options'
}] }]
}]; }];
\ No newline at end of file
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