mobile-customer-follow-parity.test.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import assert from 'node:assert/strict'
  2. import { readFileSync } from 'node:fs'
  3. import test from 'node:test'
  4. import { compile, ref } from 'vue'
  5. import { parse } from '@vue/compiler-sfc'
  6. import ts from 'typescript'
  7. const source = readFileSync(
  8. new URL('../src/views/m/crm/customer/FollowPanel.vue', import.meta.url),
  9. 'utf8'
  10. )
  11. const { descriptor } = parse(source)
  12. const ast = ts.createSourceFile(
  13. 'follow.ts',
  14. descriptor.scriptSetup!.content,
  15. ts.ScriptTarget.Latest,
  16. true
  17. )
  18. function method(name: string, bindings: Record<string, unknown> = {}) {
  19. const declaration = ast.statements.find(
  20. (item) => ts.isFunctionDeclaration(item) && item.name?.text === name
  21. )
  22. assert.ok(declaration, `缺少 ${name} 的真实实现`)
  23. return new Function(
  24. ...Object.keys(bindings),
  25. `${ts.transpile(declaration.getText(ast))}; return ${name}`
  26. )(...Object.values(bindings))
  27. }
  28. test('跟进摘要和展开详情均按Web优先显示负责人,创建人仅作回退', () => {
  29. const expressions = [
  30. ...descriptor.template!.content.matchAll(
  31. /{{\s*(row\.(?:createByName|ownerUserName)[^}]+)\s*}}/g
  32. )
  33. ]
  34. assert.equal(expressions.length, 2)
  35. for (const [, expression] of expressions) {
  36. const render = compile(`<span>{{ ${expression} }}</span>`)
  37. assert.equal(
  38. render({ row: { ownerUserName: '业务负责人', createByName: '录入人员' } }, []).children,
  39. '业务负责人'
  40. )
  41. assert.equal(render({ row: { createByName: '录入人员' } }, []).children, '录入人员')
  42. }
  43. })
  44. test('下次联系展示保留Web完整秒精度', () => {
  45. const format = method('formatNextTime')
  46. assert.equal(format('2026-10-23T10:30:45'), '2026-10-23 10:30:45')
  47. assert.equal(format(null), '')
  48. })
  49. test('四个跟进快捷日期采用Web当地日历和10点整,跨月正确且不改其他字段', () => {
  50. const form = ref({ nextTime: '', followContent: '保留正文' })
  51. const acting = ref(false)
  52. const setDate = method('setNextTimeShortcut', { form, acting })
  53. const now = new Date(2026, 9, 30, 23, 58, 59)
  54. const expected = [
  55. '2026-10-30T10:00:00',
  56. '2026-10-31T10:00:00',
  57. '2026-11-02T10:00:00',
  58. '2026-11-06T10:00:00'
  59. ]
  60. ;[0, 1, 3, 7].forEach((days, index) => {
  61. setDate(days, now)
  62. assert.equal(form.value.nextTime, expected[index])
  63. assert.equal(form.value.followContent, '保留正文')
  64. })
  65. assert.equal(now.getDate(), 30)
  66. acting.value = true
  67. setDate(0, now)
  68. assert.equal(form.value.nextTime, expected[3])
  69. })