Skip to content

Commit 1c4eb9a

Browse files
committed
chore: fix tests
1 parent f90db7f commit 1c4eb9a

11 files changed

Lines changed: 819 additions & 11 deletions

File tree

packages/layout-engine/pm-adapter/src/converters/inline-converters/generic-token.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ describe('tokenNodeToRun', () => {
8888
enableRichHyperlinks: false,
8989
},
9090
undefined,
91+
undefined,
92+
true,
93+
undefined,
9194
);
9295
});
9396

@@ -107,6 +110,9 @@ describe('tokenNodeToRun', () => {
107110
enableRichHyperlinks: false,
108111
},
109112
undefined,
113+
undefined,
114+
true,
115+
undefined,
110116
);
111117
});
112118

@@ -128,6 +134,9 @@ describe('tokenNodeToRun', () => {
128134
enableRichHyperlinks: false,
129135
},
130136
undefined,
137+
undefined,
138+
true,
139+
undefined,
131140
);
132141
});
133142

@@ -146,6 +155,9 @@ describe('tokenNodeToRun', () => {
146155
expect.any(Array),
147156
hyperlinkConfig,
148157
undefined,
158+
undefined,
159+
true,
160+
undefined,
149161
);
150162
});
151163

@@ -198,6 +210,9 @@ describe('tokenNodeToRun', () => {
198210
enableRichHyperlinks: false,
199211
},
200212
undefined,
213+
undefined,
214+
true,
215+
undefined,
201216
);
202217
});
203218

@@ -214,6 +229,9 @@ describe('tokenNodeToRun', () => {
214229
[],
215230
{ enableRichHyperlinks: false },
216231
undefined,
232+
undefined,
233+
true,
234+
undefined,
217235
);
218236
});
219237

@@ -232,6 +250,9 @@ describe('tokenNodeToRun', () => {
232250
enableRichHyperlinks: false,
233251
},
234252
undefined,
253+
undefined,
254+
true,
255+
undefined,
235256
);
236257
});
237258

@@ -261,6 +282,9 @@ describe('tokenNodeToRun', () => {
261282
[],
262283
{ enableRichHyperlinks: false },
263284
undefined,
285+
undefined,
286+
true,
287+
undefined,
264288
);
265289
});
266290
});

packages/layout-engine/pm-adapter/src/converters/inline-converters/tab.test.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,15 @@ describe('tabNodeToRun', () => {
221221
tabNodeToRun({ node: tabNode, positions, tabOrdinal: 0, paragraphAttrs });
222222

223223
expect(applyMarksToRunMock).toHaveBeenCalledTimes(1);
224-
expect(applyMarksToRunMock).toHaveBeenCalledWith(expect.objectContaining({ kind: 'tab' }), [
225-
{ type: 'underline', attrs: { underlineType: 'single' } },
226-
]);
224+
expect(applyMarksToRunMock).toHaveBeenCalledWith(
225+
expect.objectContaining({ kind: 'tab' }),
226+
[{ type: 'underline', attrs: { underlineType: 'single' } }],
227+
undefined,
228+
undefined,
229+
undefined,
230+
true,
231+
undefined,
232+
);
227233
});
228234

