fix(editor): C2 review round 1, i18n format, flip test observer
Restore i18n files from base and add only add_cancel. The flip test counted announcements with a happy-dom MutationObserver whose callback sits in a WeakRef (lost on GC); count the DOM setters instead.
This commit is contained in:
1 parent
d1779928a9
commit
c8109af719
3 files changed
+563
-937
No files matched your search
+252
-434
File diff suppressed because it is too large.
Load diff
+269
-490
File diff suppressed because it is too large.
Load diff
@@ -96,18 +96,42 @@ const cross = (width: number) =>
|
||||
|
||||
const flush = () => act(async () => undefined)
|
||||
|
||||
/** Counts the live region's updates that carry the drop note. */
|
||||
/** The prototype object that owns a property, so a wrapper can be put back exactly. */
|
||||
function ownerOf(target: object, property: string): object {
|
||||
let owner: object | null = target
|
||||
while (owner && !Object.hasOwn(owner, property)) {
|
||||
owner = Object.getPrototypeOf(owner)
|
||||
}
|
||||
return owner!
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the live region's updates that carry the drop note. It wraps the two DOM setters
|
||||
* React uses for a text change (`textContent`, `nodeValue`) instead of using a
|
||||
* MutationObserver: happy-dom keeps an observer's callback in a WeakRef, so a garbage
|
||||
* collection under load silently ends the observation (seen as a missed announcement).
|
||||
*/
|
||||
function watchNotes() {
|
||||
const seen: string[] = []
|
||||
const observer = new MutationObserver(() => {
|
||||
if (live().textContent?.includes(NOTE)) seen.push(live().textContent!)
|
||||
})
|
||||
observer.observe(live(), {
|
||||
childList: true,
|
||||
characterData: true,
|
||||
subtree: true,
|
||||
})
|
||||
return { seen, stop: () => observer.disconnect() }
|
||||
const restore: (() => void)[] = []
|
||||
const wrap = (target: object, property: string) => {
|
||||
const owner = ownerOf(target, property)
|
||||
const original = Object.getOwnPropertyDescriptor(owner, property)!
|
||||
Object.defineProperty(owner, property, {
|
||||
...original,
|
||||
set(this: Node, value: string) {
|
||||
original.set!.call(this, value)
|
||||
const region = live()
|
||||
if (region.contains(this) && region.textContent?.includes(NOTE)) {
|
||||
seen.push(region.textContent)
|
||||
}
|
||||
},
|
||||
})
|
||||
restore.push(() => Object.defineProperty(owner, property, original))
|
||||
}
|
||||
wrap(live(), 'textContent')
|
||||
wrap(document.createTextNode(''), 'nodeValue')
|
||||
return { seen, stop: () => restore.forEach((undo) => undo()) }
|
||||
}
|
||||
|
||||
async function mount(width = 1280) {
|
||||
@@ -365,10 +389,15 @@ describe('a read-only flip in the citations panel', () => {
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull(),
|
||||
)
|
||||
expect(watch.seen).toHaveLength(1)
|
||||
expect(live().textContent).toContain(
|
||||
`${NOTE} : Citation, Adresse web (URL)`,
|
||||
// The forced close announces in a later commit than the panel's exit: wait for
|
||||
// the text itself, then let any second announcement land before counting.
|
||||
await waitFor(() =>
|
||||
expect(live().textContent).toContain(
|
||||
`${NOTE} : Citation, Adresse web (URL)`,
|
||||
),
|
||||
)
|
||||
await flush()
|
||||
expect(watch.seen).toHaveLength(1)
|
||||
watch.stop()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user