import { describe, expect, it, vi } from 'vitest'; import { copyShareLink } from './useShareLink'; describe('copyShareLink', () => { it('copies deterministic share URLs through the Clipboard API', async () => { const clipboard = { writeText: vi.fn(async () => undefined), }; const result = await copyShareLink( { machineId: 'four-stroke-petrol-engine', explode: 1, }, { clipboard, urlOptions: { baseUrl: 'https://mechanica.example/explorer', }, }, ); expect(result).toEqual({ ok: true, url: 'https://mechanica.example/explorer?ex=1&m=four-stroke-petrol-engine', method: 'clipboard', }); expect(clipboard.writeText).toHaveBeenCalledWith( 'https://mechanica.example/explorer?ex=1&m=four-stroke-petrol-engine', ); }); it('reports unsupported copy when clipboard and legacy fallbacks are unavailable', async () => { const result = await copyShareLink( { machineId: 'steam-engine', }, { clipboard: null, preferLegacyFallback: false, urlOptions: { baseUrl: 'https://mechanica.example/explorer', }, }, ); expect(result.ok).toBe(false); expect(result.method).toBe('unsupported'); expect(result.url).toBe('https://mechanica.example/explorer?m=steam-engine'); }); });