Commit 0a79d1b2 authored by Tim Zallmann's avatar Tim Zallmann

Merge branch 'weimeng-fix-burndown-chart-reset-logic' into 'master'

Fix burndown negative count edge case

Closes #32401

See merge request gitlab-org/gitlab!18053
parents dbe6d4ea c57a4d9e
......@@ -53,13 +53,13 @@ export default class BurndownChartData {
// weight count on an given date. To mitigate this, we reset the current
// date's counters to 0 and carry forward the negative count to a future
// date until the total is positive again.
if (openIssuesCount < 0 || openIssuesWeight < 0) {
carriedIssuesCount = openIssuesCount;
carriedIssuesWeight = openIssuesWeight;
if (openIssuesCount + carriedIssuesCount < 0 || openIssuesWeight + carriedIssuesWeight < 0) {
carriedIssuesCount += openIssuesCount;
carriedIssuesWeight += openIssuesWeight;
openIssuesCount = 0;
openIssuesWeight = 0;
} else if (carriedIssuesCount < 0 || carriedIssuesWeight < 0) {
} else {
openIssuesCount += carriedIssuesCount;
openIssuesWeight += carriedIssuesWeight;
......
---
title: Fix burndown negative count edge case
merge_request: 18053
author:
type: fixed
......@@ -87,16 +87,20 @@ describe('BurndownChartData', () => {
});
});
describe('when first two days of milestone have negative issue count', () => {
describe('when days in milestone have negative counts', () => {
describe('and the first two days have a negative count', () => {
beforeAll(() => {
milestoneEvents.length = 0;
milestoneEvents.push(
{ created_at: '2017-03-01T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-01T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-01T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-02T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'created' },
);
});
it('sets first two dates data to 0 and carries forward negative total to the third day', () => {
it('generates an array where the first two days counts are zero', () => {
expect(burndownChartData.generate()).toEqual([
['2017-03-01', 0, 0],
['2017-03-02', 0, 0],
......@@ -104,5 +108,56 @@ describe('BurndownChartData', () => {
]);
});
});
describe('and the middle day has a negative count', () => {
// This scenario is unlikely to occur as this implies there are more
// closed issues than total issues, but we account for it anyway as a
// potential edge case.
beforeAll(() => {
milestoneEvents.length = 0;
milestoneEvents.push(
{ created_at: '2017-03-01T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-02T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-02T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'created' },
);
});
it('generates an array where the middle day count is zero', () => {
expect(burndownChartData.generate()).toEqual([
['2017-03-01', 1, 2],
['2017-03-02', 0, 0],
['2017-03-03', 1, 2],
]);
});
});
describe('and the last day has a negative count', () => {
// This scenario is unlikely to occur as this implies there are more
// closed issues than total issues, but we account for it anyway as a
// potential edge case.
beforeAll(() => {
milestoneEvents.length = 0;
milestoneEvents.push(
{ created_at: '2017-03-01T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-02T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-02T00:00:00.000Z', weight: 2, action: 'closed' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'created' },
{ created_at: '2017-03-03T00:00:00.000Z', weight: 2, action: 'closed' },
);
});
it('generates an array where all counts are zero', () => {
expect(burndownChartData.generate()).toEqual([
['2017-03-01', 0, 0],
['2017-03-02', 0, 0],
['2017-03-03', 0, 0],
]);
});
});
});
});
});
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