-
-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fill the datasets with 0s when not enough data points (#6793)
Fills datasets that do not have all the datapoints with 0 so that every line in the graph starts at the beginning and ends at the end of graph. Closes # [1-2256](https://linear.app/unleash/issue/1-2256/fill-the-data-with-0s-so-that-all-x-axis-labels-have-values) --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai> Co-authored-by: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com>
- Loading branch information
1 parent
60262e5
commit 2e0ca31
Showing
4 changed files
with
156 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...c/component/insights/componentsChart/UpdatesPerEnvironmentTypeChart/group-by-date.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { groupByDateAndFillMissingDatapoints } from './UpdatesPerEnvironmentTypeChart'; | ||
|
||
describe('groupByDate', () => { | ||
it('correctly groups items by date and includes all environment types', () => { | ||
const items = [ | ||
{ | ||
date: '2023-01-01', | ||
environmentType: 'development', | ||
totalUpdates: 5, | ||
week: '2023-01', | ||
}, | ||
{ | ||
date: '2023-01-01', | ||
environmentType: 'production', | ||
totalUpdates: 3, | ||
week: '2023-01', | ||
}, | ||
{ | ||
date: '2023-01-09', | ||
environmentType: 'development', | ||
totalUpdates: 2, | ||
week: '2023-02', | ||
}, | ||
]; | ||
const grouped = groupByDateAndFillMissingDatapoints(items); | ||
expect(Object.keys(grouped)).toEqual( | ||
expect.arrayContaining(['2023-01-01', '2023-01-09']), | ||
); | ||
expect(grouped['2023-01-01']).toMatchObject([ | ||
{ | ||
date: '2023-01-01', | ||
environmentType: 'development', | ||
totalUpdates: 5, | ||
week: '2023-01', | ||
}, | ||
{ | ||
date: '2023-01-01', | ||
environmentType: 'production', | ||
totalUpdates: 3, | ||
week: '2023-01', | ||
}, | ||
]); | ||
|
||
expect(grouped['2023-01-09']).toMatchObject([ | ||
{ | ||
date: '2023-01-09', | ||
environmentType: 'development', | ||
totalUpdates: 2, | ||
week: '2023-02', | ||
}, | ||
{ | ||
date: '2023-01-09', | ||
environmentType: 'production', | ||
totalUpdates: 0, | ||
week: '2023-02', | ||
}, | ||
]); | ||
}); | ||
|
||
it('inserts placeholder items for missing environmentType data on some dates', () => { | ||
const items = [ | ||
{ | ||
date: '2023-01-01', | ||
environmentType: 'development', | ||
totalUpdates: 4, | ||
week: '2023-01', | ||
}, | ||
{ | ||
date: '2023-01-09', | ||
environmentType: 'production', | ||
totalUpdates: 6, | ||
week: '2023-02', | ||
}, | ||
]; | ||
const grouped = groupByDateAndFillMissingDatapoints(items); | ||
const productionOnJan01 = grouped['2023-01-01']?.find( | ||
(item) => item.environmentType === 'production', | ||
) ?? { totalUpdates: -1 }; | ||
const developmentOnJan09 = grouped['2023-01-09']?.find( | ||
(item) => item.environmentType === 'development', | ||
) ?? { totalUpdates: -1 }; | ||
|
||
expect(productionOnJan01.totalUpdates).toBe(0); | ||
expect(developmentOnJan09.totalUpdates).toBe(0); | ||
expect(grouped['2023-01-01']?.[1]?.week).toBe('2023-01'); | ||
}); | ||
}); |