diff --git a/.eslintrc b/.eslintrc index 3a282c9c..bf19fb0c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -29,6 +29,7 @@ "no-magic-numbers": "off", "no-undefined": "off", "no-inline-comments": "off", + "lines-around-comment": "off", "indent": ["error", 2, { "SwitchCase": 1 } diff --git a/src/visits/GraphCard.js b/src/visits/GraphCard.js index d54c1674..5814739e 100644 --- a/src/visits/GraphCard.js +++ b/src/visits/GraphCard.js @@ -54,7 +54,7 @@ const renderGraph = (title, isBarChart, stats, max, highlightedStats) => { } return acc; - }, stats)); + }, { ...stats })); const highlightedData = highlightedStats && values({ ...zipObj(labels, labels.map(() => 0)), ...highlightedStats }); const options = { diff --git a/test/visits/GraphCard.test.js b/test/visits/GraphCard.test.js index 52975c61..545e8c22 100644 --- a/test/visits/GraphCard.test.js +++ b/test/visits/GraphCard.test.js @@ -21,12 +21,14 @@ describe('', () => { expect(doughnut).toHaveLength(1); expect(horizontal).toHaveLength(0); - const { labels, datasets: [{ title, data, backgroundColor, borderColor }] } = doughnut.prop('data'); + const { labels, datasets } = doughnut.prop('data'); + const [{ title, data, backgroundColor, borderColor }] = datasets; const { legend, scales } = doughnut.prop('options'); expect(title).toEqual('The chart'); expect(labels).toEqual(keys(stats)); expect(data).toEqual(values(stats)); + expect(datasets).toHaveLength(1); expect(backgroundColor).toEqual([ '#97BBCD', '#DCDCDC', @@ -65,4 +67,21 @@ describe('', () => { yAxes: [{ stacked: true }], }); }); + + it.each([ + [{ foo: 23 }, [ 100, 456 ], [ 23, 0 ]], + [{ foo: 50 }, [ 73, 456 ], [ 50, 0 ]], + [{ bar: 45 }, [ 123, 411 ], [ 0, 45 ]], + [{ bar: 20, foo: 13 }, [ 110, 436 ], [ 13, 20 ]], + [ undefined, [ 123, 456 ], undefined ], + ])('splits highlighted data from regular data', (highlightedStats, expectedData, expectedHighlightedData) => { + wrapper = shallow(); + const horizontal = wrapper.find(HorizontalBar); + + const { datasets: [{ data }, highlightedData ] } = horizontal.prop('data'); + + expect(data).toEqual(expectedData); + expectedHighlightedData && expect(highlightedData.data).toEqual(expectedHighlightedData); + !expectedHighlightedData && expect(highlightedData).toBeUndefined(); + }); });