mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-06 01:17:48 +00:00
33 lines
1.1 KiB
TypeScript
33 lines
1.1 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 sftp://example.com/file.iso mailto:user@example.com'
|
|
);
|
|
|
|
await expect(readClipboardDownloadUrls()).resolves.toEqual([
|
|
'https://example.com/file.zip',
|
|
'ftp://example.com/file.bin',
|
|
'sftp://example.com/file.iso',
|
|
]);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|