支持预约款式多图录入
This commit is contained in:
@@ -3,7 +3,31 @@ const assert = require('assert')
|
||||
let definition
|
||||
global.Page = value => { definition = value }
|
||||
const toastMessages = []
|
||||
global.wx = { showToast: options => toastMessages.push(options.title) }
|
||||
let selectedImagePaths = []
|
||||
let uploadResults = []
|
||||
let requestedImageCount = 0
|
||||
const uploadCalls = []
|
||||
const uploadModulePath = require.resolve('../../utils/upload')
|
||||
require.cache[uploadModulePath] = {
|
||||
id: uploadModulePath,
|
||||
filename: uploadModulePath,
|
||||
loaded: true,
|
||||
exports: {
|
||||
uploadObjectFile: async filePath => {
|
||||
uploadCalls.push(filePath)
|
||||
const result = uploadResults.shift()
|
||||
if (result instanceof Error) throw result
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
global.wx = {
|
||||
showToast: options => toastMessages.push(options.title),
|
||||
chooseMedia(options) {
|
||||
requestedImageCount = options.count
|
||||
options.success({ tempFiles: selectedImagePaths.slice(0, options.count).map(tempFilePath => ({ tempFilePath })) })
|
||||
}
|
||||
}
|
||||
global.getApp = () => ({ globalData: { userInfo: { id: 1, shopId: 2, type: 2 } } })
|
||||
require('./index')
|
||||
|
||||
@@ -37,6 +61,11 @@ assert.strictEqual(page.data.form.durationMinutes, '90')
|
||||
|
||||
page.openManualProduct()
|
||||
assert.strictEqual(page.data.manualProductSheetVisible, true)
|
||||
assert.strictEqual(page.data.manualProductMoreVisible, false)
|
||||
page.toggleManualProductMore()
|
||||
assert.strictEqual(page.data.manualProductMoreVisible, true)
|
||||
page.toggleManualProductMore()
|
||||
assert.strictEqual(page.data.manualProductMoreVisible, false)
|
||||
page.confirmManualProduct()
|
||||
assert.strictEqual(page.data.form.productId, 8)
|
||||
assert.strictEqual(page.data.manualProductSheetVisible, false)
|
||||
@@ -65,7 +94,76 @@ assert.match(wxml, /placeholder="留空时默认使用客户姓名"/)
|
||||
assert.match(wxml, /appointmentDateBadge/)
|
||||
assert.match(wxml, /class="customer-fields"/)
|
||||
assert.match(wxml, /class="manual-style-sheet"/)
|
||||
assert.match(wxml, /class="style-price-input"[^>]*data-field="amount"/)
|
||||
assert.match(wxml, /wx:if="\{\{form\.productId\}\}" class="number-field"/)
|
||||
assert.match(wxml, /class="manual-style-more-toggle" bindtap="toggleManualProductMore"/)
|
||||
assert.match(wxml, /data-field="manualProductDescription" bindinput="onInput"/)
|
||||
assert.match(wxml, /bind:openmanual="openManualProduct"/)
|
||||
assert.match(wxml, /show-manual-action="\{\{true\}\}"/)
|
||||
assert.match(wxml, /成交金额/)
|
||||
assert.match(wxml, /wx:for="\{\{form\.manualProductImages\}\}"/)
|
||||
assert.match(wxml, /manualProductImages\.length < 9/)
|
||||
assert.match(wxml, /data-index="\{\{index\}\}"[^>]*catchtap="removeManualProductImage"/)
|
||||
assert.match(wxml, /manualProductImages\.length\}\} \/ 9/)
|
||||
|
||||
async function testManualProductImages() {
|
||||
selectedImagePaths = ['/tmp/style-1.jpg', '/tmp/style-2.jpg', '/tmp/style-3.jpg']
|
||||
uploadResults = [
|
||||
{ id: 11, fileUrl: 'https://img.example/1.jpg' },
|
||||
{ id: 12, fileUrl: 'https://img.example/2.jpg' },
|
||||
{ id: 13, fileUrl: 'https://img.example/3.jpg' }
|
||||
]
|
||||
await page.chooseManualProductImage()
|
||||
assert.strictEqual(requestedImageCount, 9)
|
||||
assert.deepStrictEqual(uploadCalls.slice(-3), selectedImagePaths)
|
||||
assert.deepStrictEqual(page.data.form.manualProductImages, [
|
||||
{ fileId: '11', fileUrl: 'https://img.example/1.jpg' },
|
||||
{ fileId: '12', fileUrl: 'https://img.example/2.jpg' },
|
||||
{ fileId: '13', fileUrl: 'https://img.example/3.jpg' }
|
||||
])
|
||||
assert.strictEqual(page.data.form.manualProductImageFileIds, '11,12,13')
|
||||
assert.strictEqual(page.data.form.manualProductImageUrl, 'https://img.example/1.jpg')
|
||||
|
||||
page.removeManualProductImage({ currentTarget: { dataset: { index: 0 } } })
|
||||
assert.strictEqual(page.data.form.manualProductImageFileIds, '12,13')
|
||||
assert.strictEqual(page.data.form.manualProductImageUrl, 'https://img.example/2.jpg')
|
||||
|
||||
page.data.form.manualProductImages = Array.from({ length: 8 }, (_, index) => ({ fileId: String(index + 20), fileUrl: `https://img.example/${index + 20}.jpg` }))
|
||||
selectedImagePaths = ['/tmp/style-9.jpg', '/tmp/ignored.jpg']
|
||||
uploadResults = [{ id: 28, fileUrl: 'https://img.example/28.jpg' }]
|
||||
await page.chooseManualProductImage()
|
||||
assert.strictEqual(requestedImageCount, 1)
|
||||
assert.strictEqual(page.data.form.manualProductImages.length, 9)
|
||||
|
||||
page.data.form.manualProductImages = []
|
||||
selectedImagePaths = ['/tmp/style-partial-1.jpg', '/tmp/style-partial-2.jpg']
|
||||
uploadResults = [{ id: 29, fileUrl: 'https://img.example/29.jpg' }, new Error('第二张上传失败')]
|
||||
await page.chooseManualProductImage()
|
||||
assert.deepStrictEqual(page.data.form.manualProductImages, [
|
||||
{ fileId: '29', fileUrl: 'https://img.example/29.jpg' }
|
||||
])
|
||||
assert.strictEqual(toastMessages.pop(), '第二张上传失败')
|
||||
|
||||
page.selectProduct({ detail: { item: { id: 9, title: '清透裸粉', price: 188, priceText: '¥188', approximateDuration: '60' } } })
|
||||
assert.deepStrictEqual(page.data.form.manualProductImages, [])
|
||||
assert.strictEqual(page.data.form.manualProductImageFileIds, '')
|
||||
|
||||
global.wx.getStorageSync = () => ({ form: {
|
||||
appointmentDate: '2026-10-21',
|
||||
manualProductImageFileIds: '44',
|
||||
manualProductImageUrl: 'https://img.example/legacy.jpg'
|
||||
} })
|
||||
const legacyDraftPage = createPage()
|
||||
legacyDraftPage.loadOptions = () => {}
|
||||
legacyDraftPage.onLoad({})
|
||||
assert.deepStrictEqual(legacyDraftPage.data.form.manualProductImages, [
|
||||
{ fileId: '44', fileUrl: 'https://img.example/legacy.jpg' }
|
||||
])
|
||||
assert.strictEqual(legacyDraftPage.data.form.manualProductImageFileIds, '44')
|
||||
}
|
||||
|
||||
testManualProductImages().catch(error => {
|
||||
console.error(error)
|
||||
process.exitCode = 1
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user