feat(data): removeHistoryEntry supports optional employeeId
This commit is contained in:
1 parent
23683102bc
commit
7bda92a0a3
2 files changed
+38
-2
No files matched your search
+6
-2
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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.');
|
||||
Reference in new issue
Block a user