56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { renderToStaticMarkup } from 'react-dom/server'
|
|
import { describe, it, expect, vi } from 'vitest'
|
|
import { QAMirrorSyncView } from './QAMirrorSync'
|
|
import type { QAMirrorStatus } from './qaMirror'
|
|
const base: QAMirrorStatus = {
|
|
mode: 'local',
|
|
ready: false,
|
|
blocked: false,
|
|
revision: 0,
|
|
records: 0,
|
|
source_observed_at: null,
|
|
last_success_at: null,
|
|
next_sync_at: null,
|
|
error_code: 'initial_sync_pending',
|
|
interval_seconds: 300,
|
|
worker_ready: true,
|
|
job: null,
|
|
}
|
|
describe('local Q&A synchronization strip', () => {
|
|
it('shows pending first import rather than a successfully empty dataset', () => {
|
|
const html = renderToStaticMarkup(<QAMirrorSyncView status={base} error="" submitting={false} onSync={vi.fn()} />)
|
|
expect(html).toContain('本地数据库')
|
|
expect(html).toContain('首次同步尚未完成')
|
|
expect(html).toContain('立即同步')
|
|
expect(html).not.toContain('每 5 分钟后台同步 · 查询不请求远端')
|
|
})
|
|
it('keeps the last-good dataset visibly stale after a failed sync', () => {
|
|
const status = {
|
|
...base,
|
|
ready: true,
|
|
revision: 1,
|
|
records: 639,
|
|
last_success_at: '2026-10-18T00:00:00Z',
|
|
source_observed_at: '2026-10-18T00:00:00Z',
|
|
next_sync_at: '2026-10-18T00:05:00Z',
|
|
error_code: 'mirror_source_unavailable',
|
|
}
|
|
const html = renderToStaticMarkup(<QAMirrorSyncView status={status} error="" submitting={false} onSync={vi.fn()} />)
|
|
expect(html).toContain('639')
|
|
expect(html).toContain('保留上次成功数据')
|
|
expect(html).not.toContain('不承诺实时源快照')
|
|
})
|
|
it('distinguishes authorization blocking from an ordinary network failure', () => {
|
|
const html = renderToStaticMarkup(
|
|
<QAMirrorSyncView
|
|
status={{ ...base, blocked: true, error_code: 'mirror_source_authorization_failed' }}
|
|
error=""
|
|
submitting={false}
|
|
onSync={vi.fn()}
|
|
/>
|
|
)
|
|
expect(html).toContain('权限校验未通过')
|
|
expect(html).toContain('本地读取已阻断')
|
|
})
|
|
})
|