CUB-196: fix future timestamps, negative battery clamp, boundary tests

Grimm review fixes:
- formatRelativeTime: guard future timestamps (clock skew) → 'unknown'
- battery display: clamp negative values to 0%
- formatTimeLeft: floor fractional seconds
- Tests: +4 (future timestamp, negative battery, 15%/50% boundaries)
This commit is contained in:
2026-05-21 14:07:57 +00:00
parent 08d5ceb792
commit db4663380b
2 changed files with 32 additions and 2 deletions
+29
View File
@@ -131,4 +131,33 @@ describe('CameraCard', () => {
)
expect(screen.getByText('unknown')).toBeInTheDocument()
})
it('shows "unknown" when last_seen is in the future', () => {
const future = new Date(Date.now() + 86400000).toISOString() // +1 day
render(<CameraCard camera={makeCamera({ last_seen: future })} />)
expect(screen.getByText('unknown')).toBeInTheDocument()
})
// ── Edge cases ──────────────────────────────────────────────────────────
it('clamps negative battery_pct to 0%', () => {
render(<CameraCard camera={makeCamera({ battery_pct: -5 })} />)
expect(screen.getByText('0%')).toBeInTheDocument()
})
it('shows exact boundary: 15% battery → yellow bar', () => {
const { container } = render(
<CameraCard camera={makeCamera({ battery_pct: 15 })} />,
)
const bar = container.querySelector('[role="progressbar"] div')
expect(bar?.className).toContain('bg-rig-warning')
})
it('shows exact boundary: 50% battery → green bar', () => {
const { container } = render(
<CameraCard camera={makeCamera({ battery_pct: 50 })} />,
)
const bar = container.querySelector('[role="progressbar"] div')
expect(bar?.className).toContain('bg-rig-success')
})
})