mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-07 18:03:23 +00:00
feat(downloads): prefill Add modal from clipboard (#10)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
import { readText } from '@tauri-apps/plugin-clipboard-manager';
|
||||
import { extractValidDownloadUrls } from './url';
|
||||
|
||||
export const readClipboardDownloadUrls = async (): Promise<string[]> => {
|
||||
const clipboardText = await readText();
|
||||
return extractValidDownloadUrls(clipboardText);
|
||||
};
|
||||
Reference in New Issue
Block a user