49 lines
1.9 KiB
JavaScript
49 lines
1.9 KiB
JavaScript
const assert = require('assert')
|
|
|
|
let definition
|
|
global.Page = value => { definition = value }
|
|
global.wx = { showToast: () => {} }
|
|
global.getApp = () => ({ globalData: { userInfo: { id: 1, shopId: 2, type: 2 } } })
|
|
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
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
const page = createPage()
|
|
page.openProductModal()
|
|
assert.strictEqual(page.data.productModalVisible, true)
|
|
page.refreshAvailableTimes = () => {}
|
|
page.checkAvailability = () => {}
|
|
page.selectProduct({ detail: { item: { id: 8, title: '法式', price: 238, priceText: '¥238', approximateDuration: '90' } } })
|
|
assert.strictEqual(page.data.form.productId, 8)
|
|
assert.strictEqual(page.data.selectedProduct.title, '法式')
|
|
assert.strictEqual(page.data.selectedProductPriceText, '¥238')
|
|
assert.strictEqual(page.data.form.amount, '238')
|
|
assert.strictEqual(page.data.form.manualProductTitle, '')
|
|
assert.strictEqual(page.data.form.durationMinutes, '90')
|
|
|
|
page.onStyleTitleInput({ detail: { value: '手绘款' } })
|
|
assert.strictEqual(page.data.form.productId, '')
|
|
assert.strictEqual(page.data.form.manualProductTitle, '手绘款')
|
|
assert.strictEqual(page.data.form.amount, '238')
|
|
assert.strictEqual(page.data.selectedProductPriceText, '')
|
|
|
|
const wxml = require('fs').readFileSync(require('path').join(__dirname, 'index.wxml'), 'utf8')
|
|
assert.ok(wxml.indexOf('美甲款式') < wxml.indexOf('预约信息'))
|
|
assert.ok(wxml.indexOf('预约信息') < wxml.indexOf('>客户</text>'))
|
|
assert.match(wxml, /placeholder="款式名称(选填)"/)
|
|
assert.match(wxml, /成交金额/)
|
|
|