fix(build): isolate time tests by Docker build context
This commit is contained in:
46
frontend/tests/time-v2.test.cjs
Normal file
46
frontend/tests/time-v2.test.cjs
Normal file
@@ -0,0 +1,46 @@
|
||||
const assert = require('node:assert/strict')
|
||||
const test = require('node:test')
|
||||
const fs = require('node:fs')
|
||||
const vm = require('node:vm')
|
||||
const ts = require('typescript')
|
||||
|
||||
function loadUtility(name) {
|
||||
const source = fs.readFileSync(`${__dirname}/../utils/${name}.ts`, 'utf8')
|
||||
const { outputText } = ts.transpileModule(source, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2021 },
|
||||
})
|
||||
const exports = {}
|
||||
vm.runInNewContext(outputText, { exports })
|
||||
return exports
|
||||
}
|
||||
|
||||
const { timeSpanInput } = loadUtility('timeSpanInput')
|
||||
const { staffTimeRows, workingMinutes } = loadUtility('staffTimeSpans')
|
||||
|
||||
test('editing repeated local times preserves the original instant and rejects ambiguous new inputs', () => {
|
||||
assert.equal(timeSpanInput('2026-10-25T02:15', 'Europe/Berlin', '2026-10-25T01:15:00.000Z'), '2026-10-25T01:15:00.000Z');
|
||||
assert.equal(timeSpanInput('2026-10-25T02:15', 'Europe/Berlin', '2026-10-25T00:15:00.000Z'), '2026-10-25T00:15:00.000Z');
|
||||
assert.throws(() => timeSpanInput('2026-10-25T02:15', 'Europe/Berlin'), /zweimal/);
|
||||
assert.throws(() => timeSpanInput('2026-03-29T02:15', 'Europe/Berlin'), /existiert nicht/);
|
||||
assert.equal(timeSpanInput('2026-10-25T01:15', 'UTC'), '2026-10-25T01:15:00.000Z');
|
||||
});
|
||||
|
||||
test('dashboard keeps a paused attendance active and freezes its net working duration', () => {
|
||||
const attendance = {
|
||||
id: 'attendance-1', user_id: 'user-1', type: 'work', status: 'factual',
|
||||
started_at: '2026-10-01T06:00:00Z', ended_at: null,
|
||||
breaks: [{ started_at: '2026-10-01T10:00:00Z', ended_at: null }],
|
||||
}
|
||||
const base = { id: attendance.id, model: 'spans-v2', attendance }
|
||||
const segments = [
|
||||
{ ...base, type: 'work', startedAt: attendance.started_at, endedAt: attendance.breaks[0].started_at },
|
||||
{ ...base, type: 'pause', startedAt: attendance.breaks[0].started_at, endedAt: null },
|
||||
]
|
||||
const entries = staffTimeRows(segments, attendance.user_id, Date.parse('2026-10-01T11:00:00Z'))
|
||||
assert.equal(entries.length, 1)
|
||||
assert.equal(entries[0].type, 'work')
|
||||
assert.equal(entries[0].paused, true)
|
||||
assert.equal(entries[0].stopped_at, null)
|
||||
assert.equal(entries[0].duration_minutes, 240)
|
||||
assert.equal(workingMinutes(entries[0], Date.parse('2026-10-01T12:00:00Z')), 240)
|
||||
})
|
||||
Reference in New Issue
Block a user