65 lines
2.2 KiB
JavaScript
65 lines
2.2 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.account, '13800138000')
|
|
Object.assign(page.data.form, {
|
|
nickname: '小周',
|
|
phone: '13800138000',
|
|
account: '13800138000',
|
|
password: 'Fingertip@123',
|
|
wechatId: 'wx_zhou'
|
|
})
|
|
employeesApi.createUser = async () => 88
|
|
await page.submit()
|
|
assert.strictEqual(page.data.onboardingVisible, true)
|
|
assert.strictEqual(emitted, undefined)
|
|
page.data.pickerMode = true
|
|
page.skipFirstSchedule()
|
|
assert.strictEqual(emitted.name, 'employeeCreated')
|
|
assert.deepStrictEqual(emitted.value, { id: 88, name: '小周', title: '小周', avatar: '', autoSelect: false, scheduleSaved: false })
|
|
assert.strictEqual(navigatedBack, 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
|
|
})
|