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 management', () => { let userDataDir: string test.beforeEach(() => { userDataDir = mkdtempSync(join(tmpdir(), 'bilin-e2e-chapter-mgmt-')) }) test.afterEach(() => { if (userDataDir && existsSync(userDataDir)) { try { rmSync(userDataDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 }) } catch { /* ignore */ } } }) test('E2E-CHAP-01: double-click rename and delete chapter', async () => { const app = await launchApp(userDataDir) const page = await app.firstWindow() await skipOnboarding(page) await createBookAndOpenEditor(page, '章节管理书') await ensureChapterEditor(page) await page.getByTestId('sidebar-tab-chapters').click() const firstChapter = page.locator('.chapter-item').first() await expect(firstChapter).toBeVisible({ timeout: 10_000 }) const chapterTestId = await firstChapter.getAttribute('data-testid') const chapterId = chapterTestId?.replace('chapter-item-', '') ?? '' expect(chapterId).toBeTruthy() await firstChapter.dblclick() const renameInput = page.getByTestId(`chapter-rename-${chapterId}`) await expect(renameInput).toBeVisible({ timeout: 5000 }) await renameInput.fill('重命名章节') await renameInput.blur() await expect(firstChapter).toContainText('重命名章节', { timeout: 10_000 }) await page.getByRole('button', { name: '+ 新章' }).click() await expect(page.locator('.chapter-item')).toHaveCount(2, { timeout: 10_000 }) page.once('dialog', (dialog) => dialog.accept()) await firstChapter.hover() await page.getByTestId(`chapter-delete-${chapterId}`).click() await expect(page.locator('.chapter-item')).toHaveCount(1, { timeout: 10_000 }) await app.close() }) })