Files
superwork/vscode/src/panel/kanbanSnapshot.test.ts
T

35 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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()
})
})