feat(vacay): half vacation days (#552) (#1631)

* feat(vacay): support half vacation days (#552)

Log a vacation day as a half day (0.5) as well as a full day and count it
as such against the entitlement. A "Half day" mode joins the calendar
toolbar on desktop and mobile; half days render as a diagonal half-fill in
the day cell, and the used/remaining totals carry the fraction.

Closes #552

* refactor(vacay): half-day as a per-person toggle with a corner badge

The diagonal half-fill collided with the two-person split — one person's
half day looked like two people off. Drop the diagonal: the cell fill keeps
showing who is off, a half day gets a small corner ½ badge, and a hover
tooltip lists who is off on that date and how much (only when a half day is
present). Logging moves from a third mode to a Half-day toggle that applies
to the selected person, on desktop and mobile.

* feat(vacay): mark half days with an orange corner dot

Swap the ½ badge for a small orange dot in the bottom-right corner, mirroring
the blue trip dot — quieter in the grid, and the hover tooltip still spells
out who is on a half day.

* fix(vacay): make the fraction migration idempotent

The crosswalk test replays the migration tail (rewind + re-run), which expects
every later migration to be idempotent. Guard the vacay_entries ADD COLUMN
behind a pragma_table_info check so the second run is a no-op. Also only set
dayVisual's `half` flag when true, so full days keep their exact
{ background, numColor } shape for the mobile day-model unit test.

* style(vacay): nudge the mobile day dots slightly inward

The blue trip dot and orange half-day dot sat right in the cell corner on
mobile; move both a touch toward the centre so they read cleaner.
This commit is contained in:
Maurice
2026-07-20 23:38:47 +02:00
committed by GitHub
parent a3cb783df7
commit 7528706d00
43 changed files with 372 additions and 56 deletions
+1 -1
View File
@@ -83,7 +83,7 @@ describe('Vacay e2e (real auth guard + temp SQLite)', () => {
.set('Cookie', sessionCookie(1)).set('X-Socket-Id', 'sock-7').send({ date: '2026-07-01' });
expect(res.status).toBe(200);
expect(res.body).toEqual({ action: 'added' });
expect(svc.toggleEntry).toHaveBeenCalledWith(1, 10, '2026-07-01', 'sock-7');
expect(svc.toggleEntry).toHaveBeenCalledWith(1, 10, '2026-07-01', undefined, 'sock-7');
});
it('400 on entries/toggle without a date', async () => {
@@ -137,7 +137,13 @@ describe('VacayController (parity with the legacy /api/addons/vacay route)', ()
it('toggles for the caller', () => {
const toggleEntry = vi.fn().mockReturnValue({ action: 'added' });
expect(makeController({ ...planBase, toggleEntry }).toggleEntry(user, { date: '2026-07-01' }, 'sock')).toEqual({ action: 'added' });
expect(toggleEntry).toHaveBeenCalledWith(1, 10, '2026-07-01', 'sock');
expect(toggleEntry).toHaveBeenCalledWith(1, 10, '2026-07-01', undefined, 'sock');
});
it('forwards the half-day fraction (#552)', () => {
const toggleEntry = vi.fn().mockReturnValue({ action: 'added', fraction: 0.5 });
makeController({ ...planBase, toggleEntry }).toggleEntry(user, { date: '2026-07-01', fraction: 0.5 }, 'sock');
expect(toggleEntry).toHaveBeenCalledWith(1, 10, '2026-07-01', 0.5, 'sock');
});
});
@@ -527,6 +527,44 @@ describe('toggleEntry', () => {
.get(user.id, plan.id, '2025-08-02');
expect(row).toBeUndefined();
});
it('VACAY-SVC-033a: logs a half day when fraction is 0.5 (#552)', () => {
const { user, plan } = setupUserWithPlan();
const result = toggleEntry(user.id, plan.id, '2025-08-05', 0.5);
expect(result).toMatchObject({ action: 'added', fraction: 0.5 });
const row = testDb
.prepare('SELECT fraction FROM vacay_entries WHERE user_id = ? AND plan_id = ? AND date = ?')
.get(user.id, plan.id, '2025-08-05') as { fraction: number };
expect(row.fraction).toBe(0.5);
});
it('VACAY-SVC-033b: converts a full day into a half day in place (action: updated)', () => {
const { user, plan } = setupUserWithPlan();
toggleEntry(user.id, plan.id, '2025-08-06', 1);
const result = toggleEntry(user.id, plan.id, '2025-08-06', 0.5);
expect(result).toMatchObject({ action: 'updated', fraction: 0.5 });
const row = testDb
.prepare('SELECT fraction FROM vacay_entries WHERE user_id = ? AND plan_id = ? AND date = ?')
.get(user.id, plan.id, '2025-08-06') as { fraction: number };
expect(row.fraction).toBe(0.5);
});
it('VACAY-SVC-033c: toggling the same half day again clears it (action: removed)', () => {
const { user, plan } = setupUserWithPlan();
toggleEntry(user.id, plan.id, '2025-08-07', 0.5);
const result = toggleEntry(user.id, plan.id, '2025-08-07', 0.5);
expect(result.action).toBe('removed');
const row = testDb
.prepare('SELECT id FROM vacay_entries WHERE user_id = ? AND plan_id = ? AND date = ?')
.get(user.id, plan.id, '2025-08-07');
expect(row).toBeUndefined();
});
});
// ── toggleCompanyHoliday ──────────────────────────────────────────────────────
@@ -701,6 +739,19 @@ describe('getStats', () => {
expect(stats[0].used).toBe(2);
expect(stats[0].remaining).toBe(28);
});
it('VACAY-SVC-045a: half days count as 0.5 toward the used total (#552)', () => {
const { user, plan } = setupUserWithPlan();
const yr = new Date().getFullYear();
toggleEntry(user.id, plan.id, `${yr}-09-12`, 1); // full day
toggleEntry(user.id, plan.id, `${yr}-09-13`, 0.5); // half day
const stats = getStats(plan.id, yr);
expect(stats[0].used).toBe(1.5);
expect(stats[0].remaining).toBe(28.5);
});
});
// ── applyHolidayCalendars ─────────────────────────────────────────────────────