Files
JayuCloud/JC-Salon-WeChat/pages/appointment-detail/index.test.js
T
xiaowang 69ea01eaa4
自动发布开发环境 Nacos 配置 / publish (push) Successful in 34s
环境分支晋级检查 / environment-promotion-source (pull_request_target) Successful in 11s
小程序预约详情支持图片预览、编辑预约与完成收款拆分
2026-11-09 15:18:27 +08:00

140 lines
4.7 KiB
JavaScript

const assert = require('assert')
const fs = require('fs')
const path = require('path')
global.wx = {
showToast: () => {},
showModal: options => options.success({ confirm: false }),
navigateTo: () => {},
navigateBack: () => {}
}
let definition
global.Page = value => { definition = value }
require('./index')
function createPage() {
return {
...definition,
data: { ...definition.data },
setData(values) { Object.assign(this.data, values) }
}
}
const page = createPage()
page.applyAppointment({
orderId: 1,
orderNo: 'SALON-001',
customerName: '到店客户',
customerPhone: null,
productTitle: null,
artistName: null,
artistId: null,
assignmentStatus: 'UNASSIGNED',
startTime: null,
endTime: null,
durationMinutes: null,
amount: null,
remark: null,
status: 0,
statusText: '待确认',
canEdit: true,
canCancel: true
})
assert.strictEqual(page.data.appointment.customerPhoneText, '未留手机号')
assert.strictEqual(page.data.appointment.productTitleText, '未记录')
assert.strictEqual(page.data.appointment.artistNameText, '待分配')
assert.strictEqual(page.data.appointment.amountText, '未记录')
assert.strictEqual(page.data.appointment.remarkText, '暂无备注')
assert.strictEqual(page.data.appointment.orderNoText, 'SALON-001')
assert.strictEqual(page.data.showTransfer, true)
assert.strictEqual(page.data.showConfirm, false)
assert.strictEqual(page.data.showComplete, false)
assert.strictEqual(page.data.showCancel, true)
assert.strictEqual([
page.data.appointment.customerNameText,
page.data.appointment.customerPhoneText,
page.data.appointment.orderNoText,
page.data.appointment.productTitleText,
page.data.appointment.artistNameText,
page.data.appointment.durationText,
page.data.appointment.amountText,
page.data.appointment.remarkText
].some(value => String(value).includes('null')), false)
page.applyAppointment({
artistId: 9,
assignmentStatus: 'ASSIGNED',
status: 3,
statusText: '已取消',
canEdit: false,
canCancel: false,
cancelReason: '客户临时调整时间'
})
assert.strictEqual(page.data.appointment.cancelReasonText, '客户临时调整时间')
assert.strictEqual(page.data.showTransfer, false)
assert.strictEqual(page.data.showConfirm, false)
assert.strictEqual(page.data.showComplete, false)
assert.strictEqual(page.data.showCancel, false)
page.applyAppointment({
artistId: 9,
assignmentStatus: 'ASSIGNED',
status: 4,
statusText: '服务中',
paymentStatus: 'UNPAID',
payAmount: 268,
canEdit: false,
canCancel: true
})
assert.strictEqual(page.data.showTransfer, false)
assert.strictEqual(page.data.showCollect, true)
assert.strictEqual(page.data.showComplete, false)
assert.strictEqual(page.data.showCancel, true)
assert.strictEqual(page.data.appointment.paymentStatusText, '未收款')
page.applyAppointment({
artistId: 9,
assignmentStatus: 'ASSIGNED',
status: 1,
statusText: '待服务',
paymentStatus: 'PAID',
paidAmount: 268,
canEdit: true,
canCancel: true
})
assert.strictEqual(page.data.showCollect, false)
assert.strictEqual(page.data.showComplete, true)
assert.strictEqual(page.data.showEdit, true)
assert.strictEqual(page.data.appointment.paymentStatusText, '已收款 ¥268')
global.wx.previewImage = options => {
global.__preview = options
}
page.data.coverImages = ['https://cdn/a.png', 'https://cdn/b.png', 'https://cdn/c.png']
page._coverFailedIndexes = { 1: true }
page.previewCoverImage({ currentTarget: { dataset: { index: 2 } } })
assert.deepStrictEqual(global.__preview.urls, ['https://cdn/a.png', 'https://cdn/c.png'])
assert.strictEqual(global.__preview.current, 'https://cdn/c.png')
page.data.coverImages = ['', '']
let toastTitle = ''
global.wx.showToast = options => { toastTitle = options.title }
page.previewCoverImage({ currentTarget: { dataset: { index: 0 } } })
assert.strictEqual(toastTitle, '暂无可预览的图片')
const markup = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8')
const styles = fs.readFileSync(path.join(__dirname, 'index.wxss'), 'utf8')
;['订单编号', '服务项目', '美甲师', '时长', '成交金额', '取消原因', 'remarkText', 'customerPhoneText'].forEach(text => assert(markup.includes(text)))
assert.match(markup, /class="primary-btn transfer-action"/)
assert.match(markup, /class="danger-btn"/)
assert.match(markup, /bindtap="previewCoverImage"/)
assert.match(markup, /class="cover-thumb/)
assert.match(markup, /bindtap="collect">完成收款/)
assert.match(markup, /bindtap="goEdit"/)
assert.match(markup, /appointment\.customerPhoneAvailable && appointment\.orderId/)
assert.strictEqual(markup.includes('appointment.customerId && appointment.orderId'), false)
assert.match(styles, /\.transfer-action\s*\{[^}]*box-shadow/)
assert.match(styles, /\.call-btn\s*\{/)
assert.match(styles, /\.cover-thumb\s*\{/)