SEC_Warehouse/tests/unit/home/splitAlerts.spec.ts

50 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, it, expect } from 'vitest'
import { splitAlerts } from '@/pages/index/splitAlerts'
import type { EventItem } from '@/api/event'
const item = (over: Partial<EventItem>): EventItem => ({
id: 1,
sceneName: '客厅',
deviceName: '体征监测仪',
status: 2,
time: '2026-09-07 21:22:12',
...over
})
describe('splitAlerts', () => {
it('status=1 进入未处理组,其余进入消息组', () => {
const list = [
item({ id: 1, status: 1 }),
item({ id: 2, status: 2 }),
item({ id: 3, status: 3 })
]
const { unhandled, messages } = splitAlerts(list)
expect(unhandled.map((i) => i.id)).toEqual([1])
expect(messages.map((i) => i.id)).toEqual([2, 3])
})
it('status 异常值(如 0、99)落入消息组不丢弃', () => {
const list = [item({ id: 1, status: 0 }), item({ id: 2, status: 99 })]
const { unhandled, messages } = splitAlerts(list)
expect(unhandled).toEqual([])
expect(messages.map((i) => i.id)).toEqual([1, 2])
})
it('空列表两组均为空', () => {
const { unhandled, messages } = splitAlerts([])
expect(unhandled).toEqual([])
expect(messages).toEqual([])
})
it('两组均保持原有相对顺序', () => {
const list = [
item({ id: 3, status: 2 }),
item({ id: 1, status: 1 }),
item({ id: 2, status: 2 })
]
const { unhandled, messages } = splitAlerts(list)
expect(unhandled.map((i) => i.id)).toEqual([1])
expect(messages.map((i) => i.id)).toEqual([3, 2])
})
})