// src/utils/stringUtils.test.ts
import { describe, it, expect } from 'vitest';
import { sanitizeFilename } from './stringUtils';

describe('sanitizeFilename', () => {
  it('should replace single spaces with a hyphen', () => {
    expect(sanitizeFilename('my test file.jpg')).toBe('my-test-file.jpg');
  });

  it('should replace multiple consecutive spaces with a single hyphen', () => {
    expect(sanitizeFilename('my    test   file.jpg')).toBe('my-test-file.jpg');
  });

  it('should remove most special characters', () => {
    expect(sanitizeFilename('file!@#$%^&*()+=[]{}\\|;:\'",<>?~`.png')).toBe('file.png');
  });

  it('should replace multiple consecutive hyphens with a single one', () => {
    expect(sanitizeFilename('a---b--c.gif')).toBe('a-b-c.gif');
  });

  it('should not convert the filename to lowercase', () => {
    expect(sanitizeFilename('MyFileWithCaps.JPEG')).toBe('MyFileWithCaps.JPEG');
  });

  it('should handle a mix of issues correctly', () => {
    expect(sanitizeFilename('  A (very) messy -- file name!.pdf')).toBe('A-very-messy-file-name.pdf');
  });

  it('should leave an already clean filename unchanged', () => {
    expect(sanitizeFilename('clean-filename_123.txt')).toBe('clean-filename_123.txt');
  });

  it('should preserve underscores and periods', () => {
    expect(sanitizeFilename('archive_2024.01.01.zip')).toBe('archive_2024.01.01.zip');
  });
});