feat: 实现笔临 P0/P1 Electron 桌面应用 v0.1.0
交付写作核心(TipTap、自动保存、分卷分章)、Onboarding、7 主题与双语 i18n、快捷键设置;主进程使用 node:sqlite;补全 Vitest 与 Playwright E2E;统一 design/ 目录并移除 desigin 拼写错误路径。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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 openSettings(page: Page): Promise<void> {
|
||||
await page.getByRole('button', { name: /系统设置/ }).click()
|
||||
await expect(page.locator('#settings-page')).toBeVisible()
|
||||
}
|
||||
|
||||
test.describe('Settings', () => {
|
||||
let userDataDir: string
|
||||
|
||||
test.beforeEach(() => {
|
||||
userDataDir = mkdtempSync(join(tmpdir(), 'bilin-e2e-settings-'))
|
||||
})
|
||||
|
||||
test.afterEach(() => {
|
||||
if (userDataDir && existsSync(userDataDir)) {
|
||||
try {
|
||||
rmSync(userDataDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 })
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test('E2E-THEME: all 7 themes apply data-theme attribute', async () => {
|
||||
const themes = ['default', 'bamboo', 'moonlit', 'ricepaper', 'mist', 'teagarden', 'twilight'] as const
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await openSettings(page)
|
||||
|
||||
for (const theme of themes) {
|
||||
await page.getByTestId('settings-theme').selectOption(theme)
|
||||
const attr = await page.evaluate(() => document.documentElement.getAttribute('data-theme'))
|
||||
if (theme === 'default') {
|
||||
expect(attr).toBeNull()
|
||||
} else {
|
||||
expect(attr).toBe(theme)
|
||||
}
|
||||
}
|
||||
|
||||
await app.close()
|
||||
})
|
||||
|
||||
test('E2E-I18N: language switch updates UI text', async () => {
|
||||
const app = await launchApp(userDataDir)
|
||||
const page = await app.firstWindow()
|
||||
await skipOnboarding(page)
|
||||
await openSettings(page)
|
||||
|
||||
await expect(page.getByRole('heading', { name: '系统设置' })).toBeVisible()
|
||||
await page.getByTestId('settings-language').selectOption('en')
|
||||
await expect(page.getByRole('heading', { name: 'Settings' })).toBeVisible({ timeout: 5_000 })
|
||||
await expect(page.locator('.settings-nav-item.active')).toHaveText('General')
|
||||
|
||||
await page.getByTestId('settings-language').selectOption('zh-CN')
|
||||
await expect(page.getByText('通用')).toBeVisible({ timeout: 5_000 })
|
||||
|
||||
await app.close()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user