72 lines
2.8 KiB
JavaScript
72 lines
2.8 KiB
JavaScript
const assert = require('assert')
|
|
|
|
let definition
|
|
global.Page = value => { definition = value }
|
|
const toastMessages = []
|
|
global.wx = { showToast: options => toastMessages.push(options.title) }
|
|
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.openManualProduct()
|
|
assert.strictEqual(page.data.manualProductSheetVisible, true)
|
|
page.confirmManualProduct()
|
|
assert.strictEqual(page.data.form.productId, 8)
|
|
assert.strictEqual(page.data.manualProductSheetVisible, false)
|
|
|
|
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, '')
|
|
page.openManualProduct()
|
|
page.confirmManualProduct()
|
|
assert.strictEqual(page.data.manualProductSheetVisible, false)
|
|
assert.strictEqual(page.data.form.productId, '')
|
|
|
|
page.data.form.manualProductTitle = ''
|
|
page.openManualProduct()
|
|
page.confirmManualProduct()
|
|
assert.strictEqual(page.data.manualProductSheetVisible, true)
|
|
assert.strictEqual(toastMessages.pop(), '请填写款式名称或添加图片')
|
|
|
|
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, /class="appointment-hero"/)
|
|
assert.match(wxml, /placeholder="留空时默认使用客户姓名"/)
|
|
assert.match(wxml, /appointmentDateBadge/)
|
|
assert.match(wxml, /class="customer-fields"/)
|
|
assert.match(wxml, /class="manual-style-sheet"/)
|
|
assert.match(wxml, /bind:openmanual="openManualProduct"/)
|
|
assert.match(wxml, /show-manual-action="\{\{true\}\}"/)
|
|
assert.match(wxml, /成交金额/)
|
|
|