Skip to content

Commit 66749d0

Browse files
author
Siddhartha Bingi
committed
Adding test to verify support of categories upto 5
Signed-off-by: Siddhartha Bingi <sidbingi@amazon.com>
1 parent d1d5fd8 commit 66749d0

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

public/pages/ConfigureModel/components/CategoryField/__tests__/CategoryField.test.tsx

+58
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,64 @@ describe('<CategoryField /> spec', () => {
205205
expect(queryByText('b')).not.toBeNull();
206206
expect(queryByText('c')).toBeNull();
207207
});
208+
test(`limits selection to a maximum of 5 entities`, () => {
209+
const { getAllByRole, getByTestId, queryByText } = render(
210+
<Fragment>
211+
<Formik
212+
initialValues={{
213+
categoryField: [],
214+
}}
215+
onSubmit={() => {}}
216+
>
217+
<Fragment>
218+
<Form>
219+
<CategoryField
220+
isEdit={false}
221+
isHCDetector={true}
222+
categoryFieldOptions={['a', 'b', 'c', 'd', 'e', 'f']}
223+
setIsHCDetector={(isHCDetector: boolean) => {
224+
return;
225+
}}
226+
isLoading={false}
227+
formikProps={{
228+
values: {
229+
categoryFieldEnabled: true,
230+
},
231+
}}
232+
/>
233+
</Form>
234+
</Fragment>
235+
</Formik>
236+
</Fragment>
237+
);
238+
// open combo box
239+
fireEvent.click(getByTestId('comboBoxToggleListButton'));
240+
expect(queryByText('a')).not.toBeNull();
241+
expect(queryByText('b')).not.toBeNull();
242+
expect(queryByText('c')).not.toBeNull();
243+
expect(queryByText('d')).not.toBeNull();
244+
expect(queryByText('e')).not.toBeNull();
245+
expect(queryByText('f')).not.toBeNull();
246+
247+
// select top 6 options (a, b, c, d, e, f)
248+
fireEvent.click(getAllByRole('option')[0]);
249+
fireEvent.click(getAllByRole('option')[0]);
250+
fireEvent.click(getAllByRole('option')[0]);
251+
fireEvent.click(getAllByRole('option')[0]);
252+
fireEvent.click(getAllByRole('option')[0]);
253+
fireEvent.click(getAllByRole('option')[0]);
254+
255+
// close combo box
256+
fireEvent.click(getByTestId('comboBoxToggleListButton'));
257+
258+
// the last selection (f) is still not selected
259+
expect(queryByText('a')).not.toBeNull();
260+
expect(queryByText('b')).not.toBeNull();
261+
expect(queryByText('c')).not.toBeNull();
262+
expect(queryByText('d')).not.toBeNull();
263+
expect(queryByText('e')).not.toBeNull();
264+
expect(queryByText('f')).toBeNull();
265+
});
208266
test(`fields are readonly if editing`, () => {
209267
const { getByTestId, queryByText } = render(
210268
<Fragment>

0 commit comments

Comments
 (0)