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 } 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() }) })