mirror of
https://github.com/actualbudget/actual.git
synced 2026-05-20 14:11:32 -05:00
[AI] Fix balance forecast all future range (#7849)
* [AI] Fix forecast all future range * [AI] Add release note for balance forecast range fix
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import * as monthUtils from '@actual-app/core/shared/months';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
calculateSpendingReportTimeRange,
|
||||
calculateTimeRange,
|
||||
getFullFutureRange,
|
||||
} from './reportRanges';
|
||||
|
||||
// In test mode, monthUtils.currentMonth() returns '2017-01'
|
||||
@@ -66,3 +68,26 @@ describe('calculateSpendingReportTimeRange', () => {
|
||||
expect(compareTo).toBe('2017-01');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFullFutureRange', () => {
|
||||
it('uses a future month as the end of the range', () => {
|
||||
const start = monthUtils.currentMonth();
|
||||
const futureMonth = monthUtils.addMonths(start, 36);
|
||||
|
||||
expect(getFullFutureRange(futureMonth)).toEqual([
|
||||
start,
|
||||
futureMonth,
|
||||
'static',
|
||||
]);
|
||||
});
|
||||
|
||||
it('falls back to a default future horizon without a future month', () => {
|
||||
const start = monthUtils.currentMonth();
|
||||
|
||||
expect(getFullFutureRange()).toEqual([
|
||||
start,
|
||||
monthUtils.addMonths(start, 24),
|
||||
'static',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -184,12 +184,9 @@ export function getNextRange(offset: number) {
|
||||
export function getFullFutureRange(latestMonth?: string) {
|
||||
const start = monthUtils.currentMonth();
|
||||
const defaultEnd = monthUtils.addMonths(start, 24);
|
||||
const latestMonthValue = latestMonth
|
||||
? monthUtils.monthFromDate(latestMonth)
|
||||
: undefined;
|
||||
const end =
|
||||
latestMonthValue && monthUtils.isAfter(latestMonthValue, start)
|
||||
? latestMonthValue
|
||||
latestMonth && monthUtils.isAfter(latestMonth, start)
|
||||
? latestMonth
|
||||
: defaultEnd;
|
||||
|
||||
return [start, end, 'static'] as const;
|
||||
|
||||
@@ -301,9 +301,7 @@ function BalanceForecastInner({ widget }: BalanceForecastInnerProps) {
|
||||
end={end}
|
||||
earliestTransaction={earliestTransaction}
|
||||
latestTransaction={
|
||||
forecastData?.forecastEndDate
|
||||
? monthUtils.monthFromDate(forecastData.forecastEndDate)
|
||||
: (allMonths[0]?.name ?? monthUtils.addMonths(currentMonth, 24))
|
||||
allMonths[0]?.name ?? monthUtils.addMonths(currentMonth, 24)
|
||||
}
|
||||
mode={mode}
|
||||
onChangeDates={onChangeDates}
|
||||
|
||||
6
upcoming-release-notes/7849.md
Normal file
6
upcoming-release-notes/7849.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfixes
|
||||
authors: [samaluk]
|
||||
---
|
||||
|
||||
Fix the Balance Forecast report's All future range.
|
||||
Reference in New Issue
Block a user