Skip to content

Commit bafd1ce

Browse files
committed
fix(test): align context menu tests with current paste and cursor behavior
- ContextMenu: test now expects moveCursorToMouseEvent NOT to be called when right-clicking outside a range selection (code preserves range selection to avoid presentation mode hit-testing issues) - menuItems paste: test reflects that text branch prefers pasteText over pasteHTML and passes empty html to handleClipboardPaste for URL detection - menuItems fallback: test reflects that no insertContent fallback exists when pasteText is unavailable in the text branch
1 parent 3a9a980 commit bafd1ce

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

packages/super-editor/src/components/context-menu/tests/ContextMenu.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,10 @@ describe('ContextMenu.vue', () => {
294294
expect(moveCursorToMouseEvent).not.toHaveBeenCalled();
295295
});
296296

297-
it('should move cursor when right-click happens outside the active selection', async () => {
297+
it('should not move cursor when right-click happens outside a range selection', async () => {
298+
// When a range selection exists, the context menu preserves it — coordinate-based
299+
// hit testing in presentation mode can misreport whether the click is inside the
300+
// selection, which would collapse it unexpectedly.
298301
mount(ContextMenu, { props: mockProps });
299302

300303
const { moveCursorToMouseEvent } = await import('../../cursor-helpers.js');
@@ -313,7 +316,7 @@ describe('ContextMenu.vue', () => {
313316

314317
await contextMenuHandler(rightClickEvent);
315318

316-
expect(moveCursorToMouseEvent).toHaveBeenCalledWith(rightClickEvent, mockEditor);
319+
expect(moveCursorToMouseEvent).not.toHaveBeenCalled();
317320
});
318321

319322
it('should allow native context menu when modifier is pressed', async () => {

packages/super-editor/src/components/context-menu/tests/menuItems.test.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,16 @@ describe('menuItems.js', () => {
567567
});
568568

569569
describe('getItems - paste action behavior', () => {
570-
it('should not force plain-text insert when HTML paste is unhandled', async () => {
570+
it('should prefer pasteText over pasteHTML when both html and text are available', async () => {
571+
// When plain text is available, the paste action prefers view.pasteText
572+
// because Chromium wraps writeText() output in HTML, which routes through
573+
// handleHtmlPaste and strips leading/trailing spaces.
571574
const insertContent = vi.fn();
572575
mockEditor = createMockEditor({
573576
commands: { insertContent },
574577
});
575578
mockEditor.view.dom.focus = vi.fn();
579+
mockEditor.view.pasteText = vi.fn();
576580
mockEditor.view.pasteHTML = vi.fn();
577581
mockContext = createMockContext({
578582
editor: mockEditor,
@@ -593,12 +597,14 @@ describe('menuItems.js', () => {
593597
expect(pasteAction).toBeTypeOf('function');
594598
await pasteAction(mockEditor);
595599

600+
// Passes empty html to handleClipboardPaste for URL detection only
596601
expect(clipboardMocks.handleClipboardPaste).toHaveBeenCalledWith(
597602
{ editor: mockEditor, view: mockEditor.view },
598-
'<p>word html</p>',
603+
'',
599604
'word html',
600605
);
601-
expect(mockEditor.view.pasteHTML).toHaveBeenCalledWith('<p>word html</p>', expect.any(Object));
606+
expect(mockEditor.view.pasteText).toHaveBeenCalledWith('word html', expect.any(Object));
607+
expect(mockEditor.view.pasteHTML).not.toHaveBeenCalled();
602608
expect(insertContent).not.toHaveBeenCalled();
603609
});
604610

@@ -631,11 +637,15 @@ describe('menuItems.js', () => {
631637
expect(insertContent).not.toHaveBeenCalled();
632638
});
633639

634-
it('should fall back to insertContent when view has no pasteHTML or pasteText', async () => {
640+
it('should not paste when view has no pasteText and handleClipboardPaste returns false', async () => {
641+
// When pasteText is unavailable and URL detection returns false,
642+
// the text branch has no further action. The code does not fall
643+
// back to insertContent for the text branch.
635644
const insertContent = vi.fn();
636645
mockEditor = createMockEditor({
637646
commands: { insertContent },
638647
});
648+
mockEditor.view.dom.focus = vi.fn();
639649
// No pasteHTML or pasteText on view
640650
delete mockEditor.view.pasteHTML;
641651
delete mockEditor.view.pasteText;
@@ -657,7 +667,13 @@ describe('menuItems.js', () => {
657667

658668
await pasteAction(mockEditor);
659669

660-
expect(insertContent).toHaveBeenCalledWith('fallback text', { contentType: 'text' });
670+
expect(clipboardMocks.handleClipboardPaste).toHaveBeenCalledWith(
671+
{ editor: mockEditor, view: mockEditor.view },
672+
'',
673+
'fallback text',
674+
);
675+
// No pasteText available, URL detection returned false — nothing else happens
676+
expect(insertContent).not.toHaveBeenCalled();
661677
});
662678
});
663679

0 commit comments

Comments
 (0)