401 lines
19 KiB
TypeScript
401 lines
19 KiB
TypeScript
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { NButton, NCheckbox, NTag } from 'naive-ui'
|
|
import DramaReviewPanel from '@/features/create-drama/review/DramaReviewPanel.vue'
|
|
import { dramaReviewApi } from '@/features/create-drama/review/api'
|
|
import { projectContextKey } from '@/features/projects/context'
|
|
import { testProjectContext } from '@/testing/project-context'
|
|
import { confirmationPreview, latestReview, rewritePreview } from './fixtures'
|
|
|
|
/** 当前审核页面。 */
|
|
let wrapper: VueWrapper | undefined
|
|
beforeEach(() => {
|
|
vi.spyOn(dramaReviewApi, 'rewritePreview').mockImplementation(async id => ({
|
|
...rewritePreview(id),
|
|
ready: false,
|
|
status: 'needs_review',
|
|
episodeNumbers: [],
|
|
rewriteEpisodes: false
|
|
}))
|
|
})
|
|
afterEach(() => {
|
|
wrapper?.unmount()
|
|
wrapper = undefined
|
|
document.body.innerHTML = ''
|
|
localStorage.clear()
|
|
})
|
|
|
|
describe('审核记录中的人工问题处理', () => {
|
|
it.each([
|
|
{
|
|
episodes: [],
|
|
title: '请先核对审核问题',
|
|
description: '点击“人工确认”对照原文逐项处理',
|
|
actions: [['人工确认', 'primary']]
|
|
},
|
|
{
|
|
episodes: [2],
|
|
title: '已有改写依据,请检查改写范围',
|
|
description: '第 2 集已有改写依据',
|
|
actions: [
|
|
['人工确认', 'default'],
|
|
['改写预检', 'primary']
|
|
]
|
|
}
|
|
])('显示当前审核的下一步引导:$title', async ({ episodes, title, description, actions }) => {
|
|
const id = `review-guidance-${episodes.length}`
|
|
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(latestReview(id))
|
|
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue({
|
|
...confirmationPreview(id),
|
|
confirmedRewriteEpisodes: episodes
|
|
})
|
|
vi.mocked(dramaReviewApi.rewritePreview).mockResolvedValue({
|
|
...rewritePreview(id),
|
|
ready: episodes.length > 0,
|
|
status: episodes.length ? 'ready' : 'needs_review',
|
|
episodeNumbers: episodes,
|
|
rewriteEpisodes: episodes.length > 0
|
|
})
|
|
wrapper = mount(DramaReviewPanel, {
|
|
attachTo: document.body,
|
|
props: { projectId: id },
|
|
global: { provide: { [projectContextKey as symbol]: testProjectContext(id) } }
|
|
})
|
|
await flushPromises()
|
|
expect(wrapper.text()).toContain(title)
|
|
expect(wrapper.text()).toContain(description)
|
|
const entries = wrapper
|
|
.findAllComponents(NButton)
|
|
.filter(button => ['人工确认', '改写预检'].includes(button.attributes('aria-label') ?? ''))
|
|
const refresh = wrapper.findAllComponents(NButton).find(button => button.text() === '刷新审核')!
|
|
expect(entries.map(button => [button.attributes('aria-label'), button.props('type')])).toEqual(actions)
|
|
expect(refresh.props('type')).toBe('default')
|
|
expect(document.querySelector('.app-drawer, .app-dialog')).toBeNull()
|
|
})
|
|
it.each([
|
|
{ name: '仅需改写', targets: [2], passed: false, actions: ['改写预检'] },
|
|
{ name: '没有可处理事项', targets: [], passed: false, actions: [] },
|
|
{ name: '审核已通过', targets: [], passed: true, actions: [] }
|
|
])('$name 时只显示实际存在的入口', async ({ name, targets, passed, actions }) => {
|
|
const id = `review-visible-${name}`
|
|
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue({ ...latestReview(id), passed })
|
|
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue({
|
|
...confirmationPreview(id),
|
|
confirmedRewriteEpisodes: targets,
|
|
remainingPendingQualityIssues: [],
|
|
remainingUncertainty: []
|
|
})
|
|
vi.mocked(dramaReviewApi.rewritePreview).mockResolvedValue({
|
|
...rewritePreview(id),
|
|
ready: targets.length > 0,
|
|
status: targets.length ? 'ready' : 'needs_review',
|
|
episodeNumbers: targets,
|
|
rewriteEpisodes: targets.length > 0
|
|
})
|
|
wrapper = mount(DramaReviewPanel, {
|
|
attachTo: document.body,
|
|
props: { projectId: id },
|
|
global: { provide: { [projectContextKey as symbol]: testProjectContext(id) } }
|
|
})
|
|
await flushPromises()
|
|
const entries = wrapper
|
|
.findAllComponents(NButton)
|
|
.map(button => button.attributes('aria-label'))
|
|
.filter(label => ['人工确认', '改写预检'].includes(label ?? ''))
|
|
expect(entries).toEqual(actions)
|
|
expect(wrapper.findAllComponents(NButton).some(button => button.text() === '刷新审核')).toBe(true)
|
|
expect(wrapper.text()).not.toContain('待确认问题仍可继续人工处理')
|
|
})
|
|
it('角色或世界观单独改写没有集号时,仍按真实改写预检显示入口', async () => {
|
|
const id = 'review-visible-world-rewrite'
|
|
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(latestReview(id))
|
|
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue({
|
|
...confirmationPreview(id),
|
|
confirmedRewriteEpisodes: [],
|
|
remainingPendingQualityIssues: [],
|
|
remainingUncertainty: []
|
|
})
|
|
vi.mocked(dramaReviewApi.rewritePreview).mockResolvedValue({
|
|
...rewritePreview(id),
|
|
episodeNumbers: [],
|
|
rewriteEpisodes: false,
|
|
rewriteWorld: true
|
|
})
|
|
wrapper = mount(DramaReviewPanel, {
|
|
attachTo: document.body,
|
|
props: { projectId: id },
|
|
global: { provide: { [projectContextKey as symbol]: testProjectContext(id) } }
|
|
})
|
|
await flushPromises()
|
|
const entries = wrapper
|
|
.findAllComponents(NButton)
|
|
.filter(button => ['人工确认', '改写预检'].includes(button.attributes('aria-label') ?? ''))
|
|
expect(entries.map(button => [button.attributes('aria-label'), button.props('type')])).toEqual([
|
|
['改写预检', 'primary']
|
|
])
|
|
expect(wrapper.text()).toContain('世界观')
|
|
})
|
|
it('改写预检与当前审核保存记录不一致时隐藏旧范围并允许刷新', async () => {
|
|
const id = 'review-visible-stale-rewrite'
|
|
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(latestReview(id))
|
|
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue(confirmationPreview(id))
|
|
vi.mocked(dramaReviewApi.rewritePreview).mockResolvedValue({
|
|
...rewritePreview(id),
|
|
checkpointId: 'another-checkpoint'
|
|
})
|
|
wrapper = mount(DramaReviewPanel, {
|
|
attachTo: document.body,
|
|
props: { projectId: id },
|
|
global: { provide: { [projectContextKey as symbol]: testProjectContext(id) } }
|
|
})
|
|
await flushPromises()
|
|
expect(wrapper.find('button[aria-label="改写预检"]').exists()).toBe(false)
|
|
expect(wrapper.text()).toContain('保存记录已变化')
|
|
expect(
|
|
wrapper
|
|
.findAllComponents(NButton)
|
|
.find(button => button.text() === '刷新审核')!
|
|
.props('disabled')
|
|
).toBe(false)
|
|
})
|
|
it('预检读取失败时不展示没有当前依据的处理入口', async () => {
|
|
const id = 'review-visible-preview-error'
|
|
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(latestReview(id))
|
|
vi.spyOn(dramaReviewApi, 'preview').mockRejectedValue(new Error('预检读取失败'))
|
|
wrapper = mount(DramaReviewPanel, {
|
|
attachTo: document.body,
|
|
props: { projectId: id },
|
|
global: { provide: { [projectContextKey as symbol]: testProjectContext(id) } }
|
|
})
|
|
await flushPromises()
|
|
expect(wrapper.find('button[aria-label="人工确认"]').exists()).toBe(false)
|
|
expect(wrapper.find('button[aria-label="改写预检"]').exists()).toBe(false)
|
|
expect(wrapper.text()).toContain('预检读取失败')
|
|
})
|
|
it.each([
|
|
{ name: '来源失效', sourceValid: false, hasActiveExecution: false },
|
|
{ name: '活动任务', sourceValid: true, hasActiveExecution: true }
|
|
])('$name 时保留只读入口,不强调人工确认或改写', async ({ name, sourceValid, hasActiveExecution }) => {
|
|
const id = `review-primary-blocked-${name}`
|
|
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(latestReview(id))
|
|
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue({
|
|
...confirmationPreview(id),
|
|
confirmedRewriteEpisodes: [2],
|
|
ready: false,
|
|
sourceValid,
|
|
hasActiveExecution
|
|
})
|
|
vi.mocked(dramaReviewApi.rewritePreview).mockResolvedValue({
|
|
...rewritePreview(id),
|
|
ready: false,
|
|
status: hasActiveExecution ? 'blocked' : 'stale',
|
|
rewriteEpisodes: hasActiveExecution
|
|
})
|
|
wrapper = mount(DramaReviewPanel, {
|
|
attachTo: document.body,
|
|
props: { projectId: id },
|
|
global: { provide: { [projectContextKey as symbol]: testProjectContext(id) } }
|
|
})
|
|
await flushPromises()
|
|
const entryButtons = wrapper
|
|
.findAllComponents(NButton)
|
|
.filter(button => ['人工确认', '改写预检'].includes(button.attributes('aria-label') ?? ''))
|
|
expect(entryButtons.map(button => button.props('type'))).toEqual(
|
|
hasActiveExecution ? ['default', 'default'] : ['default']
|
|
)
|
|
})
|
|
it('手机默认收起完整正文,点击查看本集原文后展开核对区', async () => {
|
|
vi.spyOn(window, 'matchMedia').mockReturnValue({
|
|
matches: false,
|
|
media: '(min-width: 1024px)',
|
|
onchange: null,
|
|
addEventListener: vi.fn<() => void>(),
|
|
removeEventListener: vi.fn<() => void>(),
|
|
addListener: vi.fn<() => void>(),
|
|
removeListener: vi.fn<() => void>(),
|
|
dispatchEvent: () => true
|
|
})
|
|
vi.spyOn(HTMLElement.prototype, 'scrollIntoView').mockImplementation(() => {})
|
|
const id = 'review-mobile-source'
|
|
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(latestReview(id))
|
|
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue(confirmationPreview(id))
|
|
wrapper = mount(DramaReviewPanel, {
|
|
attachTo: document.body,
|
|
props: { projectId: id },
|
|
global: { provide: { [projectContextKey as symbol]: testProjectContext(id) } }
|
|
})
|
|
await flushPromises()
|
|
await wrapper.get('button[aria-label="人工确认"]').trigger('click')
|
|
await flushPromises()
|
|
const drawer = new DOMWrapper(document.querySelector<HTMLElement>('.app-drawer')!)
|
|
expect(drawer.find('.review-source-content').exists()).toBe(false)
|
|
await drawer
|
|
.get('[data-review-issue="1"]')
|
|
.findAll('button')
|
|
.find(item => item.text() === '查看本集原文')!
|
|
.trigger('click')
|
|
await flushPromises()
|
|
expect(drawer.get('.review-source-content').text()).toContain('林夏放下信件后打开房门。')
|
|
})
|
|
it('人工处理完成审核后仍可只读核对正式正文,不再显示可提交表单', async () => {
|
|
const id = 'review-panel-finalized'
|
|
const preview = confirmationPreview(id)
|
|
preview.pendingQualityIssues = [preview.pendingQualityIssues[2]!]
|
|
preview.remainingPendingQualityIssues = preview.pendingQualityIssues
|
|
preview.uncertainty = []
|
|
preview.remainingUncertainty = []
|
|
const initial = {
|
|
...latestReview(id),
|
|
pendingQualityIssues: preview.pendingQualityIssues,
|
|
qualityReview: { issues: [], uncertainty: [] }
|
|
}
|
|
const latest = vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(initial)
|
|
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue(preview)
|
|
const context = testProjectContext(id)
|
|
context.data.value!.project.status = 'need_review'
|
|
context.data.value!.project.episodes = confirmationPreview(id).episodes.map(item => ({
|
|
...item,
|
|
title: `第${item.episode}集`,
|
|
targetDurationSeconds: null
|
|
}))
|
|
vi.spyOn(dramaReviewApi, 'confirm').mockImplementation(async () => {
|
|
latest.mockResolvedValue({ ...initial, id: 'review-passed', passed: true, pendingQualityIssues: [] })
|
|
context.data.value!.project.status = 'completed'
|
|
return {
|
|
projectId: id,
|
|
reviewId: 'review-1',
|
|
checkpointId: 'final-cp',
|
|
confirmedEpisodes: [],
|
|
acceptedWarningIndexes: [0],
|
|
acceptedUncertaintyIndexes: [],
|
|
finalized: true,
|
|
remainingBlockers: 0,
|
|
blockers: {
|
|
pendingIssues: 0,
|
|
uncertainty: 0,
|
|
confirmedErrors: 0,
|
|
affectedEpisodes: 0,
|
|
contentSafety: 0
|
|
}
|
|
}
|
|
})
|
|
wrapper = mount(DramaReviewPanel, {
|
|
attachTo: document.body,
|
|
props: { projectId: id },
|
|
global: { provide: { [projectContextKey as symbol]: context } }
|
|
})
|
|
await flushPromises()
|
|
await wrapper.get('button[aria-label="人工确认"]').trigger('click')
|
|
await flushPromises()
|
|
const drawer = new DOMWrapper(document.querySelector<HTMLElement>('.app-drawer')!)
|
|
await drawer.get('[data-review-issue="0"] [role="checkbox"]').trigger('click')
|
|
await drawer.get('.app-drawer-footer [role="checkbox"]').trigger('click')
|
|
await drawer
|
|
.get('.app-drawer-footer')
|
|
.findAll('button')
|
|
.find(item => item.text() === '确认本次处理')!
|
|
.trigger('click')
|
|
await flushPromises()
|
|
expect(drawer.text()).toContain('本次处理已完成审核')
|
|
expect(drawer.text()).toContain('林夏放下信件后打开房门。')
|
|
expect(drawer.text()).not.toContain('当前没有可核对的正式正文')
|
|
expect(drawer.findAll('button').some(item => item.text() === '确认本次处理')).toBe(false)
|
|
})
|
|
it('刷新失败保留旧记录时不把旧通过结论继续标为当前成功', async () => {
|
|
const id = 'review-read-failed'
|
|
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue({ ...latestReview(id), passed: true })
|
|
wrapper = mount(DramaReviewPanel, {
|
|
attachTo: document.body,
|
|
props: { projectId: id },
|
|
global: { provide: { [projectContextKey as symbol]: testProjectContext(id) } }
|
|
})
|
|
await flushPromises()
|
|
vi.mocked(dramaReviewApi.latest).mockRejectedValue(new Error('审核读取中断'))
|
|
await wrapper
|
|
.findAll('button')
|
|
.find(button => button.text() === '刷新审核')!
|
|
.trigger('click')
|
|
await flushPromises()
|
|
expect(wrapper.getComponent(NTag).props('type')).toBe('default')
|
|
expect(wrapper.text()).not.toContain('当前审核已通过')
|
|
})
|
|
it('按集核对正式原文,默认不勾选,实际提交仍使用原始索引', async () => {
|
|
const id = 'review-panel-index'
|
|
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(latestReview(id))
|
|
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue(confirmationPreview(id))
|
|
const confirm = vi.spyOn(dramaReviewApi, 'confirm').mockResolvedValue({
|
|
projectId: id,
|
|
reviewId: 'review-1',
|
|
checkpointId: 'saved-cp',
|
|
confirmedEpisodes: [1],
|
|
acceptedWarningIndexes: [],
|
|
acceptedUncertaintyIndexes: [],
|
|
finalized: false,
|
|
remainingBlockers: 2,
|
|
blockers: {
|
|
pendingIssues: 1,
|
|
uncertainty: 0,
|
|
confirmedErrors: 1,
|
|
affectedEpisodes: 0,
|
|
contentSafety: 0
|
|
}
|
|
})
|
|
const context = testProjectContext(id)
|
|
context.data.value!.project.status = 'need_review'
|
|
wrapper = mount(DramaReviewPanel, {
|
|
attachTo: document.body,
|
|
props: { projectId: id },
|
|
global: { provide: { [projectContextKey as symbol]: context } }
|
|
})
|
|
await flushPromises()
|
|
await wrapper.get('button[aria-label="人工确认"]').trigger('click')
|
|
await flushPromises()
|
|
const drawer = new DOMWrapper(document.querySelector<HTMLElement>('.app-drawer')!)
|
|
expect(drawer.text()).toContain('正式剧本原文')
|
|
const footer = drawer.get('.app-drawer-footer')
|
|
const submit = footer.findAll('button').find(item => item.text() === '确认本次处理')!
|
|
expect(submit.attributes('disabled')).toBeDefined()
|
|
expect(confirm).not.toHaveBeenCalled()
|
|
await drawer.get('[data-review-issue="1"] [role="checkbox"]').trigger('click')
|
|
await footer.get('[role="checkbox"]').trigger('click')
|
|
await submit.trigger('click')
|
|
await flushPromises()
|
|
expect(confirm.mock.calls[0]![1]).toMatchObject({ confirmed: true, reviewId: 'review-1', issueIndexes: [1] })
|
|
expect(context.refresh).toHaveBeenCalled()
|
|
expect(drawer.text()).not.toContain('当前审核已通过')
|
|
})
|
|
it('来源过期只读展示,界面不开放人工确认', async () => {
|
|
const id = 'review-panel-stale'
|
|
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(latestReview(id))
|
|
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue({
|
|
...confirmationPreview(id),
|
|
ready: false,
|
|
sourceValid: false
|
|
})
|
|
wrapper = mount(DramaReviewPanel, {
|
|
attachTo: document.body,
|
|
props: { projectId: id },
|
|
global: { provide: { [projectContextKey as symbol]: testProjectContext(id) } }
|
|
})
|
|
await flushPromises()
|
|
expect(wrapper.text()).toContain('来源不一致')
|
|
await wrapper.get('button[aria-label="人工确认"]').trigger('click')
|
|
await flushPromises()
|
|
const drawer = new DOMWrapper(document.querySelector<HTMLElement>('.app-drawer')!)
|
|
expect(drawer.get('[data-review-issue="1"] [role="checkbox"]').attributes('aria-disabled')).toBe('true')
|
|
expect(
|
|
wrapper
|
|
.findAllComponents(NCheckbox)
|
|
.find(item => item.element.closest('[data-review-issue="1"]'))!
|
|
.props('disabled')
|
|
).toBe(true)
|
|
expect(
|
|
drawer
|
|
.get('.app-drawer-footer')
|
|
.findAll('button')
|
|
.find(item => item.text() === '确认本次处理')!
|
|
.attributes('disabled')
|
|
).toBeDefined()
|
|
})
|
|
})
|