Browse Source

Fix missing market price of today in historical market data editor

pull/7491/head
Thomas Kaul 2 hours ago
parent
commit
d1a5dee45d
  1. 19
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.spec.ts
  2. 6
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts

19
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'); 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);
});
});
}); });

6
libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts

@ -37,11 +37,11 @@ import {
format, format,
isBefore, isBefore,
isSameDay, isSameDay,
isToday,
isValid, isValid,
min, min,
parse, parse,
parseISO parseISO,
startOfToday
} from 'date-fns'; } from 'date-fns';
import ms from 'ms'; import ms from 'ms';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
@ -153,7 +153,7 @@ export class GfHistoricalMarketDataEditorComponent
const marketDataItems = [...missingMarketData, ...this.marketData()]; const marketDataItems = [...missingMarketData, ...this.marketData()];
const lastDate = marketDataItems.at(-1)?.date; const lastDate = marketDataItems.at(-1)?.date;
if (!lastDate || !isToday(lastDate)) { if (!lastDate || isBefore(lastDate, startOfToday())) {
marketDataItems.push({ date: new Date() }); marketDataItems.push({ date: new Date() });
} }

Loading…
Cancel
Save