cc-haha/desktop/src/preview-agent/popover.test.ts
程序员阿江(Relakkes) 14e7228e33 feat(desktop): add edit popover apply-edit with optimistic preview + diff
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 17:40:45 +08:00

16 lines
614 B
TypeScript

import { describe, expect, it, beforeEach } from 'vitest'
import { applyEdit } from './popover'
beforeEach(() => { document.body.innerHTML = `<h1 id="t" style="color:rgb(0,0,0)">Old</h1>` })
describe('applyEdit', () => {
it('applies text + color to the live DOM and returns a diff', () => {
const el = document.getElementById('t')!
const diff = applyEdit(el, { text: 'New', color: 'rgb(255,0,0)' })
expect(el.textContent).toBe('New')
expect(el.style.color).toBe('rgb(255, 0, 0)')
expect(diff.text).toEqual({ from: 'Old', to: 'New' })
expect(diff.color?.to).toBe('rgb(255,0,0)')
})
})