Files
bilin/e2e/helpers.ts
bing 8e5045b882 fix(test): stabilize E2E cockpit flow and add LM Studio novel integration test
Harden cockpit dismiss timing and global settings navigation in E2E helpers, tune short-chapter AI prompts for local models, fix electron-updater CJS loading, and add a 10-chapter auto-writing integration test against LM Studio.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-09 14:03:19 +08:00

105 lines
4.2 KiB
TypeScript

import path from 'path'
import { _electron as electron, type ElectronApplication, type Page, expect } from '@playwright/test'
export const ROOT = path.join(import.meta.dirname, '..')
export async function launchApp(
userDataDir: string,
extraEnv: Record<string, string> = {}
): Promise<ElectronApplication> {
return electron.launch({
args: [ROOT],
env: { ...process.env, BILIN_E2E: '1', BILIN_E2E_USER_DATA: userDataDir, ...extraEnv }
})
}
export async function skipOnboarding(page: Page): Promise<void> {
await page.waitForLoadState('domcontentloaded')
await expect(page.locator('#app')).toBeVisible({ timeout: 20_000 })
if (await page.getByText('欢迎使用笔临').isVisible()) {
await page.getByRole('button', { name: '跳过' }).click()
}
}
export async function dismissCockpitIfOpen(page: Page): Promise<void> {
const cockpit = page.locator('[data-testid="cockpit-modal"]')
try {
await cockpit.waitFor({ state: 'visible', timeout: 15_000 })
await cockpit.locator('.modal-close').click()
await expect(cockpit).toBeHidden({ timeout: 5000 })
} catch {
/* cockpit did not open */
}
}
export async function openGlobalSettings(page: Page): Promise<void> {
await page.getByTestId('topbar-settings').click()
await expect(page.locator('#settings-page')).toBeVisible({ timeout: 10_000 })
}
export async function createBookAndOpenEditor(page: Page, name: string): Promise<void> {
await page.getByRole('button', { name: /新建书籍/ }).first().click()
await page.locator('.dialog-content input').first().fill(name)
await page.getByRole('button', { name: '创建' }).click()
await expect(page.locator('#editor-layout')).toBeVisible({ timeout: 15_000 })
await dismissCockpitIfOpen(page)
}
export async function ensureChapterEditor(page: Page): Promise<void> {
await dismissCockpitIfOpen(page)
const editor = page.locator('.ProseMirror')
if (await editor.isVisible().catch(() => false)) return
await page.getByRole('button', { name: '+ 新章' }).click()
await expect(editor).toBeVisible({ timeout: 10_000 })
}
export async function openInspirationModal(page: Page): Promise<void> {
await page.keyboard.press('Control+Shift+I')
const modal = page.getByTestId('inspiration-modal')
if (!(await modal.isVisible().catch(() => false))) {
await page.evaluate(() => window.dispatchEvent(new Event('bilin:e2e-capture-inspiration')))
}
await expect(modal).toBeVisible({ timeout: 10_000 })
}
export async function openExportModal(page: Page): Promise<void> {
await page.keyboard.press('Control+Shift+E')
const modal = page.getByTestId('export-modal')
if (!(await modal.isVisible().catch(() => false))) {
await page.getByTestId('open-export').click()
}
await expect(modal).toBeVisible({ timeout: 10_000 })
}
export async function openExportAllModal(page: Page): Promise<void> {
await page.getByTestId('home-export-all').click()
await expect(page.getByTestId('export-all-modal')).toBeVisible({ timeout: 10_000 })
}
export async function openImportBookModal(page: Page): Promise<void> {
await page.getByTestId('home-import-book').click()
await expect(page.getByTestId('import-book-modal')).toBeVisible({ timeout: 10_000 })
}
export async function openBookSettings(page: Page): Promise<void> {
await page.getByTestId('panel-tab-book-settings').click()
await expect(page.getByTestId('book-settings-tab')).toBeVisible({ timeout: 10_000 })
}
export async function openCharacterSetting(page: Page, name: string): Promise<void> {
await page.getByTestId('sidebar-tab-setting').click()
await page.getByTestId(/^setting-item-/).filter({ hasText: name }).first().click()
await expect(page.getByTestId('setting-relationships')).toBeVisible({ timeout: 15_000 })
}
export async function addCharacterSetting(page: Page, name: string): Promise<void> {
await page.getByTestId('sidebar-tab-setting').click()
await page.getByTestId('setting-new').click()
await page.getByTestId('setting-name-input').fill(name)
await page.locator('.dialog-content select').selectOption('character')
await page.getByRole('button', { name: '创建' }).click()
await expect(page.getByTestId(/setting-item-/).filter({ hasText: name })).toBeVisible({
timeout: 10_000
})
}