204 lines
8.1 KiB
TypeScript
204 lines
8.1 KiB
TypeScript
import { effectScope, ref } from 'vue'
|
|
import { flushPromises } from '@vue/test-utils'
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { dramaReviewApi } from '@/features/create-drama/review/api'
|
|
import { useDramaReview } from '@/features/create-drama/review/useDramaReview'
|
|
import { confirmationPreview, latestReview } from './fixtures'
|
|
import type { ConfirmDramaIssuesResult } from '@/features/create-drama/review/types'
|
|
|
|
/** 当前测试拥有的组件作用域。 */
|
|
let scope: ReturnType<typeof effectScope> | undefined
|
|
afterEach(() => {
|
|
scope?.stop()
|
|
scope = undefined
|
|
})
|
|
|
|
/**
|
|
* 为真实裁决流程提供隔离的接口响应。
|
|
* @param id 当前项目
|
|
* @returns 流程与刷新回调
|
|
*/
|
|
async function createFlow(id: string) {
|
|
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(latestReview(id))
|
|
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue(confirmationPreview(id))
|
|
const changed = vi.fn<() => Promise<void>>().mockResolvedValue()
|
|
scope = effectScope()
|
|
const flow = scope.run(() => useDramaReview(ref(id), changed))!
|
|
await flushPromises()
|
|
return { flow, changed }
|
|
}
|
|
|
|
/**
|
|
* 构造仍有改写问题的真实回执。
|
|
* @param id 当前项目
|
|
* @returns 裁决回执
|
|
*/
|
|
function receipt(id: string): ConfirmDramaIssuesResult {
|
|
return {
|
|
projectId: id,
|
|
reviewId: 'review-1',
|
|
checkpointId: 'confirmed-cp',
|
|
confirmedEpisodes: [1],
|
|
acceptedWarningIndexes: [2],
|
|
acceptedUncertaintyIndexes: [1],
|
|
remainingBlockers: 3,
|
|
blockers: { pendingIssues: 1, uncertainty: 0, confirmedErrors: 1, affectedEpisodes: 1, contentSafety: 0 },
|
|
finalized: false
|
|
}
|
|
}
|
|
|
|
describe('人工确认审核问题', () => {
|
|
it('项目切换发生在二次预检期间时,不把旧项目选择提交到任何项目', async () => {
|
|
const id = 'review-project-switch'
|
|
const project = ref(id)
|
|
vi.spyOn(dramaReviewApi, 'latest').mockImplementation(async value => latestReview(value))
|
|
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue(confirmationPreview(id))
|
|
scope = effectScope()
|
|
const flow = scope.run(() => useDramaReview(project, vi.fn<() => Promise<void>>().mockResolvedValue()))!
|
|
await flushPromises()
|
|
const confirm = vi.spyOn(dramaReviewApi, 'confirm')
|
|
let resolve!: (value: ReturnType<typeof confirmationPreview>) => void
|
|
vi.mocked(dramaReviewApi.preview)
|
|
.mockImplementationOnce(
|
|
() =>
|
|
new Promise(done => {
|
|
resolve = done
|
|
})
|
|
)
|
|
.mockResolvedValue(confirmationPreview('another-project'))
|
|
flow.editorOpen.value = true
|
|
flow.selectedErrors.value = [1]
|
|
await flushPromises()
|
|
flow.acknowledged.value = true
|
|
const action = flow.confirm()
|
|
await flushPromises()
|
|
project.value = 'another-project'
|
|
await flushPromises()
|
|
resolve(confirmationPreview(id))
|
|
await action
|
|
expect(confirm).not.toHaveBeenCalled()
|
|
expect(flow.editorOpen.value).toBe(false)
|
|
})
|
|
it('新的正式审核到达后不保留上一轮人工完成的成功回执', async () => {
|
|
const id = 'review-receipt-stale'
|
|
const { flow } = await createFlow(id)
|
|
flow.receipt.value = { ...receipt(id), finalized: true }
|
|
vi.mocked(dramaReviewApi.latest).mockResolvedValue({ ...latestReview(id), id: 'review-2' })
|
|
vi.mocked(dramaReviewApi.preview).mockResolvedValue({
|
|
...confirmationPreview(id),
|
|
reviewId: 'review-2',
|
|
checkpointId: 'cp-new'
|
|
})
|
|
await flow.query.refresh()
|
|
expect(flow.receipt.value).toBeNull()
|
|
})
|
|
it('人工核实的补充证据按完整错误结构提交,不丢失严重程度或原文', async () => {
|
|
const id = 'review-manual-complete'
|
|
const { flow } = await createFlow(id)
|
|
const confirm = vi.spyOn(dramaReviewApi, 'confirm').mockResolvedValue(receipt(id))
|
|
flow.editorOpen.value = true
|
|
flow.addManual()
|
|
Object.assign(flow.manualDrafts.value[0]!, {
|
|
code: '动作衔接',
|
|
sourceQuote: '林夏放下信件后打开房门。',
|
|
message: '缺少动作过程',
|
|
suggestion: '补齐动作'
|
|
})
|
|
await flushPromises()
|
|
flow.acknowledged.value = true
|
|
await flow.confirm()
|
|
expect(confirm.mock.calls[0]![1].manualIssues).toEqual([
|
|
{
|
|
episode: 1,
|
|
category: 'action_continuity',
|
|
code: '动作衔接',
|
|
severity: 'error',
|
|
sourceQuote: '林夏放下信件后打开房门。',
|
|
message: '缺少动作过程',
|
|
suggestion: '补齐动作',
|
|
evidenceConfidence: 'explicit',
|
|
policyException: false
|
|
}
|
|
])
|
|
})
|
|
it('提交原始索引、明确确认和当前审核编号,成功后重读且不自动改写或放行', async () => {
|
|
const id = 'review-confirm-source'
|
|
const { flow, changed } = await createFlow(id)
|
|
const confirm = vi.spyOn(dramaReviewApi, 'confirm').mockResolvedValue(receipt(id))
|
|
flow.editorOpen.value = true
|
|
flow.selectedErrors.value = [1]
|
|
flow.selectedWarnings.value = [2]
|
|
flow.selectedUncertainty.value = [1]
|
|
await flushPromises()
|
|
expect(confirm).not.toHaveBeenCalled()
|
|
flow.acknowledged.value = true
|
|
await flow.confirm()
|
|
expect(confirm).toHaveBeenCalledWith(id, {
|
|
confirmed: true,
|
|
reviewId: 'review-1',
|
|
issueIndexes: [1],
|
|
acceptedWarningIndexes: [2],
|
|
acceptedUncertaintyIndexes: [1]
|
|
})
|
|
expect(changed).toHaveBeenCalledOnce()
|
|
expect(flow.receipt.value?.finalized).toBe(false)
|
|
expect(flow.acknowledged.value).toBe(false)
|
|
})
|
|
|
|
it('预检来源变化后清除旧选择,不提交过期裁决', async () => {
|
|
const id = 'review-source-change'
|
|
const { flow } = await createFlow(id)
|
|
const confirm = vi.spyOn(dramaReviewApi, 'confirm')
|
|
flow.editorOpen.value = true
|
|
flow.selectedErrors.value = [1]
|
|
await flushPromises()
|
|
flow.acknowledged.value = true
|
|
vi.mocked(dramaReviewApi.preview).mockResolvedValue({ ...confirmationPreview(id), checkpointId: 'new-cp' })
|
|
await flow.confirm()
|
|
expect(confirm).not.toHaveBeenCalled()
|
|
expect(flow.actionError.value).toContain('已变化')
|
|
expect(flow.selectedErrors.value).toEqual([])
|
|
expect(flow.acknowledged.value).toBe(false)
|
|
})
|
|
|
|
it('没有人工勾选或原文不匹配时不发送任何确认', async () => {
|
|
const id = 'review-manual-validation'
|
|
const { flow } = await createFlow(id)
|
|
const confirm = vi.spyOn(dramaReviewApi, 'confirm')
|
|
flow.editorOpen.value = true
|
|
flow.addManual()
|
|
Object.assign(flow.manualDrafts.value[0]!, {
|
|
code: '动作衔接',
|
|
sourceQuote: '不存在的原文',
|
|
message: '缺少动作',
|
|
suggestion: '补齐动作'
|
|
})
|
|
await flushPromises()
|
|
await flow.confirm()
|
|
expect(confirm).not.toHaveBeenCalled()
|
|
flow.acknowledged.value = true
|
|
await flow.confirm()
|
|
expect(confirm).not.toHaveBeenCalled()
|
|
expect(flow.manualErrors.value[0]).toContain('原文')
|
|
flow.removeManual(flow.manualDrafts.value[0]!.id)
|
|
await flushPromises()
|
|
expect(flow.actionError.value).toBe('')
|
|
})
|
|
|
|
it('后端明确 finalized 才展示完成,不凭阻断计数归零自行通过', async () => {
|
|
const id = 'review-finalized'
|
|
const { flow } = await createFlow(id)
|
|
vi.spyOn(dramaReviewApi, 'confirm').mockResolvedValue({
|
|
...receipt(id),
|
|
remainingBlockers: 0,
|
|
finalized: false
|
|
})
|
|
flow.editorOpen.value = true
|
|
flow.selectedUncertainty.value = [1]
|
|
await flushPromises()
|
|
flow.acknowledged.value = true
|
|
await flow.confirm()
|
|
expect(flow.receipt.value?.finalized).toBe(false)
|
|
})
|
|
})
|