import { describe, expect, it } from 'vitest';

import { getPriceScale } from './PriceHistoryChart';

describe('PriceHistoryChart scale', () => {
  it('uses a high percentile ceiling instead of the absolute max', () => {
    const scale = getPriceScale([
      ...Array.from({ length: 19 }, (_, i) => ({
        year: 2000 + i,
        price: 3_000_000 + i * 10_000,
      })),
      { year: 2025, price: 10_000_000 },
    ]);

    expect(scale.max).toBeGreaterThan(3_000_000);
    expect(scale.max).toBeLessThan(10_000_000);
    expect(Math.max(...scale.ticks)).toBe(scale.max);
  });

  it('keeps single-value data visible with a padded domain', () => {
    const scale = getPriceScale([
      { year: 2020, price: 2_500_000 },
      { year: 2021, price: 2_500_000 },
    ]);

    expect(scale.min).toBeLessThan(2_500_000);
    expect(scale.max).toBeGreaterThan(2_500_000);
  });
});
