1 parent
110a5f86cc
commit
20a6eea3b3
15 files changed
+360
-21
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { compileFunction } from 'node:vm'
|
||||
import { ref } from './vue.mjs'
|
||||
|
||||
// 将已有真实 Vue 开关事件回归纳入默认前端测试,避免只覆盖调用函数的模拟。
|
||||
import '../review/protocol-frontend.test.mjs'
|
||||
|
||||
const root = new URL('../../frontend/src/views/components/ThirdPartyAuthorization/', import.meta.url)
|
||||
const read = extension => readFileSync(new URL(`ThirdPartyAuthorization.${extension}`, root), 'utf8')
|
||||
|
||||
for (const succeeded of [false, true]) {
|
||||
test(`关闭协议时只在保存成功后清除本次明文:成功=${succeeded}`, async () => {
|
||||
const usePage = compileFunction(
|
||||
read('js').replace(/^import .*$/gm, '').replace('export function usePage', 'function usePage') + '\nreturn usePage',
|
||||
['onMounted', 'ref', 'ElMessageBox', 'ElNotification', 'http'],
|
||||
)(() => {}, ref, {}, () => {}, {
|
||||
put: async () => ({ errorNo: succeeded ? 0 : 1 }),
|
||||
})
|
||||
const page = usePage()
|
||||
const item = { protocol: 'imap', enabled: true, configured: true }
|
||||
page.generatedProtocol.value = 'imap'
|
||||
page.generatedProtocolCode.value = 'temporary-test-only'
|
||||
await page.setProtocolEnabled(item, false)
|
||||
assert.equal(item.enabled, !succeeded)
|
||||
assert.equal(page.generatedProtocolCode.value, succeeded ? '' : 'temporary-test-only')
|
||||
assert.equal(page.generatedProtocol.value, succeeded ? '' : 'imap')
|
||||
assert.equal(item.configured, true)
|
||||
assert.equal(page.protocolLoading.value, false)
|
||||
})
|
||||
}
|
||||
|
||||
test('邮件客户端文案明确区分本地服务、账号权限和可恢复的关闭状态', () => {
|
||||
const template = read('vue')
|
||||
assert.match(template, /邮件客户端协议/)
|
||||
assert.match(template, /不依赖 SMTP 中继/)
|
||||
assert.match(template, /只控制当前账号/)
|
||||
assert.match(template, /重新开启可继续使用未撤销的授权码/)
|
||||
assert.match(template, /:aria-label=/)
|
||||
assert.doesNotMatch(template, /第三方邮件|&#x[0-9a-f]+;/i)
|
||||
})
|
||||
@@ -44,19 +44,20 @@ test('一级菜单保留能力过滤和当前分类标题联动', () => {
|
||||
.replace(/export \{[\s\S]*?\}\s*$/, '') + '\nreturn usePage()',
|
||||
['computed', 'ref', 'onMounted', 'onUnmounted', 'window', 'useGlobalStatusStore', 'lang', ...names]
|
||||
)
|
||||
const capabilities = reactive(new Set(['password.change_own', 'plugin.write_own']))
|
||||
const capabilities = reactive(new Set(['password.change_own', 'user.read']))
|
||||
const store = reactive({
|
||||
settingsActiveTab: 'security',
|
||||
hasCapability: value => capabilities.has(value)
|
||||
})
|
||||
const page = createPage(computed, ref, () => {}, () => {}, { innerWidth: 1440 }, () => store,
|
||||
{ security: '安全' }, ...names.map(name => ({ name })))
|
||||
assert.deepEqual(page.settingsMenu.value.map(item => item.key), ['security', 'third-party'])
|
||||
assert.deepEqual(page.settingsMenu.value.map(item => item.key), ['security', 'third-party', 'group', 'rule'])
|
||||
assert.equal(page.settingsMenu.value.find(item => item.key === 'third-party').label, '邮件客户端')
|
||||
assert.equal(page.activeSettings.value.label, '安全')
|
||||
capabilities.add('config.read')
|
||||
store.settingsActiveTab = 'config'
|
||||
assert.equal(page.activeSettings.value.label, '配置管理')
|
||||
assert.equal(page.settingsMenu.value.length, 3)
|
||||
assert.equal(page.settingsMenu.value.length, 5)
|
||||
assert.ok(page.settingsMenu.value.every(item => item.icon && item.hint))
|
||||
capabilities.delete('config.read')
|
||||
assert.equal(page.activeSettings.value, undefined)
|
||||
|
||||
Reference in new issue
Block a user