From 7bda92a0a3f845a8bba1cb0514c98dadf1b7dcad Mon Sep 17 00:00:00 2001 From: Ferdinand Urban Date: Tue, 28 Apr 2026 10:31:38 +0000 Subject: [PATCH] feat(data): removeHistoryEntry supports optional employeeId --- js/data.js | 8 ++++++-- tests/data.test.mjs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/js/data.js b/js/data.js index d517873..37045ff 100644 --- a/js/data.js +++ b/js/data.js @@ -70,6 +70,10 @@ export function addHistoryEntries(state, entries) { state.history.sort((a, b) => a.date.localeCompare(b.date)); } -export function removeHistoryEntry(state, isoDate) { - state.history = state.history.filter(h => h.date !== isoDate); +export function removeHistoryEntry(state, isoDate, employeeId) { + if (employeeId === undefined) { + state.history = state.history.filter(h => h.date !== isoDate); + } else { + state.history = state.history.filter(h => !(h.date === isoDate && h.employeeId === employeeId)); + } } diff --git a/tests/data.test.mjs b/tests/data.test.mjs index c9c473f..b3aede8 100644 --- a/tests/data.test.mjs +++ b/tests/data.test.mjs @@ -44,4 +44,36 @@ function makeState(history = []) { assert.equal(state.history.length, 1, 'empty entries → no change'); } +// removeHistoryEntry without employeeId: removes all entries on that date +{ + const state = makeState([ + { date: '2026-04-01', employeeId: 'alice', manual: false }, + { date: '2026-04-01', employeeId: 'bob', manual: false }, + { date: '2026-04-02', employeeId: 'alice', manual: false } + ]); + removeHistoryEntry(state, '2026-04-01'); + assert.equal(state.history.length, 1, 'only 2026-04-02 alice remains'); + assert.equal(state.history[0].date, '2026-04-02', 'remaining entry is 2026-04-02'); +} + +// removeHistoryEntry with employeeId: removes only that one entry +{ + const state = makeState([ + { date: '2026-04-01', employeeId: 'alice', manual: false }, + { date: '2026-04-01', employeeId: 'bob', manual: false } + ]); + removeHistoryEntry(state, '2026-04-01', 'alice'); + assert.equal(state.history.length, 1, 'one entry remains'); + assert.equal(state.history[0].employeeId, 'bob', 'bob still there'); +} + +// removeHistoryEntry with employeeId that does not exist: no-op +{ + const state = makeState([ + { date: '2026-04-01', employeeId: 'alice', manual: false } + ]); + removeHistoryEntry(state, '2026-04-01', 'nonexistent'); + assert.equal(state.history.length, 1, 'no change when employeeId not found'); +} + console.log('All data tests passed.');