Tested how hilghlighted data behaves on GraphCards

This commit is contained in:
Alejandro Celaya
2020-04-09 09:44:14 +02:00
parent 310831a26a
commit 9177bc7cef
3 changed files with 22 additions and 2 deletions

View File

@@ -29,6 +29,7 @@
"no-magic-numbers": "off", "no-magic-numbers": "off",
"no-undefined": "off", "no-undefined": "off",
"no-inline-comments": "off", "no-inline-comments": "off",
"lines-around-comment": "off",
"indent": ["error", 2, { "indent": ["error", 2, {
"SwitchCase": 1 "SwitchCase": 1
} }

View File

@@ -54,7 +54,7 @@ const renderGraph = (title, isBarChart, stats, max, highlightedStats) => {
} }
return acc; return acc;
}, stats)); }, { ...stats }));
const highlightedData = highlightedStats && values({ ...zipObj(labels, labels.map(() => 0)), ...highlightedStats }); const highlightedData = highlightedStats && values({ ...zipObj(labels, labels.map(() => 0)), ...highlightedStats });
const options = { const options = {

View File

@@ -21,12 +21,14 @@ describe('<GraphCard />', () => {
expect(doughnut).toHaveLength(1); expect(doughnut).toHaveLength(1);
expect(horizontal).toHaveLength(0); 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'); const { legend, scales } = doughnut.prop('options');
expect(title).toEqual('The chart'); expect(title).toEqual('The chart');
expect(labels).toEqual(keys(stats)); expect(labels).toEqual(keys(stats));
expect(data).toEqual(values(stats)); expect(data).toEqual(values(stats));
expect(datasets).toHaveLength(1);
expect(backgroundColor).toEqual([ expect(backgroundColor).toEqual([
'#97BBCD', '#97BBCD',
'#DCDCDC', '#DCDCDC',
@@ -65,4 +67,21 @@ describe('<GraphCard />', () => {
yAxes: [{ stacked: true }], 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(<GraphCard isBarChart title="The chart" stats={stats} highlightedStats={highlightedStats} />);
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();
});
}); });