Files
tennis-book/src/main/menuBarModel.test.ts
2026-07-16 11:03:32 +08:00

76 lines
2.0 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, expect, it } from 'vitest'
import type { CourtSummary, MonitorAlert, MonitorTask } from '../shared/contracts'
import { createMonitorMenuBarModel } from './menuBarModel'
const court: CourtSummary = {
id: 'test-court',
name: '测试球场',
shortName: '测试',
accent: '#123456',
status: 'online'
}
function task(overrides: Partial<MonitorTask> = {}): MonitorTask {
return {
id: 'task-1',
courtId: court.id,
startTime: '08:00',
endTime: '10:00',
enabled: true,
createdAt: '2026-07-16T00:00:00.000Z',
availableCount: 0,
stats: {
totalChecks: 0,
successfulChecks: 0,
partialFailureChecks: 0,
failedChecks: 0,
alertsSent: 0,
availableObservations: 0
},
autoBooking: { enabled: false, status: 'disabled', attemptCount: 0 },
...overrides
}
}
function alert(taskId = 'task-1'): MonitorAlert {
return {
taskId,
courtId: court.id,
targetDate: '2026-07-17',
startTime: '08:00',
endTime: '10:00',
slotLabels: ['1 号场 08:0010:00'],
occurredAt: '2026-07-16T01:00:00.000Z'
}
}
describe('createMonitorMenuBarModel', () => {
it('汇总运行任务、未读提醒和空场状态', () => {
const model = createMonitorMenuBarModel(
[task({ availableCount: 2 }), task({ id: 'task-2', enabled: false })],
[court],
[alert()]
)
expect(model.summary).toBe('2 个任务 · 1 个运行中')
expect(model.unreadSummary).toBe('1 条空场提醒待查看')
expect(model.tasks[0]).toMatchObject({
label: '测试球场 · 未来 7 天 · 08:0010:00',
status: '发现 2 个完整空场',
hasUnreadAlert: true
})
expect(model.tasks[1]?.status).toBe('已暂停')
})
it('优先展示监控异常', () => {
const model = createMonitorMenuBarModel(
[task({ availableCount: 3, lastError: '网络失败' })],
[court],
[]
)
expect(model.tasks[0]?.status).toBe('检查异常 · 网络失败')
expect(model.unreadSummary).toBe('暂无未读空场提醒')
})
})