|
| 1 | +import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types'; |
| 2 | +import shouldPopoverUseScrollView from '@libs/shouldPopoverUseScrollView'; |
| 3 | +import CONST from '@src/CONST'; |
| 4 | + |
| 5 | +describe('shouldPopoverUseScrollView', () => { |
| 6 | + const createOption = (value: string, subMenuItems?: Array<{value: string; text: string}>): DropdownOption<string> => ({ |
| 7 | + value, |
| 8 | + text: value, |
| 9 | + ...(subMenuItems && {subMenuItems: subMenuItems.map((item) => ({...item, key: item.value}))}), |
| 10 | + }); |
| 11 | + |
| 12 | + it('returns false when there are few top-level options and no large submenus', () => { |
| 13 | + const options = [createOption('a'), createOption('b'), createOption('c')]; |
| 14 | + expect(shouldPopoverUseScrollView(options)).toBe(false); |
| 15 | + }); |
| 16 | + |
| 17 | + it('returns true when there are 5 or more top-level options', () => { |
| 18 | + const options = Array.from({length: CONST.DROPDOWN_SCROLL_THRESHOLD}, (_, i) => createOption(`option-${i}`)); |
| 19 | + expect(shouldPopoverUseScrollView(options)).toBe(true); |
| 20 | + }); |
| 21 | + |
| 22 | + it('returns true when any option has 5 or more submenu items', () => { |
| 23 | + const subMenuItems = Array.from({length: CONST.DROPDOWN_SCROLL_THRESHOLD}, (_, i) => ({ |
| 24 | + value: `sub-${i}`, |
| 25 | + text: `Sub ${i}`, |
| 26 | + })); |
| 27 | + const options = [createOption('parent', subMenuItems)]; |
| 28 | + expect(shouldPopoverUseScrollView(options)).toBe(true); |
| 29 | + }); |
| 30 | + |
| 31 | + it('returns false when submenu has fewer than threshold items', () => { |
| 32 | + const subMenuItems = [ |
| 33 | + {value: 'sub-1', text: 'Sub 1'}, |
| 34 | + {value: 'sub-2', text: 'Sub 2'}, |
| 35 | + ]; |
| 36 | + const options = [createOption('parent', subMenuItems)]; |
| 37 | + expect(shouldPopoverUseScrollView(options)).toBe(false); |
| 38 | + }); |
| 39 | +}); |
0 commit comments