import { describe, it, expect } from 'vitest';
import { classifyFormFactor } from '@/lib/form-factor';

describe('classifyFormFactor', () => {
  it('returns "mobile" for an iPhone UA', () => {
    expect(
      classifyFormFactor(
        'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148',
      ),
    ).toBe('mobile');
  });

  it('returns "mobile" for an iPad UA', () => {
    expect(
      classifyFormFactor(
        'Mozilla/5.0 (iPad; CPU OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148',
      ),
    ).toBe('mobile');
  });

  it('returns "mobile" for an Android UA', () => {
    expect(
      classifyFormFactor(
        'Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 Mobile Safari/537.36',
      ),
    ).toBe('mobile');
  });

  it('returns "desktop" for a Mac Safari UA', () => {
    expect(
      classifyFormFactor(
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/605.1.15 Version/17.0 Safari/605.1.15',
      ),
    ).toBe('desktop');
  });

  it('returns "desktop" for a Linux Chrome UA', () => {
    expect(
      classifyFormFactor(
        'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/120.0 Safari/537.36',
      ),
    ).toBe('desktop');
  });

  it('returns "desktop" for missing UA', () => {
    expect(classifyFormFactor(null)).toBe('desktop');
    expect(classifyFormFactor(undefined)).toBe('desktop');
    expect(classifyFormFactor('')).toBe('desktop');
  });
});
