feat: build Onyx SSR shell and plan hero with mock data
This commit is contained in:
1 parent
84c20992f9
commit
2db494fb10
34 files changed
+3197
-2
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { buildStaffing, planWeekStart, applyScenario } from '../shared/staffing'
|
||||
import type { Point } from '../shared/types'
|
||||
|
||||
const now = '2026-11-14T08:12:00Z'
|
||||
|
||||
function mondayPoints(value = 100): Point[] {
|
||||
return Array.from({ length: 24 }, (_, hour) => ({
|
||||
t: new Date(Date.UTC(2026, 10, 15, 23 + hour)).toISOString().replace('.000Z', 'Z'),
|
||||
v: value,
|
||||
}))
|
||||
}
|
||||
|
||||
describe('planWeekStart', () => {
|
||||
it('returns the Monday after the demo Saturday', () => {
|
||||
expect(planWeekStart(now)).toBe('2026-11-16')
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildStaffing', () => {
|
||||
it('applies the contract heuristic to a flat 10:00-20:00 day', () => {
|
||||
const build = buildStaffing({
|
||||
sensor: 'hn-stadtgalerie-01',
|
||||
scenario: 'base',
|
||||
standard: 'standard',
|
||||
points: mondayPoints(100),
|
||||
weekStart: '2026-11-16',
|
||||
data_version: 'data',
|
||||
model_version: 'model',
|
||||
context_version: 'context',
|
||||
})
|
||||
|
||||
expect(build.byDate['2026-11-16']).toHaveLength(10)
|
||||
expect(build.response.shifts).toEqual([
|
||||
{ date: '2026-11-16', start: '10:00', end: '14:00', staff: 5 },
|
||||
{ date: '2026-11-16', start: '14:00', end: '18:00', staff: 5 },
|
||||
{ date: '2026-11-16', start: '18:00', end: '20:00', staff: 5 },
|
||||
])
|
||||
expect(build.response.summary.coverage_pct).toBe(100)
|
||||
expect(build.response.summary.cost_eur).toBe(800)
|
||||
expect(build.response.summary.flat_schedule_cost_eur).toBe(800)
|
||||
expect(build.response.summary.understaffed_hours).toBe(0)
|
||||
})
|
||||
|
||||
it('uses the block peak so low hours become overstaffed, not understaffed', () => {
|
||||
const points = mondayPoints(60).map((point, index) =>
|
||||
index === 11 ? { ...point, v: 200 } : point,
|
||||
)
|
||||
const build = buildStaffing({
|
||||
sensor: 'hn-stadtgalerie-01',
|
||||
scenario: 'base',
|
||||
standard: 'standard',
|
||||
points,
|
||||
weekStart: '2026-11-16',
|
||||
data_version: 'data',
|
||||
model_version: 'model',
|
||||
context_version: 'context',
|
||||
})
|
||||
const firstHour = build.byDate['2026-11-16']?.[0]
|
||||
expect(firstHour?.required_staff).toBe(3)
|
||||
expect(firstHour?.scheduled_staff).toBe(10)
|
||||
expect(build.response.summary.overstaffed_hours).toBeGreaterThan(0)
|
||||
expect(build.response.summary.understaffed_hours).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('applyScenario', () => {
|
||||
const saturday: Point = { t: '2026-11-21T12:00:00Z', v: 100, lo: 80, hi: 120 }
|
||||
|
||||
it('raises Saturday for the sunny market scenario', () => {
|
||||
expect(applyScenario([saturday], 'sunny-saturday-market')[0]?.v).toBe(120)
|
||||
})
|
||||
|
||||
it('lowers Saturday for the rainy scenario', () => {
|
||||
expect(applyScenario([saturday], 'rainy-saturday')[0]?.v).toBe(82)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user