Browse Source

fix: restrict option_id to choice types and update tests

master
mortezaei 4 days ago
parent
commit
cc68e1dc27
  1. 10
      src/components/Componentes/question-answer-storage.tsx
  2. 14
      src/components/Componentes/question-sheet.test.tsx

10
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;
}

14
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,7 +98,8 @@ describe("QuestionSheet component", () => {
fireEvent.click(iranBtn);
// Trigger should now show Iran
await waitFor(() => {
await waitFor(
() => {
expect(screen.getByText("ایران")).toBeDefined();
expect(document.body.classList.contains("dropdown-open")).toBe(false);
expect(document.body.classList.contains("question-sheet-open")).toBe(
@ -100,7 +108,9 @@ describe("QuestionSheet component", () => {
expect(
(document.querySelector(".app-shell") as HTMLElement).style.overflowY,
).toBe("");
});
},
{ timeout: 1000 },
);
});
it("supports multi-selection with confirm button", async () => {

Loading…
Cancel
Save