Skip to content

Commit d5c98d5

Browse files
committed
add test for select.tsx regarding multiple property
1 parent 7d74f67 commit d5c98d5

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

chartlets.js/packages/lib/src/plugins/mui/Select.test.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,47 @@ describe("Select", () => {
105105
});
106106
});
107107

108+
it("should fire 'value' property with an array of multiple values", () => {
109+
const { recordedEvents, onChange } = createChangeHandler();
110+
render(
111+
<Select
112+
id="sel"
113+
type={"Select"}
114+
label={"Colors"}
115+
options={[10, 11, 12]}
116+
value={[]}
117+
onChange={onChange}
118+
multiple={true}
119+
/>,
120+
);
121+
// open the Select component's list box
122+
// note, we must use "mouseDown" as "click" doesn't work
123+
fireEvent.mouseDown(screen.getByRole("combobox"));
124+
// click item in the Select component's list box
125+
const listBox = within(screen.getByRole("listbox"));
126+
fireEvent.click(listBox.getByText(/11/i));
127+
fireEvent.click(listBox.getByText(/12/i));
128+
expect(recordedEvents.length).toBe(2);
129+
expect(recordedEvents[1]).toEqual({
130+
componentType: "Select",
131+
id: "sel",
132+
property: "value",
133+
value: [12],
134+
});
135+
expect(recordedEvents).toEqual([{
136+
componentType: "Select",
137+
id: "sel",
138+
property: "value",
139+
value: [11],
140+
},
141+
{
142+
componentType: "Select",
143+
id: "sel",
144+
property: "value",
145+
value: [12],
146+
}]);
147+
});
148+
108149
it("should fire 'value' property with object options", () => {
109150
const { recordedEvents, onChange } = createChangeHandler();
110151
render(

0 commit comments

Comments
 (0)