|
|
|
@ -90,6 +90,33 @@ function TestComponent({ slug }: { slug: string }) { |
|
|
|
Set Checkbox |
|
|
|
</button> |
|
|
|
|
|
|
|
<button |
|
|
|
data-testid="set-multi-dropdown" |
|
|
|
onClick={() => |
|
|
|
setAnswerValue( |
|
|
|
{ |
|
|
|
id: "q_multi_drop", |
|
|
|
type: "dropdown", |
|
|
|
title: "Q Multi Drop", |
|
|
|
order: 3, |
|
|
|
required: true, |
|
|
|
baseRequired: true, |
|
|
|
isVisible: true, |
|
|
|
description: "", |
|
|
|
tooltip: "", |
|
|
|
extras: { placeHolder: "", options: [], range: [1, 10] }, |
|
|
|
options: [ |
|
|
|
{ id: "opt_d1", value: "D1", label: "Option D1", order: 1 }, |
|
|
|
{ id: "opt_d2", value: "D2", label: "Option D2", order: 2 }, |
|
|
|
], |
|
|
|
}, |
|
|
|
["opt_d1", "opt_d2"], |
|
|
|
) |
|
|
|
} |
|
|
|
> |
|
|
|
Set Multi Dropdown |
|
|
|
</button> |
|
|
|
|
|
|
|
<button data-testid="save" onClick={() => flushAnswers()}> |
|
|
|
Save |
|
|
|
</button> |
|
|
|
@ -214,6 +241,51 @@ describe("Question Answer & Schema Integration", () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it("should send array of option_ids for multi-select dropdown", async () => { |
|
|
|
const queryClient = new QueryClient({ |
|
|
|
defaultOptions: { queries: { retry: false } }, |
|
|
|
}); |
|
|
|
|
|
|
|
render( |
|
|
|
<QueryClientProvider client={queryClient}> |
|
|
|
<QuestionAnswersProvider |
|
|
|
slug="test_slug" |
|
|
|
questions={[ |
|
|
|
{ |
|
|
|
id: "q_multi_drop", |
|
|
|
type: "dropdown", |
|
|
|
title: "Q Multi Drop", |
|
|
|
order: 3, |
|
|
|
required: true, |
|
|
|
baseRequired: true, |
|
|
|
isVisible: true, |
|
|
|
description: "", |
|
|
|
tooltip: "", |
|
|
|
extras: { placeHolder: "", options: [], range: [1, 10] }, |
|
|
|
options: [ |
|
|
|
{ id: "opt_d1", value: "D1", label: "Option D1", order: 1 }, |
|
|
|
{ id: "opt_d2", value: "D2", label: "Option D2", order: 2 }, |
|
|
|
], |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<TestComponent slug="test_slug" /> |
|
|
|
</QuestionAnswersProvider> |
|
|
|
</QueryClientProvider>, |
|
|
|
); |
|
|
|
|
|
|
|
fireEvent.click(screen.getByTestId("set-multi-dropdown")); |
|
|
|
fireEvent.click(screen.getByTestId("save")); |
|
|
|
|
|
|
|
await waitFor(() => { |
|
|
|
expect(capturedPayload).not.toBeNull(); |
|
|
|
const field = capturedPayload.fields.find( |
|
|
|
(f: any) => f.key === "q_multi_drop", |
|
|
|
); |
|
|
|
expect(field.option_id).toEqual(["opt_d1", "opt_d2"]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it("batches all dirty answers into one mutation", async () => { |
|
|
|
const queryClient = new QueryClient({ |
|
|
|
defaultOptions: { queries: { retry: false } }, |
|
|
|
|