fix(vacay): open on the current year instead of the last one added (#2056)

The year list comes back sorted, so picking its last element meant Vacay always
landed on the highest year — add 2030 to plan ahead and every visit from then on
opened 2030. It now opens the leave-year period today falls into, falls back to
the closest year the plan has when that period has none, and keeps the year the
viewer is on when a live update reloads the list.
This commit is contained in:
Maurice
2026-08-27 10:55:27 +02:00
committed by GitHub
parent d194d2cf6f
commit f61bab3ffd
4 changed files with 114 additions and 11 deletions
+29
View File
@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest'
import {
DEFAULT_YEAR_SETTINGS,
currentPeriodYear,
defaultPeriodYear,
gridWindow,
inGridWindow,
resolveYearWindow,
@@ -125,3 +126,31 @@ describe('currentPeriodYear', () => {
expect(currentPeriodYear(fiscal(7), new Date(2026, 6, 1))).toBe(2026)
})
})
describe('defaultPeriodYear', () => {
// FE-VACAY-YEARWINDOW-014
it('picks the current period when the plan has it', () => {
const today = new Date(2026, 2, 15)
expect(defaultPeriodYear([2024, 2025, 2026, 2030], DEFAULT_YEAR_SETTINGS, today)).toBe(2026)
})
// FE-VACAY-YEARWINDOW-015
it('falls back to the closest year and prefers the coming one on a tie', () => {
const today = new Date(2026, 2, 15)
expect(defaultPeriodYear([2022, 2024], DEFAULT_YEAR_SETTINGS, today)).toBe(2024)
expect(defaultPeriodYear([2028, 2030], DEFAULT_YEAR_SETTINGS, today)).toBe(2028)
expect(defaultPeriodYear([2024, 2028], DEFAULT_YEAR_SETTINGS, today)).toBe(2028)
})
// FE-VACAY-YEARWINDOW-016
it('is the current period for an empty plan', () => {
expect(defaultPeriodYear([], DEFAULT_YEAR_SETTINGS, new Date(2026, 2, 15))).toBe(2026)
})
// FE-VACAY-YEARWINDOW-017
it('follows a shifted leave year rather than the calendar year', () => {
const today = new Date(2026, 2, 15)
expect(defaultPeriodYear([2025, 2026], fiscal(7), today)).toBe(2025)
expect(defaultPeriodYear([2026], fiscal(7), today)).toBe(2026)
})
})