From 5a5a4877386e11a465fc61abfc59bee4759b5861 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Mon, 8 May 2017 15:50:46 +0200 Subject: [PATCH] SONAR-8911 Fix timeline error on project page --- .../js/apps/overview/components/Timeline.js | 4 +- .../components/__tests__/Timeline-test.js | 50 ++++++++++++ .../__snapshots__/Timeline-test.js.snap | 77 +++++++++++++++++++ 3 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/overview/components/__tests__/Timeline-test.js create mode 100644 server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/Timeline-test.js.snap 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 ( { + expect(shallow()).toMatchSnapshot(); +}); + +it('should render correctly with a "before" range', () => { + expect(shallow()).toMatchSnapshot(); +}); + +it('should have a correct domain with strings or numbers', () => { + const date = new Date('2017-05-08T00:00:00.000Z'); + const wrapper = shallow(); + 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`] = ` + +`; + +exports[`should render correctly with an "after" range 1`] = ` + +`; -- 2.39.5