import { describe, it, expect } from 'vitest'; import { clipboardIntent, isMacPlatform, type ClipboardKey } from '../src/lib/terminal-clipboard'; function key(k: string, mods: Partial = {}): ClipboardKey { return { key: k, ctrlKey: false, shiftKey: false, metaKey: false, altKey: false, ...mods }; } describe('clipboardIntent (Linux / Windows)', () => { it('copie sur Ctrl+Shift+C quand il y a une sélection', () => { expect(clipboardIntent(key('C', { ctrlKey: true, shiftKey: true }), true, false)).toBe('copy'); }); it('laisse passer Ctrl+Shift+C sans sélection (rien à copier)', () => { expect(clipboardIntent(key('C', { ctrlKey: true, shiftKey: true }), false, false)).toBeNull(); }); it('colle sur Ctrl+Shift+V, sélection ou pas', () => { expect(clipboardIntent(key('V', { ctrlKey: true, shiftKey: true }), false, false)).toBe('paste'); expect(clipboardIntent(key('v', { ctrlKey: true, shiftKey: true }), true, false)).toBe('paste'); }); it("n'intercepte JAMAIS Ctrl+C seul : c'est SIGINT", () => { expect(clipboardIntent(key('c', { ctrlKey: true }), true, false)).toBeNull(); expect(clipboardIntent(key('c', { ctrlKey: true }), false, false)).toBeNull(); }); it('laisse passer Ctrl+V seul (le collage natif d’xterm suffit)', () => { expect(clipboardIntent(key('v', { ctrlKey: true }), false, false)).toBeNull(); }); it('ignore les combinaisons avec Alt ou Meta', () => { expect(clipboardIntent(key('c', { ctrlKey: true, shiftKey: true, altKey: true }), true, false)).toBeNull(); expect(clipboardIntent(key('c', { ctrlKey: true, shiftKey: true, metaKey: true }), true, false)).toBeNull(); }); it('supporte Ctrl+Insert / Shift+Insert', () => { expect(clipboardIntent(key('Insert', { ctrlKey: true }), true, false)).toBe('copy'); expect(clipboardIntent(key('Insert', { ctrlKey: true }), false, false)).toBeNull(); expect(clipboardIntent(key('Insert', { shiftKey: true }), false, false)).toBe('paste'); expect(clipboardIntent(key('Insert', { ctrlKey: true, shiftKey: true }), true, false)).toBeNull(); }); }); describe('clipboardIntent (macOS)', () => { it('copie sur Cmd+C avec sélection, colle sur Cmd+V', () => { expect(clipboardIntent(key('c', { metaKey: true }), true, true)).toBe('copy'); expect(clipboardIntent(key('c', { metaKey: true }), false, true)).toBeNull(); expect(clipboardIntent(key('v', { metaKey: true }), false, true)).toBe('paste'); }); it('garde Ctrl+C en SIGINT sur macOS aussi', () => { expect(clipboardIntent(key('c', { ctrlKey: true }), true, true)).toBeNull(); }); it('ignore Ctrl+Shift+C sur macOS (réservé Cmd)', () => { expect(clipboardIntent(key('c', { ctrlKey: true, shiftKey: true }), true, true)).toBeNull(); }); }); describe('isMacPlatform', () => { it('reconnaît macOS et iPadOS, pas Linux ni Windows', () => { expect(isMacPlatform({ platform: 'MacIntel', userAgent: 'Mozilla/5.0 (Macintosh)' })).toBe(true); expect(isMacPlatform({ platform: 'iPhone', userAgent: '' })).toBe(true); expect(isMacPlatform({ platform: 'Linux x86_64', userAgent: 'Mozilla/5.0 (X11; Linux)' })).toBe(false); expect(isMacPlatform({ platform: 'Win32', userAgent: 'Mozilla/5.0 (Windows NT 10.0)' })).toBe(false); }); });