alarmHistory.test.mjs 2.8 KB

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