Money tracker: vertical month/year gridlines on wealth chart, keep range in ?range= URL param
All checks were successful
Deploy production / deploy (push) Successful in 2m36s
All checks were successful
Deploy production / deploy (push) Successful in 2m36s
This commit is contained in:
@@ -4,6 +4,9 @@ import {
|
||||
accountColor,
|
||||
balanceSeries,
|
||||
forecastSeries,
|
||||
parseHistoryRange,
|
||||
timeGrid,
|
||||
yearLabels,
|
||||
utilityEstimate,
|
||||
wealthProjection,
|
||||
wealthTimeline
|
||||
@@ -308,4 +311,42 @@ describe('history range', () => {
|
||||
expect(byAccount.map((line) => line.label)).toEqual(['Bank', 'Parents', 'Total']);
|
||||
expect(byAccount.at(-1)!.points[0].value).toBe(1000);
|
||||
});
|
||||
|
||||
it('reads the history range from the URL, defaulting to one year', () => {
|
||||
expect(parseHistoryRange('3y')).toBe('3y');
|
||||
expect(parseHistoryRange('all')).toBe('all');
|
||||
expect(parseHistoryRange('1y')).toBe('1y');
|
||||
expect(parseHistoryRange('5y')).toBe('1y');
|
||||
expect(parseHistoryRange(null)).toBe('1y');
|
||||
});
|
||||
|
||||
it('puts a gridline on every month start and marks 1 January as a year line', () => {
|
||||
const lines = timeGrid('2025-10-24', '2026-03-01', 'months');
|
||||
expect(lines).toEqual([
|
||||
{ date: '2025-11-01', year: false },
|
||||
{ date: '2025-12-01', year: false },
|
||||
{ date: '2026-01-01', year: true },
|
||||
{ date: '2026-02-01', year: false },
|
||||
{ date: '2026-03-01', year: false }
|
||||
]);
|
||||
expect(timeGrid('2025-01-01', '2025-02-15', 'months').map((line) => line.date)).toEqual([
|
||||
'2025-01-01',
|
||||
'2025-02-01'
|
||||
]);
|
||||
});
|
||||
|
||||
it('puts only year lines on the all-time grid and thins crowded year labels', () => {
|
||||
const lines = timeGrid('2007-02-01', '2027-10-24', 'years');
|
||||
expect(lines).toHaveLength(20);
|
||||
expect(lines.every((line) => line.year && line.date.endsWith('-01-01'))).toBe(true);
|
||||
expect(lines[0].date).toBe('2008-01-01');
|
||||
expect(yearLabels(lines, 30)).toHaveLength(20);
|
||||
expect(yearLabels(lines, 6).map((date) => date.slice(0, 4))).toEqual([
|
||||
'2010',
|
||||
'2015',
|
||||
'2020',
|
||||
'2025'
|
||||
]);
|
||||
expect(timeGrid('2026-01-02', '2026-01-01', 'months')).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user