Something went wrong. Try again.
Synapse is a study workspace. Organize courses read and annotate the material, train with generated exercises and watch your progress forked from denishovart.com/synapse
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { revealPack, saveFile, savePack } from './savePack';
// isTauri() is false under jsdom, so every function takes its browser branch:// savePack/saveFile trigger an anchor download and report an untargeted,// non-revealable SaveResult; revealPack is a no-op with no shell to ask.
describe('savePack (browser fallback)', () => { let click: ReturnType<typeof vi.fn<() => void>>;
beforeEach(() => { globalThis.URL.createObjectURL = vi.fn(() => 'blob:fake'); globalThis.URL.revokeObjectURL = vi.fn(); click = vi.fn<() => void>(); vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(click); }); afterEach(() => vi.restoreAllMocks());
it('savePack downloads and reports an untargeted, non-revealable save', async () => { const result = await savePack(new Blob(['pack']), 'workspace.zip'); expect(result).toEqual({ target: null, name: 'workspace.zip', revealable: false, saved: true, }); expect(click).toHaveBeenCalledTimes(1); // The object URL is created for the download and released afterwards. expect(globalThis.URL.createObjectURL).toHaveBeenCalledTimes(1); expect(globalThis.URL.revokeObjectURL).toHaveBeenCalledWith('blob:fake'); });
it('saveFile downloads with the suggested name', async () => { const result = await saveFile(new Blob(['x']), 'notes.md', { name: 'Markdown', ext: 'md' }); expect(result).toEqual({ target: null, name: 'notes.md', revealable: false, saved: true }); expect(click).toHaveBeenCalledTimes(1); });
it('revealPack does nothing without a shell', async () => { await expect(revealPack('/some/path')).resolves.toBeUndefined(); });});