mirror of
https://github.com/nimbold/Firelink.git
synced 2026-07-26 12:08:27 +00:00
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { readClipboardDownloadUrls } from './clipboard';
|
|
import { readText } from '@tauri-apps/plugin-clipboard-manager';
|
|
|
|
vi.mock('@tauri-apps/plugin-clipboard-manager', () => ({
|
|
readText: vi.fn(),
|
|
}));
|
|
|
|
describe('clipboard URL extraction', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('reads only supported, unique download URLs from clipboard text', async () => {
|
|
vi.mocked(readText).mockResolvedValue(
|
|
'https://example.com/file.zip\nhttps://example.com/file.zip ftp://example.com/file.bin mailto:user@example.com'
|
|
);
|
|
|
|
await expect(readClipboardDownloadUrls()).resolves.toEqual([
|
|
'https://example.com/file.zip',
|
|
'ftp://example.com/file.bin',
|
|
]);
|
|
});
|
|
|
|
it('preserves clipboard read failures for the caller to handle', async () => {
|
|
const error = new Error('clipboard unavailable');
|
|
vi.mocked(readText).mockRejectedValue(error);
|
|
|
|
await expect(readClipboardDownloadUrls()).rejects.toBe(error);
|
|
});
|
|
});
|