import { describe, it, expect } from 'vitest';
import { isCardioExercise } from '@/lib/exerciseOptions';

describe('isCardioExercise', () => {
  it('treats type "cardio" as cardio', () => {
    expect(isCardioExercise({ type: 'cardio', muscleGroups: '["cardio"]' })).toBe(true);
  });

  it('treats the cardio muscle group as cardio even when type differs (Assault Bike)', () => {
    expect(
      isCardioExercise({ type: 'assault bike', muscleGroups: '["cardio","legs","back","shoulders"]' })
    ).toBe(true);
  });

  it('is case/whitespace-insensitive on the muscle group', () => {
    expect(isCardioExercise({ type: 'other', muscleGroups: '[" Cardio "]' })).toBe(true);
  });

  it('treats strength work (no cardio signal) as non-cardio', () => {
    expect(isCardioExercise({ type: 'barbell', muscleGroups: '["back","biceps"]' })).toBe(false);
  });

  it('handles missing/empty fields without throwing', () => {
    expect(isCardioExercise({})).toBe(false);
    expect(isCardioExercise({ type: null, muscleGroups: null })).toBe(false);
    expect(isCardioExercise({ type: '', muscleGroups: 'not json' })).toBe(false);
  });
});
