feat(notifications): 新增可定制的通知配置页面
- NotificationSettingsPanel: 支持通知时机、字段排序、三种模板、预览与确认发送测试 - NotificationMarkdownPreview: 安全渲染消息预览,支持 emoji 与自定义文案 - notificationApi: 接入后端通知偏好接口并补充 Markdown 回归测试
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { after, test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { createServer } from 'vite'
|
||||
|
||||
const server = await createServer({
|
||||
server: { middlewareMode: true, hmr: false, ws: false },
|
||||
appType: 'custom',
|
||||
})
|
||||
const { notificationInlineParts } = await server.ssrLoadModule(
|
||||
'/src/utils/notificationMarkdown.ts',
|
||||
)
|
||||
after(() => server.close())
|
||||
|
||||
test('通知预览呈现加粗、代码和 HTTP(S) 链接', () => {
|
||||
const parts = notificationInlineParts(
|
||||
'项目 **role-user** · `v1.2` [详情](https://example.com/runs)',
|
||||
)
|
||||
assert.equal(parts.find((part) => part.kind === 'strong').text, 'role-user')
|
||||
assert.equal(parts.find((part) => part.kind === 'code').text, 'v1.2')
|
||||
assert.equal(
|
||||
parts.find((part) => part.kind === 'link').href,
|
||||
'https://example.com/runs',
|
||||
)
|
||||
})
|
||||
test('危险协议和包含凭据的链接按纯文本呈现', () => {
|
||||
for (const url of [
|
||||
'javascript:alert',
|
||||
'data:text/html,hello',
|
||||
'https://user:pass@example.com/',
|
||||
]) {
|
||||
assert.equal(
|
||||
notificationInlineParts(`[链接](${url})`).some(
|
||||
(part) => part.kind === 'link',
|
||||
),
|
||||
false,
|
||||
)
|
||||
}
|
||||
})
|
||||
test('模板 HTML 保留为文本节点,不生成可执行节点', () => {
|
||||
const text = '<img src=x onerror=alert(1)><script>alert(1)</script>'
|
||||
assert.deepEqual(notificationInlineParts(text), [{ kind: 'text', text }])
|
||||
})
|
||||
Reference in New Issue
Block a user