Files
bilin/e2e/knowledge-injection-history.spec.ts
T
bing d4122c8f95 feat: ship v0.9.0 with pomodoro, achievements, and injection history
Add pomodoro timer with goal notifications, writing streak milestones, and knowledge injection logging with UI previews across AI writing flows.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 19:15:52 +08:00

109 lines
4.6 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')
if (await page.getByText('欢迎使用笔临').isVisible()) {
await page.getByRole('button', { name: '跳过' }).click()
}
}
async function openBookWithContent(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 })
const cockpit = page.locator('[data-testid="cockpit-modal"]')
if (await cockpit.isVisible({ timeout: 3000 }).catch(() => false)) {
await page.locator('[data-testid="cockpit-modal"] .modal-close').click()
}
await page.getByRole('button', { name: '+ 新章' }).click()
const editor = page.locator('.ProseMirror')
await expect(editor).toBeVisible({ timeout: 10_000 })
await editor.click()
await editor.pressSequentially('林远站在演武场中央,众人目光汇聚。')
await page.keyboard.press('Control+s')
await expect(page.getByText('已保存')).toBeVisible({ timeout: 15_000 })
}
async function addApprovedKnowledge(page: Page, title: string): Promise<string> {
await page.locator('[data-testid="panel-tab-knowledge"]').click()
await page.locator('[data-testid="knowledge-new"]').click()
await page.locator('[data-testid="knowledge-title-input"]').fill(title)
await page.locator('[data-testid="knowledge-save"]').click()
await page.locator('[data-testid="knowledge-tab-pending"]').click()
const approveBtn = page.locator('[data-testid^="knowledge-approve-"]').first()
const testId = await approveBtn.getAttribute('data-testid')
await approveBtn.click()
const entryId = testId?.replace('knowledge-approve-', '') ?? ''
return entryId
}
async function openWizardToContext(page: Page): Promise<void> {
await page.getByTestId('panel-tab-ai').click()
await page.getByTestId('ai-session-new').click()
await expect(page.getByTestId('ai-mode-tab-wizard')).toBeEnabled({ timeout: 10_000 })
await page.getByTestId('ai-mode-tab-wizard').click()
await expect(page.getByTestId('wizard-panel')).toBeVisible({ timeout: 10_000 })
await page.getByTestId('wizard-goal-input').fill('林远通过入门考核')
await page.getByRole('button', { name: '下一步' }).click()
await page.getByTestId('wizard-rhythm-mixed').click()
await page.getByRole('button', { name: '下一步' }).click()
await page.getByRole('button', { name: '下一步' }).click()
await expect(page.getByTestId('wizard-context-edit')).toBeVisible({ timeout: 10_000 })
}
test.describe('Knowledge injection history P6.1', () => {
let userDataDir: string
test.beforeEach(() => {
userDataDir = mkdtempSync(join(tmpdir(), 'bilin-e2e-inj-'))
})
test.afterEach(async () => {
if (userDataDir && existsSync(userDataDir)) {
try {
rmSync(userDataDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 })
} catch {
/* ignore */
}
}
})
test('E2E-INJ-01: wizard confirmContext shows injection preview', async () => {
const app = await launchApp(userDataDir)
const page = await app.firstWindow()
await skipOnboarding(page)
await openBookWithContent(page)
const entryId = await addApprovedKnowledge(page, '测灵石异常')
expect(entryId).toBeTruthy()
await openWizardToContext(page)
await page.getByTestId('wizard-context-edit').click()
await expect(page.getByTestId('context-editor-modal')).toBeVisible({ timeout: 10_000 })
await page.getByTestId('context-tab-knowledge').click()
await page.locator(`[data-testid="context-knowledge-item-${entryId}"] input`).check()
await page.getByTestId('context-save').click()
await page.getByRole('button', { name: '下一步' }).click()
await page.locator('[data-testid="panel-tab-knowledge"]').click()
await page.locator('[data-testid="knowledge-tab-all"]').click()
await expect(page.locator(`[data-testid="knowledge-injection-preview-${entryId}"]`)).toBeVisible({
timeout: 10_000
})
await app.close()
})
})