feat(home): add AI story expand button and modal

This commit is contained in:
saturn
2026-03-24 23:53:26 +08:00
parent 4e469074e0
commit fd8f5f8635
28 changed files with 615 additions and 3 deletions

View File

@@ -0,0 +1,50 @@
import { describe, expect, it, vi } from 'vitest'
import { expandHomeStory } from '@/lib/home/ai-story-expand'
vi.mock('@/lib/task/client', () => ({
resolveTaskResponse: vi.fn(),
}))
import { resolveTaskResponse } from '@/lib/task/client'
function buildJsonResponse(body: unknown, status = 200): Response {
return new Response(JSON.stringify(body), {
status,
headers: { 'Content-Type': 'application/json' },
})
}
describe('expandHomeStory', () => {
it('posts the prompt to the user ai-story-expand route and returns expanded text', async () => {
const apiFetch = vi.fn(async () => buildJsonResponse({ async: true, taskId: 'task-1' }))
vi.mocked(resolveTaskResponse).mockResolvedValue({
expandedText: '扩写后的故事正文',
})
const result = await expandHomeStory({
apiFetch,
prompt: '宫廷复仇女主回京',
})
expect(apiFetch).toHaveBeenCalledWith('/api/user/ai-story-expand', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
prompt: '宫廷复仇女主回京',
}),
})
expect(result).toEqual({
expandedText: '扩写后的故事正文',
})
})
it('fails explicitly when the route does not return expandedText', async () => {
const apiFetch = vi.fn(async () => buildJsonResponse({ async: true, taskId: 'task-1' }))
vi.mocked(resolveTaskResponse).mockResolvedValue({})
await expect(expandHomeStory({
apiFetch,
prompt: '宫廷复仇女主回京',
})).rejects.toThrow('AI story expand response missing expandedText')
})
})

View File

@@ -59,6 +59,10 @@ vi.mock('@/lib/home/create-project-launch', () => ({
createHomeProjectLaunch: vi.fn(),
}))
vi.mock('@/lib/home/ai-story-expand', () => ({
expandHomeStory: vi.fn(),
}))
describe('resolveTextareaTargetHeight', () => {
it('keeps the home quick-start input at least three rows tall', () => {
expect(resolveTextareaTargetHeight({