aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-05-08 15:50:46 +0200
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-05-10 11:56:20 +0200
commit5a5a4877386e11a465fc61abfc59bee4759b5861 (patch)
tree28567e0719526dd2e84616ba429891c79b24f457 /server/sonar-web/src
parente8eb4c2591dd1645509d07036a9dadc474eb58f1 (diff)
downloadsonarqube-5a5a4877386e11a465fc61abfc59bee4759b5861.tar.gz
sonarqube-5a5a4877386e11a465fc61abfc59bee4759b5861.zip
SONAR-8911 Fix timeline error on project page
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/Timeline.js4
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/__tests__/Timeline-test.js50
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/Timeline-test.js.snap77
3 files changed, 128 insertions, 3 deletions
diff --git a/server/sonar-web/src/main/js/apps/overview/components/Timeline.js b/server/sonar-web/src/main/js/apps/overview/components/Timeline.js
index 4edc52bff06..476707db58c 100644
--- a/server/sonar-web/src/main/js/apps/overview/components/Timeline.js
+++ b/server/sonar-web/src/main/js/apps/overview/components/Timeline.js
@@ -50,9 +50,7 @@ export default class Timeline extends React.PureComponent {
const data = snapshots.map((snapshot, index) => {
return { x: index, y: snapshot.value };
});
-
- const domain = [0, max(this.props.history, d => d.value)];
-
+ const domain = [0, max(this.props.history, d => parseFloat(d.value))];
return (
<LineChart
data={data}
diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/Timeline-test.js b/server/sonar-web/src/main/js/apps/overview/components/__tests__/Timeline-test.js
new file mode 100644
index 00000000000..186f707fc34
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/Timeline-test.js
@@ -0,0 +1,50 @@
+/*
+ * 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 Timeline from '../Timeline';
+
+const range = new Date('2017-05-01T00:00:00.000Z');
+const history = [
+ { date: new Date('2017-04-08T00:00:00.000Z'), value: '29.6' },
+ { date: new Date('2017-04-09T00:00:00.000Z'), value: '170.8' },
+ { date: new Date('2017-05-08T00:00:00.000Z'), value: '360' },
+ { date: new Date('2017-05-09T00:00:00.000Z'), value: '39' }
+];
+
+it('should render correctly with an "after" range', () => {
+ expect(shallow(<Timeline after={range} history={history} />)).toMatchSnapshot();
+});
+
+it('should render correctly with a "before" range', () => {
+ expect(shallow(<Timeline before={range} history={history} />)).toMatchSnapshot();
+});
+
+it('should have a correct domain with strings or numbers', () => {
+ const date = new Date('2017-05-08T00:00:00.000Z');
+ const wrapper = shallow(<Timeline after={range} history={history} />);
+ expect(wrapper.find('LineChart').props().domain).toEqual([0, 360]);
+
+ wrapper.setProps({ history: [{ date, value: '360.33' }, { date, value: '39.54' }] });
+ expect(wrapper.find('LineChart').props().domain).toEqual([0, 360.33]);
+
+ wrapper.setProps({ history: [{ date, value: 360 }, { date, value: 39 }] });
+ expect(wrapper.find('LineChart').props().domain).toEqual([0, 360]);
+});
diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/Timeline-test.js.snap b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/Timeline-test.js.snap
new file mode 100644
index 00000000000..c25e28b7e3f
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/Timeline-test.js.snap
@@ -0,0 +1,77 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly with a "before" range 1`] = `
+<LineChart
+ data={
+ Array [
+ Object {
+ "x": 0,
+ "y": "29.6",
+ },
+ Object {
+ "x": 1,
+ "y": "170.8",
+ },
+ ]
+ }
+ displayBackdrop={true}
+ displayPoints={false}
+ displayVerticalGrid={false}
+ domain={
+ Array [
+ 0,
+ 360,
+ ]
+ }
+ height={80}
+ interpolate="basis"
+ padding={
+ Array [
+ 0,
+ 0,
+ 0,
+ 0,
+ ]
+ }
+ xTicks={Array []}
+ xValues={Array []}
+/>
+`;
+
+exports[`should render correctly with an "after" range 1`] = `
+<LineChart
+ data={
+ Array [
+ Object {
+ "x": 0,
+ "y": "360",
+ },
+ Object {
+ "x": 1,
+ "y": "39",
+ },
+ ]
+ }
+ displayBackdrop={true}
+ displayPoints={false}
+ displayVerticalGrid={false}
+ domain={
+ Array [
+ 0,
+ 360,
+ ]
+ }
+ height={80}
+ interpolate="basis"
+ padding={
+ Array [
+ 0,
+ 0,
+ 0,
+ 0,
+ ]
+ }
+ xTicks={Array []}
+ xValues={Array []}
+/>
+`;