58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
const assert = require('assert')
|
|
const authApi = require('../../api/auth')
|
|
|
|
let definition
|
|
let toast
|
|
global.Page = value => { definition = value }
|
|
global.wx = { showToast: options => { toast = options.title } }
|
|
require('./index')
|
|
|
|
function createPage() {
|
|
return {
|
|
...definition,
|
|
data: JSON.parse(JSON.stringify(definition.data)),
|
|
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() {
|
|
const page = createPage()
|
|
page.data.registrationTicket = 'valid-ticket'
|
|
page.data.role = 'staff'
|
|
page.data.form.shopId = '20'
|
|
authApi.register = async () => ({
|
|
applicationId: '88',
|
|
status: 'APPROVED',
|
|
rejectReason: null,
|
|
contentModerationStatus: 'PENDING',
|
|
contentModerationReason: '图片审核仍在处理'
|
|
})
|
|
await page.submit()
|
|
assert.strictEqual(page.data.registrationStatusText, '已通过')
|
|
assert.strictEqual(page.data.contentStatusText, '资料内容正在审核,审核完成前不会展示')
|
|
assert.strictEqual(page.data.contentStatusReason, '图片审核仍在处理')
|
|
assert.strictEqual(page.data.step, 3)
|
|
|
|
const expired = createPage()
|
|
expired.data.registrationTicket = 'spent-ticket'
|
|
expired.data.role = 'staff'
|
|
expired.data.form.shopId = '20'
|
|
authApi.register = async () => { throw new Error('注册票据已失效,请重新发起快捷登录') }
|
|
await expired.submit()
|
|
assert.strictEqual(expired.data.ticketInvalid, true)
|
|
assert.strictEqual(expired.data.step, 1)
|
|
assert.strictEqual(toast, undefined)
|
|
}
|
|
|
|
run().catch(error => {
|
|
console.error(error)
|
|
process.exitCode = 1
|
|
})
|