优化:统一小程序业务引用选择交互
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
const assert = require('assert')
|
||||
|
||||
global.wx = {
|
||||
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
||||
getDeviceInfo: () => ({ platform: 'devtools' }),
|
||||
getStorageSync: () => '',
|
||||
setStorageSync: () => {},
|
||||
removeStorageSync: () => {},
|
||||
showToast: () => {},
|
||||
navigateTo: () => {}
|
||||
}
|
||||
global.getApp = () => ({ globalData: { userInfo: { type: 2, id: 1, shopId: 2 } } })
|
||||
|
||||
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 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.data.manualCustomerForm = { name: '新客户', phone: '13900139000' }
|
||||
page.useManualCustomer()
|
||||
assert.strictEqual(page.data.form.customerUserId, '')
|
||||
assert.strictEqual(page.data.form.customerName, '新客户')
|
||||
assert.strictEqual(page.data.form.phone, '13900139000')
|
||||
|
||||
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
|
||||
})
|
||||
Reference in New Issue
Block a user