This commit is contained in:
@@ -1,20 +1,18 @@
|
||||
const assert = require('assert')
|
||||
|
||||
const modalChoices = []
|
||||
const toasts = []
|
||||
const modals = []
|
||||
global.wx = {
|
||||
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
||||
getDeviceInfo: () => ({ platform: 'devtools' }),
|
||||
getStorageSync: () => '',
|
||||
setStorageSync: () => {},
|
||||
removeStorageSync: () => {}
|
||||
}
|
||||
|
||||
const appMock = {
|
||||
globalData: {
|
||||
userInfo: { type: 2 },
|
||||
openEmployeeReview: true
|
||||
showToast: options => toasts.push(options.title),
|
||||
showModal: options => {
|
||||
modals.push(options)
|
||||
options.success({ confirm: modalChoices.shift() !== false })
|
||||
}
|
||||
}
|
||||
global.getApp = () => appMock
|
||||
global.getApp = () => ({ globalData: { userInfo: { type: 2 }, openEmployeeReview: false } })
|
||||
|
||||
let definition
|
||||
global.Page = value => { definition = value }
|
||||
@@ -24,26 +22,61 @@ function createPage() {
|
||||
return {
|
||||
...definition,
|
||||
data: { ...definition.data, isManager: true },
|
||||
setData(values) { Object.assign(this.data, values) }
|
||||
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[parts[index]] = target[parts[index]] || {}
|
||||
target = target[parts[index]]
|
||||
}
|
||||
target[parts[parts.length - 1]] = value
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const employeesApi = require('../../api/employees')
|
||||
employeesApi.reviewApplications = async () => [{
|
||||
const planningApi = require('../../api/planning')
|
||||
const application = {
|
||||
id: 12,
|
||||
applicationNo: 'SALON-001',
|
||||
applicantNickname: '小周',
|
||||
createTime: '2026-10-12T10:30:00'
|
||||
}]
|
||||
applicantNickname: '微信昵称',
|
||||
applicantAvatar: 'https://example.test/avatar.png',
|
||||
targetArtistUserId: 22
|
||||
}
|
||||
employeesApi.reviewApplications = async () => [application]
|
||||
employeesApi.unboundArtists = async () => [
|
||||
{ userId: 22, nickname: '门店员工A', avatar: '/staff-a.png' },
|
||||
{ userId: 23, nickname: '门店员工B' }
|
||||
]
|
||||
employeesApi.list = async () => []
|
||||
planningApi.calendar = async () => ({ appointments: [], artists: [] })
|
||||
let submitted
|
||||
employeesApi.approveApplication = async (id, payload) => { submitted = { id, payload } }
|
||||
|
||||
const page = createPage()
|
||||
await page.onShow()
|
||||
page.data.reviewApplications = [application]
|
||||
await page.approveApplication({ currentTarget: { dataset: { id: 12 } } })
|
||||
assert.strictEqual(page.data.associationSheetVisible, true)
|
||||
assert.strictEqual(page.data.associationSelectedId, '22')
|
||||
assert.deepStrictEqual(page.data.associationItems.map(item => item.title), ['门店员工A', '门店员工B'])
|
||||
|
||||
assert.strictEqual(appMock.globalData.openEmployeeReview, false)
|
||||
assert.strictEqual(page.data.reviewExpanded, true)
|
||||
assert.strictEqual(page.data.reviewPendingCount, 1)
|
||||
assert.strictEqual(page.data.reviewApplications[0].applicationTimeText, '2026-10-12 10:30')
|
||||
modalChoices.push(true, false, true)
|
||||
await page.confirmApprovalAssociation()
|
||||
assert.deepStrictEqual(submitted, {
|
||||
id: '12',
|
||||
payload: { targetArtistUserId: 22, useApplicantNickname: true, useApplicantAvatar: false }
|
||||
})
|
||||
assert.strictEqual(page.data.associationSheetVisible, false)
|
||||
assert.strictEqual(page.data.reviewingId, '')
|
||||
assert(toasts.includes('申请已通过'))
|
||||
|
||||
employeesApi.unboundArtists = async () => []
|
||||
page.data.reviewApplications = [application]
|
||||
await page.approveApplication({ currentTarget: { dataset: { id: 12 } } })
|
||||
assert.strictEqual(page.data.associationSheetVisible, false)
|
||||
assert(modals.some(item => String(item.content || '').includes('当前门店没有未关联微信的美甲师档案')))
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
|
||||
Reference in New Issue
Block a user