import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { captureFilename } from '~/lib/filename';
describe('captureFilename', () => {
beforeEach(() => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-05-23T14:07:09'));
});
afterEach(() => {
vi.useRealTimers();
});
it('slugifies ASCII preset names', () => {
expect(captureFilename('Forest Floor', 'png')).toBe(
'physarum-forest-floor-20260523-140709.png',
);
});
it('strips combining diacritics (Umlaute, accents)', () => {
expect(captureFilename('Über Mündung', 'png')).toBe(
'physarum-uber-mundung-20260523-140709.png',
);
expect(captureFilename('Café Noir', 'webm')).toBe('physarum-cafe-noir-20260523-140709.webm');
});
it('collapses runs of non-alphanumerics and trims dashes', () => {
expect(captureFilename('!! ~~ Wild Thing ~~ !!', 'png')).toBe(
'physarum-wild-thing-20260523-140709.png',
);
});
it('falls back to "preset" when the name slugifies to empty', () => {
expect(captureFilename('!!!', 'png')).toBe('physarum-preset-20260523-140709.png');
expect(captureFilename('', 'png')).toBe('physarum-preset-20260523-140709.png');
});
});