Commit 8b5eadfa authored by wortschi's avatar wortschi

Fix trendline error

- This MR fixes an error
when adding a date item
to the scatterplot that is
out of the date range. It adds
a sanity check to the
transformScatterData method.

Changelog: fixed
EE: true
parent de873efa
......@@ -97,7 +97,13 @@ export const transformScatterData = (data, startDate, endDate) => {
if (dayDiff > -1) {
const idx = totalItems - (dayDiff + 1);
result[idx].push(data[id]);
// When dealing with different time zones (merged_at is in UTC but endDate is in the browser's timezone)
// the computed idx might be out of bounds because the result array (and its length) is initialized
// via initDateArray (which takes only the browser's timezone into account)
// This would lead to result[idx] being undefined, thus we need a sanity check here
if (result[idx]) {
result[idx].push(data[id]);
}
}
});
......
......@@ -93,6 +93,26 @@ describe('Productivity Analytics utils', () => {
];
expect(result).toEqual(expected);
});
describe('when a data item is out of the start/end date range', () => {
it('ensures that the sanity check is performed', () => {
const startDate = new Date('2021-04-30');
const endDate = new Date('2021-05-02');
const data = {
1: { merged_at: '2021-04-29T16:28:57.078Z', metric: 10 }, // this item is before the startDate
2: { merged_at: '2021-04-30T09:44:22.012Z', metric: 20 },
3: { merged_at: '2021-05-02T23:09:31.715Z', metric: 40 },
};
const result = transformScatterData(data, startDate, endDate);
const expected = [
[{ merged_at: '2021-04-30T09:44:22.012Z', metric: 20 }],
[],
[{ merged_at: '2021-05-02T23:09:31.715Z', metric: 40 }],
];
expect(result).toEqual(expected);
});
});
});
describe('getScatterPlotData', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment