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>
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
import path from 'path'
|
||||
import { mkdtempSync, rmSync, existsSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { tmpdir } from 'os'
|
||||
import { DatabaseSync } from 'node:sqlite'
|
||||
import { test, expect, _electron as electron, type Page } from '@playwright/test'
|
||||
|
||||
const ROOT = path.join(import.meta.dirname, '..')
|
||||
|
||||
async function launchApp(userDataDir: string, extraEnv: Record<string, string> = {}) {
|
||||
return electron.launch({
|
||||
args: [ROOT],
|
||||
env: {
|
||||
...process.env,
|
||||
BILIN_E2E: '1',
|
||||
BILIN_E2E_USER_DATA: userDataDir,
|
||||
...extraEnv
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
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 dismissCockpitIfOpen(page: Page): Promise<void> {
|
||||
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 expect(cockpit).toBeHidden({ timeout: 5000 })
|
||||
}
|
||||
}
|
||||
|
||||
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 })
|
||||
await dismissCockpitIfOpen(page)
|
||||
}
|
||||
|
||||
async function ensureChapterEditor(page: Page): Promise<void> {
|
||||
const items = page.locator('.chapter-item')
|
||||
if ((await items.count()) === 0) {
|
||||
await page.getByRole('button', { name: '+ 新章' }).click()
|
||||
} else {
|
||||
await items.first().click()
|
||||
}
|
||||
await expect(page.locator('.ProseMirror')).toBeVisible({ timeout: 10_000 })
|
||||
}
|
||||
|
||||
function seedMilestone(userDataDir: string, bookId: string, milestone: string): void {
|
||||
const dbPath = join(userDataDir, 'writing_logs.sqlite')
|
||||
const db = new DatabaseSync(dbPath)
|
||||
db.prepare('INSERT INTO writing_milestones (book_id, milestone) VALUES (?, ?)').run(
|
||||
bookId,
|
||||
milestone
|
||||
)
|
||||
db.close()
|
||||
}
|
||||
|
||||
test.describe('Writing goals P5.3', () => {
|
||||
let userDataDir: string
|
||||
|
||||
test.beforeEach(() => {
|
||||
userDataDir = mkdtempSync(join(tmpdir(), 'bilin-e2e-goal-'))
|
||||
})
|
||||
|
||||
test.afterEach(async () => {
|
||||
if (userDataDir && existsSync(userDataDir)) {
|
||||
try {
|
||||
rmSync(userDataDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 })
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test('E2E-GOAL-01: daily goal met shows progress and toast', async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await createAndOpenBook(page, '目标测试书')
|
||||
await ensureChapterEditor(page)
|
||||
|
||||
await page.getByRole('button', { name: '设置' }).click()
|
||||
await page.locator('[data-testid="settings-daily-word-goal"]').fill('100')
|
||||
await page.getByRole('button', { name: '书籍' }).click()
|
||||
await ensureChapterEditor(page)
|
||||
|
||||
const editor = page.locator('.ProseMirror')
|
||||
await editor.click()
|
||||
await editor.pressSequentially(
|
||||
'这是一段用于测试每日写作目标达标的示例文字,需要足够长度才能触发字数统计与达标提醒通知。'
|
||||
)
|
||||
await page.waitForTimeout(1500)
|
||||
|
||||
await expect(page.locator('[data-testid="status-daily-goal"].goal-met')).toBeVisible({
|
||||
timeout: 15_000
|
||||
})
|
||||
await expect(page.locator('.toast')).toContainText(/目标|goal/i, { timeout: 10_000 })
|
||||
await app.close()
|
||||
})
|
||||
|
||||
test('E2E-GOAL-02: cockpit shows unlocked achievement badge', async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await createAndOpenBook(page, '成就测试书')
|
||||
const bookId = await page.evaluate(async () => {
|
||||
const res = await window.electronAPI.book.list()
|
||||
return res.ok ? res.data[0]?.id : null
|
||||
})
|
||||
expect(bookId).toBeTruthy()
|
||||
await app.close()
|
||||
|
||||
seedMilestone(userDataDir, bookId!, 'streak_7')
|
||||
|
||||
const app2 = await launchApp(userDataDir)
|
||||
const page2 = await app2.firstWindow()
|
||||
await skipOnboarding(page2)
|
||||
await page2.locator('.book-card').filter({ hasText: '成就测试书' }).click()
|
||||
await expect(page2.locator('#editor-layout')).toBeVisible({ timeout: 15_000 })
|
||||
await dismissCockpitIfOpen(page2)
|
||||
await page2.getByTestId('topbar-cockpit').click()
|
||||
await expect(page2.locator('[data-testid="cockpit-modal"]')).toBeVisible({ timeout: 10_000 })
|
||||
const badge = page2.locator('[data-testid="cockpit-achievements"] .cockpit-achievement-badge.unlocked')
|
||||
await expect(badge).toHaveCount(1, { timeout: 10_000 })
|
||||
await app2.close()
|
||||
})
|
||||
|
||||
test('E2E-GOAL-03: pomodoro completes with toast', async () => {
|
||||
const app = await launchApp(userDataDir, { POMODORO_TEST_SEC: '3' })
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await createAndOpenBook(page, '番茄测试书')
|
||||
await ensureChapterEditor(page)
|
||||
|
||||
await page.locator('[data-testid="pomodoro-control"] button').first().click()
|
||||
await expect(page.locator('.pomodoro-time')).toBeVisible()
|
||||
await page.waitForTimeout(4500)
|
||||
await expect(page.locator('.toast')).toContainText(/番茄|Pomodoro|完成|complete/i, {
|
||||
timeout: 10_000
|
||||
})
|
||||
await app.close()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user