aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2018-06-11 17:13:50 +0200
committerSonarTech <sonartech@sonarsource.com>2018-06-12 20:20:57 +0200
commit3fb70514d8fb7157cb2354b7faf60261e5e68163 (patch)
tree4d9e0e224e4ac88be455cafd83321e070bc6c0c7 /server/sonar-web/src/main/js/apps
parentbc5f256338bf3b46834f1dde1113d31cf79dead8 (diff)
downloadsonarqube-3fb70514d8fb7157cb2354b7faf60261e5e68163.tar.gz
sonarqube-3fb70514d8fb7157cb2354b7faf60261e5e68163.zip
fix project home page timeline with missing values
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/Timeline.tsx7
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/__tests__/Timeline-test.tsx62
-rw-r--r--server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/Timeline-test.tsx.snap110
3 files changed, 177 insertions, 2 deletions
diff --git a/server/sonar-web/src/main/js/apps/overview/components/Timeline.tsx b/server/sonar-web/src/main/js/apps/overview/components/Timeline.tsx
index 2b372ce80dd..51fade7572d 100644
--- a/server/sonar-web/src/main/js/apps/overview/components/Timeline.tsx
+++ b/server/sonar-web/src/main/js/apps/overview/components/Timeline.tsx
@@ -49,9 +49,12 @@ export default class Timeline extends React.PureComponent<Props> {
}
const data = snapshots.map((snapshot, index) => {
- return { x: index, y: Number(snapshot.value) };
+ return { x: index, y: snapshot.value !== undefined ? Number(snapshot.value) : undefined };
});
- const domain = [0, max(this.props.history, d => parseFloat(d.value))] as [number, number];
+ const domain = [
+ 0,
+ max(this.props.history, d => (d.value !== undefined ? parseFloat(d.value) : 0))
+ ] as [number, number];
return (
<LineChart
data={data}
diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/Timeline-test.tsx b/server/sonar-web/src/main/js/apps/overview/components/__tests__/Timeline-test.tsx
new file mode 100644
index 00000000000..c3ef5ec6d49
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/Timeline-test.tsx
@@ -0,0 +1,62 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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 * as React from 'react';
+import { shallow } from 'enzyme';
+import Timeline from '../Timeline';
+import { parseDate } from '../../../../helpers/dates';
+
+const range = parseDate('2017-05-01T00:00:00.000Z');
+const history = [
+ { date: parseDate('2017-04-08T00:00:00.000Z'), value: '29.6' },
+ { date: parseDate('2017-04-09T00:00:00.000Z'), value: '170.8' },
+ { date: parseDate('2017-05-08T00:00:00.000Z'), value: '360' },
+ { date: parseDate('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 = parseDate('2017-05-08T00:00:00.000Z');
+ const wrapper = shallow(<Timeline after={range} history={history} />);
+ expect(wrapper.find('LineChart').prop('domain')).toEqual([0, 360]);
+
+ wrapper.setProps({ history: [{ date, value: '360.33' }, { date, value: '39.54' }] });
+ expect(wrapper.find('LineChart').prop('domain')).toEqual([0, 360.33]);
+
+ wrapper.setProps({ history: [{ date, value: 360 }, { date, value: 39 }] });
+ expect(wrapper.find('LineChart').prop('domain')).toEqual([0, 360]);
+});
+
+it('should not fail when a value is missing', () => {
+ expect(
+ shallow(
+ <Timeline
+ before={range}
+ history={[{ date: parseDate('2017-04-07T00:00:00.000Z') }, ...history]}
+ />
+ )
+ ).toMatchSnapshot();
+});
diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/Timeline-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/Timeline-test.tsx.snap
new file mode 100644
index 00000000000..710cbbf695a
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/Timeline-test.tsx.snap
@@ -0,0 +1,110 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should not fail when a value is missing 1`] = `
+<LineChart
+ data={
+ Array [
+ Object {
+ "x": 0,
+ "y": undefined,
+ },
+ Object {
+ "x": 1,
+ "y": 29.6,
+ },
+ Object {
+ "x": 2,
+ "y": 170.8,
+ },
+ ]
+ }
+ displayBackdrop={true}
+ displayPoints={false}
+ displayVerticalGrid={false}
+ domain={
+ Array [
+ 0,
+ 360,
+ ]
+ }
+ height={80}
+ padding={
+ Array [
+ 0,
+ 0,
+ 0,
+ 0,
+ ]
+ }
+/>
+`;
+
+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}
+ padding={
+ Array [
+ 0,
+ 0,
+ 0,
+ 0,
+ ]
+ }
+/>
+`;
+
+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}
+ padding={
+ Array [
+ 0,
+ 0,
+ 0,
+ 0,
+ ]
+ }
+/>
+`;