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

describe('AnalyticsMetricsViewModel', () => {
  it('maps raw metrics fields from data', () => {
    const vm = new AnalyticsMetricsViewModel({
      pageViews: 1234,
      uniqueVisitors: 567,
      averageSessionDuration: 180,
      bounceRate: 42.5,
    });

    expect(vm.pageViews).toBe(1234);
    expect(vm.uniqueVisitors).toBe(567);
    expect(vm.averageSessionDuration).toBe(180);
    expect(vm.bounceRate).toBe(42.5);
  });

  it('formats counts using locale formatting helpers', () => {
    const vm = new AnalyticsMetricsViewModel({
      pageViews: 1200,
      uniqueVisitors: 3500,
      averageSessionDuration: 75,
      bounceRate: 10,
    });

    expect(vm.formattedPageViews).toBe((1200).toLocaleString());
    expect(vm.formattedUniqueVisitors).toBe((3500).toLocaleString());
  });

  it('formats session duration as mm:ss', () => {
    const vm = new AnalyticsMetricsViewModel({
      pageViews: 0,
      uniqueVisitors: 0,
      averageSessionDuration: 125,
      bounceRate: 0,
    });

    expect(vm.formattedSessionDuration).toBe('2:05');
  });

  it('formats bounce rate as percentage with one decimal', () => {
    const vm = new AnalyticsMetricsViewModel({
      pageViews: 0,
      uniqueVisitors: 0,
      averageSessionDuration: 0,
      bounceRate: 37.345,
    });

    expect(vm.formattedBounceRate).toBe('37.3%');
  });
});
