68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
const assert = require('assert')
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
let pageDefinition
|
|
let currentProfile
|
|
|
|
global.Page = definition => { pageDefinition = definition }
|
|
global.wx = { showToast: () => {} }
|
|
|
|
const profileCache = require('../../utils/profile-cache')
|
|
profileCache.getProfile = async () => currentProfile
|
|
require('./index')
|
|
|
|
async function loadProfile(profile) {
|
|
currentProfile = profile
|
|
const page = {
|
|
data: { ...pageDefinition.data },
|
|
setData(values) {
|
|
Object.entries(values).forEach(([key, value]) => {
|
|
const parts = key.split('.')
|
|
if (parts.length === 1) this.data[key] = value
|
|
else this.data[parts[0]] = { ...this.data[parts[0]], [parts[1]]: value }
|
|
})
|
|
}
|
|
}
|
|
await pageDefinition.loadProfile.call(page)
|
|
return page.data
|
|
}
|
|
|
|
async function run() {
|
|
const empty = await loadProfile({
|
|
type: 2,
|
|
shopBusinessExpireTime: null,
|
|
shopBusinessExpired: false,
|
|
shopBusinessRemainingDays: null
|
|
})
|
|
assert.strictEqual(empty.businessExpireDateText, '未设置')
|
|
assert.strictEqual(empty.businessExpiryStatusText, '有效期未设置')
|
|
|
|
const active = await loadProfile({
|
|
type: 2,
|
|
shopBusinessExpireTime: '2026-12-31T23:59:59',
|
|
shopBusinessExpired: false,
|
|
shopBusinessRemainingDays: 66
|
|
})
|
|
assert.strictEqual(active.businessExpireDateText, '2026-12-31')
|
|
assert.strictEqual(active.businessExpiryStatusText, '剩余 66 天')
|
|
|
|
const expired = await loadProfile({
|
|
type: 2,
|
|
shopBusinessExpireTime: '2026-10-01T00:00:00',
|
|
shopBusinessExpired: true,
|
|
shopBusinessRemainingDays: 0
|
|
})
|
|
assert.strictEqual(expired.businessExpiryStatusText, '已过期,暂不能新增预约')
|
|
|
|
const shopSettingsWxml = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8')
|
|
const accountSettingsWxml = fs.readFileSync(path.join(__dirname, '../account-settings/index.wxml'), 'utf8')
|
|
assert(shopSettingsWxml.includes('wx:if="{{profile.type == 2}}" class="card business-expiry-card"'))
|
|
assert(!accountSettingsWxml.includes('business-expiry-card'))
|
|
}
|
|
|
|
run().catch(error => {
|
|
console.error(error)
|
|
process.exitCode = 1
|
|
})
|