Skip to content

Commit 6e177a5

Browse files
committed
fix: combobox tests
1 parent d9513ce commit 6e177a5

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

src/components/fields/ComboBox/ComboBox.test.tsx

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ describe('<ComboBox />', () => {
8787
await userEvent.type(combobox, 're');
8888

8989
await waitFor(() => {
90-
const listbox = getByRole('listbox');
91-
const options = getAllByRole('option', { container: listbox });
90+
expect(getByRole('listbox')).toBeInTheDocument();
91+
const options = getAllByRole('option');
9292
// Should match "Red" and "Green" (contains 're')
9393
expect(options).toHaveLength(2);
9494
expect(options[0]).toHaveTextContent('Red');
@@ -98,6 +98,12 @@ describe('<ComboBox />', () => {
9898
// Clear and test with custom filter
9999
await userEvent.clear(combobox);
100100

101+
// Wait for clear to complete and popover to close
102+
await waitFor(() => {
103+
expect(combobox).toHaveValue('');
104+
expect(queryByRole('listbox')).not.toBeInTheDocument();
105+
});
106+
101107
rerender(
102108
<ComboBox label="test" filter={customFilterFn}>
103109
{items.map((item) => (
@@ -109,8 +115,8 @@ describe('<ComboBox />', () => {
109115
await userEvent.type(combobox, 're');
110116

111117
await waitFor(() => {
112-
const listbox = getByRole('listbox');
113-
const options = getAllByRole('option', { container: listbox });
118+
expect(getByRole('listbox')).toBeInTheDocument();
119+
const options = getAllByRole('option');
114120
// Should only match "Red" (starts with 're')
115121
expect(options).toHaveLength(1);
116122
expect(options[0]).toHaveTextContent('Red');
@@ -120,6 +126,12 @@ describe('<ComboBox />', () => {
120126
// Clear and test with filter disabled
121127
await userEvent.clear(combobox);
122128

129+
// Wait for clear to complete and popover to close
130+
await waitFor(() => {
131+
expect(combobox).toHaveValue('');
132+
expect(queryByRole('listbox')).not.toBeInTheDocument();
133+
});
134+
123135
rerender(
124136
<ComboBox label="test" filter={false}>
125137
{items.map((item) => (
@@ -131,15 +143,21 @@ describe('<ComboBox />', () => {
131143
await userEvent.type(combobox, 're');
132144

133145
await waitFor(() => {
134-
const listbox = getByRole('listbox');
135-
const options = getAllByRole('option', { container: listbox });
146+
expect(getByRole('listbox')).toBeInTheDocument();
147+
const options = getAllByRole('option');
136148
// Should show all items when filter is disabled
137149
expect(options).toHaveLength(7);
138150
});
139151

140152
// Test filtering with sections
141153
await userEvent.clear(combobox);
142154

155+
// Wait for clear to complete and popover to close
156+
await waitFor(() => {
157+
expect(combobox).toHaveValue('');
158+
expect(queryByRole('listbox')).not.toBeInTheDocument();
159+
});
160+
143161
rerender(
144162
<ComboBox label="test">
145163
<ComboBox.Section key="warm" title="Warm Colors">
@@ -158,14 +176,20 @@ describe('<ComboBox />', () => {
158176
await userEvent.type(combobox, 'e');
159177

160178
await waitFor(() => {
161-
const listbox = getByRole('listbox');
162-
const options = getAllByRole('option', { container: listbox });
179+
expect(getByRole('listbox')).toBeInTheDocument();
180+
const options = getAllByRole('option');
163181
// Should match "Red", "Orange", "Yellow", "Green", "Blue", "Purple"
164182
expect(options.length).toBeGreaterThan(0);
165183
});
166184

167185
// Test no results
168186
await userEvent.clear(combobox);
187+
188+
// Wait for clear to complete
189+
await waitFor(() => {
190+
expect(combobox).toHaveValue('');
191+
});
192+
169193
await userEvent.type(combobox, 'zzz');
170194

171195
await waitFor(() => {

0 commit comments

Comments
 (0)