feat(short-drama-agent-front): 接入素材预览审核并完善创作流程
This commit is contained in:
1 parent
f8b0fbb8ca
commit
dc8bb17a23
66 files changed
+2864
-632
No files matched your search
@@ -0,0 +1,102 @@
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
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
|
||||
|
||||
/**
|
||||
* 挂载审核面板并从系统核查入口打开真实确认弹窗。
|
||||
* @param id 当前测试项目
|
||||
* @returns 系统核查弹窗
|
||||
*/
|
||||
async function openSystemReview(id: string) {
|
||||
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(latestReview(id))
|
||||
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue(confirmationPreview(id))
|
||||
vi.spyOn(dramaReviewApi, 'rewritePreview').mockResolvedValue({
|
||||
...rewritePreview(id),
|
||||
ready: false,
|
||||
status: 'needs_review',
|
||||
rewriteCharacters: false,
|
||||
rewriteWorld: false,
|
||||
rewriteEpisodes: false,
|
||||
episodeNumbers: []
|
||||
})
|
||||
wrapper = mount(DramaReviewPanel, {
|
||||
attachTo: document.body,
|
||||
props: { projectId: id },
|
||||
global: { provide: { [projectContextKey as symbol]: testProjectContext(id) } }
|
||||
})
|
||||
await flushPromises()
|
||||
const entry = wrapper.findAll('button').find(button => button.text() === '系统重新核查')
|
||||
expect(entry).toBeDefined()
|
||||
await entry!.trigger('click')
|
||||
await flushPromises()
|
||||
return new DOMWrapper(document.querySelector<HTMLElement>('.app-dialog[aria-label="系统重新核查"]')!)
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
wrapper = undefined
|
||||
document.body.innerHTML = ''
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
describe('系统核查已保存剧本', () => {
|
||||
it('打开或取消仅预检,不自动调用模型', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
projectId: 'system-cancel',
|
||||
checkpointId: 'cp1',
|
||||
episodeCount: 2,
|
||||
ready: true,
|
||||
readOnly: true
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const dialog = await openSystemReview('system-cancel')
|
||||
expect(dialog.text()).toContain('已保存的 2 集')
|
||||
expect(dialog.text()).toContain('不会重写正文')
|
||||
await dialog
|
||||
.findAll('button')
|
||||
.find(button => button.text() === '取消')!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls.every(([, options]) => !options?.method || options.method === 'GET')).toBe(true)
|
||||
})
|
||||
|
||||
it('确认前版本变化时禁止发起收费审核请求', async () => {
|
||||
let reads = 0
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(
|
||||
async () =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
projectId: 'system-stale',
|
||||
checkpointId: ++reads === 1 ? 'cp1' : 'cp2',
|
||||
episodeCount: 2,
|
||||
ready: true,
|
||||
readOnly: true
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const dialog = await openSystemReview('system-stale')
|
||||
await dialog
|
||||
.findAll('button')
|
||||
.find(button => button.text() === '开始系统核查')!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
expect(dialog.text()).toContain('已变化')
|
||||
expect(fetcher.mock.calls.every(([, options]) => !options?.method || options.method === 'GET')).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user