新增复制排版内容,同时提供富文本HTML与可读纯文本,保留MD下载。 各模式独立使用最新正文,不包含预览工具栏和原文查看器;局域网HTTP走原生复制回退,失败不虚报。 验证:富文本双格式、API缺失/拒绝/失败及复制入口先红后绿,编辑保存状态机回归、完整门禁和原生备份恢复通过。
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { writeFormattedClipboard } from './qaWeeklyClipboard'
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
describe('rendered weekly clipboard', () => {
|
||||
it.each(['missing', 'denied'])('uses the native rich copy path when the clipboard API is %s', async (kind) => {
|
||||
vi.stubGlobal(
|
||||
'navigator',
|
||||
kind === 'missing' ? {} : { clipboard: { write: vi.fn().mockRejectedValue(Error('denied')) } }
|
||||
)
|
||||
vi.stubGlobal(
|
||||
'ClipboardItem',
|
||||
class {
|
||||
constructor(readonly data: Record<string, Blob>) {}
|
||||
}
|
||||
)
|
||||
const fallback = vi.fn(() => true)
|
||||
await writeFormattedClipboard({ html: '<h2>正文</h2>', text: '正文' }, fallback)
|
||||
expect(fallback).toHaveBeenCalledOnce()
|
||||
})
|
||||
it('reports a failure instead of claiming success when neither copy path succeeds', async () => {
|
||||
vi.stubGlobal('navigator', {})
|
||||
await expect(writeFormattedClipboard({ html: '<p>正文</p>', text: '正文' }, () => false)).rejects.toThrow(
|
||||
'复制未成功'
|
||||
)
|
||||
})
|
||||
|
||||
it('writes rendered HTML plus readable text, never Markdown source', async () => {
|
||||
const write = vi.fn().mockResolvedValue(undefined)
|
||||
vi.stubGlobal('navigator', { clipboard: { write } })
|
||||
vi.stubGlobal(
|
||||
'ClipboardItem',
|
||||
class {
|
||||
constructor(readonly data: Record<string, Blob>) {}
|
||||
}
|
||||
)
|
||||
const fallback = vi.fn(() => true)
|
||||
await writeFormattedClipboard(
|
||||
{ html: '<h1>Weekly report</h1><p><strong>重点</strong></p>', text: 'Weekly report\n\n重点' },
|
||||
fallback
|
||||
)
|
||||
expect(write).toHaveBeenCalledTimes(1)
|
||||
const data = write.mock.calls[0][0][0].data
|
||||
expect(await data['text/html'].text()).toContain('<h1>Weekly report</h1>')
|
||||
expect(await data['text/plain'].text()).toBe('Weekly report\n\n重点')
|
||||
expect(fallback).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user