| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import test from 'node:test'
- import assert from 'node:assert/strict'
- import { readFile } from 'node:fs/promises'
- import { groupAlarmHistory, historyDayLabel, historyTime } from '../src/views/subSystem/alarm/alarmHistoryModel.js'
- test('history day labels show only today or yesterday, retaining dates for older records', () => {
- const now = new Date(2026, 8, 24, 0, 10)
- assert.equal(historyDayLabel('2026-09-24', now), '今天')
- assert.equal(historyDayLabel('2026-09-23', now), '昨天')
- assert.equal(historyDayLabel('2026-09-22', now), '9月22日')
- assert.equal(historyDayLabel('2025-09-24', now), '2025年9月24日')
- assert.equal(historyDayLabel('2026-09-25', now), '9月25日')
- })
- test('yesterday labels handle calendar month, year and leap day boundaries', () => {
- assert.equal(historyDayLabel('2026-08-31', new Date(2026, 8, 1, 0, 1)), '昨天')
- assert.equal(historyDayLabel('2025-12-31', new Date(2026, 0, 1, 0, 1)), '昨天')
- assert.equal(historyDayLabel('2024-02-29', new Date(2024, 2, 1, 0, 1)), '昨天')
- })
- test('missing or invalid dates have a clear fallback', () => {
- const now = new Date(2026, 8, 24)
- for (const value of [null, undefined, '', '时间未记录', 'invalid', '2026-02-30', '2026-13-01']) {
- assert.equal(historyDayLabel(value, now), '时间未记录')
- }
- })
- test('history is grouped by date descending then time and log id descending without mutating input', () => {
- const logs = [
- { logId: '8', operTime: '2026-09-23 18:00:00' },
- { logId: '9007199254740992', operTime: '2026-09-24 09:00:00' },
- { logId: '9007199254740993', operTime: '2026-09-24 09:00:00' },
- { logId: '10', operTime: '2026-09-24T10:00:00' },
- { logId: '11', operTime: null }
- ]
- const groups = groupAlarmHistory(logs)
- assert.deepEqual(groups.map(g => g.day), ['2026-09-24', '2026-09-23', '时间未记录'])
- assert.deepEqual(groups[0].items.map(item => item.logId), ['10', '9007199254740993', '9007199254740992'])
- assert.equal(logs[0].logId, '8')
- assert.equal(historyTime('2026-09-24T10:00:01'), '10:00:01')
- assert.equal(historyTime(null), '—')
- })
- test('audit and operations use the same dispose-style history with safe description text and image previews', async () => {
- for (const name of ['index.vue', 'AlarmDetail.vue']) {
- const source = await readFile('src/views/subSystem/alarm/' + name, 'utf8')
- assert.ok(source.includes('<AlarmHistory'))
- assert.ok(!source.includes('<el-timeline'))
- }
- const source = await readFile('src/views/subSystem/alarm/AlarmHistory.vue', 'utf8')
- assert.ok(source.includes('historyDayLabel(group.day)'))
- assert.ok(source.includes(':title="group.day"'))
- for (const text of ['按时间倒序分组', 'history-day', 'history-time', 'item.operUserName', '{{ item.operDesc }}', 'AlarmAttachments']) assert.ok(source.includes(text))
- assert.ok(!source.includes('v-html'))
- })
|