guanghu/e2e/debug-content-bug.spec.ts
冰朔 8739805f99
Some checks failed
Auto-update PR branches / Update open PR branches (push) Has been cancelled
CI / Frontend Static Quality Checks (push) Has been cancelled
CI / Frontend Tests & Coverage (push) Has been cancelled
CI / Rust Tests & Quality Checks (push) Has been cancelled
CI / Linux build verification (push) Has been cancelled
Release (Alpha) / Compute alpha version (push) Has been cancelled
Release (Alpha) / Build release artifacts (push) Has been cancelled
Release (Alpha) / GitHub Release (alpha) (push) Has been cancelled
Release (Alpha) / Update docs and release pages (push) Has been cancelled
Deploy docs / Build VitePress site (push) Has been cancelled
Deploy docs / Deploy to GitHub Pages (push) Has been cancelled
光湖开源源码快照 · Tolaria AGPL 分叉基线 · 独立更新链
2026-07-05 17:45:16 +08:00

39 lines
1.4 KiB
TypeScript

import { test, expect } from '@playwright/test'
test.use({ baseURL: 'http://localhost:5201' })
/**
* Regression test: editor content must appear after clicking a note.
*
* Root cause: BlockNote's replaceBlocks/insertBlocks internally calls flushSync,
* which fails silently when invoked from inside React's useEffect lifecycle.
* Fix: defer the content swap via queueMicrotask.
*/
test('editor content appears on first note click', async ({ page }) => {
const errors: string[] = []
page.on('console', msg => {
if (msg.type() === 'error') errors.push(msg.text())
})
await page.goto('/')
// Wait for note list to load
await page.waitForSelector('.app__note-list .cursor-pointer', { timeout: 15000 })
await page.waitForTimeout(200)
// Click the first note in the note list
const noteList = page.locator('.app__note-list')
const firstNote = noteList.locator('.cursor-pointer').first()
await firstNote.click()
// Wait for ProseMirror editor to have content
const pm = page.locator('.ProseMirror')
await expect(async () => {
const text = await pm.textContent()
expect(text?.trim().length, 'Editor content should not be empty').toBeGreaterThan(5)
}).toPass({ timeout: 5000 })
// Verify no flushSync errors appeared
const flushSyncErrors = errors.filter(e => e.includes('flushSync'))
expect(flushSyncErrors, 'No flushSync-inside-lifecycle errors should occur').toHaveLength(0)
})