fix(planning): plan TIME_WINDOW rules on the picked calendar dates #315

Merged
nessar merged 1 commits from feature/311-time-window-local-dates into develop 2026-10-19 15:40:14 +02:00
2 changed files with 39 additions and 3 deletions

No files matched your search

@@ -1,7 +1,7 @@
import { provideZonelessChangeDetection } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { vi } from '../../testing/vitest-compat';
import { CalendarService } from './calendar-service';
import { CalendarService, SelectableDayType } from './calendar-service';
import { CalendarSettingsService } from './calendar-settings-service';
import type {
PlanOutcome,
@@ -11,6 +11,7 @@ import type {
PlanningReason,
} from './leave-planner.service';
import { PlanningCalculationService } from './planning-calculation.service';
import { RuleService, RuleType } from './rule-service';
import { UserInputService } from './user-input-service';
function deferred<T>() {
@@ -119,6 +120,33 @@ describe('PlanningCalculationService', () => {
expect(submission.labels).toBeDefined();
});
it('hands TIME_WINDOW rules the picked calendar dates east of Paris', () => {
const previousTimeZone = process.env['TZ'];
process.env['TZ'] = 'Pacific/Auckland';
try {
TestBed.inject(RuleService).addRule({
id: 'christmas',
name: 'Christmas',
type: RuleType.TIME_WINDOW,
enabled: true,
force: 'obligation',
startDate: new Date(2026, 11, 20),
endDate: new Date(2026, 11, 31),
placeDays: 3,
placeType: SelectableDayType.CP,
});
queue(fakeCalculation('first'));
service.start();
const submitted = create.mock.calls[0][0].rules.find(
(rule: { id: string }) => rule.id === 'christmas',
);
expect(submitted).toMatchObject({ startDate: '2026-12-20', endDate: '2026-12-31' });
} finally {
// bun test defaults to UTC without setting TZ; deleting it would fall back to the host zone.
process.env['TZ'] = previousTimeZone ?? 'UTC';
}
});
it('reports the stage and submission of the latest calculation only, until Cancel', () => {
queue(fakeCalculation('old'), fakeCalculation('latest'));
service.start();
@@ -11,7 +11,7 @@ import type {
PlanningRequest,
PlanningSnapshot,
} from './leave-planner.service';
import { RuleService } from './rule-service';
import { RuleService, RuleType } from './rule-service';
import { TranslationService } from './translation-service';
import { UserInputService } from './user-input-service';
@@ -85,7 +85,15 @@ export class PlanningCalculationService {
: undefined,
expiryDate: dayjs(balance.expiryDate).format('YYYY-MM-DD'),
})),
rules: this.rules.rules,
rules: this.rules.rules.map((rule) =>
rule.type === RuleType.TIME_WINDOW
? {
...rule,
startDate: dayjs(rule.startDate).format('YYYY-MM-DD'),
endDate: dayjs(rule.endDate).format('YYYY-MM-DD'),
}
: rule,
),
};
});