import { describe, expect, it } from 'vitest'; import { canEditProfileQuestion, DependentProfileQuestion, isProfileQuestionVisible, ProfileQuestionAnswerValue } from './profileQuestionLogic'; describe('profile question logic', () => { it('keeps admin-managed questions read-only outside admin editing mode', () => { const question = { id: 1, admin_only_edit: true, can_edit: true }; expect(canEditProfileQuestion(question, false)).toBe(false); expect(canEditProfileQuestion(question, true)).toBe(true); }); it('does not allow editing when the API marks a question read-only', () => { expect(canEditProfileQuestion({ id: 1, admin_only_edit: false, can_edit: false }, true)).toBe(false); }); it('shows dependent questions when boolean answers match', () => { const parent: DependentProfileQuestion = { id: 1, depends_on_question_id: null, depends_on_value: null }; const child: DependentProfileQuestion = { id: 2, depends_on_question_id: 1, depends_on_value: 'true' }; const questionsById = new Map([[parent.id, parent], [child.id, child]]); const answers: Record = { 1: true }; expect(isProfileQuestionVisible(child, questionsById, answers)).toBe(true); }); it('hides dependent questions when select answers do not match', () => { const parent: DependentProfileQuestion = { id: 1, depends_on_question_id: null, depends_on_value: null }; const child: DependentProfileQuestion = { id: 2, depends_on_question_id: 1, depends_on_value: 'completed' }; const questionsById = new Map([[parent.id, parent], [child.id, child]]); const answers: Record = { 1: 'pending' }; expect(isProfileQuestionVisible(child, questionsById, answers)).toBe(false); }); });