85 lines
3.2 KiB
JavaScript
85 lines
3.2 KiB
JavaScript
const assert = require('assert')
|
|
|
|
global.wx = {
|
|
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
|
getDeviceInfo: () => ({ platform: 'devtools' }),
|
|
getStorageSync: () => '',
|
|
setStorageSync: () => {},
|
|
removeStorageSync: () => {},
|
|
showToast: () => {},
|
|
showModal: options => options.success({ confirm: modalConfirm }),
|
|
navigateTo: () => {}
|
|
}
|
|
global.getApp = () => ({ globalData: { userInfo: { type: 2, id: 1, shopId: 2 } } })
|
|
|
|
let modalConfirm = true
|
|
|
|
let definition
|
|
global.Page = value => { definition = value }
|
|
require('./index')
|
|
const customersApi = require('../../api/customers')
|
|
|
|
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 page = createPage()
|
|
page.selectCustomer({ detail: { item: { id: 18, name: '小周', phone: '13800138000' } } })
|
|
assert.strictEqual(page.data.form.customerUserId, 18)
|
|
assert.strictEqual(page.data.form.customerName, '小周')
|
|
assert.strictEqual(page.data.form.phone, '13800138000')
|
|
assert.strictEqual(page.data.customerSheetVisible, false)
|
|
|
|
page.data.form.customerUserId = 18
|
|
page.onCustomerInput({ currentTarget: { dataset: { field: 'customerName' } }, detail: { value: '新客户' } })
|
|
assert.strictEqual(page.data.form.customerUserId, '')
|
|
assert.strictEqual(page.data.form.customerName, '新客户')
|
|
assert.strictEqual(page.data.form.phone, '13800138000')
|
|
|
|
customersApi.matchIdentityForAppointment = async () => []
|
|
customersApi.create = async () => { throw new Error('预约客户建档应随预约请求提交') }
|
|
assert.strictEqual(await page.ensureCustomerBeforeSubmit(), true)
|
|
assert.strictEqual(page.data.form.customerUserId, '')
|
|
assert.strictEqual(page.data.form.createCustomerRecord, true)
|
|
|
|
page.data.form.customerUserId = ''
|
|
page.data.form.customerName = '小周'
|
|
page.data.form.phone = '13800138000'
|
|
customersApi.matchIdentityForAppointment = async (name, wechatId, phone) => {
|
|
assert.strictEqual(name, '小周')
|
|
assert.strictEqual(wechatId, undefined)
|
|
assert.strictEqual(phone, '13800138000')
|
|
return [{ id: '18', name: '小周', phone: '13800138000' }]
|
|
}
|
|
assert.strictEqual(await page.ensureCustomerBeforeSubmit(), true)
|
|
assert.strictEqual(page.data.form.customerUserId, '18')
|
|
|
|
page.data.artists = [{ id: 1, name: '小周' }, { id: 2, name: '小李' }]
|
|
page.onArtistSearch({ detail: { value: '李' } })
|
|
assert.deepStrictEqual(page.data.artistSelectorItems.map(item => item.id), [2])
|
|
|
|
page.refreshAvailableTimes = async () => {}
|
|
page.checkAvailability = () => {}
|
|
page.selectArtist({ detail: { item: { id: 2, name: '小李' } } })
|
|
assert.strictEqual(page.data.form.artistId, 2)
|
|
assert.strictEqual(page.data.selectedArtist.name, '小李')
|
|
assert.strictEqual(page.data.artistSheetVisible, false)
|
|
}
|
|
|
|
run().catch(error => {
|
|
console.error(error)
|
|
process.exitCode = 1
|
|
})
|