Files
bilin/e2e/chapter-management.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

56 lines
2.0 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 } 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()
})
})