Files
JayuCloud/JC-Salon-WeChat/pages/employee-create/index.test.js
T
xiaowang 7b40ee1650
自动发布开发环境 Nacos 配置 / publish (push) Successful in 26s
Salon美甲师注册申请关联微信账号
2026-10-30 03:46:24 +08:00

111 lines
3.9 KiB
JavaScript

const assert = require('assert')
const employeesApi = require('../../api/employees')
let navigatedBack = false
let navigatedTo = ''
global.wx = {
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
getDeviceInfo: () => ({ platform: 'devtools' }),
showToast: () => {},
navigateBack: () => { navigatedBack = true },
navigateTo: options => { navigatedTo = options.url }
}
global.setTimeout = callback => { callback(); return 1 }
let definition
global.Page = value => { definition = value }
require('./index')
let emitted
const page = {
...definition,
data: JSON.parse(JSON.stringify(definition.data)),
getOpenerEventChannel: () => ({ emit: (name, value) => { emitted = { name, value } } }),
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() {
page.onInput({ currentTarget: { dataset: { field: 'phone' } }, detail: { value: '13800138000' } })
assert.strictEqual(page.data.form.phone, '13800138000')
assert.strictEqual(page.data.form.account, undefined)
assert.strictEqual(page.data.form.password, undefined)
assert.strictEqual(page.data.form.color, '#8FB89A')
Object.assign(page.data.form, {
nickname: '小周',
phone: '13800138000',
wechatId: ''
})
let createPayload
employeesApi.createUser = async payload => {
createPayload = payload
assert.strictEqual(payload.wechatId, '')
assert.strictEqual(payload.color, '#8FB89A')
return 88
}
employeesApi.unassociatedApplications = async () => []
await page.submit()
assert.deepStrictEqual(createPayload, {
nickname: '小周',
phone: '13800138000',
contactPhone: '13800138000',
wechatId: '',
color: '#8FB89A',
avatar: undefined,
type: 3
})
assert.strictEqual(page.data.onboardingVisible, true)
assert.strictEqual(emitted, undefined)
let schedulePayload
page.data.pickerMode = true
employeesApi.saveScheduleRule = async payload => {
schedulePayload = payload
}
page.skipFirstSchedule()
await new Promise(resolve => setImmediate(resolve))
assert.deepStrictEqual(schedulePayload.workDays, [1, 2, 3, 4, 5, 6, 7])
assert.strictEqual(schedulePayload.startTime, '00:00')
assert.strictEqual(schedulePayload.endTime, '23:59')
assert.strictEqual(emitted.name, 'employeeCreated')
assert.deepStrictEqual(emitted.value, { id: 88, name: '小周', title: '小周', avatar: '', autoSelect: true, scheduleSaved: true })
assert.strictEqual(navigatedBack, true)
let associatedApplication
employeesApi.unassociatedApplications = async () => [{
id: 42,
applicantNickname: '微信昵称',
applicantMaskedPhone: '138****8000',
applicationNo: 'SALON-042'
}]
employeesApi.preAssociateApplication = async (applicationId, employeeId) => {
associatedApplication = { applicationId, employeeId }
}
page.setData({ onboardingVisible: false, associationSheetVisible: false })
await page.offerPendingAssociation()
assert.strictEqual(page.data.associationSheetVisible, true)
assert.strictEqual(page.data.associationItems[0].title, '微信昵称')
await page.selectAssociation({ detail: { item: { id: 42 } } })
assert.deepStrictEqual(associatedApplication, { applicationId: 42, employeeId: 88 })
assert.strictEqual(page.data.associationSheetVisible, false)
assert.strictEqual(page.data.onboardingVisible, true)
page.data.onboardingVisible = true
page.data.createdEmployee = { id: 88, name: '小周' }
page.data.appointmentContext = { date: '2026-10-12', time: '14:00', durationMinutes: '60' }
page.setupFirstSchedule()
assert.strictEqual(navigatedTo.includes('/pages/schedule-setting/index?id=88&onboarding=1&source=appointment'), true)
}
run().catch(error => {
console.error(error)
process.exitCode = 1
})