feat(data): removeHistoryEntry supports optional employeeId

This commit is contained in:
ferdi2go committed 2026-04-28 10:31:38 +00:00
1 parent 23683102bc
commit 7bda92a0a3
2 files changed
+38 -2

No files matched your search

+6 -2
View File
@@ -70,6 +70,10 @@ export function addHistoryEntries(state, entries) {
state.history.sort((a, b) => a.date.localeCompare(b.date)); state.history.sort((a, b) => a.date.localeCompare(b.date));
} }
export function removeHistoryEntry(state, isoDate) { export function removeHistoryEntry(state, isoDate, employeeId) {
state.history = state.history.filter(h => h.date !== isoDate); 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));
}
} }
+32
View File
@@ -44,4 +44,36 @@ function makeState(history = []) {
assert.equal(state.history.length, 1, 'empty entries → no change'); 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.'); console.log('All data tests passed.');