25 lines
1.8 KiB
JavaScript
25 lines
1.8 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import fs from 'node:fs'
|
|
import { createRequire } from 'node:module'
|
|
|
|
const require = createRequire(new URL('../../admin/package.json', import.meta.url))
|
|
const { parse, compileScript, compileTemplate } = require('@vue/compiler-sfc')
|
|
const filename = new URL('../../admin/src/views/account/login.vue', import.meta.url).pathname
|
|
const source = fs.readFileSync(filename, 'utf8')
|
|
const { descriptor, errors } = parse(source, { filename })
|
|
assert.deepEqual(errors, [])
|
|
const template = descriptor.template.content
|
|
assert.equal((template.match(/@click="handleIamLogin"/g) || []).length, 1, 'exactly one IAM entry')
|
|
const section = template.match(/<section v-if="iamEnabled" class="iam-login-alternative"[\s\S]*?<\/section>/)?.[0]
|
|
assert.ok(section, 'IAM alternative is enabled only by iamEnabled')
|
|
assert.match(section, /@click="handleIamLogin"/)
|
|
assert.ok(template.indexOf(section) > template.indexOf('@click="lockLogin"'), 'IAM follows local login')
|
|
assert.ok(template.indexOf(section) > template.indexOf('请使用企业微信扫描二维码登录'), 'IAM follows WeCom region')
|
|
assert.ok(template.indexOf(section) > template.indexOf('</el-radio-group>'), 'no IAM above mode switch')
|
|
assert.match(template, /<el-radio-button value="account">账号登录<\/el-radio-button>/)
|
|
assert.match(template, /<el-radio-button value="wxwork">企业微信<\/el-radio-button>/)
|
|
const script = compileScript(descriptor, { id: 'iam-login-placement' })
|
|
const compiled = compileTemplate({ source: template, filename, id: 'iam-login-placement', compilerOptions: { bindingMetadata: script.bindings } })
|
|
assert.deepEqual(compiled.errors, [])
|
|
console.log('PASS IAM placement: single optional bottom entry, original handler, account/WeCom switch, local/WeCom ordering, SFC script/template compilation')
|