import { readFileSync } from 'fs'; import { describe, expect, it } from 'vitest'; const mobileRoute = readFileSync( new URL('../src/routes/mobile/mobileAdminRoutes.ts', import.meta.url), 'utf8' ); const requestJs = readFileSync( new URL('../../miniprogram/utils/request.js', import.meta.url), 'utf8' ); 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' ); describe('小程序商品溯源日期查询', () => { it('forwards Web search date params on mobile /trace/search', () => { expect(mobileRoute).toMatch(/dateFrom: String\(req\.query\?\.date_from/); expect(mobileRoute).toMatch(/dateTo: String\(req\.query\?\.date_to/); expect(mobileRoute).toMatch(/dateField: String\(req\.query\?\.date_field/); expect(requestJs).toMatch(/date_from=/); expect(requestJs).toMatch(/date_field=/); }); it('defaults to order date today; custom is a from-to range', () => { expect(panelJs).toMatch(/dateField: 'order_created'/); expect(panelJs).toMatch(/datePreset: 'today'/); expect(panelJs).toMatch(/resolveQueryRange/); expect(panelJs).not.toMatch(/本周/); expect(panelWxml).toMatch(/自定义/); expect(panelWxml).toMatch(/openRangeModal/); expect(panelWxml).toMatch(/confirmRangeModal/); expect(panelWxml).toMatch(/customRangeText/); expect(panelWxml).not.toMatch(/wx:if="\{\{datePreset === 'custom'\}\}"/); expect(panelWxml).toMatch(/下单日/); expect(panelWxml).toMatch(/入库日/); expect(panelWxml).toMatch(/catchtap="openHit"/); expect(panelJs).toMatch(/toggleExpand/); }); });