aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorJeremy Davis <jeremy.davis@sonarsource.com>2019-08-27 16:04:38 +0200
committerSonarTech <sonartech@sonarsource.com>2019-09-24 20:21:16 +0200
commit45f8d835abdaf01287e2cf4a149b87ab2abfd156 (patch)
tree6aa2395100e943138acbbb070122c8d7fc0b962b /server/sonar-web
parent1bd13d06f1600169edb47200f6531ae6dfef66f2 (diff)
downloadsonarqube-45f8d835abdaf01287e2cf4a149b87ab2abfd156.tar.gz
sonarqube-45f8d835abdaf01287e2cf4a149b87ab2abfd156.zip
SONAR-12415 Fix Leak title in project overview
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/js/app/types.d.ts6
-rw-r--r--server/sonar-web/src/main/js/apps/component-measures/components/LeakPeriodLegend.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/LeakPeriodLegend.tsx9
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/LeakPeriodLegend-test.tsx.snap2
-rw-r--r--server/sonar-web/src/main/js/helpers/__tests__/periods-test.ts108
-rw-r--r--server/sonar-web/src/main/js/helpers/periods.ts35
-rw-r--r--server/sonar-web/src/main/js/helpers/testMocks.ts9
7 files changed, 154 insertions, 17 deletions
diff --git a/server/sonar-web/src/main/js/app/types.d.ts b/server/sonar-web/src/main/js/app/types.d.ts
index c5ccff569da..d2a89083b22 100644
--- a/server/sonar-web/src/main/js/app/types.d.ts
+++ b/server/sonar-web/src/main/js/app/types.d.ts
@@ -578,7 +578,7 @@ declare namespace T {
export interface Period {
date: string;
index: number;
- mode: PeriodMode;
+ mode: PeriodMode | NewCodePeriodSettingType;
modeParam?: string;
parameter?: string;
}
@@ -589,6 +589,10 @@ declare namespace T {
value: string;
}
+ /*
+ * These are old baseline setting types, necessary for
+ * backward compatibility.
+ */
export type PeriodMode =
| 'days'
| 'date'
diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/LeakPeriodLegend.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/LeakPeriodLegend.tsx
index d5dcd6bdb7f..39f368b436c 100644
--- a/server/sonar-web/src/main/js/apps/component-measures/components/LeakPeriodLegend.tsx
+++ b/server/sonar-web/src/main/js/apps/component-measures/components/LeakPeriodLegend.tsx
@@ -64,7 +64,7 @@ export class LeakPeriodLegend extends React.PureComponent<Props & InjectedIntlPr
</div>
);
- if (period.mode === 'days') {
+ if (period.mode === 'days' || period.mode === 'NUMBER_OF_DAYS') {
return label;
}
diff --git a/server/sonar-web/src/main/js/apps/overview/components/LeakPeriodLegend.tsx b/server/sonar-web/src/main/js/apps/overview/components/LeakPeriodLegend.tsx
index 265c7f49b29..70e132f22c3 100644
--- a/server/sonar-web/src/main/js/apps/overview/components/LeakPeriodLegend.tsx
+++ b/server/sonar-web/src/main/js/apps/overview/components/LeakPeriodLegend.tsx
@@ -31,6 +31,11 @@ interface Props {
period: T.Period;
}
+const MODE_INCLUDES_TIME: T.Dict<boolean> = {
+ manual_baseline: true,
+ SPECIFIC_ANALYSIS: true
+};
+
export class LeakPeriodLegend extends React.PureComponent<Props & InjectedIntlProps> {
formatDate = (date: string) => {
return this.props.intl.formatDate(date, longFormatterOption);
@@ -44,13 +49,13 @@ export class LeakPeriodLegend extends React.PureComponent<Props & InjectedIntlPr
const { period } = this.props;
const leakPeriodLabel = getPeriodLabel(
period,
- period.mode === 'manual_baseline' ? this.formatDateTime : this.formatDate
+ MODE_INCLUDES_TIME[period.mode] ? this.formatDateTime : this.formatDate
);
if (!leakPeriodLabel) {
return null;
}
- if (period.mode === 'days') {
+ if (period.mode === 'days' || period.mode === 'NUMBER_OF_DAYS') {
return (
<div className="overview-legend overview-legend-spaced-line">
{translateWithParameters('overview.new_code_period_x', leakPeriodLabel)}
diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/LeakPeriodLegend-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/LeakPeriodLegend-test.tsx.snap
index 5afaacc0459..5a16ef23f03 100644
--- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/LeakPeriodLegend-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/LeakPeriodLegend-test.tsx.snap
@@ -51,7 +51,7 @@ exports[`manual_baseline 2`] = `
<div
className="overview-legend"
>
- overview.new_code_period_x.overview.period.previous_version.1.1.2
+ overview.new_code_period_x.overview.period.manual_baseline.1.1.2
<br />
<DateFromNow
date={2013-09-21T22:00:00.000Z}
diff --git a/server/sonar-web/src/main/js/helpers/__tests__/periods-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/periods-test.ts
new file mode 100644
index 00000000000..917b797d311
--- /dev/null
+++ b/server/sonar-web/src/main/js/helpers/__tests__/periods-test.ts
@@ -0,0 +1,108 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import { getPeriodLabel } from '../periods';
+import { mockPeriod } from '../testMocks';
+
+const formatter = jest.fn(v => v);
+
+beforeEach(() => {
+ formatter.mockClear();
+});
+
+describe('getPeriodLabel', () => {
+ it('should handle missing value', () => {
+ expect(getPeriodLabel(undefined, formatter)).toBeUndefined();
+ });
+
+ it('should handle date', () => {
+ expect(getPeriodLabel(mockPeriod({ mode: 'date' }), formatter)).toBe('overview.period.date.');
+ expect(
+ getPeriodLabel(mockPeriod({ mode: 'date', parameter: '2019-02-21T01:11:21+0100' }), formatter)
+ ).toBe('overview.period.date.2019-02-21T01:11:21+0100');
+ expect(formatter).toBeCalledTimes(1);
+ });
+
+ it('should handle days', () => {
+ expect(getPeriodLabel(mockPeriod({ mode: 'days', modeParam: '12' }), formatter)).toBe(
+ 'overview.period.days.12'
+ );
+ expect(formatter).not.toBeCalled();
+ });
+
+ it('should handle previous analysis', () => {
+ expect(
+ getPeriodLabel(mockPeriod({ mode: 'previous_analysis', parameter: 'param' }), formatter)
+ ).toBe('overview.period.previous_analysis.param');
+ expect(formatter).not.toBeCalled();
+ });
+
+ it('should handle previous version', () => {
+ expect(getPeriodLabel(mockPeriod({ mode: 'previous_version' }), formatter)).toBe(
+ 'overview.period.previous_version_only_date'
+ );
+ expect(
+ getPeriodLabel(mockPeriod({ mode: 'previous_version', parameter: '7.9' }), formatter)
+ ).toBe('overview.period.previous_version.7.9');
+ expect(formatter).not.toBeCalled();
+ });
+
+ it('should handle version', () => {
+ expect(getPeriodLabel(mockPeriod({ mode: 'version', modeParam: '7.2' }), formatter)).toBe(
+ 'overview.period.version.7.2'
+ );
+ expect(
+ getPeriodLabel(mockPeriod({ mode: 'previous_version', parameter: '7.9' }), formatter)
+ ).toBe('overview.period.previous_version.7.9');
+ expect(formatter).not.toBeCalled();
+ });
+
+ it('should handle manual baseline', () => {
+ expect(
+ getPeriodLabel(mockPeriod({ mode: 'manual_baseline', modeParam: 'A658678DE' }), formatter)
+ ).toBe('overview.period.manual_baseline.A658678DE');
+ expect(getPeriodLabel(mockPeriod({ mode: 'manual_baseline' }), formatter)).toBe(
+ 'overview.period.manual_baseline.2019-04-23T02:12:32+0100'
+ );
+ expect(formatter).toBeCalledTimes(1);
+ });
+
+ it('should handle SPECIFIC_ANALYSIS', () => {
+ expect(
+ getPeriodLabel(
+ mockPeriod({
+ mode: 'SPECIFIC_ANALYSIS',
+ parameter: 'should be overriden'
+ }),
+ formatter
+ )
+ ).toBe('overview.period.specific_analysis.2019-04-23T02:12:32+0100');
+ expect(formatter).toBeCalled();
+ });
+
+ it('should handle PREVIOUS_VERSION', () => {
+ expect(
+ getPeriodLabel(mockPeriod({ mode: 'PREVIOUS_VERSION', parameter: 'A658678DE' }), formatter)
+ ).toBe('overview.period.previous_version.A658678DE');
+ expect(getPeriodLabel(mockPeriod({ mode: 'PREVIOUS_VERSION' }), formatter)).toBe(
+ 'overview.period.previous_version.2019-04-23T02:12:32+0100'
+ );
+ expect(formatter).toBeCalledTimes(1);
+ });
+});
diff --git a/server/sonar-web/src/main/js/helpers/periods.ts b/server/sonar-web/src/main/js/helpers/periods.ts
index 9c36b32efd7..6a9702fec7b 100644
--- a/server/sonar-web/src/main/js/helpers/periods.ts
+++ b/server/sonar-web/src/main/js/helpers/periods.ts
@@ -39,22 +39,33 @@ export function getPeriodLabel(
return undefined;
}
- let parameter = period.modeParam || period.parameter;
- if (period.mode === 'previous_version' && !parameter) {
- return translate('overview.period.previous_version_only_date');
- }
+ let parameter = period.modeParam || period.parameter || '';
- if (period.mode === 'date' && parameter) {
- parameter = dateFormatter(parameter);
- } else if (period.mode === 'manual_baseline') {
- if (!parameter) {
+ switch (period.mode) {
+ case 'SPECIFIC_ANALYSIS':
parameter = dateFormatter(period.date);
- } else {
- return translateWithParameters('overview.period.previous_version', parameter);
- }
+ break;
+ case 'PREVIOUS_VERSION':
+ parameter = parameter || dateFormatter(period.date);
+ break;
+ /*
+ * Handle legacy period modes, that predate MMF-1579
+ */
+ case 'previous_version':
+ if (!parameter) {
+ return translate('overview.period.previous_version_only_date');
+ }
+ break;
+ case 'date':
+ parameter = parameter && dateFormatter(parameter);
+ break;
+ case 'manual_baseline':
+ parameter = parameter || dateFormatter(period.date);
+ break;
+ default: // No change in the parameter
}
- return translateWithParameters(`overview.period.${period.mode}`, parameter || '');
+ return translateWithParameters(`overview.period.${period.mode.toLowerCase()}`, parameter);
}
export function getPeriodDate(period?: { date?: string }): Date | undefined {
diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts
index 4498df5013e..0b159181b44 100644
--- a/server/sonar-web/src/main/js/helpers/testMocks.ts
+++ b/server/sonar-web/src/main/js/helpers/testMocks.ts
@@ -523,6 +523,15 @@ export function mockOrganizationWithAlm(
});
}
+export function mockPeriod(overrides: Partial<T.Period> = {}): T.Period {
+ return {
+ date: '2019-04-23T02:12:32+0100',
+ index: 0,
+ mode: 'previous_version',
+ ...overrides
+ };
+}
+
export function mockQualityGate(overrides: Partial<T.QualityGate> = {}): T.QualityGate {
return {
id: 1,