import {
  PROFILE_AVATAR_MAX_ZOOM,
  PROFILE_AVATAR_MIN_ZOOM,
  clampProfileAvatarTransform,
  clampProfileAvatarZoom,
  resolveProfileAvatarStorageFileName,
  resolveProfileAvatarBaseScale
} from './profile-avatar.models';

describe('profile-avatar models', () => {
  it('clamps zoom inside allowed range', () => {
    expect(clampProfileAvatarZoom(0.1)).toBe(PROFILE_AVATAR_MIN_ZOOM);
    expect(clampProfileAvatarZoom(9)).toBe(PROFILE_AVATAR_MAX_ZOOM);
    expect(clampProfileAvatarZoom(2.5)).toBe(2.5);
  });

  it('resolves cover scale for portrait images', () => {
    expect(resolveProfileAvatarBaseScale({ width: 200, height: 400 }, 224)).toBeCloseTo(1.12);
  });

  it('clamps transform offsets so image still covers crop frame', () => {
    const transform = clampProfileAvatarTransform(
      { width: 320, height: 240 },
      { zoom: 1, offsetX: 500, offsetY: -500 },
      224
    );

    expect(transform.offsetX).toBeCloseTo(37.333333, 4);
    expect(transform.offsetY).toBe(0);
  });

  it('maps avatar mime types to storage file names', () => {
    expect(resolveProfileAvatarStorageFileName('image/gif')).toBe('profile.gif');
    expect(resolveProfileAvatarStorageFileName('image/jpeg')).toBe('profile.jpg');
    expect(resolveProfileAvatarStorageFileName('image/webp')).toBe('profile.webp');
    expect(resolveProfileAvatarStorageFileName(undefined)).toBe('profile.webp');
  });
});
