import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import test from 'node:test' import { compile, ref } from 'vue' import { parse } from '@vue/compiler-sfc' import ts from 'typescript' const source = readFileSync( new URL('../src/views/m/crm/customer/FollowPanel.vue', import.meta.url), 'utf8' ) const { descriptor } = parse(source) const ast = ts.createSourceFile( 'follow.ts', descriptor.scriptSetup!.content, ts.ScriptTarget.Latest, true ) function method(name: string, bindings: Record = {}) { const declaration = ast.statements.find( (item) => ts.isFunctionDeclaration(item) && item.name?.text === name ) assert.ok(declaration, `缺少 ${name} 的真实实现`) return new Function( ...Object.keys(bindings), `${ts.transpile(declaration.getText(ast))}; return ${name}` )(...Object.values(bindings)) } test('跟进摘要和展开详情均按Web优先显示负责人,创建人仅作回退', () => { const expressions = [ ...descriptor.template!.content.matchAll( /{{\s*(row\.(?:createByName|ownerUserName)[^}]+)\s*}}/g ) ] assert.equal(expressions.length, 2) for (const [, expression] of expressions) { const render = compile(`{{ ${expression} }}`) assert.equal( render({ row: { ownerUserName: '业务负责人', createByName: '录入人员' } }, []).children, '业务负责人' ) assert.equal(render({ row: { createByName: '录入人员' } }, []).children, '录入人员') } }) test('下次联系展示保留Web完整秒精度', () => { const format = method('formatNextTime') assert.equal(format('2026-10-23T10:30:45'), '2026-10-23 10:30:45') assert.equal(format(null), '') }) test('四个跟进快捷日期采用Web当地日历和10点整,跨月正确且不改其他字段', () => { const form = ref({ nextTime: '', followContent: '保留正文' }) const acting = ref(false) const setDate = method('setNextTimeShortcut', { form, acting }) const now = new Date(2026, 9, 30, 23, 58, 59) const expected = [ '2026-10-30T10:00:00', '2026-10-31T10:00:00', '2026-11-02T10:00:00', '2026-11-06T10:00:00' ] ;[0, 1, 3, 7].forEach((days, index) => { setDate(days, now) assert.equal(form.value.nextTime, expected[index]) assert.equal(form.value.followContent, '保留正文') }) assert.equal(now.getDate(), 30) acting.value = true setDate(0, now) assert.equal(form.value.nextTime, expected[3]) })