⚡ perf(vscode): 看板打开先出快照、评论只拉末页
This commit is contained in:
1 parent
904ab7491d
commit
a68caf5f6e
9 files changed
+447
-115
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parseKanbanSnapshot, snapshotScriptTag, snapshotToScriptJson } from './kanbanSnapshot'
|
||||
|
||||
const sample = {
|
||||
issues: [{ id: 'o/r#1', number: 1, title: '</script><img>', column: 'todo' as const, assignees: [], htmlUrl: 'https://x' }],
|
||||
scope: 'mine' as const,
|
||||
me: 'cruldra',
|
||||
globalAutoReview: true,
|
||||
youtrackConfigured: false,
|
||||
}
|
||||
|
||||
describe('kanbanSnapshot', () => {
|
||||
it('往返:注入 JSON 不含原始 </script>,parse 还原标题', () => {
|
||||
const json = snapshotToScriptJson(sample)
|
||||
expect(json).not.toContain('</script>')
|
||||
expect(json).toContain('\\u003c')
|
||||
const parsed = parseKanbanSnapshot(JSON.parse(json))
|
||||
expect(parsed?.issues[0].title).toBe('</script><img>')
|
||||
expect(parsed?.scope).toBe('mine')
|
||||
})
|
||||
|
||||
it('script 标签带 nonce 和 id', () => {
|
||||
const tag = snapshotScriptTag('abc', sample)
|
||||
expect(tag).toContain('id="kanban-snapshot"')
|
||||
expect(tag).toContain('nonce="abc"')
|
||||
expect(tag).toContain('type="application/json"')
|
||||
expect(tag).not.toContain('</script><img>')
|
||||
})
|
||||
|
||||
it('垃圾数据返回 null', () => {
|
||||
expect(parseKanbanSnapshot(null)).toBeNull()
|
||||
expect(parseKanbanSnapshot({ scope: 'mine' })).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user