import { mkdtempSync, rmSync, existsSync, statSync } from 'fs' import { join } from 'path' import { tmpdir } from 'os' import { test, expect } from '@playwright/test' import { launchApp, skipOnboarding, createBookAndOpenEditor, ensureChapterEditor, openExportModal, dismissCockpitIfOpen } from './helpers' test.describe('Export matrix', () => { let userDataDir: string let pdfPath: string test.beforeEach(() => { userDataDir = mkdtempSync(join(tmpdir(), 'bilin-e2e-matrix-')) pdfPath = join(userDataDir, 'chapter.pdf') }) test.afterEach(() => { if (userDataDir && existsSync(userDataDir)) { try { rmSync(userDataDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 }) } catch { /* ignore */ } } }) test('E2E-PDF-01: export chapter as PDF', async () => { const app = await launchApp(userDataDir, { BILIN_E2E_PDF_SAVE: pdfPath }) const page = await app.firstWindow() await skipOnboarding(page) await createBookAndOpenEditor(page, 'PDF导出测试') await dismissCockpitIfOpen(page) await ensureChapterEditor(page) const editor = page.locator('.ProseMirror') await editor.click() await editor.pressSequentially('PDF导出测试正文。') await page.keyboard.press('Control+S') await openExportModal(page) await page.getByTestId('export-kind-select').selectOption('matrix') await page.getByTestId('export-matrix-format').selectOption('pdf') await page.getByTestId('export-matrix-scope').selectOption('chapter') await page.getByTestId('export-matrix-btn').click() await expect(page.getByText(/已保存|Saved to/)).toBeVisible({ timeout: 30_000 }) expect(existsSync(pdfPath)).toBe(true) expect(statSync(pdfPath).size).toBeGreaterThan(500) await app.close() }) })