229235
it('calls applyMarksToRun with inherited marks', () => {
@@ -238,9 +244,15 @@ describe('tabNodeToRun', () => {
238244
tabNodeToRun({ node: tabNode, positions, tabOrdinal: 0, paragraphAttrs, inheritedMarks });
239245

240246
expect(applyMarksToRunMock).toHaveBeenCalledTimes(1);
241-
expect(applyMarksToRunMock).toHaveBeenCalledWith(expect.objectContaining({ kind: 'tab' }), [
242-
{ type: 'underline', attrs: { underlineType: 'single' } },
243-
]);
247+
expect(applyMarksToRunMock).toHaveBeenCalledWith(
248+
expect.objectContaining({ kind: 'tab' }),
249+
[{ type: 'underline', attrs: { underlineType: 'single' } }],
250+
undefined,
251+
undefined,
252+
undefined,
253+
true,
254+
undefined,
255+
);
244256
});
245257

246258
it('combines node marks and inherited marks', () => {
@@ -258,10 +270,15 @@ describe('tabNodeToRun', () => {
258270
tabNodeToRun({ node: tabNode, positions, tabOrdinal: 0, paragraphAttrs, inheritedMarks });
259271

260272
expect(applyMarksToRunMock).toHaveBeenCalledTimes(1);
261-
expect(applyMarksToRunMock).toHaveBeenCalledWith(expect.objectContaining({ kind: 'tab' }), [
262-
{ type: 'bold' },
263-
{ type: 'underline', attrs: { underlineType: 'single' } },
264-
]);
273+
expect(applyMarksToRunMock).toHaveBeenCalledWith(
274+
expect.objectContaining({ kind: 'tab' }),
275+
[{ type: 'bold' }, { type: 'underline', attrs: { underlineType: 'single' } }],
276+
undefined,
277+
undefined,
278+
undefined,
279+
true,
280+
undefined,
281+
);
265282
});
266283

267284
it('does not call applyMarksToRun when no marks present', () => {

packages/layout-engine/pm-adapter/src/converters/inline-converters/text-run.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe('textNodeToRun', () => {
7474
undefined,
7575
undefined,
7676
false,
77+
undefined,
7778
);
7879
});
7980

@@ -125,6 +126,7 @@ describe('textNodeToRun', () => {
125126
undefined,
126127
undefined,
127128
false,
129+
undefined,
128130
);
129131
});
130132

@@ -147,6 +149,7 @@ describe('textNodeToRun', () => {
147149
undefined,
148150
undefined,
149151
false,
152+
undefined,
150153
);
151154
});
152155

@@ -171,6 +174,7 @@ describe('textNodeToRun', () => {
171174
undefined,
172175
undefined,
173176
false,
177+
undefined,
174178
);
175179
});
176180

@@ -220,6 +224,7 @@ describe('textNodeToRun', () => {
220224
undefined,
221225
undefined,
222226
false,
227+
undefined,
223228
);
224229
});
225230

@@ -298,6 +303,7 @@ describe('textNodeToRun', () => {
298303
undefined,
299304
undefined,
300305
false,
306+
undefined,
301307
);
302308
});
303309

@@ -337,6 +343,7 @@ describe('textNodeToRun', () => {
337343
undefined,
338344
undefined,
339345
false,
346+
undefined,
340347
);
341348
});
342349
});

