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()
|
||||
|
||||
Reference in New Issue
Block a user