Files
lik 76197b838f feat(ai): 等待气泡展示后台处理进度
- AI 聊天用工具/子代理/推理帧推断等待阶段,提示已完成步数,子代理输出不再并入主回答
- 下单弹层去掉 01-04 编号分组标题
- 同步首页设计规范与 UI 测试断言,补充首页品牌图
2026-11-18 22:31:58 +08:00

139 lines
6.1 KiB
JavaScript

const { test } = require('node:test')
const assert = require('node:assert/strict')
const fs = require('node:fs')
const path = require('node:path')
const vm = require('node:vm')
const root = path.resolve(__dirname, '..')
test('当前预约使用两行摘要,日期、姓名、服务及状态共用首行,不显示时间', () => {
const wxml = fs.readFileSync(path.join(root, 'pages/home/index.wxml'), 'utf8')
assert.match(wxml, /section-title">当前预约/)
assert.doesNotMatch(wxml, /pending-service-row/)
const match = /<view class="pending-summary">([\s\S]*?)<\/view>/.exec(wxml)
assert.ok(match, '预约卡片应包含首行摘要')
const summary = match[1]
for (const field of ['whenText', 'patientName', 'serviceName', 'statusText']) {
assert.ok(summary.includes(`item.${field}`))
}
assert.match(wxml, /pending-hospital">{{item.hospitalName}}/)
assert.match(summary, /pending-when">{{item.whenText}}/)
assert.match(summary, /pending-patient">{{item.patientName}}/)
assert.ok(summary.indexOf('item.whenText') < summary.indexOf('item.patientName'))
assert.ok(summary.indexOf('item.patientName') < summary.indexOf('item.serviceName'))
assert.doesNotMatch(wxml, /item\.timeText/)
assert.equal((wxml.match(/class="pending-patient"/g) || []).length, 1)
const afterSummary = wxml.slice(wxml.indexOf('</view>', wxml.indexOf('class="pending-summary"')))
assert.doesNotMatch(afterSummary, /class="pending-patient"/)
})
test('预约卡片长内容可换行,保留详情入口和完整无障碍摘要', () => {
const wxml = fs.readFileSync(path.join(root, 'pages/home/index.wxml'), 'utf8')
const wxss = fs.readFileSync(path.join(root, 'pages/home/index.wxss'), 'utf8')
const rule = (name) => {
const match = new RegExp(`\\.${name}\\s*\\{([^}]+)\\}`).exec(wxss)
assert.ok(match, `缺少 ${name} 样式`)
return match[1]
}
assert.match(rule('pending-summary'), /flex-wrap:\s*wrap/)
for (const name of ['pending-service', 'pending-hospital', 'pending-patient']) {
assert.match(rule(name), /word-break:\s*break-all/)
assert.doesNotMatch(rule(name), /ellipsis|nowrap|overflow:\s*hidden/)
}
assert.match(rule('pending-content'), /min-width:\s*0/)
assert.match(rule('pending-arrow'), /flex-shrink:\s*0/)
const card = /<view class="pending-card"[^>]+>/.exec(wxml)[0]
assert.match(card, /data-id="{{item.id}}" bindtap="goToRecordDetail"/)
const label = /aria-label="([^"]+)"/.exec(card)[1]
for (const field of ['whenText', 'serviceName', 'statusText', 'hospitalName', 'patientName']) {
assert.ok(label.includes(`item.${field}`))
}
})
function createHome(wx = {}) {
let page
let restored = 0
vm.runInNewContext(fs.readFileSync(path.join(root, 'pages/home/index.js'), 'utf8'), {
Page(value) { page = value },
require(name) {
if (name === '../../utils/api.js') return {}
if (name === '../../utils/auth.js') return {}
if (name === '../../utils/navigation.js') return { restoreLightNavigation() { restored++ } }
return require(path.resolve(root, 'pages/home', name))
},
wx,
console: { warn() {} }
})
page.data = JSON.parse(JSON.stringify(page.data))
page.setData = function (data) { Object.assign(this.data, data) }
return { page, restored: () => restored }
}
test('首页品牌导航根据状态栏与胶囊尺寸布局,兼容系统信息旧接口', () => {
for (const method of ['getWindowInfo', 'getSystemInfoSync']) {
const { page } = createHome({
[method]: () => ({ statusBarHeight: 44 }),
getMenuButtonBoundingClientRect: () => ({ top: 50, height: 32, left: 280 })
})
page.updateNavigationLayout()
assert.equal(page.data.topbarStyle, 'padding-top: 44px; height: 88px;')
assert.equal(page.data.brandStyle, 'height: 44px; max-width: 248px;')
}
})
test('导航信息不可用时保留默认布局,视图就绪恢复深色文字', () => {
const { page, restored } = createHome()
page.updateNavigationLayout()
assert.equal(page.data.topbarStyle, '')
page.onReady()
assert.equal(restored(), 1)
})
test('预约预览保留时间数据、状态和完整医院名,缺值使用可读提示', () => {
const { page } = createHome()
const result = page.formatPendingRecord({
_id: '1', status: 'pending',
schedule: { date: '2026-11-15', startTime: '13:00' },
hospital: { name: '中国人民解放军总医院第九医学中心' }
})
assert.equal(result.whenText, '11-15')
assert.equal(result.timeText, '13:00')
assert.equal(result.statusText, '待确认')
assert.equal(result.hospitalName, '中国人民解放军总医院第九医学中心')
const empty = page.formatPendingRecord({})
assert.equal(empty.timeText, '时间待定')
assert.equal(empty.whenText, '日期待定')
assert.equal(empty.hospitalName, '医院待定')
assert.equal(empty.serviceName, '陪诊服务')
assert.equal(empty.patientName, '待补充')
})
test('预约预览保留完整长文本,取消申请状态优先展示', () => {
const { page } = createHome()
const item = {
_id: 'long-record',
status: 'confirmed',
cancelStatus: 'requested',
hospital: { name: '中国人民解放军总医院第九医学中心门诊部' },
patient: { name: '阿依古丽·阿卜杜拉' },
escort: { serviceName: '全天陪诊与出入院手续代办服务' }
}
const result = page.formatPendingRecord(item)
assert.equal(result.hospitalName, item.hospital.name)
assert.equal(result.patientName, item.patient.name)
assert.equal(result.serviceName, item.escort.serviceName)
assert.equal(result.statusText, '待取消')
assert.equal(result.statusTone, 'doing')
})
test('预约预览按日期时间排序、最多三条,不修改原数组', () => {
const { page } = createHome()
const records = ['15:00', '08:00', '13:00', '10:00'].map((startTime, index) => ({
_id: String(index), schedule: { date: '2026-11-15', startTime }
}))
const before = JSON.stringify(records)
const result = page.buildPendingPreview(records)
assert.equal(result.length, 3)
assert.equal(result[0].timeText, '08:00')
assert.equal(result[2].timeText, '13:00')
assert.equal(JSON.stringify(records), before)
})