From 33e68fd792458053de7492ba6cba4edf0f517ac7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Tue, 20 Jun 2017 17:07:51 +0200 Subject: [PATCH] SONAR-9440 Fix usage of measures/search_history api --- .../details/history/MeasureHistory.js | 2 +- .../__tests__/ProjectActivityGraphs-test.js | 81 ++++++++++++++++++ .../ProjectActivityGraphs-test.js.snap | 84 +++++++++++++++++++ .../js/components/charts/AdvancedTimeline.js | 11 ++- .../main/js/components/charts/line-chart.js | 9 +- 5 files changed, 182 insertions(+), 5 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityGraphs-test.js create mode 100644 server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityGraphs-test.js.snap diff --git a/server/sonar-web/src/main/js/apps/component-measures/details/history/MeasureHistory.js b/server/sonar-web/src/main/js/apps/component-measures/details/history/MeasureHistory.js index c653d64e7b8..7cbf786922d 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/details/history/MeasureHistory.js +++ b/server/sonar-web/src/main/js/apps/component-measures/details/history/MeasureHistory.js @@ -76,7 +76,7 @@ export default class MeasureHistory extends React.PureComponent { if (r.measures.length === 0) { return []; } - return r.measures[0].history.map(analysis => ({ + return r.measures[0].history.filter(analysis => analysis.value != null).map(analysis => ({ date: moment(analysis.date).toDate(), value: analysis.value })); diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityGraphs-test.js b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityGraphs-test.js new file mode 100644 index 00000000000..57f093bd56d --- /dev/null +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityGraphs-test.js @@ -0,0 +1,81 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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 React from 'react'; +import { shallow } from 'enzyme'; +import ProjectActivityGraphs from '../ProjectActivityGraphs'; + +const ANALYSES = [ + { + key: 'A1', + date: '2016-10-27T16:33:50+0200', + events: [ + { + key: 'E1', + category: 'VERSION', + name: '6.5-SNAPSHOT' + } + ] + }, + { + key: 'A2', + date: '2016-10-27T12:21:15+0200', + events: [] + }, + { + key: 'A3', + date: '2016-10-26T12:17:29+0200', + events: [ + { + key: 'E2', + category: 'VERSION', + name: '6.4' + }, + { + key: 'E3', + category: 'OTHER', + name: 'foo' + } + ] + } +]; + +const DEFAULT_PROPS = { + analyses: ANALYSES, + leakPeriodDate: '2017-05-16T13:50:02+0200', + loading: false, + measuresHistory: [ + { + metric: 'code_smells', + history: [ + { date: new Date('2016-10-26T12:17:29+0200'), value: '2286' }, + { date: new Date('2016-10-27T12:21:15+0200'), value: '1749' }, + { date: new Date('2016-10-27T16:33:50+0200'), value: '500' } + ] + } + ], + metricsType: 'INT', + project: 'org.sonarsource.sonarqube:sonarqube', + query: { category: '', graph: 'overview', project: 'org.sonarsource.sonarqube:sonarqube' }, + updateQuery: () => {} +}; + +it('should render correctly the graph and legends', () => { + expect(shallow()).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityGraphs-test.js.snap b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityGraphs-test.js.snap new file mode 100644 index 00000000000..27471bc95a8 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityGraphs-test.js.snap @@ -0,0 +1,84 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly the graph and legends 1`] = ` +
+ + +
+`; diff --git a/server/sonar-web/src/main/js/components/charts/AdvancedTimeline.js b/server/sonar-web/src/main/js/components/charts/AdvancedTimeline.js index ad24130a782..bae8d1ec00d 100644 --- a/server/sonar-web/src/main/js/components/charts/AdvancedTimeline.js +++ b/server/sonar-web/src/main/js/components/charts/AdvancedTimeline.js @@ -160,7 +160,10 @@ export default class AdvancedTimeline extends React.PureComponent { }; renderLines = (xScale: Scale, yScale: Scale) => { - const lineGenerator = d3Line().x(d => xScale(d.x)).y(d => yScale(d.y)); + const lineGenerator = d3Line() + .defined(d => d.y || d.y === 0) + .x(d => xScale(d.x)) + .y(d => yScale(d.y)); if (this.props.basisCurve) { lineGenerator.curve(curveBasis); } @@ -178,7 +181,11 @@ export default class AdvancedTimeline extends React.PureComponent { }; renderAreas = (xScale: Scale, yScale: Scale) => { - const areaGenerator = area().x(d => xScale(d.x)).y1(d => yScale(d.y)).y0(yScale(0)); + const areaGenerator = area() + .defined(d => d.y || d.y === 0) + .x(d => xScale(d.x)) + .y1(d => yScale(d.y)) + .y0(yScale(0)); if (this.props.basisCurve) { areaGenerator.curve(curveBasis); } diff --git a/server/sonar-web/src/main/js/components/charts/line-chart.js b/server/sonar-web/src/main/js/components/charts/line-chart.js index e2941cf2ce0..f230a6ea48f 100644 --- a/server/sonar-web/src/main/js/components/charts/line-chart.js +++ b/server/sonar-web/src/main/js/components/charts/line-chart.js @@ -63,6 +63,7 @@ export const LineChart = React.createClass({ .x(d => xScale(d.x)) .y0(yScale.range()[0]) .y1(d => yScale(d.y)) + .defined(d => d.y != null) .curve(curveBasis); let data = this.props.data; @@ -77,7 +78,7 @@ export const LineChart = React.createClass({ if (!this.props.displayPoints) { return null; } - const points = this.props.data.map((point, index) => { + const points = this.props.data.filter(point => point.y != null).map((point, index) => { const x = xScale(point.x); const y = yScale(point.y); return ; @@ -125,7 +126,11 @@ export const LineChart = React.createClass({ }, renderLine(xScale, yScale) { - const p = d3Line().x(d => xScale(d.x)).y(d => yScale(d.y)).curve(curveBasis); + const p = d3Line() + .x(d => xScale(d.x)) + .y(d => yScale(d.y)) + .defined(d => d.y != null) + .curve(curveBasis); return ; }, -- 2.39.5