96 lines
3.4 KiB
JavaScript
96 lines
3.4 KiB
JavaScript
const assert = require('assert')
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
const modalChoices = []
|
|
const toasts = []
|
|
const modals = []
|
|
const navigations = []
|
|
global.wx = {
|
|
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
|
getDeviceInfo: () => ({ platform: 'devtools' }),
|
|
showToast: options => toasts.push(options.title),
|
|
showModal: options => {
|
|
modals.push(options)
|
|
options.success({ confirm: modalChoices.shift() !== false })
|
|
},
|
|
navigateTo: options => navigations.push(options.url)
|
|
}
|
|
global.getApp = () => ({ globalData: { userInfo: { type: 2 }, openEmployeeReview: false } })
|
|
|
|
let definition
|
|
global.Page = value => { definition = value }
|
|
require('./index')
|
|
|
|
function createPage() {
|
|
return {
|
|
...definition,
|
|
data: { ...definition.data, isManager: true },
|
|
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 styles = fs.readFileSync(path.join(__dirname, 'index.wxss'), 'utf8')
|
|
assert(styles.includes('min-width: 0;'))
|
|
assert(styles.includes('.review-main'))
|
|
assert(styles.includes('@media (max-width: 390px)'))
|
|
assert(styles.includes('text-overflow: ellipsis;'))
|
|
const employeesApi = require('../../api/employees')
|
|
const planningApi = require('../../api/planning')
|
|
const application = {
|
|
id: 12,
|
|
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()
|
|
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'])
|
|
|
|
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 => item.confirmText === '去新建'))
|
|
assert.strictEqual(navigations.pop(), '/pages/employee-create/index?applicationId=12&applicationNo=')
|
|
}
|
|
|
|
run().catch(error => {
|
|
console.error(error)
|
|
process.exitCode = 1
|
|
})
|