|
|
@ -214,14 +214,14 @@ describe("QuestionSheet component", () => { |
|
|
pushState.mockRestore(); |
|
|
pushState.mockRestore(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it("opens a searchable sheet without focusing search", () => { |
|
|
|
|
|
|
|
|
it("opens a searchable sheet for 7+ options without focusing search", () => { |
|
|
const question = { |
|
|
const question = { |
|
|
id: "q_country", |
|
|
id: "q_country", |
|
|
title: "کشور", |
|
|
title: "کشور", |
|
|
type: "dropdown", |
|
|
type: "dropdown", |
|
|
required: true, |
|
|
required: true, |
|
|
extras: { placeHolder: "انتخاب کشور" }, |
|
|
extras: { placeHolder: "انتخاب کشور" }, |
|
|
options: Array.from({ length: 6 }, (_, index) => ({ |
|
|
|
|
|
|
|
|
options: Array.from({ length: 7 }, (_, index) => ({ |
|
|
id: `country-${index}`, |
|
|
id: `country-${index}`, |
|
|
value: `country-${index}`, |
|
|
value: `country-${index}`, |
|
|
label: `کشور ${index + 1}`, |
|
|
label: `کشور ${index + 1}`, |
|
|
@ -246,7 +246,7 @@ describe("QuestionSheet component", () => { |
|
|
); |
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it("sizes a short options sheet to its content", () => { |
|
|
|
|
|
|
|
|
it("sizes a short options sheet to its content (4 options)", () => { |
|
|
const question = { |
|
|
const question = { |
|
|
id: "q_short", |
|
|
id: "q_short", |
|
|
title: "انتخاب کوتاه", |
|
|
title: "انتخاب کوتاه", |
|
|
@ -277,4 +277,99 @@ describe("QuestionSheet component", () => { |
|
|
"max-h-[82svh]", |
|
|
"max-h-[82svh]", |
|
|
); |
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("compact boundary: 5 options → compact, no search", () => { |
|
|
|
|
|
const question = { |
|
|
|
|
|
id: "q_boundary_5", |
|
|
|
|
|
title: "پنج گزینه", |
|
|
|
|
|
type: "dropdown", |
|
|
|
|
|
required: true, |
|
|
|
|
|
extras: { placeHolder: "انتخاب" }, |
|
|
|
|
|
options: Array.from({ length: 5 }, (_, i) => ({ |
|
|
|
|
|
id: `opt-${i}`, |
|
|
|
|
|
value: `opt-${i}`, |
|
|
|
|
|
label: `گزینه ${i + 1}`, |
|
|
|
|
|
order: i + 1, |
|
|
|
|
|
})), |
|
|
|
|
|
ui_config: {}, |
|
|
|
|
|
} as QuestionField; |
|
|
|
|
|
|
|
|
|
|
|
render( |
|
|
|
|
|
<QueryClientProvider client={queryClient}> |
|
|
|
|
|
<QuestionAnswersProvider slug="test" questions={[question]}> |
|
|
|
|
|
<QuestionSheet question={question} /> |
|
|
|
|
|
</QuestionAnswersProvider> |
|
|
|
|
|
</QueryClientProvider>, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "انتخاب" })); |
|
|
|
|
|
|
|
|
|
|
|
const section = screen.getByRole("dialog").querySelector("section"); |
|
|
|
|
|
expect(section).toHaveClass("h-auto", "max-h-[82svh]"); |
|
|
|
|
|
expect(screen.queryByPlaceholderText("جستجو...")).toBeNull(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("compact boundary: 6 options → compact, no search", () => { |
|
|
|
|
|
const question = { |
|
|
|
|
|
id: "q_boundary_6", |
|
|
|
|
|
title: "شش گزینه", |
|
|
|
|
|
type: "dropdown", |
|
|
|
|
|
required: true, |
|
|
|
|
|
extras: { placeHolder: "انتخاب" }, |
|
|
|
|
|
options: Array.from({ length: 6 }, (_, i) => ({ |
|
|
|
|
|
id: `opt-${i}`, |
|
|
|
|
|
value: `opt-${i}`, |
|
|
|
|
|
label: `گزینه ${i + 1}`, |
|
|
|
|
|
order: i + 1, |
|
|
|
|
|
})), |
|
|
|
|
|
ui_config: {}, |
|
|
|
|
|
} as QuestionField; |
|
|
|
|
|
|
|
|
|
|
|
render( |
|
|
|
|
|
<QueryClientProvider client={queryClient}> |
|
|
|
|
|
<QuestionAnswersProvider slug="test" questions={[question]}> |
|
|
|
|
|
<QuestionSheet question={question} /> |
|
|
|
|
|
</QuestionAnswersProvider> |
|
|
|
|
|
</QueryClientProvider>, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "انتخاب" })); |
|
|
|
|
|
|
|
|
|
|
|
const section = screen.getByRole("dialog").querySelector("section"); |
|
|
|
|
|
expect(section).toHaveClass("h-auto", "max-h-[82svh]"); |
|
|
|
|
|
expect(section).not.toHaveClass("h-[82svh]"); |
|
|
|
|
|
expect(screen.queryByPlaceholderText("جستجو...")).toBeNull(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("compact boundary: 7 options → large sheet with search", () => { |
|
|
|
|
|
const question = { |
|
|
|
|
|
id: "q_boundary_7", |
|
|
|
|
|
title: "هفت گزینه", |
|
|
|
|
|
type: "dropdown", |
|
|
|
|
|
required: true, |
|
|
|
|
|
extras: { placeHolder: "انتخاب" }, |
|
|
|
|
|
options: Array.from({ length: 7 }, (_, i) => ({ |
|
|
|
|
|
id: `opt-${i}`, |
|
|
|
|
|
value: `opt-${i}`, |
|
|
|
|
|
label: `گزینه ${i + 1}`, |
|
|
|
|
|
order: i + 1, |
|
|
|
|
|
})), |
|
|
|
|
|
ui_config: {}, |
|
|
|
|
|
} as QuestionField; |
|
|
|
|
|
|
|
|
|
|
|
render( |
|
|
|
|
|
<QueryClientProvider client={queryClient}> |
|
|
|
|
|
<QuestionAnswersProvider slug="test" questions={[question]}> |
|
|
|
|
|
<QuestionSheet question={question} /> |
|
|
|
|
|
</QuestionAnswersProvider> |
|
|
|
|
|
</QueryClientProvider>, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(screen.getByRole("button", { name: "انتخاب" })); |
|
|
|
|
|
|
|
|
|
|
|
const section = screen.getByRole("dialog").querySelector("section"); |
|
|
|
|
|
expect(section).toHaveClass("h-[82svh]"); |
|
|
|
|
|
expect(section).not.toHaveClass("h-auto"); |
|
|
|
|
|
expect(screen.getByPlaceholderText("جستجو...")).toBeDefined(); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |