From cc68e1dc27b7dfa2b26a8e76abf67548df87ebc0 Mon Sep 17 00:00:00 2001 From: mortezaei Date: Thu, 20 Aug 2026 16:31:44 +0330 Subject: [PATCH] fix: restrict option_id to choice types and update tests --- .../Componentes/question-answer-storage.tsx | 10 +++++-- .../Componentes/question-sheet.test.tsx | 30 ++++++++++++------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/components/Componentes/question-answer-storage.tsx b/src/components/Componentes/question-answer-storage.tsx index 3a52c92..149470e 100644 --- a/src/components/Componentes/question-answer-storage.tsx +++ b/src/components/Componentes/question-answer-storage.tsx @@ -132,7 +132,13 @@ function createQuestionField( ): MarriageField { let option_id: string | string[] | undefined; - if (question.options && Array.isArray(question.options) && question.options.length > 0) { + const isChoiceType = + question.type === "dropdown" || + question.type === "radio" || + question.type === "checkbox" || + question.type === "scale"; + + if (isChoiceType && question.options && Array.isArray(question.options) && question.options.length > 0) { if (Array.isArray(value)) { option_id = value; } else if (typeof value === "string" && value) { @@ -159,7 +165,7 @@ function createQuestionField( type: question.type, value, private: question.private, - option_id: option_id, + option_id: isChoiceType ? option_id : undefined, } as MarriageField; } diff --git a/src/components/Componentes/question-sheet.test.tsx b/src/components/Componentes/question-sheet.test.tsx index 205dd26..497c82b 100644 --- a/src/components/Componentes/question-sheet.test.tsx +++ b/src/components/Componentes/question-sheet.test.tsx @@ -15,6 +15,13 @@ vi.mock("@/translations/provider", () => ({ useI18n: vi.fn(() => ({ locale: "fa", dictionary: { Confirm: "تایید" } })), })); +vi.mock("@/hooks/marriage/use-profile-main", () => ({ + useMarriageProfileQuery: vi.fn(() => ({ + data: { id: 1, can_edit_profile: true }, + isLoading: false, + })), +})); + vi.mock("@/hooks/marriage/use-section-data", () => ({ applyProfilePatchResultToCache: vi.fn(), useMarriageSectionDataQuery: vi.fn(() => ({ @@ -91,16 +98,19 @@ describe("QuestionSheet component", () => { fireEvent.click(iranBtn); // Trigger should now show Iran - await waitFor(() => { - expect(screen.getByText("ایران")).toBeDefined(); - expect(document.body.classList.contains("dropdown-open")).toBe(false); - expect(document.body.classList.contains("question-sheet-open")).toBe( - false, - ); - expect( - (document.querySelector(".app-shell") as HTMLElement).style.overflowY, - ).toBe(""); - }); + await waitFor( + () => { + expect(screen.getByText("ایران")).toBeDefined(); + expect(document.body.classList.contains("dropdown-open")).toBe(false); + expect(document.body.classList.contains("question-sheet-open")).toBe( + false, + ); + expect( + (document.querySelector(".app-shell") as HTMLElement).style.overflowY, + ).toBe(""); + }, + { timeout: 1000 }, + ); }); it("supports multi-selection with confirm button", async () => {