feat(short-drama-agent-front): 新增项目标题输入
This commit is contained in:
@@ -40,6 +40,27 @@ async function submit() {
|
||||
}
|
||||
|
||||
describe('统一的 Naive UI 表单校验', () => {
|
||||
it('新建剧本要求填写项目标题,并将清理后的标题提交给后端', async () => {
|
||||
const fetcher = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockResolvedValue(new Response('{"projectId":"created","status":"generating"}', { status: 202 }))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(CreateProjectDialog, { attachTo: document.body })
|
||||
button('新建剧本').click()
|
||||
await flushPromises()
|
||||
expect(document.querySelector('#title')).toBeInstanceOf(HTMLInputElement)
|
||||
await input('#topic', '雨夜来信')
|
||||
await submit()
|
||||
expect(feedback()).toContain('请填写项目标题')
|
||||
expect(fetcher).not.toHaveBeenCalled()
|
||||
await input('#title', ' 记忆当铺 ')
|
||||
await submit()
|
||||
expect(JSON.parse(fetcher.mock.calls[0]![1]!.body as string)).toMatchObject({
|
||||
title: '记忆当铺',
|
||||
topic: '雨夜来信'
|
||||
})
|
||||
})
|
||||
|
||||
it('新建剧本使用字段反馈拦截空白主题和小数集数,修正后只发送一次请求', async () => {
|
||||
const fetcher = vi
|
||||
.fn<typeof fetch>()
|
||||
@@ -50,6 +71,7 @@ describe('统一的 Naive UI 表单校验', () => {
|
||||
await flushPromises()
|
||||
expect(document.querySelector('form')!.noValidate).toBe(true)
|
||||
expect(document.querySelector('[required]')).toBeNull()
|
||||
await input('#title', '测试剧本')
|
||||
await input('#topic', ' ')
|
||||
const focus = vi.spyOn(HTMLTextAreaElement.prototype, 'focus')
|
||||
await submit()
|
||||
|
||||
@@ -1452,6 +1452,9 @@ describe('工作台页面交互', () => {
|
||||
wrapper = mount(CreateProjectDialog, { attachTo: document.body })
|
||||
button('新建剧本').click()
|
||||
await flushPromises()
|
||||
const title = document.querySelector<HTMLInputElement>('#title')!
|
||||
title.value = ' 记忆当铺 '
|
||||
title.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
const topic = document.querySelector<HTMLTextAreaElement>('#topic')!
|
||||
topic.value = ' 雨夜来信 '
|
||||
topic.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
@@ -1462,6 +1465,7 @@ describe('工作台页面交互', () => {
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('created')).toEqual([['created']])
|
||||
expect(JSON.parse(fetcher.mock.calls[0]![1]!.body as string)).toEqual({
|
||||
title: '记忆当铺',
|
||||
topic: '雨夜来信',
|
||||
style: '',
|
||||
episodeCount: 6
|
||||
|
||||
@@ -110,11 +110,12 @@ describe('后端 API 契约', () => {
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
expect(await projectsApi.list()).toEqual([{ id: 'p1' }])
|
||||
expect(await projectsApi.create({ topic: '故事', style: '悬疑', episodeCount: 3 })).toEqual({
|
||||
expect(await projectsApi.create({ title: '测试剧本', topic: '故事', style: '悬疑', episodeCount: 3 })).toEqual({
|
||||
projectId: 'p2',
|
||||
status: 'generating'
|
||||
})
|
||||
expect(JSON.parse(fetcher.mock.calls[1]![1].body as string)).toEqual({
|
||||
title: '测试剧本',
|
||||
topic: '故事',
|
||||
style: '悬疑',
|
||||
episodeCount: 3
|
||||
|
||||
Reference in New Issue
Block a user