]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9440 Fix usage of measures/search_history api
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Tue, 20 Jun 2017 15:07:51 +0000 (17:07 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Tue, 4 Jul 2017 12:15:34 +0000 (14:15 +0200)
server/sonar-web/src/main/js/apps/component-measures/details/history/MeasureHistory.js
server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityGraphs-test.js [new file with mode: 0644]
server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/__snapshots__/ProjectActivityGraphs-test.js.snap [new file with mode: 0644]
server/sonar-web/src/main/js/components/charts/AdvancedTimeline.js
server/sonar-web/src/main/js/components/charts/line-chart.js

index c653d64e7b8e58b7ebf1ab8be0acb4aabbfb5d31..7cbf786922d42fe87634b27b294f482bd4b18a2c 100644 (file)
@@ -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 (file)
index 0000000..57f093b
--- /dev/null
@@ -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(<ProjectActivityGraphs {...DEFAULT_PROPS} />)).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 (file)
index 0000000..27471bc
--- /dev/null
@@ -0,0 +1,84 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly the graph and legends 1`] = `
+<div
+  className="project-activity-layout-page-main-inner boxed-group boxed-group-inner"
+>
+  <ProjectActivityGraphsHeader
+    graph="overview"
+    updateQuery={[Function]}
+  />
+  <StaticGraphs
+    analyses={
+      Array [
+        Object {
+          "date": "2016-10-27T16:33:50+0200",
+          "events": Array [
+            Object {
+              "category": "VERSION",
+              "key": "E1",
+              "name": "6.5-SNAPSHOT",
+            },
+          ],
+          "key": "A1",
+        },
+        Object {
+          "date": "2016-10-27T12:21:15+0200",
+          "events": Array [],
+          "key": "A2",
+        },
+        Object {
+          "date": "2016-10-26T12:17:29+0200",
+          "events": Array [
+            Object {
+              "category": "VERSION",
+              "key": "E2",
+              "name": "6.4",
+            },
+            Object {
+              "category": "OTHER",
+              "key": "E3",
+              "name": "foo",
+            },
+          ],
+          "key": "A3",
+        },
+      ]
+    }
+    eventFilter=""
+    leakPeriodDate="2017-05-16T13:50:02+0200"
+    loading={false}
+    measuresHistory={
+      Array [
+        Object {
+          "history": Array [
+            Object {
+              "date": 2016-10-26T10:17:29.000Z,
+              "value": "2286",
+            },
+            Object {
+              "date": 2016-10-27T10:21:15.000Z,
+              "value": "1749",
+            },
+            Object {
+              "date": 2016-10-27T14:33:50.000Z,
+              "value": "500",
+            },
+          ],
+          "metric": "code_smells",
+        },
+      ]
+    }
+    metricsType="INT"
+    project="org.sonarsource.sonarqube:sonarqube"
+    seriesOrder={
+      Array [
+        "bugs",
+        "code_smells",
+        "vulnerabilities",
+      ]
+    }
+    showAreas={false}
+  />
+</div>
+`;
index ad24130a7823d13f55e13ff5378ea39cb30cb98f..bae8d1ec00d0fb5e45036b0a88951a75e549b08e 100644 (file)
@@ -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);
     }
index e2941cf2ce05433fbbaf2de85e19f3cdb185148e..f230a6ea48f1f2464911ae80ee3d035d177ec7df 100644 (file)
@@ -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 <circle key={index} className="line-chart-point" r="3" cx={x} cy={y} />;
@@ -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 <path className="line-chart-path" d={p(this.props.data)} />;
   },