packages/layout-engine/pm-adapter/src/converters/paragraph.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,6 +2731,7 @@ describe('paragraph converters', () => {
27312731
applyMarksToRun,
27322732
undefined,
27332733
true,
2734+
undefined,
27342735
);
27352736

27362737
const paraBlock = blocks[0] as ParagraphBlock;

packages/layout-engine/pm-adapter/src/tracked-changes.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,15 @@ describe('tracked-changes', () => {
745745
const applyMarksToRun = vi.fn();
746746

747747
applyFormatChangeMarks(run, config, hyperlinkConfig, applyMarksToRun);
748-
expect(applyMarksToRun).toHaveBeenCalledWith(run, beforeMarks, hyperlinkConfig, undefined, undefined, true);
748+
expect(applyMarksToRun).toHaveBeenCalledWith(
749+
run,
750+
beforeMarks,
751+
hyperlinkConfig,
752+
undefined,
753+
undefined,
754+
true,
755+
undefined,
756+
);
749757
});
750758

751759
it('should handle errors in applyMarksToRun by resetting formatting', () => {

packages/super-editor/src/editors/v1/core/presentation-editor/input/PresentationInputBridge.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { isInRegisteredSurface } from '../utils/uiSurfaceRegistry.js';
22
import { CONTEXT_MENU_HANDLED_FLAG } from '../../../components/context-menu/event-flags.js';
33

4+
const BRIDGE_FORWARDED_FLAG = Symbol('presentation-input-bridge-forwarded');
5+
46
export class PresentationInputBridge {
57
#windowRoot: Window;
68
#layoutSurfaces: Set<EventTarget>;
@@ -275,6 +277,9 @@ export class PresentationInputBridge {
275277
* @param event - The keyboard event from the layout surface
276278
*/
277279
#forwardKeyboardEvent(event: KeyboardEvent) {
280+
if (this.#wasForwardedByBridge(event)) {
281+
return;
282+
}
278283
if (!this.#isEditable()) {
279284
return;
280285
}
@@ -290,6 +295,7 @@ export class PresentationInputBridge {
290295
if (this.#isPlainCharacterKey(event)) {
291296
return;
292297
}
298+
this.#markForwardedByBridge(event);
293299

294300
// Dispatch synchronously so browser defaults can still be prevented
295301
const synthetic = new KeyboardEvent(event.type, {
@@ -355,6 +361,9 @@ export class PresentationInputBridge {
355361
* @param event - The input event from the layout surface
356362
*/
357363
#forwardTextEvent(event: InputEvent | TextEvent) {
364+
if (this.#wasForwardedByBridge(event)) {
365+
return;
366+
}
358367
if (!this.#isEditable()) {
359368
return;
360369
}
@@ -364,6 +373,7 @@ export class PresentationInputBridge {
364373
if (event.defaultPrevented) {
365374
return;
366375
}
376+
this.#markForwardedByBridge(event);
367377

368378
const dispatchSyntheticEvent = () => {
369379
// Only re-check mutable state - surface check was already done
@@ -435,6 +445,9 @@ export class PresentationInputBridge {
435445
* @param event - The composition event from the layout surface
436446
*/
437447
#forwardCompositionEvent(event: CompositionEvent) {
448+
if (this.#wasForwardedByBridge(event)) {
449+
return;
450+
}
438451
if (!this.#isEditable()) {
439452
return;
440453
}
@@ -444,6 +457,7 @@ export class PresentationInputBridge {
444457
if (event.defaultPrevented) {
445458
return;
446459
}
460+
this.#markForwardedByBridge(event);
447461

448462
let synthetic: Event;
449463
if (typeof CompositionEvent !== 'undefined') {
@@ -505,6 +519,9 @@ export class PresentationInputBridge {
505519
if (handledByContextMenu) {
506520
return;
507521
}
522+
if (this.#wasForwardedByBridge(event)) {
523+
return;
524+
}
508525
if (!this.#isEditable()) {
509526
return;
510527
}
@@ -514,6 +531,7 @@ export class PresentationInputBridge {
514531
if (event.defaultPrevented) {
515532
return;
516533
}
534+
this.#markForwardedByBridge(event);
517535
const synthetic = new MouseEvent('contextmenu', {
518536
bubbles: true,
519537
cancelable: true,
@@ -592,6 +610,14 @@ export class PresentationInputBridge {
592610
return origin ? this.#layoutSurfaces.has(origin) : false;
593611
}
594612

613+
#wasForwardedByBridge(event: Event): boolean {
614+
return Boolean((event as Event & { [BRIDGE_FORWARDED_FLAG]?: boolean })[BRIDGE_FORWARDED_FLAG]);
615+
}
616+
617+
#markForwardedByBridge(event: Event) {
618+
(event as Event & { [BRIDGE_FORWARDED_FLAG]?: boolean })[BRIDGE_FORWARDED_FLAG] = true;
619+
}
620+
595621
/**
596622
* Returns the set of event targets to attach listeners to.
597623
* Includes registered layout surfaces and optionally the window for fallback.

packages/super-editor/src/editors/v1/core/presentation-editor/tests/PresentationInputBridge.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,31 @@ describe('PresentationInputBridge - Context Menu Handling', () => {
239239
});
240240

241241
describe('stale hidden-editor rerouting', () => {
242+
it('does not double-forward layout-surface composing beforeinput when window fallback is enabled', () => {
243+
const event = new InputEvent('beforeinput', {
244+
data: 'e',
245+
inputType: 'insertCompositionText',
246+
bubbles: true,
247+
cancelable: true,
248+
});
249+
Object.defineProperty(event, 'isComposing', { value: true, writable: false });
250+
251+
const forwardedEvents: string[] = [];
252+
targetDom.addEventListener('beforeinput', () => {
253+
forwardedEvents.push('beforeinput');
254+
});
255+
256+
bridge.destroy();
257+
bridge = new PresentationInputBridge(windowRoot, layoutSurface, getTargetDom, isEditable, undefined, {
258+
useWindowFallback: true,
259+
});
260+
bridge.bind();
261+
262+
layoutSurface.dispatchEvent(event);
263+
264+
expect(forwardedEvents).toEqual(['beforeinput']);
265+
});
266+
242267
it('reroutes beforeinput from a stale hidden editor to the active target when window fallback is enabled', () => {
243268
const staleBodyEditor = document.createElement('div');
244269
staleBodyEditor.className = 'ProseMirror';

0 commit comments

Comments
 (0)