Files
bilin/e2e/chapter-template.spec.ts
T
bing fe127ec3ed feat: ship v1.2.0 Wave 1 foundation with book settings, chapter management, and focus mode
Deliver schema v9, book/chapter IPC extensions, BookSettingsTab, chapter meta/tags,
AI session menu, focus mode and TTS, template context enrich, and Wave 1 E2E coverage.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-08 15:22:58 +08:00

76 lines
3.1 KiB
TypeScript

import { mkdtempSync, rmSync, existsSync } from 'fs'
import { join } from 'path'
import { tmpdir } from 'os'
import { test, expect } from '@playwright/test'
import { launchApp, skipOnboarding, createBookAndOpenEditor, ensureChapterEditor, addCharacterSetting, dismissCockpitIfOpen } from './helpers'
test.describe('Chapter template', () => {
let userDataDir: string
test.beforeEach(() => {
userDataDir = mkdtempSync(join(tmpdir(), 'bilin-e2e-templ-'))
})
test.afterEach(() => {
if (userDataDir && existsSync(userDataDir)) {
try {
rmSync(userDataDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 })
} catch {
/* ignore */
}
}
})
test('E2E-TEMPL-01: quick create from template fills editor', async () => {
const app = await launchApp(userDataDir)
const page = await app.firstWindow()
await skipOnboarding(page)
await createBookAndOpenEditor(page, '模板测试书')
await page.getByTestId('chapter-quick-new').click()
await expect(page.getByTestId('template-quick-create-modal')).toBeVisible()
await page.getByTestId('template-chapter-title').fill('觉醒之路')
await page.getByTestId('template-create-btn').click()
await expect(page.getByTestId('template-quick-create-modal')).toBeHidden({ timeout: 10_000 })
const editor = page.locator('.ProseMirror')
await expect(editor).toBeVisible({ timeout: 10_000 })
await expect(editor).toContainText('觉醒之路', { timeout: 10_000 })
await expect(editor).toContainText('第')
await app.close()
})
test('E2E-TEMPL-05: characterList from settings in quick create', async () => {
const app = await launchApp(userDataDir)
const page = await app.firstWindow()
await skipOnboarding(page)
await createBookAndOpenEditor(page, '角色模板书')
await addCharacterSetting(page, '林远')
await addCharacterSetting(page, '苏晴')
await page.locator('#topbar .top-btn').filter({ hasText: '⚙' }).click()
await page.getByTestId('settings-nav-templates').click()
await page.getByTestId('setting-template-add').click()
const customCard = page.locator('.template-settings-item').filter({ hasText: '新模板' }).last()
await customCard.getByRole('button', { name: '编辑' }).click()
await page.locator('.template-edit-panel textarea').fill('出场角色:{characterList}\n\n正文')
await page.locator('#topbar .tab').filter({ hasText: '角色模板书' }).click()
await expect(page.locator('#editor-layout')).toBeVisible({ timeout: 10_000 })
await dismissCockpitIfOpen(page)
await page.getByTestId('sidebar-tab-chapters').click()
await page.getByTestId('chapter-quick-new').click()
await expect(page.getByTestId('template-quick-create-modal')).toBeVisible()
await page.locator('.template-card').filter({ hasText: '新模板' }).click()
await page.getByTestId('template-chapter-title').fill('角色章')
await page.getByTestId('template-create-btn').click()
const editor = page.locator('.ProseMirror')
await expect(editor).toContainText('林远', { timeout: 10_000 })
await expect(editor).toContainText('苏晴')
await app.close()
})
})