import { describe, expect, it } from 'vitest';
import {
  cloneAssessment,
  getFinalizeDisabledReason,
  isAssessmentComplete,
  isExerciseComplete
} from './assessmentState';

describe('assessmentState', () => {
  it('treats regular exercises as complete only when all values are filled', () => {
    expect(isExerciseComplete({ values: ['1', '2', '3'] })).toBe(true);
    expect(isExerciseComplete({ values: ['1', '', '3'] })).toBe(false);
  });

  it('treats split exercises as complete only when both rows are filled', () => {
    expect(isExerciseComplete({ subA: ['1', '2'], subB: ['3', '4'] })).toBe(true);
    expect(isExerciseComplete({ subA: ['1', '2'], subB: ['3', ''] })).toBe(false);
  });

  it('marks assessments incomplete until name, date and all exercise values are present', () => {
    const baseAssessment = {
      name: 'Stefan',
      datum: '2026-03-21',
      exercises: [{ values: ['1', '2', '3'] }]
    };

    expect(isAssessmentComplete(baseAssessment)).toBe(true);
    expect(getFinalizeDisabledReason(baseAssessment)).toBe('');
    expect(isAssessmentComplete({ ...baseAssessment, name: '' })).toBe(false);
    expect(isAssessmentComplete({ ...baseAssessment, exercises: [{ values: ['1', '', '3'] }] })).toBe(false);
  });

  it('deep clones assessments before editing', () => {
    const source = {
      name: 'Stefan',
      exercises: [{ values: ['1', '2'] }]
    };

    const clone = cloneAssessment(source);
    clone.exercises[0].values[0] = '9';

    expect(source.exercises[0].values[0]).toBe('1');
  });
});
