import { describe, it, expect } from 'vitest';
import { splitFileName, fileCategory, categoryColorClass } from './fileType';

describe('splitFileName', () => {
  it('splits a normal name into stem + ext (ext keeps the dot)', () => {
    expect(splitFileName('report.xlsx')).toEqual({ stem: 'report', ext: '.xlsx' });
  });
  it('uses the LAST dot for multi-dot names', () => {
    expect(splitFileName('archive.tar.gz')).toEqual({ stem: 'archive.tar', ext: '.gz' });
  });
  it('treats a leading-dot dotfile as having no extension', () => {
    expect(splitFileName('.gitignore')).toEqual({ stem: '.gitignore', ext: '' });
  });
  it('returns empty ext when there is no dot', () => {
    expect(splitFileName('README')).toEqual({ stem: 'README', ext: '' });
  });
});

describe('fileCategory', () => {
  it('maps known extensions (case-insensitive)', () => {
    expect(fileCategory('a.PNG')).toBe('image');
    expect(fileCategory('a.pdf')).toBe('pdf');
    expect(fileCategory('a.xlsx')).toBe('spreadsheet');
    expect(fileCategory('a.md')).toBe('document');
    expect(fileCategory('a.pptx')).toBe('presentation');
    expect(fileCategory('main.ts')).toBe('code');
    expect(fileCategory('a.zip')).toBe('archive');
    expect(fileCategory('a.mp3')).toBe('audio');
    expect(fileCategory('a.mp4')).toBe('video');
  });
  it('falls back to other for unknown or missing extensions', () => {
    expect(fileCategory('a.unknownext')).toBe('other');
    expect(fileCategory('README')).toBe('other');
    expect(fileCategory('.gitignore')).toBe('other');
  });
});

describe('categoryColorClass', () => {
  it('returns a literal tailwind text-color class for every category', () => {
    for (const cat of ['image', 'pdf', 'spreadsheet', 'document', 'presentation', 'code', 'archive', 'audio', 'video', 'other'] as const) {
      expect(categoryColorClass(cat)).toMatch(/^text-\w+-\d{3}$/);
    }
  });
});
