101 lines
3.1 KiB
JavaScript
101 lines
3.1 KiB
JavaScript
const assert = require('assert')
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
let definition
|
|
let exitOptions
|
|
let toastOptions
|
|
let modalOptions
|
|
let navigatedTo
|
|
let modalChoice = { confirm: false, cancel: true }
|
|
let modalCount = 0
|
|
|
|
global.Page = value => { definition = value }
|
|
global.wx = {
|
|
exitMiniProgram(options) {
|
|
exitOptions = options
|
|
},
|
|
showToast(options) {
|
|
toastOptions = options
|
|
},
|
|
showModal(options) {
|
|
modalOptions = options
|
|
modalCount += 1
|
|
if (options.success) options.success(modalChoice)
|
|
},
|
|
navigateTo(options) {
|
|
navigatedTo = options.url
|
|
}
|
|
}
|
|
|
|
require('./index')
|
|
|
|
function createPage() {
|
|
return {
|
|
...definition,
|
|
data: {
|
|
...definition.data,
|
|
agreements: [
|
|
{ agreementType: 'USER_TERMS', version: '1' },
|
|
{ agreementType: 'PRIVACY_POLICY', version: '1' }
|
|
]
|
|
},
|
|
setData(values, callback) {
|
|
Object.assign(this.data, values)
|
|
if (callback) callback()
|
|
}
|
|
}
|
|
}
|
|
|
|
async function run() {
|
|
const page = createPage()
|
|
page.loadAgreements = async () => {}
|
|
|
|
assert.strictEqual(await page.ensureCanLogin(), false)
|
|
assert.strictEqual(page.data.agreementPromptVisible, true)
|
|
|
|
let loginStarted = false
|
|
page.quickLogin = () => { loginStarted = true }
|
|
page.acceptAgreementPrompt()
|
|
assert.strictEqual(page.data.agreementAccepted, true)
|
|
assert.strictEqual(page.data.agreementPromptVisible, false)
|
|
assert.strictEqual(loginStarted, true)
|
|
|
|
page.declineAgreementPrompt()
|
|
assert.ok(exitOptions)
|
|
exitOptions.fail()
|
|
assert.strictEqual(toastOptions.title, '请同意协议后使用')
|
|
|
|
const statePage = createPage()
|
|
statePage.handleResult({ status: 'PENDING_REVIEW', message: '申请审核中' })
|
|
assert.strictEqual(modalOptions.title, '申请审核中')
|
|
assert.strictEqual(modalOptions.showCancel, false)
|
|
assert.strictEqual(statePage._presentedLoginState.startsWith('PENDING_REVIEW:'), true)
|
|
|
|
const modalCountBeforeError = modalCount
|
|
const errorPage = createPage()
|
|
errorPage.handleResult({ status: 'ERROR', message: '网络连接失败' })
|
|
errorPage.handleResult({ status: 'ERROR', message: '网络连接失败' })
|
|
assert.strictEqual(modalOptions.title, '登录失败')
|
|
assert.strictEqual(modalCount, modalCountBeforeError + 1)
|
|
|
|
modalChoice = { confirm: true, cancel: false }
|
|
const rejectedPage = createPage()
|
|
rejectedPage.handleResult({ status: 'REJECTED', message: '资料需修改', registrationTicket: 'ticket-1', registrationApplicationId: 23 })
|
|
assert.match(navigatedTo, /registrationTicket=ticket-1/)
|
|
assert.match(navigatedTo, /applicationId=23/)
|
|
|
|
const template = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8')
|
|
assert.match(template, /用户协议与隐私政策提示/)
|
|
assert.match(template, /不同意并退出/)
|
|
assert.match(template, /同意并继续/)
|
|
assert.match(template, /data-type="USER_TERMS" catchtap="openAgreement"/)
|
|
assert.match(template, /data-type="PRIVACY_POLICY" catchtap="openAgreement"/)
|
|
assert.doesNotMatch(template, /class="state-line"/)
|
|
}
|
|
|
|
run().catch(error => {
|
|
console.error(error)
|
|
process.exitCode = 1
|
|
})
|