补齐 check-pages 与首页、预约记录、下单页的 node --test 用例, 并在 package.json 挂上对应命令,改动样式后可先跑脚本再进开发者工具。
131 lines
5.4 KiB
JavaScript
131 lines
5.4 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, '..')
|
|
|
|
function createPage(name, api = {}, app = {}) {
|
|
let definition
|
|
const colors = []
|
|
vm.runInNewContext(fs.readFileSync(path.join(root, `pages/escort/${name}.js`), 'utf8'), {
|
|
Page(value) { definition = value },
|
|
require(module) {
|
|
if (module === '../../utils/api.js') return api
|
|
if (module === '../../utils/navigation.js') {
|
|
return { restoreLightNavigation() { colors.push('black') } }
|
|
}
|
|
return require(path.resolve(root, 'pages/escort', module))
|
|
},
|
|
getApp: () => app,
|
|
wx: { showToast() {} },
|
|
console
|
|
})
|
|
const instance = {
|
|
...definition,
|
|
data: JSON.parse(JSON.stringify(definition.data)),
|
|
setData(value) { Object.assign(this.data, value) }
|
|
}
|
|
return { instance, colors }
|
|
}
|
|
|
|
const pending = {
|
|
_id: 'order-1', status: 'pending',
|
|
patient: { name: '测试就诊人' },
|
|
hospital: { name: '中国人民解放军总医院第九医学中心' },
|
|
escort: { serviceId: 3, serviceName: '代问诊', sexRequirement: 'none' },
|
|
schedule: { date: '2026-11-15', startTime: '13:00' },
|
|
payment: { status: 'unpaid', payChannel: 'offline', totalFee: 280 }
|
|
}
|
|
|
|
test('列表和详情保留待确认、已取消退款的业务状态与操作权限', () => {
|
|
const list = createPage('recordlist').instance
|
|
const detail = createPage('recorddetail').instance
|
|
const active = list.formatRecord(pending)
|
|
assert.equal(active.isClosed, false)
|
|
assert.equal(active.hospital, pending.hospital.name)
|
|
assert.equal(active.paymentStatusText, '线下支付')
|
|
const activeDetail = detail.formatRecord(pending)
|
|
assert.equal(activeDetail.canCancel, true)
|
|
assert.equal(activeDetail.canEditBooking, true)
|
|
assert.equal(activeDetail.canPay, false)
|
|
assert.equal(activeDetail.scheduleDateText, '2026年11月15日')
|
|
assert.equal(activeDetail.scheduleWeekdayText, '周日')
|
|
assert.equal(activeDetail.scheduleTimeText, '13:00')
|
|
const cancelled = {
|
|
...pending, cancelStatus: 'cancelled',
|
|
payment: { status: 'refunded', method: 'online_wechat', totalFee: 0.1 }
|
|
}
|
|
assert.equal(list.formatRecord(cancelled).isClosed, true)
|
|
const closedDetail = detail.formatRecord(cancelled)
|
|
assert.equal(closedDetail.canEditBooking, false)
|
|
assert.equal(closedDetail.canCancel, false)
|
|
assert.equal(closedDetail.canRebook, true)
|
|
assert.equal(closedDetail.paymentStatusText, '已退款')
|
|
assert.match(closedDetail.refundNote, /原路退回微信/)
|
|
})
|
|
|
|
test('无效日期不生成错误星期,时间仍独立显示', () => {
|
|
const detail = createPage('recorddetail').instance
|
|
const meta = detail.buildScheduleMeta({ date: '2026-02-30', startTime: '08:00' })
|
|
assert.equal(meta.dateText, '')
|
|
assert.equal(meta.weekdayText, '')
|
|
assert.equal(meta.timeText, '08:00')
|
|
})
|
|
|
|
test('两个页面每次显示都恢复浅色背景的深色导航文字', () => {
|
|
for (const name of ['recordlist', 'recorddetail']) {
|
|
const { instance, colors } = createPage(name)
|
|
instance.loadRecords = () => {}
|
|
instance.onShow()
|
|
assert.deepEqual(colors, ['black'])
|
|
const config = JSON.parse(fs.readFileSync(path.join(root, `pages/escort/${name}.json`), 'utf8'))
|
|
assert.equal(config.navigationBarTextStyle, 'black')
|
|
}
|
|
})
|
|
|
|
test('手势被系统取消时清除拖动偏移,不遗留平移卡片', () => {
|
|
const { instance } = createPage('recordlist')
|
|
instance.data.dragX = 100
|
|
instance.data.dragging = true
|
|
instance.touchStart = { x: 0, y: 0 }
|
|
instance.onTouchCancel()
|
|
assert.equal(instance.data.dragX, 0)
|
|
assert.equal(instance.data.dragging, false)
|
|
assert.equal(instance.touchStart, null)
|
|
})
|
|
|
|
test('快速切换筛选后,过期请求不能覆盖新列表和数量', async () => {
|
|
const requests = []
|
|
const api = { escort: { getMyRecords(params) {
|
|
return new Promise(resolve => requests.push({ params, resolve }))
|
|
} } }
|
|
const { instance } = createPage('recordlist', api, {
|
|
waitForAuth: async () => true, globalData: { user: { _id: 'user' } }
|
|
})
|
|
const first = instance.loadRecords(true)
|
|
await new Promise(resolve => setImmediate(resolve))
|
|
instance.setData({ statusFilter: '' })
|
|
const second = instance.loadRecords(true)
|
|
await new Promise(resolve => setImmediate(resolve))
|
|
assert.equal(requests[0].params.status, 'pending,confirmed,in_progress')
|
|
assert.equal(requests[1].params.includeCancelled, 1)
|
|
requests[1].resolve({ code: 0, data: { records: [pending], total: 1, counts: { ongoing: 0, all: 1 } } })
|
|
await second
|
|
requests[0].resolve({ code: 0, data: { records: [], total: 0, counts: { ongoing: 0, all: 0 } } })
|
|
await first
|
|
assert.equal(instance.data.records.length, 1)
|
|
assert.equal(instance.data.statusTabs[1].count, 1)
|
|
assert.equal(instance.data.loading, false)
|
|
})
|
|
|
|
test('详情入口移至摘要底部,医院独占整行,零数量和手势取消均有绑定', () => {
|
|
const detail = fs.readFileSync(path.join(root, 'pages/escort/recorddetail.wxml'), 'utf8')
|
|
const list = fs.readFileSync(path.join(root, 'pages/escort/recordlist.wxml'), 'utf8')
|
|
assert.ok(detail.indexOf('class="details-expand"') > detail.indexOf('class="cancel-summary"'))
|
|
assert.match(detail, /class="appt-row hospital-row"/)
|
|
assert.match(detail, /scheduleWeekdayText/)
|
|
assert.match(list, /bindtouchcancel="onTouchCancel"/)
|
|
assert.match(list, /<text class="seg-count">{{item.count}}<\/text>/)
|
|
}) |