feat: 实现 Sense 本地事件只读查看 (#73)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import request from '@/utils/request'
|
||||
import { getLocalEvent, listLocalEvents } from '@/api/sense/local-event'
|
||||
|
||||
jest.mock('@/utils/request', () => jest.fn())
|
||||
|
||||
describe('Sense local event API', () => {
|
||||
beforeEach(() => request.mockReset())
|
||||
|
||||
test('uses read-only local endpoints', () => {
|
||||
listLocalEvents({ pageIndex: 1, pageSize: 10 })
|
||||
getLocalEvent('event/unsafe')
|
||||
expect(request).toHaveBeenNthCalledWith(1, { url: '/api/v1/local-events', method: 'get', params: { pageIndex: 1, pageSize: 10 }})
|
||||
expect(request).toHaveBeenNthCalledWith(2, { url: '/api/v1/local-events/event%2Funsafe', method: 'get' })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,23 @@
|
||||
import { buildLocalEventQuery, candidateLabel, evidenceLabel, evidenceType, retentionLabel } from '@/views/sense/local-event/localEventState'
|
||||
|
||||
describe('Sense local event presentation state', () => {
|
||||
test('keeps candidate and evidence states distinct', () => {
|
||||
expect(candidateLabel('candidate')).toBe('候选')
|
||||
expect(candidateLabel('confirmed')).toBe('已确认事件')
|
||||
expect(evidenceLabel('pending')).toBe('处理中')
|
||||
expect(evidenceLabel('success')).toBe('成功')
|
||||
expect(evidenceLabel('failed')).toBe('失败')
|
||||
expect(evidenceType('failed')).toBe('danger')
|
||||
})
|
||||
|
||||
test('builds an allowlisted query with RFC3339 time bounds', () => {
|
||||
const result = buildLocalEventQuery({ pageIndex: 2, pageSize: 20, candidateState: 'candidate', evidenceState: 'failed', ruleRef: ' rule-1 ', keyword: ' camera-3 ', ignored: 'not-sent' }, ['2026-08-27T00:00:00Z', '2026-08-28T00:00:00Z'])
|
||||
expect(result).toEqual({ pageIndex: 2, pageSize: 20, candidateState: 'candidate', evidenceState: 'failed', ruleRef: 'rule-1', keyword: 'camera-3', occurredAfter: '2026-08-27T00:00:00.000Z', occurredBefore: '2026-08-28T00:00:00.000Z' })
|
||||
})
|
||||
|
||||
test('describes retention without inventing a global duration', () => {
|
||||
expect(retentionLabel({ retainUntil: '2026-09-09T00:00:00Z', retentionState: 'active', remainingDays: 12 })).toBe('保留至 2026-09-09')
|
||||
expect(retentionLabel({ retainUntil: '2026-08-30T00:00:00Z', retentionState: 'expiring', remainingDays: 2 })).toBe('2 天内到期')
|
||||
expect(retentionLabel({ retainUntil: '2026-08-01T00:00:00Z', retentionState: 'expired', remainingDays: 0 })).toBe('已到期')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user