import assert from 'node:assert/strict' import { ringSlicePath } from '../../../src/modules/cockpit/domain/ringGeometry.js' import { planStatusPie } from '../../../src/modules/cockpit/domain/statusPie.js' import { donutBlock } from '../../../src/modules/cockpit/domain/panelBlocks.js' import { planEventLocate } from '../../../src/modules/cockpit/domain/eventDetail.js' import { eventTimeWindow, historyWindows } from '../../../src/modules/cockpit/domain/eventRange.js' import { resolveDeviceImageUrl } from '../../../src/modules/cockpit/services/deviceImage.js' // Full rings need four arcs, not a coincident-endpoint single arc. assert.equal((ringSlicePath(0, 360).match(/ A /g) || []).length, 4) const donut = donutBlock('single', [{ code: 'MANHOLE', label: '窨井', count: 7 }]) assert.equal(donut.slices.length, 1) assert.equal((donut.slices[0].path.match(/ A /g) || []).length, 4) const pie = planStatusPie({ distribution: { available: true, counts: { UNKNOWN: 7 } }, rows: [{ key: 'UNKNOWN', label: '状态未发布', tone: 'point-unknown' }] }) assert.equal((pie.slices[0].path.match(/ A /g) || []).length, 4) assert.ok(!pie.slices[0].path.includes('NaN')) // Precise device identity wins even if a parent point comes first. const point = { kind: 'monitoring-point', code: 'P', deviceCodes: ['D'], coordinate: { renderable: true }, longitude: 110, latitude: 28 } const device = { kind: 'unassociated-equipment', code: 'D', deviceCodes: [], coordinate: { renderable: true }, longitude: 110.1, latitude: 28.1 } assert.equal(planEventLocate({ deviceCode: 'D' }, [point, device]).object, device) assert.equal(planEventLocate({ deviceCode: 'D', coordinate: { validated: true, renderable: false } }, [device]).result, 'ok') assert.equal(planEventLocate({ deviceCode: 'D' }, [{ ...device, kind: 'monitoring-device' }]).result, 'ok') // Inclusive hourly server buckets are disjoint and cover the entire 90-day window. const range = eventTimeWindow('LAST_90_DAYS', Date.parse('2026-10-13T12:34:00+08:00')) const windows = historyWindows(range.startTime, range.endTime) const seen = new Set() for (const window of windows) { assert.ok(Date.parse(window.endTime) - Date.parse(window.startTime) < 31 * 86400000) for (let hour = Math.floor(Date.parse(window.startTime) / 3600000); hour <= Math.floor(Date.parse(window.endTime) / 3600000); hour++) { assert.ok(!seen.has(hour), 'hour was requested twice') seen.add(hour) } } assert.equal(seen.size, Math.floor(Date.parse(range.endTime) / 3600000) - Math.floor(Date.parse(range.startTime) / 3600000) + 1) assert.equal(resolveDeviceImageUrl('/profile/upload/test.jpg', { dataSource: 'real', api: { baseUrl: 'https://backend.example/api/cockpit/v1' } }), 'https://backend.example/profile/upload/test.jpg') console.log('UI feedback regressions passed')