calendar-copy.test.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import assert from 'node:assert/strict'
  2. import test from 'node:test'
  3. import type { Plan } from '../src/api/pl'
  4. import { toCalendarTrips, filterVehicleScope } from '../src/views/pl/dispatch-calendar/model'
  5. import { calendarCopyTitle, calendarCopyText } from '../src/views/pl/dispatch-calendar/copy'
  6. test('复制标题按点击当天计算,支持跨月、跨年及过去日期', () => {
  7. const today = new Date(2026, 9, 25, 23, 59)
  8. assert.equal(calendarCopyTitle('2026-10-26', today), '明日计划 10.26')
  9. assert.equal(calendarCopyTitle('2026-10-27', today), '后日计划 10.27')
  10. assert.equal(calendarCopyTitle('2026-10-28', today), '运输计划 10.28')
  11. assert.equal(calendarCopyTitle('2026-10-25', today), '运输计划 10.25')
  12. assert.equal(calendarCopyTitle('2026-10-24', today), '运输计划 10.24')
  13. assert.equal(calendarCopyTitle('2027-01-01', new Date(2026, 11, 31)), '明日计划 01.01')
  14. assert.equal(calendarCopyTitle('2024-03-01', new Date(2024, 1, 28)), '后日计划 03.01')
  15. })
  16. const plan = (id: string, override: Partial<Plan> = {}): Plan =>
  17. ({
  18. id,
  19. planNo: id,
  20. followStatus: 'pending',
  21. planDate: '2026-10-26',
  22. licensePlate: '皖HA3690',
  23. vehicleId: 'own',
  24. calendarVehicleType: 'self',
  25. load: { customerName: '安庆山峡' },
  26. deliveries: [
  27. { customerName: '安徽云栋', products: [{ productId: 'acid', productName: 'cp酸' }] }
  28. ],
  29. ...override
  30. }) as Plan
  31. test('复制一车一行,合并任务保留数量,使用简称并带真实备注', () => {
  32. const plans = [
  33. plan('p1', { remark: ' 下午待定\n请联系 ' }),
  34. plan('p2'),
  35. plan('p3', {
  36. licensePlate: '皖H10291',
  37. vehicleId: 'carrier',
  38. calendarVehicleType: 'carrier'
  39. })
  40. ]
  41. const trips = toCalendarTrips(plans, '2026-10')
  42. assert.equal(
  43. calendarCopyText('2026-10-26', filterVehicleScope(trips), plans, new Date(2026, 9, 25)),
  44. '明日计划 10.26\n• 皖HA3690 / cp酸 山峡 - 云栋(2车次) / 下午待定 请联系'
  45. )
  46. assert.match(calendarCopyText('2026-10-26', trips, plans), /\n• 皖H10291 \/ cp酸 山峡 - 云栋/)
  47. assert.equal(calendarCopyText('2026-10-27', trips, plans), '')
  48. })
  49. test('同一车辆多个送货段分别显示,不串联收货方,重复段保留段次数', () => {
  50. const plans = [
  51. plan('p1', {
  52. deliveries: [
  53. { customerName: '甲', products: [{ productId: 'acid', productName: '98酸' }] },
  54. { customerName: '甲', products: [{ productId: 'acid', productName: '98酸' }] },
  55. { customerName: '乙', products: [{ productId: 'base', productName: '液碱' }] }
  56. ]
  57. })
  58. ]
  59. assert.equal(
  60. calendarCopyText('2026-10-26', toCalendarTrips(plans, '2026-10'), plans, new Date(2026, 9, 25)),
  61. '明日计划 10.26\n• 皖HA3690 / 98酸 山峡 - 甲(1车次 / 2段次) / 液碱 山峡 - 乙'
  62. )
  63. })