aac51bf183
Implement schema v2 migration, outline/setting/inspiration CRUD, unified TipTap editing, reference panel with mentions, FTS global search, chapter version history, writing landmarks, word frequency analysis, light theme contrast fixes, and full unit/E2E test coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
88 lines
3.0 KiB
TypeScript
88 lines
3.0 KiB
TypeScript
import path from 'path'
|
|
import { mkdtempSync, rmSync, existsSync } from 'fs'
|
|
import { join } from 'path'
|
|
import { tmpdir } from 'os'
|
|
import { test, expect, _electron as electron, type Page } from '@playwright/test'
|
|
|
|
const ROOT = path.join(import.meta.dirname, '..')
|
|
|
|
async function launchApp(userDataDir: string) {
|
|
return electron.launch({
|
|
args: [ROOT],
|
|
env: {
|
|
...process.env,
|
|
BILIN_E2E: '1',
|
|
BILIN_E2E_USER_DATA: userDataDir
|
|
}
|
|
})
|
|
}
|
|
|
|
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()
|
|
await expect(page.getByText('欢迎使用笔临')).toBeHidden({ timeout: 10_000 })
|
|
}
|
|
}
|
|
|
|
async function createAndOpenBook(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 })
|
|
}
|
|
|
|
test.describe('Outline persistence', () => {
|
|
let userDataDir: string
|
|
|
|
test.beforeEach(() => {
|
|
userDataDir = mkdtempSync(join(tmpdir(), 'bilin-e2e-outline-'))
|
|
})
|
|
|
|
test.afterEach(() => {
|
|
if (userDataDir && existsSync(userDataDir)) {
|
|
try {
|
|
rmSync(userDataDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 })
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|
|
})
|
|
|
|
test('E2E-OUTLINE: outline content persists after restart', async () => {
|
|
const app1 = await launchApp(userDataDir)
|
|
const page1 = await app1.firstWindow()
|
|
await skipOnboarding(page1)
|
|
await createAndOpenBook(page1, '持久化测试书')
|
|
|
|
await page1.getByTestId('sidebar-tab-outline').click()
|
|
await expect(page1.getByTestId('outline-new')).toBeVisible({ timeout: 5_000 })
|
|
await page1.getByTestId('outline-new').click()
|
|
await expect(page1.locator('#editor-layout')).toBeVisible({ timeout: 5_000 })
|
|
await expect(page1.locator('.outline-item').first()).toBeVisible({ timeout: 15_000 })
|
|
|
|
const editor = page1.locator('.ProseMirror')
|
|
await expect(editor).toBeVisible({ timeout: 10_000 })
|
|
await editor.click()
|
|
await editor.pressSequentially('主角踏上旅程的关键转折点')
|
|
await page1.waitForTimeout(3000)
|
|
|
|
await app1.close()
|
|
|
|
const app2 = await launchApp(userDataDir)
|
|
const page2 = await app2.firstWindow()
|
|
await skipOnboarding(page2)
|
|
await page2.getByText('持久化测试书').click()
|
|
await expect(page2.locator('#editor-layout')).toBeVisible({ timeout: 15_000 })
|
|
|
|
await page2.getByTestId('sidebar-tab-outline').click()
|
|
await page2.locator('.outline-item').first().click()
|
|
await expect(page2.locator('.ProseMirror')).toContainText('主角踏上旅程的关键转折点', {
|
|
timeout: 10_000
|
|
})
|
|
|
|
await app2.close()
|
|
})
|
|
})
|