156 lines
5.4 KiB
JavaScript
156 lines
5.4 KiB
JavaScript
const assert = require('assert')
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const planningApi = require('../../api/planning')
|
|
|
|
let appGlobalData = { userInfo: { type: 2 } }
|
|
global.wx = {
|
|
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
|
getDeviceInfo: () => ({ platform: 'devtools' }),
|
|
removeStorageSync: () => {},
|
|
setStorageSync: () => {},
|
|
showToast: () => {},
|
|
showModal: options => { if (options.success) options.success({ confirm: true }) },
|
|
navigateTo: () => {},
|
|
navigateBack: () => {},
|
|
setNavigationBarTitle: () => {},
|
|
redirectTo: () => {}
|
|
}
|
|
global.getApp = () => ({ globalData: appGlobalData })
|
|
global.getCurrentPages = () => []
|
|
|
|
let definition
|
|
global.Page = value => { definition = value }
|
|
require('./index')
|
|
|
|
function createPage() {
|
|
return {
|
|
...definition,
|
|
data: JSON.parse(JSON.stringify(definition.data)),
|
|
setData(values) {
|
|
Object.entries(values).forEach(([key, value]) => {
|
|
const parts = key.split('.')
|
|
let target = this.data
|
|
for (let index = 0; index < parts.length - 1; index += 1) target = target[parts[index]]
|
|
target[parts[parts.length - 1]] = value
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
async function run() {
|
|
const appointmentWxml = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8')
|
|
const artistIndex = appointmentWxml.indexOf('bindtap="openArtistSheet"')
|
|
const timeIndex = appointmentWxml.indexOf('bindtap="openTimeSheet"')
|
|
assert.ok(artistIndex > -1 && timeIndex > -1)
|
|
assert.ok(artistIndex < timeIndex, '美甲师字段应位于预约时间之前')
|
|
assert.match(appointmentWxml, /editMode \? '保存修改' : '提交预约'/)
|
|
|
|
planningApi.appointment = async () => ({
|
|
orderItemId: 88,
|
|
orderId: 77,
|
|
orderNo: 'SALON-088',
|
|
customerUserId: 31,
|
|
customerName: '测试客户',
|
|
customerPhone: '138****8000',
|
|
customerPhoneAvailable: false,
|
|
artistId: 9,
|
|
artistName: '小李',
|
|
startTime: '2027-05-01T10:30:00',
|
|
endTime: '2027-05-01T11:30:00',
|
|
durationMinutes: 60,
|
|
amount: 268,
|
|
productId: 41,
|
|
productTitle: '猫眼甲',
|
|
productSourceType: 'LIBRARY',
|
|
remark: '加急',
|
|
status: 1,
|
|
canEdit: true
|
|
})
|
|
planningApi.calendar = async () => ({
|
|
businessStartTime: '09:00',
|
|
businessEndTime: '20:00',
|
|
artists: [{ id: 9, name: '小李' }],
|
|
schedules: [{ artistId: 9, date: '2027-05-01', status: 1, capacity: 1, startTime: '09:00', endTime: '20:00' }],
|
|
appointments: [{ orderItemId: 88, artistId: 9, startTime: '2027-05-01T10:30:00', endTime: '2027-05-01T11:30:00' }]
|
|
})
|
|
planningApi.products = async () => ({ list: [{ id: 41, title: '猫眼甲', price: 268, approximateDuration: '60分钟' }] })
|
|
|
|
const page = createPage()
|
|
page.data.form.durationMinutes = '60'
|
|
await page.loadEditAppointment(88)
|
|
|
|
assert.strictEqual(page.data.editMode, true)
|
|
assert.strictEqual(page._editMode, true)
|
|
assert.strictEqual(page.data.form.customerName, '测试客户')
|
|
assert.strictEqual(page.data.form.phone, '')
|
|
assert.strictEqual(page.data.form.appointmentDate, '2027-05-01')
|
|
assert.strictEqual(page.data.form.appointmentTime, '10:30')
|
|
assert.strictEqual(String(page.data.form.artistId), '9')
|
|
assert.strictEqual(String(page.data.form.productId), '41')
|
|
assert.strictEqual(page.data.form.amount, '268')
|
|
assert.ok(Object.keys(page.data.availableTimeGroups).length > -1 || page._editOriginalSchedule)
|
|
|
|
const availability = await page.checkAvailability()
|
|
assert.strictEqual(availability.ok, true)
|
|
|
|
let updatedPayload = null
|
|
let updatedId = ''
|
|
let creatorCalled = false
|
|
planningApi.updateAppointment = async (id, payload) => {
|
|
updatedId = id
|
|
updatedPayload = payload
|
|
return { orderItemId: 88 }
|
|
}
|
|
planningApi.createAppointment = async () => {
|
|
creatorCalled = true
|
|
return {}
|
|
}
|
|
page.cancelDraftSave = () => {}
|
|
await page.submit()
|
|
|
|
assert.strictEqual(creatorCalled, false)
|
|
assert.strictEqual(updatedId, '88')
|
|
assert.strictEqual(updatedPayload.customerName, '测试客户')
|
|
assert.strictEqual(updatedPayload.amount, 268)
|
|
assert.strictEqual(updatedPayload.appointmentTime, '10:30')
|
|
|
|
const original = page.isEditOriginalSchedule('2027-05-01', '10:30')
|
|
assert.strictEqual(original, true)
|
|
assert.strictEqual(page.isEditOriginalSchedule('2027-05-01', '11:00'), false)
|
|
|
|
const manualPage = createPage()
|
|
planningApi.appointment = async () => ({
|
|
orderItemId: 89,
|
|
customerName: '散客',
|
|
customerPhoneAvailable: false,
|
|
artistId: null,
|
|
startTime: '2027-05-02T09:00:00',
|
|
durationMinutes: 90,
|
|
amount: 150,
|
|
productId: 55,
|
|
productSourceType: 'MANAGER_APPOINTMENT',
|
|
productTitle: '手绘款',
|
|
productDescription: '渐变',
|
|
productImageFileIds: 'f1,f2',
|
|
coverImages: ['https://cdn/f1.png'],
|
|
status: 1,
|
|
canEdit: true
|
|
})
|
|
planningApi.products = async () => ({ list: [] })
|
|
planningApi.calendar = async () => ({ businessStartTime: '09:00', businessEndTime: '20:00', artists: [], schedules: [], appointments: [] })
|
|
await manualPage.loadEditAppointment(89)
|
|
|
|
assert.strictEqual(manualPage.data.form.productId, '')
|
|
assert.strictEqual(manualPage.data.form.manualProductTitle, '手绘款')
|
|
assert.strictEqual(manualPage.data.form.manualProductDescription, '渐变')
|
|
assert.strictEqual(manualPage.data.form.manualProductImages.length, 2)
|
|
assert.strictEqual(manualPage.data.form.artistId, '')
|
|
assert.strictEqual(manualPage.data.selectedArtist.id, '__unassigned__')
|
|
}
|
|
|
|
run().catch(error => {
|
|
console.error(error)
|
|
process.exitCode = 1
|
|
})
|