import { readFileSync } from 'fs'; import { describe, expect, it } from 'vitest'; /** * 小程序「商品溯源」面板布局(2026-10-22 对齐配送系统小程序): * - 公开链接由裸 URL 改为「复制链接」按钮; * - 订单号展示短号(不动接口/存储); * - 链路带节点时间; * - 检验报告固定紧跟「链路」,附件可预览/打开; * - 报告区块必须排在照片区之前(否则被照片墙挤到看不见)。 */ const panelJs = readFileSync( new URL('../../miniprogram/components/product-trace-panel/index.js', import.meta.url), 'utf8' ); const panelWxml = readFileSync( new URL('../../miniprogram/components/product-trace-panel/index.wxml', import.meta.url), 'utf8' ); const panelWxss = readFileSync( new URL('../../miniprogram/components/product-trace-panel/index.wxss', import.meta.url), 'utf8' ); describe('小程序商品溯源:布局对齐', () => { it('公开链接是「复制链接」按钮,不再把裸 URL 打成文字', () => { expect(panelWxml).toContain('复制链接'); expect(panelWxml).toContain('catchtap="onCopyPublicLink"'); expect(panelWxml).not.toContain('公开链接:'); expect(panelJs).toContain('wx.setClipboardData'); expect(panelWxss).toContain('.btn-copy'); }); it('订单号展示短号,接口参数不变', () => { expect(panelJs).toContain('function shortenOrderCode'); expect(panelJs).toContain("return `ORD_${parts[2]}`"); expect(panelJs).toContain('order_code_text'); expect(panelWxml).toContain('item.detail.order_code_text'); }); it('链路每段带时间', () => { expect(panelJs).toContain('function withTimelineTimeText'); expect(panelJs).toContain('at_text: step && step.at ? formatTime(step.at)'); expect(panelWxml).toContain('step.at_text'); }); it('检验报告紧跟链路、排在照片区之前,附件可预览/打开', () => { const timelineAt = panelWxml.indexOf('链路'); const reportAt = panelWxml.indexOf('检验报告'); const photoAt = panelWxml.indexOf('验收照片'); expect(timelineAt).toBeGreaterThan(-1); expect(reportAt).toBeGreaterThan(timelineAt); expect(photoAt).toBeGreaterThan(reportAt); expect(panelWxml).toContain('report-files'); expect(panelWxml).toContain('previewReportFile'); expect(panelWxml).toContain('openReportFile'); expect(panelJs).toContain('wx.openDocument'); expect(panelWxss).toContain('.report-thumb'); }); it('空报告地址被过滤(避免点不动的「查看文档」)', () => { expect(panelJs).toContain('r.file_urls.map(absolutizeMediaUrl).filter(Boolean)'); }); it('内联 base64 照片原样透传(防裂图)', () => { expect(panelJs).toContain("if (/^data:/i.test(raw)) return raw;"); }); });