From d1a5dee45dbf821b5821cfc9af7a02a0b237df76 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 29 Nov 2026 09:48:22 +0100 Subject: [PATCH] Fix missing market price of today in historical market data editor --- ...rical-market-data-editor.component.spec.ts | 19 +++++++++++++++++++ ...historical-market-data-editor.component.ts | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.spec.ts b/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.spec.ts index 7cb9636f0e..e3526df8f5 100644 --- a/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.spec.ts +++ b/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.spec.ts @@ -57,4 +57,23 @@ describe('GfHistoricalMarketDataEditorComponent', () => { expect(component.formatDay(31)).toBe('31'); }); }); + + describe('ngOnChanges', () => { + afterEach(() => { + jest.useRealTimers(); + }); + + it('should keep the market price of today if the last item is in the future', () => { + jest.useFakeTimers().setSystemTime(new Date(2026, 10, 29, 20)); + + fixture.componentRef.setInput('marketData', [ + { date: new Date(2026, 10, 29), marketPrice: 1 }, + { date: new Date(2026, 10, 30), marketPrice: 2 } + ]); + + fixture.detectChanges(); + + expect(component.marketDataByMonth['2026-11']['29'].marketPrice).toBe(1); + }); + }); }); diff --git a/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts b/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts index 6da916a8ef..8d8aee1a93 100644 --- a/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts +++ b/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts @@ -37,11 +37,11 @@ import { format, isBefore, isSameDay, - isToday, isValid, min, parse, - parseISO + parseISO, + startOfToday } from 'date-fns'; import ms from 'ms'; import { DeviceDetectorService } from 'ngx-device-detector'; @@ -153,7 +153,7 @@ export class GfHistoricalMarketDataEditorComponent const marketDataItems = [...missingMarketData, ...this.marketData()]; const lastDate = marketDataItems.at(-1)?.date; - if (!lastDate || !isToday(lastDate)) { + if (!lastDate || isBefore(lastDate, startOfToday())) { marketDataItems.push({ date: new Date() }); }