feat: deliver P2 v0.2.0 with unified editor, search, and snapshots
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>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
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')
|
||||
if (await page.getByText('欢迎使用笔临').isVisible()) {
|
||||
await page.getByRole('button', { name: '跳过' }).click()
|
||||
}
|
||||
}
|
||||
|
||||
async function createAndOpenBook(page: Page): Promise<void> {
|
||||
await page.getByRole('button', { name: /新建书籍/ }).first().click()
|
||||
await page.locator('.dialog-content input').first().fill('覆盖度测试')
|
||||
await page.getByRole('button', { name: '创建' }).click()
|
||||
await expect(page.locator('#editor-layout')).toBeVisible({ timeout: 15_000 })
|
||||
}
|
||||
|
||||
test.describe('Outline coverage', () => {
|
||||
let userDataDir: string
|
||||
|
||||
test.beforeEach(() => {
|
||||
userDataDir = mkdtempSync(join(tmpdir(), 'bilin-e2e-cov-'))
|
||||
})
|
||||
|
||||
test.afterEach(() => {
|
||||
if (userDataDir && existsSync(userDataDir)) {
|
||||
try {
|
||||
rmSync(userDataDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 })
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test('E2E-COV-01: uncovered outline shows warning border', async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await createAndOpenBook(page)
|
||||
await page.getByTestId('sidebar-tab-outline').click()
|
||||
await page.getByTestId('outline-new').click()
|
||||
await expect(page.locator('.outline-item[data-uncovered="true"]').first()).toBeVisible({
|
||||
timeout: 10_000
|
||||
})
|
||||
await expect(page.locator('[data-testid="outline-warn"]').first()).toBeVisible()
|
||||
await app.close()
|
||||
})
|
||||
|
||||
test('E2E-COV-02: filter uncovered hides covered items', async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await createAndOpenBook(page)
|
||||
await page.getByTestId('sidebar-tab-outline').click()
|
||||
await page.getByTestId('outline-new').click()
|
||||
await expect(page.locator('.outline-item').first()).toBeVisible({ timeout: 10_000 })
|
||||
await page.getByTestId('outline-filter').selectOption('uncovered')
|
||||
await expect(page.locator('.outline-item[data-uncovered="true"]')).toHaveCount(1)
|
||||
await app.close()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,87 @@
|
||||
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()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,189 @@
|
||||
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')
|
||||
if (await page.getByText('欢迎使用笔临').isVisible()) {
|
||||
await page.getByRole('button', { name: '跳过' }).click()
|
||||
}
|
||||
}
|
||||
|
||||
async function createAndOpenBook(page: Page, name = 'P2测试书'): 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 })
|
||||
}
|
||||
|
||||
async function ensureChapterEditor(page: Page): Promise<void> {
|
||||
await page.getByRole('button', { name: '+ 新章' }).click()
|
||||
await expect(page.locator('.ProseMirror')).toBeVisible({ timeout: 10_000 })
|
||||
}
|
||||
|
||||
test.describe('P2 features', () => {
|
||||
let userDataDir: string
|
||||
|
||||
test.beforeEach(() => {
|
||||
userDataDir = mkdtempSync(join(tmpdir(), 'bilin-e2e-p2-'))
|
||||
})
|
||||
|
||||
test.afterEach(() => {
|
||||
if (userDataDir && existsSync(userDataDir)) {
|
||||
try {
|
||||
rmSync(userDataDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 })
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test('E2E-P2-REF-01: reference panel drag inserts setting text', async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await createAndOpenBook(page)
|
||||
await ensureChapterEditor(page)
|
||||
|
||||
await page.getByTestId('sidebar-tab-setting').click()
|
||||
await page.getByTestId('setting-new').click()
|
||||
await page.getByTestId('setting-name-input').fill('主角林远')
|
||||
await page.locator('.dialog-content select').selectOption('character')
|
||||
await page.getByRole('button', { name: '创建' }).click()
|
||||
await expect(page.getByTestId(/setting-item-/)).toBeVisible({ timeout: 10_000 })
|
||||
|
||||
const editor = page.locator('.ProseMirror')
|
||||
await editor.click()
|
||||
await page.getByTestId('open-reference').click()
|
||||
await expect(page.getByTestId('reference-panel')).toBeVisible()
|
||||
|
||||
const refItem = page.locator('[data-testid^="ref-item-"]').first()
|
||||
await refItem.dragTo(editor)
|
||||
await page.evaluate(() => {
|
||||
const editorEl = document.querySelector('.ProseMirror')
|
||||
if (!editorEl) return
|
||||
const rect = editorEl.getBoundingClientRect()
|
||||
const dt = new DataTransfer()
|
||||
dt.setData('text/plain', '主角林远')
|
||||
editorEl.dispatchEvent(
|
||||
new DragEvent('drop', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
clientX: rect.left + rect.width / 2,
|
||||
clientY: rect.top + rect.height / 2,
|
||||
dataTransfer: dt
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
await expect(editor).toContainText('主角', { timeout: 5_000 })
|
||||
await app.close()
|
||||
})
|
||||
|
||||
test('E2E-P2-SEARCH-01: global search finds chapter text and jumps', async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await createAndOpenBook(page)
|
||||
await ensureChapterEditor(page)
|
||||
|
||||
const unique = '搜索专用词XYZ'
|
||||
const editor = page.locator('.ProseMirror')
|
||||
await editor.click()
|
||||
await editor.pressSequentially(unique)
|
||||
await page.keyboard.press('Control+S')
|
||||
await expect(page.getByText('已保存')).toBeVisible({ timeout: 10_000 })
|
||||
|
||||
await page.evaluate(() => window.dispatchEvent(new Event('bilin:e2e-open-search')))
|
||||
await expect(page.getByTestId('search-modal')).toBeVisible({ timeout: 5_000 })
|
||||
await page.getByTestId('search-input').fill(unique)
|
||||
await expect(page.locator('.search-result').first()).toBeVisible({ timeout: 10_000 })
|
||||
await page.keyboard.press('Enter')
|
||||
await expect(page.getByTestId('search-modal')).toBeHidden({ timeout: 5_000 })
|
||||
await expect(editor).toContainText(unique)
|
||||
await app.close()
|
||||
})
|
||||
|
||||
test('E2E-P2-SNAP-01: manual snapshot shows diff', async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await createAndOpenBook(page)
|
||||
await ensureChapterEditor(page)
|
||||
|
||||
const editor = page.locator('.ProseMirror')
|
||||
await editor.click()
|
||||
await editor.pressSequentially('版本快照内容A')
|
||||
await page.waitForTimeout(2500)
|
||||
|
||||
await page.getByTestId('open-version').click()
|
||||
await expect(page.getByTestId('version-modal')).toBeVisible()
|
||||
await page.getByRole('button', { name: '创建快照' }).click()
|
||||
await expect(page.locator('.version-item').first()).toBeVisible({ timeout: 10_000 })
|
||||
await page.getByRole('button', { name: '取消' }).click()
|
||||
await expect(page.getByTestId('version-modal')).toBeHidden()
|
||||
|
||||
await editor.click()
|
||||
await editor.press('Control+a')
|
||||
await editor.pressSequentially('版本快照内容B')
|
||||
await page.waitForTimeout(2500)
|
||||
|
||||
await page.getByTestId('open-version').click()
|
||||
await page.locator('.version-item').first().click()
|
||||
await expect(page.locator('.diff-view')).toContainText('内容')
|
||||
await app.close()
|
||||
})
|
||||
|
||||
test('E2E-P2-LAND-01: insert landmark appears in list modal', async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await createAndOpenBook(page)
|
||||
await ensureChapterEditor(page)
|
||||
|
||||
await page.evaluate(() => {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('bilin:e2e-insert-landmark', { detail: { label: '待查伏笔' } })
|
||||
)
|
||||
})
|
||||
await expect(page.locator('.landmark-mark')).toContainText('待查伏笔', { timeout: 5_000 })
|
||||
|
||||
await page.evaluate(() => window.dispatchEvent(new Event('bilin:e2e-open-landmarks')))
|
||||
await expect(page.getByTestId('landmarks-modal')).toBeVisible({ timeout: 5_000 })
|
||||
await expect(page.locator('[data-testid^="landmark-item-"]')).toContainText('待查伏笔')
|
||||
await app.close()
|
||||
})
|
||||
|
||||
test('E2E-P2-WORD-01: word frequency click selects token in editor', async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await createAndOpenBook(page)
|
||||
await ensureChapterEditor(page)
|
||||
|
||||
const token = '测'
|
||||
const editor = page.locator('.ProseMirror')
|
||||
await editor.click()
|
||||
await editor.pressSequentially(token.repeat(20))
|
||||
await page.keyboard.press('Control+S')
|
||||
await expect(page.getByText('已保存')).toBeVisible({ timeout: 10_000 })
|
||||
|
||||
await page.getByTestId('panel-tab-wordfreq').click()
|
||||
await expect(page.getByTestId('wordfreq-panel')).toBeVisible()
|
||||
await expect(page.getByTestId(`wordfreq-${token}`)).toBeVisible({ timeout: 10_000 })
|
||||
await page.getByTestId(`wordfreq-${token}`).click()
|
||||
await expect(page.locator('.editor-content-wrap')).toHaveAttribute('data-highlight-token', token)
|
||||
await app.close()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,146 @@
|
||||
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, '..')
|
||||
|
||||
const LIGHT_THEMES = ['ricepaper', 'mist', 'teagarden'] as const
|
||||
|
||||
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 openSettings(page: Page): Promise<void> {
|
||||
await page.getByRole('button', { name: /系统设置/ }).click()
|
||||
await expect(page.locator('#settings-page')).toBeVisible()
|
||||
}
|
||||
|
||||
function parseRgb(color: string): [number, number, number] | null {
|
||||
const m = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/)
|
||||
if (!m) return null
|
||||
return [Number(m[1]), Number(m[2]), Number(m[3])]
|
||||
}
|
||||
|
||||
function relativeLuminance(r: number, g: number, b: number): number {
|
||||
const [rs, gs, bs] = [r, g, b].map((c) => {
|
||||
const s = c / 255
|
||||
return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4)
|
||||
})
|
||||
return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs
|
||||
}
|
||||
|
||||
function contrastRatio(fg: string, bg: string): number {
|
||||
const fgRgb = parseRgb(fg)
|
||||
const bgRgb = parseRgb(bg)
|
||||
if (!fgRgb || !bgRgb) return 0
|
||||
const l1 = relativeLuminance(...fgRgb)
|
||||
const l2 = relativeLuminance(...bgRgb)
|
||||
const lighter = Math.max(l1, l2)
|
||||
const darker = Math.min(l1, l2)
|
||||
return (lighter + 0.05) / (darker + 0.05)
|
||||
}
|
||||
|
||||
test.describe('Theme contrast', () => {
|
||||
let userDataDir: string
|
||||
|
||||
test.beforeEach(() => {
|
||||
userDataDir = mkdtempSync(join(tmpdir(), 'bilin-e2e-contrast-'))
|
||||
})
|
||||
|
||||
test.afterEach(() => {
|
||||
if (userDataDir && existsSync(userDataDir)) {
|
||||
try {
|
||||
rmSync(userDataDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 })
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
for (const theme of LIGHT_THEMES) {
|
||||
test(`E2E-CONTRAST: ${theme} theme has readable form controls`, async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await openSettings(page)
|
||||
|
||||
await page.getByTestId('settings-theme').selectOption(theme)
|
||||
await expect(page.locator('html')).toHaveAttribute('data-theme', theme)
|
||||
|
||||
await expect(page.getByRole('heading', { name: '系统设置' })).toBeVisible()
|
||||
await expect(page.locator('.setting-item').first()).toBeVisible()
|
||||
|
||||
const penNameOk = await page.evaluate(() => {
|
||||
const el = document.querySelector('[data-testid="settings-pen-name"]') as HTMLElement | null
|
||||
if (!el) return false
|
||||
const cs = getComputedStyle(el)
|
||||
const fg = cs.color
|
||||
const bg = cs.backgroundColor
|
||||
if (fg === 'rgba(0, 0, 0, 0)' || bg === 'rgba(0, 0, 0, 0)') return false
|
||||
if (fg === bg) return false
|
||||
return true
|
||||
})
|
||||
expect(penNameOk).toBe(true)
|
||||
|
||||
const ratio = await page.evaluate(() => {
|
||||
const el = document.querySelector('[data-testid="settings-pen-name"]') as HTMLElement
|
||||
const cs = getComputedStyle(el)
|
||||
return { fg: cs.color, bg: cs.backgroundColor }
|
||||
})
|
||||
expect(contrastRatio(ratio.fg, ratio.bg)).toBeGreaterThanOrEqual(4.5)
|
||||
|
||||
await app.close()
|
||||
})
|
||||
}
|
||||
|
||||
test('E2E-CONTRAST: light themes show visible headings on main page', async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await openSettings(page)
|
||||
|
||||
for (const theme of LIGHT_THEMES) {
|
||||
await page.getByTestId('settings-theme').selectOption(theme)
|
||||
await page.locator('.logo-area').click()
|
||||
await expect(page.locator('#settings-page')).toBeHidden()
|
||||
|
||||
const headingVisible = await page.evaluate(() => {
|
||||
const selectors = ['h1', 'h2', 'button', '.setting-item']
|
||||
for (const sel of selectors) {
|
||||
const el = document.querySelector(`#app ${sel}`) as HTMLElement | null
|
||||
if (!el) continue
|
||||
const cs = getComputedStyle(el)
|
||||
if (cs.visibility === 'hidden' || cs.display === 'none') continue
|
||||
const fg = cs.color
|
||||
if (fg === 'rgba(0, 0, 0, 0)') continue
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
expect(headingVisible).toBe(true)
|
||||
|
||||
await page.getByRole('button', { name: '⚙ 系统设置' }).click()
|
||||
await expect(page.locator('#settings-page')).toBeVisible()
|
||||
}
|
||||
|
||||
await app.close()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user