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

describe('normalizeExerciseValue', () => {
  it('keeps only digits', () => {
    expect(normalizeExerciseValue({}, '1a-2')).toBe('12');
  });

  it('clamps values to the configured range', () => {
    expect(normalizeExerciseValue({ minValue: 0, maxValue: 4 }, '8')).toBe('4');
    expect(normalizeExerciseValue({ minValue: 0, maxValue: 3 }, '9')).toBe('3');
  });

  it('supports separate ranges for split exercise rows', () => {
    const exercise = {
      subValueRanges: {
        a: { minValue: 0, maxValue: 6 },
        b: { minValue: 0, maxValue: 10 }
      }
    };

    expect(normalizeExerciseValue(exercise, '8', 'a')).toBe('6');
    expect(normalizeExerciseValue(exercise, '12', 'b')).toBe('10');
  });

  it('keeps empty values empty', () => {
    expect(normalizeExerciseValue({ minValue: 0, maxValue: 4 }, '')).toBe('');
  });
});
