36 lines
2.6 KiB
JavaScript
36 lines
2.6 KiB
JavaScript
const fs = require('node:fs')
|
|
const path = require('node:path')
|
|
const assert = require('node:assert/strict')
|
|
const test = require('node:test')
|
|
const { parse, compileScript } = require('@vue/compiler-sfc')
|
|
const ts = require('typescript')
|
|
const vue = require('vue')
|
|
const { renderToString } = require('vue/server-renderer')
|
|
const src = path.join(__dirname, '../src')
|
|
const read = rel => fs.readFileSync(path.join(src, rel), 'utf8')
|
|
const pages = ["channel/h5","channel/open_setting","channel/weapp","channel/wx_oa/config","channel/wx_oa/reply/default_reply","channel/wx_oa/reply/follow_reply","channel/wx_oa/reply/keyword_reply","article/column/index","finance/balance_details","finance/recharge_record","message/notice/index","setting/pay/config/index","setting/system/cache"]
|
|
test('普通说明仅在 V2 使用原生 info 图标,经典版保留 warning;内容与关闭行为不变', async () => {
|
|
const filename = path.join(src, 'components/AdminPageHint.vue')
|
|
const { descriptor } = parse(fs.readFileSync(filename, 'utf8'), { filename })
|
|
const { content } = compileScript(descriptor, { id: 'hint', inlineTemplate: true })
|
|
const js = ts.transpileModule(content, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 } }).outputText
|
|
for (const [adminUi, type] of [['v2','info'], ['legacy','warning']]) {
|
|
const m = { exports: {} }
|
|
new Function('require', 'module', 'exports', js)(k => k === '@/stores/modules/setting' ? { default: () => ({ adminUi }) } : require(k), m, m.exports)
|
|
let actual
|
|
const app = vue.createSSRApp(m.exports.default, { title: '用户充值记录' })
|
|
app.component('el-alert', { props: { title: String, type: String, closable: Boolean, showIcon: Boolean },
|
|
setup(props) { actual = { ...props };return () => vue.h('div', props.title) } })
|
|
assert.match(await renderToString(app), /用户充值记录/)
|
|
assert.deepEqual(actual, { title: '用户充值记录', type, closable: false, showIcon: true })
|
|
}
|
|
})
|
|
test('仅这 13 个常驻使用说明启用;存储迁移、身份冲突和退款仍使用原语义', () => {
|
|
for (const page of pages) assert.match(read('views/'+page+'.vue'), /<admin-page-hint title="温馨提示:[^"]+"\s*\/>/)
|
|
const storage = read('views/setting/storage/index.vue')
|
|
assert.match(storage, /<el-alert type="warning"/)
|
|
assert.match(storage, /请勿随意切换存储方式/)
|
|
assert.match(read('views/permission/identity/index.vue'), /type="warning"/)
|
|
assert.doesNotMatch(read('views/finance/refund_record.vue'), /admin-page-hint/)
|
|
})
|