import { describe, it, expect } from 'vitest';
import { ActivityItemViewModel } from './ActivityItemViewModel';

describe('ActivityItemViewModel', () => {
  it('maps basic properties from input data', () => {
    const data = {
      id: 'activity-1',
      type: 'race' as const,
      message: 'Test activity',
      time: '2025-01-01T12:00:00Z',
      impressions: 1234,
    };

    const viewModel = new ActivityItemViewModel(data);

    expect(viewModel.id).toBe('activity-1');
    expect(viewModel.type).toBe('race');
    expect(viewModel.message).toBe('Test activity');
    expect(viewModel.time).toBe('2025-01-01T12:00:00Z');
    expect(viewModel.impressions).toBe(1234);
  });

  it('returns the correct typeColor for each supported type', () => {
    const race = new ActivityItemViewModel({ id: '1', type: 'race', message: '', time: '' });
    const league = new ActivityItemViewModel({ id: '2', type: 'league', message: '', time: '' });
    const team = new ActivityItemViewModel({ id: '3', type: 'team', message: '', time: '' });
    const driver = new ActivityItemViewModel({ id: '4', type: 'driver', message: '', time: '' });
    const platform = new ActivityItemViewModel({ id: '5', type: 'platform', message: '', time: '' });

    expect(race.typeColor).toBe('bg-warning-amber');
    expect(league.typeColor).toBe('bg-primary-blue');
    expect(team.typeColor).toBe('bg-purple-400');
    expect(driver.typeColor).toBe('bg-performance-green');
    expect(platform.typeColor).toBe('bg-racing-red');
  });

  it('falls back to a default typeColor for unknown types', () => {
    const unknown = new ActivityItemViewModel({
      id: 'unknown',
      type: 'unknown',
      message: '',
      time: '',
    } as any);

    expect(unknown.typeColor).toBe('bg-gray-500');
  });

  it('formats impressions when provided', () => {
    const impressions = 1234;
    const viewModel = new ActivityItemViewModel({
      id: 'activity-2',
      type: 'race',
      message: '',
      time: '',
      impressions,
    });

    expect(viewModel.formattedImpressions).toBe(impressions.toLocaleString());
  });

  it('returns null for formattedImpressions when impressions is undefined or zero', () => {
    const noImpressions = new ActivityItemViewModel({
      id: 'activity-3',
      type: 'race',
      message: '',
      time: '',
    });

    const zeroImpressions = new ActivityItemViewModel({
      id: 'activity-4',
      type: 'race',
      message: '',
      time: '',
      impressions: 0,
    });

    expect(noImpressions.formattedImpressions).toBeNull();
    expect(zeroImpressions.formattedImpressions).toBeNull();
  });
});
