@ssa-ui-kit/core 0.0.11-alpha → 0.0.12-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc.js +4 -4
- package/.storybook/main.ts +43 -43
- package/.storybook/preview.tsx +22 -22
- package/.storybook/style.css +31 -31
- package/custom-shots/components-popover--hint-opened__[w1920px].png +0 -0
- package/custom-shots/components-table-filters--opened__[w1920px].png +0 -0
- package/customTest.tsx +46 -46
- package/dist/components/Button/fixtures.d.ts +8 -8
- package/dist/components/Icon/icons/UnArchive.d.ts +2 -0
- package/dist/components/Icon/icons/iconsList.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/jest-setup.ts +17 -17
- package/lostpixel.config.ts +26 -26
- package/package.json +1 -1
- package/playwright.config.ts +7 -7
- package/src/components/AccordionGroup/Accordion.tsx +25 -25
- package/src/components/AccordionGroup/AccordionContent.tsx +21 -21
- package/src/components/AccordionGroup/AccordionContext.tsx +66 -66
- package/src/components/AccordionGroup/AccordionGroup.spec.tsx +195 -195
- package/src/components/AccordionGroup/AccordionGroup.tsx +71 -71
- package/src/components/AccordionGroup/AccordionTitle.tsx +41 -41
- package/src/components/AccordionGroup/index.ts +6 -6
- package/src/components/AccordionGroup/stories/AccordionGroup.stories.tsx +107 -107
- package/src/components/AccordionGroup/stories/helpers.tsx +86 -86
- package/src/components/AccordionGroup/styles.ts +121 -121
- package/src/components/AccordionGroup/types.ts +59 -59
- package/src/components/Avatar/Avatar.tsx +15 -15
- package/src/components/Avatar/index.ts +1 -1
- package/src/components/Badge/Badge.spec.tsx +113 -113
- package/src/components/Badge/Badge.stories.tsx +156 -156
- package/src/components/Badge/Badge.tsx +45 -45
- package/src/components/Badge/BadgeBase.tsx +19 -19
- package/src/components/Badge/helpers.ts +49 -49
- package/src/components/Badge/index.ts +1 -1
- package/src/components/Badge/styles.ts +20 -20
- package/src/components/Badge/types.ts +7 -7
- package/src/components/Button/Button.spec.tsx +529 -529
- package/src/components/Button/Button.stories.tsx +124 -124
- package/src/components/Button/Button.tsx +121 -121
- package/src/components/Button/ButtonBase.tsx +14 -14
- package/src/components/Button/ButtonText.tsx +67 -67
- package/src/components/Button/fixtures.ts +165 -165
- package/src/components/Button/helpers.ts +30 -30
- package/src/components/Button/index.ts +1 -1
- package/src/components/Button/styles.ts +168 -168
- package/src/components/Button/types.ts +48 -48
- package/src/components/ButtonGroup/ButtonGroup.spec.tsx +60 -60
- package/src/components/ButtonGroup/ButtonGroup.stories.tsx +42 -42
- package/src/components/ButtonGroup/ButtonGroup.tsx +40 -40
- package/src/components/ButtonGroup/helpers.ts +7 -7
- package/src/components/ButtonGroup/index.ts +2 -2
- package/src/components/ButtonGroup/styles.ts +53 -53
- package/src/components/ButtonGroup/types.ts +14 -14
- package/src/components/Card/Card.spec.tsx +94 -94
- package/src/components/Card/Card.stories.tsx +253 -253
- package/src/components/Card/Card.tsx +13 -13
- package/src/components/Card/CardBase.tsx +20 -20
- package/src/components/Card/index.ts +2 -2
- package/src/components/Card/types.ts +8 -8
- package/src/components/CardContent/CardContent.tsx +17 -17
- package/src/components/CardContent/CardContentBase.tsx +12 -12
- package/src/components/CardContent/index.ts +1 -1
- package/src/components/CardHeader/CardHeader.tsx +26 -26
- package/src/components/CardHeader/CardHeaderBase.tsx +21 -21
- package/src/components/CardHeader/index.ts +1 -1
- package/src/components/Checkbox/Checkbox.spec.tsx +193 -193
- package/src/components/Checkbox/Checkbox.stories.tsx +93 -93
- package/src/components/Checkbox/Checkbox.tsx +79 -79
- package/src/components/Checkbox/CheckboxBase.tsx +71 -71
- package/src/components/Checkbox/index.ts +3 -3
- package/src/components/Checkbox/styles.tsx +70 -70
- package/src/components/Checkbox/types.ts +32 -32
- package/src/components/ColorPicker/ColorPicker.spec.tsx +58 -58
- package/src/components/ColorPicker/ColorPicker.stories.tsx +48 -48
- package/src/components/ColorPicker/ColorPicker.tsx +47 -47
- package/src/components/ColorPicker/index.ts +1 -1
- package/src/components/ColorPicker/styles.ts +14 -14
- package/src/components/ColorPicker/types.ts +21 -21
- package/src/components/Dropdown/Dropdown.context.ts +16 -16
- package/src/components/Dropdown/Dropdown.spec.tsx +332 -332
- package/src/components/Dropdown/Dropdown.stories.tsx +155 -155
- package/src/components/Dropdown/Dropdown.tsx +135 -135
- package/src/components/Dropdown/index.ts +2 -2
- package/src/components/Dropdown/types.ts +17 -17
- package/src/components/DropdownArrow/DropdownArrow.tsx +17 -17
- package/src/components/DropdownArrow/index.ts +1 -1
- package/src/components/DropdownBase/DropdownBase.tsx +10 -10
- package/src/components/DropdownBase/index.ts +1 -1
- package/src/components/DropdownOption/DropdownOption.tsx +56 -56
- package/src/components/DropdownOption/index.ts +1 -1
- package/src/components/DropdownOptions/DropdownOptions.tsx +102 -102
- package/src/components/DropdownOptions/index.ts +2 -2
- package/src/components/DropdownOptions/types.ts +9 -9
- package/src/components/DropdownToggle/DropdownToggle.tsx +148 -148
- package/src/components/DropdownToggle/index.ts +1 -1
- package/src/components/DropdownToggle/types.ts +22 -22
- package/src/components/Form/Form.stories.mdx +118 -118
- package/src/components/Form/Form.stories.tsx +432 -432
- package/src/components/Form/Form.tsx +9 -9
- package/src/components/Form/index.ts +1 -1
- package/src/components/FormAction/FormAction.tsx +8 -8
- package/src/components/FormAction/index.ts +1 -1
- package/src/components/FormCheckbox/FormCheckbox.tsx +33 -33
- package/src/components/FormCheckbox/index.ts +1 -1
- package/src/components/FormCheckbox/types.ts +10 -10
- package/src/components/FormGroup/FormGroup.tsx +15 -15
- package/src/components/FormGroup/index.ts +1 -1
- package/src/components/FormHelperText/FormHelperText.tsx +18 -18
- package/src/components/FormHelperText/FormHelperTextBase.tsx +22 -22
- package/src/components/FormHelperText/index.ts +1 -1
- package/src/components/FormHelperText/types.ts +8 -8
- package/src/components/FormRadioGroup/FormRadioGroup.spec.tsx +74 -74
- package/src/components/FormRadioGroup/FormRadioGroup.stories.tsx +90 -90
- package/src/components/FormRadioGroup/FormRadioGroup.tsx +35 -35
- package/src/components/FormRadioGroup/index.ts +1 -1
- package/src/components/FormRadioGroup/types.ts +12 -12
- package/src/components/Icon/Icon.tsx +7 -7
- package/src/components/Icon/Icons.spec.tsx +89 -89
- package/src/components/Icon/Icons.stories.tsx +62 -62
- package/src/components/Icon/icons/Archive.tsx +36 -36
- package/src/components/Icon/icons/ArrowDown.tsx +27 -27
- package/src/components/Icon/icons/ArrowUp.tsx +27 -27
- package/src/components/Icon/icons/Attention.tsx +23 -23
- package/src/components/Icon/icons/Bin.tsx +29 -29
- package/src/components/Icon/icons/Calendar.tsx +17 -17
- package/src/components/Icon/icons/CarrotDown.tsx +25 -25
- package/src/components/Icon/icons/CarrotLeft.tsx +25 -25
- package/src/components/Icon/icons/CarrotRight.tsx +25 -25
- package/src/components/Icon/icons/CarrotUp.tsx +21 -21
- package/src/components/Icon/icons/Change.tsx +17 -17
- package/src/components/Icon/icons/Chart.tsx +38 -38
- package/src/components/Icon/icons/Check.tsx +21 -21
- package/src/components/Icon/icons/CheckCircle.tsx +31 -31
- package/src/components/Icon/icons/Circle.tsx +23 -23
- package/src/components/Icon/icons/Clock.tsx +32 -32
- package/src/components/Icon/icons/Copy.tsx +24 -24
- package/src/components/Icon/icons/Cross.tsx +28 -28
- package/src/components/Icon/icons/Diet.tsx +17 -17
- package/src/components/Icon/icons/Email.tsx +20 -20
- package/src/components/Icon/icons/Filter.tsx +19 -19
- package/src/components/Icon/icons/Home.tsx +17 -17
- package/src/components/Icon/icons/Information.tsx +29 -29
- package/src/components/Icon/icons/Invisible.tsx +56 -56
- package/src/components/Icon/icons/Lock.tsx +18 -18
- package/src/components/Icon/icons/LogIn.tsx +22 -22
- package/src/components/Icon/icons/LogOut.tsx +22 -22
- package/src/components/Icon/icons/Measurements.tsx +23 -23
- package/src/components/Icon/icons/Minus.tsx +21 -21
- package/src/components/Icon/icons/More.tsx +25 -25
- package/src/components/Icon/icons/MoreVertical.tsx +20 -20
- package/src/components/Icon/icons/Notification.tsx +23 -23
- package/src/components/Icon/icons/Plus.tsx +28 -28
- package/src/components/Icon/icons/RadioOn.tsx +24 -24
- package/src/components/Icon/icons/Robot.tsx +19 -19
- package/src/components/Icon/icons/Search.tsx +19 -19
- package/src/components/Icon/icons/Settings.tsx +25 -25
- package/src/components/Icon/icons/Sleep.tsx +21 -21
- package/src/components/Icon/icons/Stats.tsx +21 -21
- package/src/components/Icon/icons/Trainings.tsx +17 -17
- package/src/components/Icon/icons/UnArchive.tsx +45 -0
- package/src/components/Icon/icons/Union.tsx +20 -20
- package/src/components/Icon/icons/User.tsx +35 -35
- package/src/components/Icon/icons/Visible.tsx +28 -28
- package/src/components/Icon/icons/Warning.tsx +23 -23
- package/src/components/Icon/icons/iconsList.tsx +56 -55
- package/src/components/Icon/icons/index.tsx +117 -115
- package/src/components/Icon/index.ts +2 -2
- package/src/components/Icon/types.ts +14 -14
- package/src/components/Indicator/Indicator.spec.tsx +67 -67
- package/src/components/Indicator/Indicator.stories.tsx +106 -106
- package/src/components/Indicator/Indicator.tsx +86 -86
- package/src/components/Indicator/IndicatorBase.tsx +27 -27
- package/src/components/Indicator/index.ts +1 -1
- package/src/components/Indicator/types.ts +9 -9
- package/src/components/Input/Input.spec.tsx +95 -95
- package/src/components/Input/Input.stories.tsx +215 -215
- package/src/components/Input/Input.tsx +70 -70
- package/src/components/Input/InputBase.tsx +42 -42
- package/src/components/Input/InputGroup.tsx +12 -12
- package/src/components/Input/InputStatusError.tsx +20 -20
- package/src/components/Input/InputStatusSuccess.tsx +16 -16
- package/src/components/Input/index.ts +1 -1
- package/src/components/Input/styles.ts +111 -111
- package/src/components/Input/types.ts +36 -36
- package/src/components/Label/Label.spec.tsx +57 -57
- package/src/components/Label/Label.tsx +20 -20
- package/src/components/Label/LabelBase.tsx +14 -14
- package/src/components/Label/index.ts +1 -1
- package/src/components/Label/types.ts +9 -9
- package/src/components/LargeTab/LargeTab.tsx +38 -38
- package/src/components/LargeTab/LargeTabBase.tsx +39 -39
- package/src/components/LargeTab/index.ts +1 -1
- package/src/components/LargeTab/styles.ts +17 -17
- package/src/components/Link/Link.tsx +10 -10
- package/src/components/Link/Link.types.ts +4 -4
- package/src/components/Link/LinkBase.ts +5 -5
- package/src/components/Link/index.tsx +1 -1
- package/src/components/Modal/Modal.context.tsx +9 -9
- package/src/components/Modal/Modal.spec.tsx +154 -154
- package/src/components/Modal/Modal.stories.tsx +97 -97
- package/src/components/Modal/Modal.tsx +12 -12
- package/src/components/Modal/index.ts +2 -2
- package/src/components/Modal/types.ts +4 -4
- package/src/components/ModalContent/ModalContent.tsx +21 -21
- package/src/components/ModalContent/index.ts +1 -1
- package/src/components/ModalDialog/ModalDialog.tsx +67 -67
- package/src/components/ModalDialog/index.ts +2 -2
- package/src/components/ModalDialog/types.ts +7 -7
- package/src/components/ModalDismissButton/ModalDismissButton.tsx +15 -15
- package/src/components/ModalDismissButton/index.ts +1 -1
- package/src/components/ModalOpenButton/ModalOpenButton.tsx +15 -15
- package/src/components/ModalOpenButton/index.ts +1 -1
- package/src/components/MultipleDropdown/MultipleDropdown.context.ts +20 -20
- package/src/components/MultipleDropdown/MultipleDropdown.spec.tsx +414 -414
- package/src/components/MultipleDropdown/MultipleDropdown.tsx +217 -217
- package/src/components/MultipleDropdown/index.ts +1 -1
- package/src/components/MultipleDropdown/stories/MultipleDropdown.stories.tsx +239 -239
- package/src/components/MultipleDropdown/stories/consts.ts +5 -5
- package/src/components/MultipleDropdown/types.ts +20 -20
- package/src/components/MultipleDropdown/utils.ts +32 -32
- package/src/components/MultipleDropdownNotification/MultipleDropdownNotification.tsx +13 -13
- package/src/components/MultipleDropdownNotification/index.ts +1 -1
- package/src/components/MultipleDropdownOptions/MultipleDropdownOptions.tsx +156 -156
- package/src/components/MultipleDropdownOptions/index.ts +2 -2
- package/src/components/MultipleDropdownOptions/types.ts +7 -7
- package/src/components/Popover/Popover.e2e.ts +26 -26
- package/src/components/Popover/Popover.spec.tsx +17 -17
- package/src/components/Popover/Popover.tsx +21 -21
- package/src/components/Popover/PopoverClose.tsx +21 -21
- package/src/components/Popover/PopoverContent.tsx +37 -37
- package/src/components/Popover/PopoverDescription.tsx +21 -21
- package/src/components/Popover/PopoverHeading.tsx +25 -25
- package/src/components/Popover/PopoverTrigger.tsx +47 -47
- package/src/components/Popover/hooks/usePopover.tsx +109 -109
- package/src/components/Popover/hooks/usePopoverContext.tsx +16 -16
- package/src/components/Popover/index.ts +6 -6
- package/src/components/Popover/stories/Popover.stories.tsx +39 -39
- package/src/components/Popover/stories/StoryComponent.tsx +42 -42
- package/src/components/Popover/types.ts +45 -45
- package/src/components/Progress/Progress.spec.tsx +85 -85
- package/src/components/Progress/Progress.stories.tsx +234 -234
- package/src/components/Progress/Progress.tsx +7 -7
- package/src/components/Progress/index.ts +1 -1
- package/src/components/Progress/types.ts +5 -5
- package/src/components/ProgressBar/ProgressBar.tsx +68 -68
- package/src/components/ProgressBar/index.ts +1 -1
- package/src/components/ProgressBar/styles.ts +15 -15
- package/src/components/ProgressBar/types.ts +7 -7
- package/src/components/ProgressCircle/ProgressCircle.spec.tsx +37 -37
- package/src/components/ProgressCircle/ProgressCircle.stories.tsx +96 -96
- package/src/components/ProgressCircle/ProgressCircle.tsx +60 -60
- package/src/components/ProgressCircle/ProgressCircleBase.tsx +45 -45
- package/src/components/ProgressCircle/ProgressCircleInner.tsx +16 -16
- package/src/components/ProgressCircle/ProgressCircleOuter.tsx +14 -14
- package/src/components/ProgressCircle/index.ts +1 -1
- package/src/components/ProgressCircle/styles.ts +20 -20
- package/src/components/ProgressCircle/types.ts +7 -7
- package/src/components/ProgressLegend/ProgressLegend.tsx +41 -41
- package/src/components/ProgressLegend/index.ts +1 -1
- package/src/components/ProgressLegend/types.ts +12 -12
- package/src/components/ProgressLegendItem/ProgressLegendItem.tsx +52 -52
- package/src/components/ProgressLegendItem/index.ts +1 -1
- package/src/components/ProgressLegendItem/types.ts +6 -6
- package/src/components/ProgressVertical/ProgressVertical.tsx +23 -23
- package/src/components/ProgressVertical/index.ts +1 -1
- package/src/components/ProgressVertical/types.ts +5 -5
- package/src/components/Radio/Radio.spec.tsx +234 -234
- package/src/components/Radio/Radio.stories.tsx +52 -52
- package/src/components/Radio/Radio.tsx +56 -56
- package/src/components/Radio/RadioBase.tsx +36 -36
- package/src/components/Radio/index.ts +1 -1
- package/src/components/Radio/types.ts +11 -11
- package/src/components/RadioGroup/RadioGroup.spec.tsx +116 -116
- package/src/components/RadioGroup/RadioGroup.stories.tsx +84 -84
- package/src/components/RadioGroup/RadioGroup.tsx +49 -49
- package/src/components/RadioGroup/RadioGroupBase.tsx +3 -3
- package/src/components/RadioGroup/index.ts +1 -1
- package/src/components/RadioGroup/types.ts +10 -10
- package/src/components/ResponsiveImage/ResponsiveImage.spec.tsx +43 -43
- package/src/components/ResponsiveImage/ResponsiveImage.stories.tsx +33 -33
- package/src/components/ResponsiveImage/ResponsiveImage.tsx +14 -14
- package/src/components/ResponsiveImage/index.tsx +1 -1
- package/src/components/ResponsiveImage/types.ts +7 -7
- package/src/components/Step/Step.context.ts +21 -21
- package/src/components/Step/Step.tsx +58 -58
- package/src/components/Step/index.ts +2 -2
- package/src/components/StepConnector/StepConnector.tsx +34 -34
- package/src/components/StepConnector/index.ts +1 -1
- package/src/components/StepConnector/style.ts +24 -24
- package/src/components/StepLabel/StepLabel.tsx +65 -65
- package/src/components/StepLabel/index.ts +1 -1
- package/src/components/StepLabel/styles.ts +38 -38
- package/src/components/Stepper/Stepper.context.ts +16 -16
- package/src/components/Stepper/Stepper.spec.tsx +128 -128
- package/src/components/Stepper/Stepper.stories.tsx +292 -292
- package/src/components/Stepper/Stepper.tsx +49 -49
- package/src/components/Stepper/index.ts +5 -5
- package/src/components/Stepper/types.ts +17 -17
- package/src/components/Switch/Switch.spec.tsx +181 -181
- package/src/components/Switch/Switch.stories.tsx +64 -64
- package/src/components/Switch/Switch.tsx +21 -21
- package/src/components/Switch/SwitchBase.tsx +62 -62
- package/src/components/Switch/SwitchContext.tsx +38 -38
- package/src/components/Switch/index.ts +6 -6
- package/src/components/Switch/types.ts +4 -4
- package/src/components/Tab/Tab.tsx +31 -31
- package/src/components/Tab/TabBase.tsx +31 -31
- package/src/components/Tab/index.ts +1 -1
- package/src/components/TabBar/TabBar.spec.tsx +290 -290
- package/src/components/TabBar/TabBar.tsx +43 -43
- package/src/components/TabBar/TabBarContext.tsx +43 -43
- package/src/components/TabBar/index.ts +6 -6
- package/src/components/TabBar/stories/TimePeriodTabBar.stories.tsx +84 -84
- package/src/components/TabBar/stories/WeekTabBar.stories.tsx +136 -136
- package/src/components/TabBar/stories/helpers.tsx +69 -69
- package/src/components/TabBar/types.ts +39 -39
- package/src/components/Table/Table.spec.tsx +86 -86
- package/src/components/Table/Table.tsx +13 -13
- package/src/components/Table/index.ts +1 -1
- package/src/components/Table/stories/SortableTable.tsx +78 -78
- package/src/components/Table/stories/Table.stories.tsx +94 -94
- package/src/components/Table/stories/consts.ts +6 -6
- package/src/components/Table/stories/mock.ts +16 -16
- package/src/components/Table/stories/types.ts +9 -9
- package/src/components/Table/stories/utils.ts +2 -2
- package/src/components/TableBody/TableBody.tsx +8 -8
- package/src/components/TableBody/index.ts +1 -1
- package/src/components/TableCell/TableCell.tsx +16 -16
- package/src/components/TableCell/index.ts +1 -1
- package/src/components/TableHead/TableHead.tsx +15 -15
- package/src/components/TableHead/index.ts +1 -1
- package/src/components/TableRow/TableRow.tsx +12 -12
- package/src/components/TableRow/index.ts +1 -1
- package/src/components/Tag/Tag.spec.tsx +121 -121
- package/src/components/Tag/Tag.stories.tsx +96 -96
- package/src/components/Tag/Tag.tsx +47 -47
- package/src/components/Tag/index.ts +1 -1
- package/src/components/Tag/styles.ts +123 -123
- package/src/components/Tag/types.ts +7 -7
- package/src/components/TextField/TextField.spec.tsx +171 -171
- package/src/components/TextField/TextField.stories.tsx +221 -221
- package/src/components/TextField/TextField.tsx +61 -61
- package/src/components/TextField/index.ts +1 -1
- package/src/components/TextField/types.ts +14 -14
- package/src/components/Textarea/Textarea.spec.tsx +56 -56
- package/src/components/Textarea/Textarea.stories.tsx +59 -59
- package/src/components/Textarea/Textarea.tsx +37 -37
- package/src/components/Textarea/TextareaBase.tsx +46 -46
- package/src/components/Textarea/index.ts +1 -1
- package/src/components/Textarea/types.ts +16 -16
- package/src/components/Tooltip/ProgressChartTooltip.tsx +48 -48
- package/src/components/Tooltip/SimpleChartTooltip.tsx +20 -20
- package/src/components/Tooltip/Tooltip.spec.tsx +305 -305
- package/src/components/Tooltip/Tooltip.stories.tsx +160 -160
- package/src/components/Tooltip/Tooltip.tsx +22 -22
- package/src/components/Tooltip/TooltipArrow.tsx +26 -26
- package/src/components/Tooltip/TooltipContentBase.tsx +9 -9
- package/src/components/Tooltip/index.ts +5 -5
- package/src/components/Tooltip/styles.ts +16 -16
- package/src/components/Tooltip/types.ts +88 -88
- package/src/components/Tooltip/useTooltip.tsx +74 -74
- package/src/components/Tooltip/useTooltipContext.tsx +16 -16
- package/src/components/Tooltip/utils.tsx +8 -8
- package/src/components/TooltipContent/TooltipContent.tsx +49 -49
- package/src/components/TooltipContent/index.ts +1 -1
- package/src/components/TooltipTrigger/TooltipTrigger.tsx +21 -21
- package/src/components/TooltipTrigger/index.ts +1 -1
- package/src/components/Typography/Typography.spec.tsx +259 -259
- package/src/components/Typography/Typography.stories.tsx +68 -68
- package/src/components/Typography/Typography.tsx +52 -52
- package/src/components/Typography/index.ts +1 -1
- package/src/components/Typography/styles.ts +85 -85
- package/src/components/Typography/types.ts +22 -22
- package/src/components/Wrapper/Wrapper.spec.tsx +15 -15
- package/src/components/Wrapper/Wrapper.tsx +19 -19
- package/src/components/Wrapper/index.ts +1 -1
- package/src/consts.ts +18 -18
- package/src/index.ts +94 -94
- package/src/injectGlobal.ts +41 -41
- package/src/styles/global.ts +91 -91
- package/src/styles/safari-focus-outline.ts +37 -37
- package/src/styles/styles.spec.tsx +42 -42
- package/src/themes/main.ts +116 -116
- package/src/types/emotion.d.ts +7 -7
- package/src/types/emotion.ts +132 -132
- package/src/types/global.d.ts +7 -7
- package/src/types/global.ts +19 -19
- package/storybook-static/1283.a11004a1.iframe.bundle.js +1 -0
- package/storybook-static/1326.74edde53.iframe.bundle.js +1 -0
- package/storybook-static/2912.4c6e14cb.iframe.bundle.js +1 -0
- package/storybook-static/3547.515f04ab.iframe.bundle.js +1 -0
- package/storybook-static/3624.1414516c.iframe.bundle.js +1 -0
- package/storybook-static/3753.bd2e2900.iframe.bundle.js +1 -0
- package/storybook-static/4106.7f1435f2.iframe.bundle.js +402 -0
- package/storybook-static/4106.7f1435f2.iframe.bundle.js.LICENSE.txt +62 -0
- package/storybook-static/4106.7f1435f2.iframe.bundle.js.map +1 -0
- package/storybook-static/4166.6fdf56d2.iframe.bundle.js +1 -0
- package/storybook-static/4339.437b4af1.iframe.bundle.js +1 -0
- package/storybook-static/4995.d16abbf0.iframe.bundle.js +1 -0
- package/storybook-static/5199.6867eb61.iframe.bundle.js +1 -0
- package/storybook-static/5374.19c2f606.iframe.bundle.js +6 -0
- package/storybook-static/5374.19c2f606.iframe.bundle.js.LICENSE.txt +8 -0
- package/storybook-static/5374.19c2f606.iframe.bundle.js.map +1 -0
- package/storybook-static/5417.e7b726cc.iframe.bundle.js +1 -0
- package/storybook-static/5497.0b734124.iframe.bundle.js +44 -0
- package/storybook-static/5497.0b734124.iframe.bundle.js.map +1 -0
- package/storybook-static/5521.fbe15eea.iframe.bundle.js +1 -0
- package/storybook-static/5540.fa362783.iframe.bundle.js +1 -0
- package/storybook-static/5938.713bc0f1.iframe.bundle.js +1 -0
- package/storybook-static/6092.0baa0be2.iframe.bundle.js +1 -0
- package/storybook-static/6216.8da65c4d.iframe.bundle.js +1 -0
- package/storybook-static/6374.b662bb7e.iframe.bundle.js +1 -0
- package/storybook-static/7076.fc69dc87.iframe.bundle.js +1 -0
- package/storybook-static/7263.784ad817.iframe.bundle.js +1 -0
- package/storybook-static/7609.fa84d5d0.iframe.bundle.js +1 -0
- package/storybook-static/7633.6d7427ee.iframe.bundle.js +1 -0
- package/storybook-static/7767.2ce7411d.iframe.bundle.js +1 -0
- package/storybook-static/8069.7d70ab4a.iframe.bundle.js +1 -0
- package/storybook-static/8251.01f55356.iframe.bundle.js +1 -0
- package/storybook-static/9134.27efc9b6.iframe.bundle.js +1 -0
- package/storybook-static/9185.5e034211.iframe.bundle.js +133 -0
- package/storybook-static/9185.5e034211.iframe.bundle.js.map +1 -0
- package/storybook-static/9661.7fb349c2.iframe.bundle.js +1 -0
- package/storybook-static/9672.98d487be.iframe.bundle.js +1 -0
- package/storybook-static/973.378dae04.iframe.bundle.js +1 -0
- package/storybook-static/components-AccordionGroup-stories-AccordionGroup-stories.c8781719.iframe.bundle.js +1 -0
- package/storybook-static/components-Badge-Badge-stories.34ed507d.iframe.bundle.js +1 -0
- package/storybook-static/components-Button-Button-stories.42cf6ebc.iframe.bundle.js +1 -0
- package/storybook-static/components-Card-Card-stories.dce075fe.iframe.bundle.js +1 -0
- package/storybook-static/components-Checkbox-Checkbox-stories.c3b0ba2a.iframe.bundle.js +1 -0
- package/storybook-static/components-ColorPicker-ColorPicker-stories.227d5d28.iframe.bundle.js +1 -0
- package/storybook-static/components-Dropdown-Dropdown-stories.a86e6d8b.iframe.bundle.js +1 -0
- package/storybook-static/components-Form-Form-stories-mdx.febb9417.iframe.bundle.js +2 -0
- package/storybook-static/components-Form-Form-stories-mdx.febb9417.iframe.bundle.js.LICENSE.txt +9 -0
- package/storybook-static/components-Form-Form-stories.1030ead7.iframe.bundle.js +1 -0
- package/storybook-static/components-FormRadioGroup-FormRadioGroup-stories.9d91e8c9.iframe.bundle.js +1 -0
- package/storybook-static/components-Icon-Icons-stories.fe368cd9.iframe.bundle.js +1 -0
- package/storybook-static/components-Input-Input-stories.ecfd89af.iframe.bundle.js +1 -0
- package/storybook-static/components-Modal-Modal-stories.bd406807.iframe.bundle.js +1 -0
- package/storybook-static/components-MultipleDropdown-MultipleDropdown-stories.80762ee2.iframe.bundle.js +1 -0
- package/storybook-static/components-Popover-stories-Popover-stories.5bbb9c19.iframe.bundle.js +1 -0
- package/storybook-static/components-Progress-Progress-stories.924b6ce3.iframe.bundle.js +1 -0
- package/storybook-static/components-ProgressCircle-ProgressCircle-stories.abf7a711.iframe.bundle.js +1 -0
- package/storybook-static/components-Radio-Radio-stories.ea10f6ac.iframe.bundle.js +1 -0
- package/storybook-static/components-RadioGroup-RadioGroup-stories.8be03b3f.iframe.bundle.js +1 -0
- package/storybook-static/components-ResponsiveImage-ResponsiveImage-stories.d6d0fc31.iframe.bundle.js +1 -0
- package/storybook-static/components-Stepper-Stepper-stories.55fe429d.iframe.bundle.js +1 -0
- package/storybook-static/components-Switch-Switch-stories.760b85d7.iframe.bundle.js +1 -0
- package/storybook-static/components-TabBar-stories-TimePeriodTabBar-stories.6f0ee7ee.iframe.bundle.js +1 -0
- package/storybook-static/components-TabBar-stories-WeekTabBar-stories.1d8887da.iframe.bundle.js +1 -0
- package/storybook-static/components-Table-Table-stories.cf62219e.iframe.bundle.js +1 -0
- package/storybook-static/components-Tag-Tag-stories.dc89b8dd.iframe.bundle.js +1 -0
- package/storybook-static/components-TextField-TextField-stories.23ab264d.iframe.bundle.js +1 -0
- package/storybook-static/components-Textarea-Textarea-stories.5d16dfd0.iframe.bundle.js +1 -0
- package/storybook-static/components-Tooltip-Tooltip-stories.4cf83194.iframe.bundle.js +1 -0
- package/storybook-static/components-Typography-Typography-stories.b04f7644.iframe.bundle.js +1 -0
- package/storybook-static/favicon.svg +7 -0
- package/storybook-static/iframe.html +355 -0
- package/storybook-static/index.html +130 -0
- package/storybook-static/index.json +1 -0
- package/storybook-static/main.17671a9a.iframe.bundle.js +1 -0
- package/storybook-static/project.json +1 -0
- package/storybook-static/runtime~main.a44b94df.iframe.bundle.js +1 -0
- package/storybook-static/sb-addons/essentials-actions-2/manager-bundle.js +4 -0
- package/storybook-static/sb-addons/essentials-actions-2/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-actions-2/manager-bundle.js.map +7 -0
- package/storybook-static/sb-addons/essentials-backgrounds-3/manager-bundle.js +13 -0
- package/storybook-static/sb-addons/essentials-backgrounds-3/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-backgrounds-3/manager-bundle.js.map +7 -0
- package/storybook-static/sb-addons/essentials-controls-1/manager-bundle.js +115 -0
- package/storybook-static/sb-addons/essentials-controls-1/manager-bundle.js.LEGAL.txt +18 -0
- package/storybook-static/sb-addons/essentials-controls-1/manager-bundle.js.map +7 -0
- package/storybook-static/sb-addons/essentials-measure-6/manager-bundle.js +4 -0
- package/storybook-static/sb-addons/essentials-measure-6/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-measure-6/manager-bundle.js.map +7 -0
- package/storybook-static/sb-addons/essentials-outline-7/manager-bundle.js +4 -0
- package/storybook-static/sb-addons/essentials-outline-7/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-outline-7/manager-bundle.js.map +7 -0
- package/storybook-static/sb-addons/essentials-toolbars-5/manager-bundle.js +4 -0
- package/storybook-static/sb-addons/essentials-toolbars-5/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-toolbars-5/manager-bundle.js.map +7 -0
- package/storybook-static/sb-addons/essentials-viewport-4/manager-bundle.js +4 -0
- package/storybook-static/sb-addons/essentials-viewport-4/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/essentials-viewport-4/manager-bundle.js.map +7 -0
- package/storybook-static/sb-addons/interactions-8/manager-bundle.js +28 -0
- package/storybook-static/sb-addons/interactions-8/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/interactions-8/manager-bundle.js.map +7 -0
- package/storybook-static/sb-addons/links-0/manager-bundle.js +4 -0
- package/storybook-static/sb-addons/links-0/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/links-0/manager-bundle.js.map +7 -0
- package/storybook-static/sb-addons/pseudo-states-9/manager-bundle.js +4 -0
- package/storybook-static/sb-addons/pseudo-states-9/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-static/sb-addons/pseudo-states-9/manager-bundle.js.map +7 -0
- package/storybook-static/sb-common-assets/fonts.css +31 -0
- package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
- package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
- package/storybook-static/sb-manager/CRUD-I5EZL2FS-LBZVDZXV.js +1 -0
- package/storybook-static/sb-manager/Communicate-7JXCND2Z-6SIVXWT4.js +1 -0
- package/storybook-static/sb-manager/Devices-SUYACUPO-DMGV6ENX.js +1 -0
- package/storybook-static/sb-manager/Documents-SGWAY3KW-XZRZ6I6S.js +1 -0
- package/storybook-static/sb-manager/Editing-7QFB6ZMG-J5U6QGB6.js +1 -0
- package/storybook-static/sb-manager/Git-DZ2D5ZUL-VKBWYJHE.js +1 -0
- package/storybook-static/sb-manager/GlobalScrollAreaStyles-4LLX2B3H-DOBSPBNW.js +7 -0
- package/storybook-static/sb-manager/Images-S2WTXNGG-NXAYS4VP.js +1 -0
- package/storybook-static/sb-manager/Logos-SJTNNI74-F3IVL4UV.js +1 -0
- package/storybook-static/sb-manager/OS-YZ2Y4VYS-KGSGCOHC.js +1 -0
- package/storybook-static/sb-manager/OverlayScrollbars-OL4C4TVX-FNYA4OIC.js +1 -0
- package/storybook-static/sb-manager/People-OD4EV7WZ-DBPUNUXW.js +1 -0
- package/storybook-static/sb-manager/Wayfinding-BB4H7CHP-N2QAVLVA.js +1 -0
- package/storybook-static/sb-manager/WithTooltip-YBG737T3-GLWUADFI.js +1 -0
- package/storybook-static/sb-manager/chunk-6KNXZZZ5.js +207 -0
- package/storybook-static/sb-manager/chunk-DP4DR4LA.js +15 -0
- package/storybook-static/sb-manager/chunk-GBCXFRBK.js +1 -0
- package/storybook-static/sb-manager/chunk-IFNK3PLJ.js +1 -0
- package/storybook-static/sb-manager/chunk-JMPBYCHU.js +1 -0
- package/storybook-static/sb-manager/chunk-JSPL73I3.js +1 -0
- package/storybook-static/sb-manager/chunk-SJD7EFYL.js +136 -0
- package/storybook-static/sb-manager/chunk-UBXIQABM.js +447 -0
- package/storybook-static/sb-manager/chunk-V7GYLJLR.js +7 -0
- package/storybook-static/sb-manager/chunk-Z4NRYNHR.js +1 -0
- package/storybook-static/sb-manager/formatter-6736J7QO-TGL2ZGQC.js +156 -0
- package/storybook-static/sb-manager/globals.js +1 -0
- package/storybook-static/sb-manager/index.js +1 -0
- package/storybook-static/sb-manager/runtime.js +1 -0
- package/storybook-static/sb-manager/syntaxhighlighter-4OVWVELQ-5IZ45DZY.js +1 -0
- package/storybook-static/sb-preview/globals.js +1 -0
- package/storybook-static/sb-preview/runtime.js +105 -0
- package/storybook-static/stories.json +1 -0
- package/tasks/create.js +45 -45
- package/tasks/firebase-import-meal-nutrients.js +66 -66
- package/tsbuildcache +1 -1
- package/tsconfig.build.json +44 -44
- package/tsconfig.json +20 -20
- package/tsconfig.tsbuildinfo +1 -0
- package/webpack.config.js +26 -26
- package/LICENSE +0 -21
|
@@ -1,414 +1,414 @@
|
|
|
1
|
-
import { within } from '@testing-library/dom';
|
|
2
|
-
import userEvent from '@testing-library/user-event';
|
|
3
|
-
|
|
4
|
-
import DropdownOption from '@components/DropdownOption';
|
|
5
|
-
|
|
6
|
-
import MultipleDropdown from '.';
|
|
7
|
-
import { DynamicallyChangedItems } from './stories/MultipleDropdown.stories';
|
|
8
|
-
|
|
9
|
-
interface Item {
|
|
10
|
-
value: number;
|
|
11
|
-
label: string;
|
|
12
|
-
subText: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const items = [
|
|
16
|
-
{ value: 1, label: 'First Item', subText: 'Sub text 1' },
|
|
17
|
-
{ value: 2, label: 'Second Item', subText: 'Sub text 2' },
|
|
18
|
-
{ value: 3, label: 'Third Item', subText: 'Sub text 3' },
|
|
19
|
-
{ value: 4, label: 'Fourth Item', subText: 'Sub text 4' },
|
|
20
|
-
{ value: 5, label: 'Fifth Item', subText: 'Sub text 5' },
|
|
21
|
-
{ value: 6, label: 'Sixth Item', subText: 'Sub text 6' },
|
|
22
|
-
{ value: 7, label: 'Seventh Item', subText: 'Sub text 7' },
|
|
23
|
-
];
|
|
24
|
-
const selectedItems = [items[2], items[4]];
|
|
25
|
-
const selectedItemsValues = selectedItems.map((item) => item.value);
|
|
26
|
-
const placeholder = 'Strategy';
|
|
27
|
-
|
|
28
|
-
const getListItemValue = (item: Item) => item.label;
|
|
29
|
-
|
|
30
|
-
describe('MultipleDropdown', () => {
|
|
31
|
-
function setup(props = {}) {
|
|
32
|
-
const mockOnChange = jest.fn();
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
user: userEvent.setup(),
|
|
36
|
-
mockOnChange,
|
|
37
|
-
...render(
|
|
38
|
-
<MultipleDropdown isMultiple onChange={mockOnChange} {...props}>
|
|
39
|
-
{items.map((item, index) => (
|
|
40
|
-
<DropdownOption key={index} value={item.value}>
|
|
41
|
-
{item.label}
|
|
42
|
-
</DropdownOption>
|
|
43
|
-
))}
|
|
44
|
-
</MultipleDropdown>,
|
|
45
|
-
),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
it('Renders without a selected item', async () => {
|
|
50
|
-
const {
|
|
51
|
-
user,
|
|
52
|
-
mockOnChange,
|
|
53
|
-
getByRole,
|
|
54
|
-
queryByRole,
|
|
55
|
-
getByTestId,
|
|
56
|
-
findByTitle,
|
|
57
|
-
} = setup();
|
|
58
|
-
|
|
59
|
-
expect(mockOnChange).not.toBeCalled();
|
|
60
|
-
|
|
61
|
-
const dropdownEl = getByTestId('dropdown');
|
|
62
|
-
|
|
63
|
-
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
64
|
-
expect(dropdownToggleEl).toHaveTextContent('Select something');
|
|
65
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'false');
|
|
66
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-haspopup', 'listbox');
|
|
67
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-controls');
|
|
68
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-labelledby');
|
|
69
|
-
findByTitle('Carrot down');
|
|
70
|
-
|
|
71
|
-
let listboxEl = queryByRole('listbox');
|
|
72
|
-
expect(listboxEl).not.toBeInTheDocument();
|
|
73
|
-
|
|
74
|
-
await user.click(dropdownToggleEl);
|
|
75
|
-
|
|
76
|
-
listboxEl = getByRole('listbox');
|
|
77
|
-
const listItemEls = within(listboxEl).getAllByRole('listitem');
|
|
78
|
-
expect(listItemEls.length).toBe(items.length);
|
|
79
|
-
|
|
80
|
-
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
81
|
-
expect(dropdownToggleEl).toHaveFocus();
|
|
82
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'true');
|
|
83
|
-
findByTitle('Carrot up');
|
|
84
|
-
|
|
85
|
-
for (let i = 0; i < items.length; ++i) {
|
|
86
|
-
const listItem = items[i];
|
|
87
|
-
const listItemEl = listItemEls[i];
|
|
88
|
-
expect(listItemEl).toHaveAttribute('aria-selected', 'false');
|
|
89
|
-
const itemListValue = getListItemValue(listItem);
|
|
90
|
-
expect(within(listItemEl).getByRole('button')).toHaveTextContent(
|
|
91
|
-
itemListValue,
|
|
92
|
-
);
|
|
93
|
-
await within(listItemEl).findByText(itemListValue);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('Renders with a selected item', async () => {
|
|
98
|
-
const { user, mockOnChange, getByRole, queryByRole, getByTestId } = setup({
|
|
99
|
-
selectedItems,
|
|
100
|
-
label: placeholder,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
expect(mockOnChange).not.toBeCalled();
|
|
104
|
-
|
|
105
|
-
const dropdownEl = getByTestId('dropdown');
|
|
106
|
-
|
|
107
|
-
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
108
|
-
expect(dropdownToggleEl).toHaveTextContent(
|
|
109
|
-
placeholder + ': ' + selectedItems[0].label,
|
|
110
|
-
);
|
|
111
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'false');
|
|
112
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-haspopup', 'listbox');
|
|
113
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-controls');
|
|
114
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-labelledby');
|
|
115
|
-
await within(dropdownToggleEl).findByTitle('Carrot down');
|
|
116
|
-
|
|
117
|
-
let listboxEl = queryByRole('listbox');
|
|
118
|
-
expect(listboxEl).not.toBeInTheDocument();
|
|
119
|
-
|
|
120
|
-
await user.click(dropdownToggleEl);
|
|
121
|
-
|
|
122
|
-
listboxEl = getByRole('listbox');
|
|
123
|
-
const listItemEls = within(listboxEl).getAllByRole('listitem');
|
|
124
|
-
expect(listItemEls.length).toBe(items.length);
|
|
125
|
-
|
|
126
|
-
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
127
|
-
|
|
128
|
-
expect(dropdownToggleEl).toHaveFocus();
|
|
129
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'true');
|
|
130
|
-
await within(dropdownToggleEl).findByTitle('Carrot up');
|
|
131
|
-
|
|
132
|
-
for (let i = 0; i < items.length; ++i) {
|
|
133
|
-
const listItem = items[i];
|
|
134
|
-
const listItemEl = listItemEls[i];
|
|
135
|
-
|
|
136
|
-
const itemListValue = getListItemValue(listItem);
|
|
137
|
-
|
|
138
|
-
await within(listItemEl).findByText(itemListValue);
|
|
139
|
-
expect(within(listItemEl).getByRole('button')).toHaveTextContent(
|
|
140
|
-
itemListValue,
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
if (selectedItemsValues.includes(listItem.value)) {
|
|
144
|
-
expect(listItemEl).toHaveAttribute('aria-selected', 'true');
|
|
145
|
-
} else {
|
|
146
|
-
expect(listItemEl).toHaveAttribute('aria-selected', 'false');
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('Renders with an empty items array', async () => {
|
|
152
|
-
const mockOnChange = jest.fn();
|
|
153
|
-
const { getByTestId, queryByRole, getByRole } = render(
|
|
154
|
-
<MultipleDropdown isMultiple onChange={mockOnChange}>
|
|
155
|
-
{null}
|
|
156
|
-
</MultipleDropdown>,
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
expect(mockOnChange).not.toBeCalled();
|
|
160
|
-
|
|
161
|
-
const dropdownEl = getByTestId('dropdown');
|
|
162
|
-
|
|
163
|
-
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
164
|
-
|
|
165
|
-
expect(dropdownToggleEl).toHaveTextContent('Select something');
|
|
166
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'false');
|
|
167
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-haspopup', 'listbox');
|
|
168
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-controls');
|
|
169
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-labelledby');
|
|
170
|
-
await within(dropdownToggleEl).findByTitle('Carrot down');
|
|
171
|
-
|
|
172
|
-
let listboxEl = queryByRole('listbox');
|
|
173
|
-
|
|
174
|
-
expect(listboxEl).not.toBeInTheDocument();
|
|
175
|
-
|
|
176
|
-
await userEvent.click(dropdownToggleEl);
|
|
177
|
-
|
|
178
|
-
listboxEl = getByRole('listbox');
|
|
179
|
-
|
|
180
|
-
const listItemEl = within(listboxEl).getByRole('listitem');
|
|
181
|
-
|
|
182
|
-
expect(listItemEl).toHaveAttribute('aria-selected', 'false');
|
|
183
|
-
within(listItemEl).getByText('No items');
|
|
184
|
-
|
|
185
|
-
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
186
|
-
|
|
187
|
-
expect(dropdownToggleEl).toHaveFocus();
|
|
188
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'true');
|
|
189
|
-
|
|
190
|
-
await within(dropdownToggleEl).findByTitle('Carrot up');
|
|
191
|
-
|
|
192
|
-
// Items list hides when clicked
|
|
193
|
-
await userEvent.click(within(listItemEl).getByRole('button'));
|
|
194
|
-
|
|
195
|
-
expect(within(listItemEl).getByRole('button')).toHaveTextContent(
|
|
196
|
-
'No items',
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
200
|
-
|
|
201
|
-
expect(dropdownToggleEl).toHaveTextContent('Select something');
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it("Chooses an item when it's clicked [isMultiple = true]", async () => {
|
|
205
|
-
const { user, mockOnChange, getByRole, queryByRole, getByTestId } = setup({
|
|
206
|
-
selectedItems,
|
|
207
|
-
label: placeholder,
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
const dropdownEl = getByTestId('dropdown');
|
|
211
|
-
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
212
|
-
|
|
213
|
-
expect(dropdownToggleEl).toHaveTextContent(
|
|
214
|
-
'Strategy: Third Item+1Carrot down',
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
await user.click(dropdownToggleEl);
|
|
218
|
-
|
|
219
|
-
const listItemEls = within(getByRole('listbox')).getAllByRole('button');
|
|
220
|
-
|
|
221
|
-
await user.click(listItemEls[0]);
|
|
222
|
-
|
|
223
|
-
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
224
|
-
|
|
225
|
-
expect(dropdownToggleEl).toHaveTextContent(getListItemValue(items[0]));
|
|
226
|
-
expect(mockOnChange).toHaveBeenCalledWith(1, true);
|
|
227
|
-
expect(queryByRole('listbox')).toBeInTheDocument();
|
|
228
|
-
|
|
229
|
-
await within(dropdownToggleEl).findByTitle('Carrot up');
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("Chooses an item when it's clicked [isMultiple = false]", async () => {
|
|
233
|
-
const { user, mockOnChange, getByRole, queryByRole, getByTestId } = setup({
|
|
234
|
-
selectedItems: [items[2]],
|
|
235
|
-
label: placeholder,
|
|
236
|
-
isMultiple: false,
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
const dropdownEl = getByTestId('dropdown');
|
|
240
|
-
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
241
|
-
|
|
242
|
-
expect(dropdownToggleEl).toHaveTextContent('Third ItemCarrot down');
|
|
243
|
-
|
|
244
|
-
await user.click(dropdownToggleEl);
|
|
245
|
-
|
|
246
|
-
const listItemEls = within(getByRole('listbox')).getAllByRole('button');
|
|
247
|
-
|
|
248
|
-
await user.click(listItemEls[0]);
|
|
249
|
-
|
|
250
|
-
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
251
|
-
|
|
252
|
-
expect(dropdownToggleEl).toHaveTextContent(getListItemValue(items[0]));
|
|
253
|
-
expect(mockOnChange).toHaveBeenCalledWith(1, true);
|
|
254
|
-
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
255
|
-
|
|
256
|
-
await within(dropdownToggleEl).findByTitle('Carrot down');
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('Closes when clicked outside', async () => {
|
|
260
|
-
const { user, getByRole, queryByRole } = setup();
|
|
261
|
-
|
|
262
|
-
await user.click(getByRole('combobox'));
|
|
263
|
-
getByRole('listbox');
|
|
264
|
-
|
|
265
|
-
await user.click(document.body);
|
|
266
|
-
|
|
267
|
-
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
268
|
-
|
|
269
|
-
// Doesn't open up when clicked outside again
|
|
270
|
-
await user.click(document.body);
|
|
271
|
-
|
|
272
|
-
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it('Do not trigger onChange if clicked on the same option', async () => {
|
|
276
|
-
const { user, mockOnChange, getByRole, getByTestId } = setup({
|
|
277
|
-
selectedItems: [items[2]],
|
|
278
|
-
label: placeholder,
|
|
279
|
-
isMultiple: false,
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
const dropdownEl = getByTestId('dropdown');
|
|
283
|
-
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
284
|
-
|
|
285
|
-
await user.click(dropdownToggleEl);
|
|
286
|
-
|
|
287
|
-
const listItemEls = within(getByRole('listbox')).getAllByRole('button');
|
|
288
|
-
|
|
289
|
-
await user.click(listItemEls[2]);
|
|
290
|
-
|
|
291
|
-
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
292
|
-
|
|
293
|
-
await user.click(dropdownToggleEl);
|
|
294
|
-
await user.click(listItemEls[2]);
|
|
295
|
-
|
|
296
|
-
expect(mockOnChange).toHaveBeenCalledTimes(0);
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it('Renders with a custom placeholder', () => {
|
|
300
|
-
const { getByTestId } = setup({
|
|
301
|
-
label: 'Strategy',
|
|
302
|
-
placeholder: 'Choose at least one option',
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
const dropdownToggleEl = within(getByTestId('dropdown')).getByRole(
|
|
306
|
-
'combobox',
|
|
307
|
-
);
|
|
308
|
-
expect(dropdownToggleEl).toHaveTextContent('Choose at least one option');
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it('Renders with a hidden placeholder', () => {
|
|
312
|
-
const { getByTestId } = setup({
|
|
313
|
-
label: 'Strategy',
|
|
314
|
-
showPlaceholder: false,
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
const dropdownToggleEl = within(getByTestId('dropdown')).getByRole(
|
|
318
|
-
'combobox',
|
|
319
|
-
);
|
|
320
|
-
expect(dropdownToggleEl).toHaveTextContent('StrategyCarrot down');
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
it('Renders in the disabled state', async () => {
|
|
324
|
-
const { user, mockOnChange, queryByRole, getByTestId } = setup({
|
|
325
|
-
isDisabled: true,
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
const dropdownEl = getByTestId('dropdown');
|
|
329
|
-
|
|
330
|
-
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
331
|
-
expect(dropdownToggleEl).toHaveTextContent('Select something');
|
|
332
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'false');
|
|
333
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-haspopup', 'listbox');
|
|
334
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-controls');
|
|
335
|
-
expect(dropdownToggleEl).toHaveAttribute('aria-labelledby');
|
|
336
|
-
expect(dropdownToggleEl).toHaveAttribute('disabled');
|
|
337
|
-
await within(dropdownToggleEl).findByTitle('Carrot down');
|
|
338
|
-
|
|
339
|
-
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
340
|
-
|
|
341
|
-
await user.click(dropdownToggleEl);
|
|
342
|
-
|
|
343
|
-
expect(mockOnChange).not.toBeCalled();
|
|
344
|
-
|
|
345
|
-
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
346
|
-
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
347
|
-
expect(dropdownToggleEl).not.toHaveFocus();
|
|
348
|
-
expect(dropdownToggleEl).toHaveTextContent('Select something');
|
|
349
|
-
expect(dropdownToggleEl).toHaveAttribute('disabled');
|
|
350
|
-
await within(dropdownToggleEl).findByTitle('Carrot down');
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
it('Closes when changes state to disabled', async () => {
|
|
354
|
-
const { rerender, user, queryByRole, getByTestId } = setup();
|
|
355
|
-
|
|
356
|
-
const dropdownToggleEl = within(getByTestId('dropdown')).getByRole(
|
|
357
|
-
'combobox',
|
|
358
|
-
);
|
|
359
|
-
|
|
360
|
-
await user.click(dropdownToggleEl);
|
|
361
|
-
|
|
362
|
-
expect(queryByRole('listbox')).toBeInTheDocument();
|
|
363
|
-
|
|
364
|
-
rerender(
|
|
365
|
-
<MultipleDropdown isMultiple isDisabled>
|
|
366
|
-
{items.map((item, index) => (
|
|
367
|
-
<DropdownOption key={index} value={item.value}>
|
|
368
|
-
{item.label}
|
|
369
|
-
</DropdownOption>
|
|
370
|
-
))}
|
|
371
|
-
</MultipleDropdown>,
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
it('Renders opened', () => {
|
|
378
|
-
const { queryByRole } = setup({ isOpen: true });
|
|
379
|
-
|
|
380
|
-
expect(queryByRole('listbox')).toBeInTheDocument();
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
it('New item should be rendered correctly', async () => {
|
|
384
|
-
const args = {
|
|
385
|
-
isDisabled: false,
|
|
386
|
-
isMultiple: true,
|
|
387
|
-
selectedItems: [],
|
|
388
|
-
label: 'Strategy',
|
|
389
|
-
};
|
|
390
|
-
const mockOnChange = jest.fn();
|
|
391
|
-
const { getByTestId, getByText, getByRole } = render(
|
|
392
|
-
<DynamicallyChangedItems {...args} />,
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
expect(mockOnChange).not.toBeCalled();
|
|
396
|
-
|
|
397
|
-
const dropdownEl = getByTestId('dropdown');
|
|
398
|
-
|
|
399
|
-
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
400
|
-
await userEvent.click(dropdownToggleEl);
|
|
401
|
-
|
|
402
|
-
let listItemEls = within(getByRole('listbox')).getAllByRole('button');
|
|
403
|
-
expect(listItemEls.length).toEqual(3);
|
|
404
|
-
|
|
405
|
-
const updateItemsButton = getByText('Update items');
|
|
406
|
-
await userEvent.click(updateItemsButton);
|
|
407
|
-
|
|
408
|
-
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
409
|
-
await userEvent.click(dropdownToggleEl);
|
|
410
|
-
|
|
411
|
-
listItemEls = within(getByRole('listbox')).getAllByRole('button');
|
|
412
|
-
expect(listItemEls.length).toEqual(4);
|
|
413
|
-
});
|
|
414
|
-
});
|
|
1
|
+
import { within } from '@testing-library/dom';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
|
|
4
|
+
import DropdownOption from '@components/DropdownOption';
|
|
5
|
+
|
|
6
|
+
import MultipleDropdown from '.';
|
|
7
|
+
import { DynamicallyChangedItems } from './stories/MultipleDropdown.stories';
|
|
8
|
+
|
|
9
|
+
interface Item {
|
|
10
|
+
value: number;
|
|
11
|
+
label: string;
|
|
12
|
+
subText: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const items = [
|
|
16
|
+
{ value: 1, label: 'First Item', subText: 'Sub text 1' },
|
|
17
|
+
{ value: 2, label: 'Second Item', subText: 'Sub text 2' },
|
|
18
|
+
{ value: 3, label: 'Third Item', subText: 'Sub text 3' },
|
|
19
|
+
{ value: 4, label: 'Fourth Item', subText: 'Sub text 4' },
|
|
20
|
+
{ value: 5, label: 'Fifth Item', subText: 'Sub text 5' },
|
|
21
|
+
{ value: 6, label: 'Sixth Item', subText: 'Sub text 6' },
|
|
22
|
+
{ value: 7, label: 'Seventh Item', subText: 'Sub text 7' },
|
|
23
|
+
];
|
|
24
|
+
const selectedItems = [items[2], items[4]];
|
|
25
|
+
const selectedItemsValues = selectedItems.map((item) => item.value);
|
|
26
|
+
const placeholder = 'Strategy';
|
|
27
|
+
|
|
28
|
+
const getListItemValue = (item: Item) => item.label;
|
|
29
|
+
|
|
30
|
+
describe('MultipleDropdown', () => {
|
|
31
|
+
function setup(props = {}) {
|
|
32
|
+
const mockOnChange = jest.fn();
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
user: userEvent.setup(),
|
|
36
|
+
mockOnChange,
|
|
37
|
+
...render(
|
|
38
|
+
<MultipleDropdown isMultiple onChange={mockOnChange} {...props}>
|
|
39
|
+
{items.map((item, index) => (
|
|
40
|
+
<DropdownOption key={index} value={item.value}>
|
|
41
|
+
{item.label}
|
|
42
|
+
</DropdownOption>
|
|
43
|
+
))}
|
|
44
|
+
</MultipleDropdown>,
|
|
45
|
+
),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
it('Renders without a selected item', async () => {
|
|
50
|
+
const {
|
|
51
|
+
user,
|
|
52
|
+
mockOnChange,
|
|
53
|
+
getByRole,
|
|
54
|
+
queryByRole,
|
|
55
|
+
getByTestId,
|
|
56
|
+
findByTitle,
|
|
57
|
+
} = setup();
|
|
58
|
+
|
|
59
|
+
expect(mockOnChange).not.toBeCalled();
|
|
60
|
+
|
|
61
|
+
const dropdownEl = getByTestId('dropdown');
|
|
62
|
+
|
|
63
|
+
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
64
|
+
expect(dropdownToggleEl).toHaveTextContent('Select something');
|
|
65
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'false');
|
|
66
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-haspopup', 'listbox');
|
|
67
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-controls');
|
|
68
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-labelledby');
|
|
69
|
+
findByTitle('Carrot down');
|
|
70
|
+
|
|
71
|
+
let listboxEl = queryByRole('listbox');
|
|
72
|
+
expect(listboxEl).not.toBeInTheDocument();
|
|
73
|
+
|
|
74
|
+
await user.click(dropdownToggleEl);
|
|
75
|
+
|
|
76
|
+
listboxEl = getByRole('listbox');
|
|
77
|
+
const listItemEls = within(listboxEl).getAllByRole('listitem');
|
|
78
|
+
expect(listItemEls.length).toBe(items.length);
|
|
79
|
+
|
|
80
|
+
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
81
|
+
expect(dropdownToggleEl).toHaveFocus();
|
|
82
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'true');
|
|
83
|
+
findByTitle('Carrot up');
|
|
84
|
+
|
|
85
|
+
for (let i = 0; i < items.length; ++i) {
|
|
86
|
+
const listItem = items[i];
|
|
87
|
+
const listItemEl = listItemEls[i];
|
|
88
|
+
expect(listItemEl).toHaveAttribute('aria-selected', 'false');
|
|
89
|
+
const itemListValue = getListItemValue(listItem);
|
|
90
|
+
expect(within(listItemEl).getByRole('button')).toHaveTextContent(
|
|
91
|
+
itemListValue,
|
|
92
|
+
);
|
|
93
|
+
await within(listItemEl).findByText(itemListValue);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('Renders with a selected item', async () => {
|
|
98
|
+
const { user, mockOnChange, getByRole, queryByRole, getByTestId } = setup({
|
|
99
|
+
selectedItems,
|
|
100
|
+
label: placeholder,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(mockOnChange).not.toBeCalled();
|
|
104
|
+
|
|
105
|
+
const dropdownEl = getByTestId('dropdown');
|
|
106
|
+
|
|
107
|
+
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
108
|
+
expect(dropdownToggleEl).toHaveTextContent(
|
|
109
|
+
placeholder + ': ' + selectedItems[0].label,
|
|
110
|
+
);
|
|
111
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'false');
|
|
112
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-haspopup', 'listbox');
|
|
113
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-controls');
|
|
114
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-labelledby');
|
|
115
|
+
await within(dropdownToggleEl).findByTitle('Carrot down');
|
|
116
|
+
|
|
117
|
+
let listboxEl = queryByRole('listbox');
|
|
118
|
+
expect(listboxEl).not.toBeInTheDocument();
|
|
119
|
+
|
|
120
|
+
await user.click(dropdownToggleEl);
|
|
121
|
+
|
|
122
|
+
listboxEl = getByRole('listbox');
|
|
123
|
+
const listItemEls = within(listboxEl).getAllByRole('listitem');
|
|
124
|
+
expect(listItemEls.length).toBe(items.length);
|
|
125
|
+
|
|
126
|
+
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
127
|
+
|
|
128
|
+
expect(dropdownToggleEl).toHaveFocus();
|
|
129
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'true');
|
|
130
|
+
await within(dropdownToggleEl).findByTitle('Carrot up');
|
|
131
|
+
|
|
132
|
+
for (let i = 0; i < items.length; ++i) {
|
|
133
|
+
const listItem = items[i];
|
|
134
|
+
const listItemEl = listItemEls[i];
|
|
135
|
+
|
|
136
|
+
const itemListValue = getListItemValue(listItem);
|
|
137
|
+
|
|
138
|
+
await within(listItemEl).findByText(itemListValue);
|
|
139
|
+
expect(within(listItemEl).getByRole('button')).toHaveTextContent(
|
|
140
|
+
itemListValue,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
if (selectedItemsValues.includes(listItem.value)) {
|
|
144
|
+
expect(listItemEl).toHaveAttribute('aria-selected', 'true');
|
|
145
|
+
} else {
|
|
146
|
+
expect(listItemEl).toHaveAttribute('aria-selected', 'false');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('Renders with an empty items array', async () => {
|
|
152
|
+
const mockOnChange = jest.fn();
|
|
153
|
+
const { getByTestId, queryByRole, getByRole } = render(
|
|
154
|
+
<MultipleDropdown isMultiple onChange={mockOnChange}>
|
|
155
|
+
{null}
|
|
156
|
+
</MultipleDropdown>,
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
expect(mockOnChange).not.toBeCalled();
|
|
160
|
+
|
|
161
|
+
const dropdownEl = getByTestId('dropdown');
|
|
162
|
+
|
|
163
|
+
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
164
|
+
|
|
165
|
+
expect(dropdownToggleEl).toHaveTextContent('Select something');
|
|
166
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'false');
|
|
167
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-haspopup', 'listbox');
|
|
168
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-controls');
|
|
169
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-labelledby');
|
|
170
|
+
await within(dropdownToggleEl).findByTitle('Carrot down');
|
|
171
|
+
|
|
172
|
+
let listboxEl = queryByRole('listbox');
|
|
173
|
+
|
|
174
|
+
expect(listboxEl).not.toBeInTheDocument();
|
|
175
|
+
|
|
176
|
+
await userEvent.click(dropdownToggleEl);
|
|
177
|
+
|
|
178
|
+
listboxEl = getByRole('listbox');
|
|
179
|
+
|
|
180
|
+
const listItemEl = within(listboxEl).getByRole('listitem');
|
|
181
|
+
|
|
182
|
+
expect(listItemEl).toHaveAttribute('aria-selected', 'false');
|
|
183
|
+
within(listItemEl).getByText('No items');
|
|
184
|
+
|
|
185
|
+
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
186
|
+
|
|
187
|
+
expect(dropdownToggleEl).toHaveFocus();
|
|
188
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'true');
|
|
189
|
+
|
|
190
|
+
await within(dropdownToggleEl).findByTitle('Carrot up');
|
|
191
|
+
|
|
192
|
+
// Items list hides when clicked
|
|
193
|
+
await userEvent.click(within(listItemEl).getByRole('button'));
|
|
194
|
+
|
|
195
|
+
expect(within(listItemEl).getByRole('button')).toHaveTextContent(
|
|
196
|
+
'No items',
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
200
|
+
|
|
201
|
+
expect(dropdownToggleEl).toHaveTextContent('Select something');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("Chooses an item when it's clicked [isMultiple = true]", async () => {
|
|
205
|
+
const { user, mockOnChange, getByRole, queryByRole, getByTestId } = setup({
|
|
206
|
+
selectedItems,
|
|
207
|
+
label: placeholder,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const dropdownEl = getByTestId('dropdown');
|
|
211
|
+
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
212
|
+
|
|
213
|
+
expect(dropdownToggleEl).toHaveTextContent(
|
|
214
|
+
'Strategy: Third Item+1Carrot down',
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
await user.click(dropdownToggleEl);
|
|
218
|
+
|
|
219
|
+
const listItemEls = within(getByRole('listbox')).getAllByRole('button');
|
|
220
|
+
|
|
221
|
+
await user.click(listItemEls[0]);
|
|
222
|
+
|
|
223
|
+
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
224
|
+
|
|
225
|
+
expect(dropdownToggleEl).toHaveTextContent(getListItemValue(items[0]));
|
|
226
|
+
expect(mockOnChange).toHaveBeenCalledWith(1, true);
|
|
227
|
+
expect(queryByRole('listbox')).toBeInTheDocument();
|
|
228
|
+
|
|
229
|
+
await within(dropdownToggleEl).findByTitle('Carrot up');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("Chooses an item when it's clicked [isMultiple = false]", async () => {
|
|
233
|
+
const { user, mockOnChange, getByRole, queryByRole, getByTestId } = setup({
|
|
234
|
+
selectedItems: [items[2]],
|
|
235
|
+
label: placeholder,
|
|
236
|
+
isMultiple: false,
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
const dropdownEl = getByTestId('dropdown');
|
|
240
|
+
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
241
|
+
|
|
242
|
+
expect(dropdownToggleEl).toHaveTextContent('Third ItemCarrot down');
|
|
243
|
+
|
|
244
|
+
await user.click(dropdownToggleEl);
|
|
245
|
+
|
|
246
|
+
const listItemEls = within(getByRole('listbox')).getAllByRole('button');
|
|
247
|
+
|
|
248
|
+
await user.click(listItemEls[0]);
|
|
249
|
+
|
|
250
|
+
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
251
|
+
|
|
252
|
+
expect(dropdownToggleEl).toHaveTextContent(getListItemValue(items[0]));
|
|
253
|
+
expect(mockOnChange).toHaveBeenCalledWith(1, true);
|
|
254
|
+
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
255
|
+
|
|
256
|
+
await within(dropdownToggleEl).findByTitle('Carrot down');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('Closes when clicked outside', async () => {
|
|
260
|
+
const { user, getByRole, queryByRole } = setup();
|
|
261
|
+
|
|
262
|
+
await user.click(getByRole('combobox'));
|
|
263
|
+
getByRole('listbox');
|
|
264
|
+
|
|
265
|
+
await user.click(document.body);
|
|
266
|
+
|
|
267
|
+
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
268
|
+
|
|
269
|
+
// Doesn't open up when clicked outside again
|
|
270
|
+
await user.click(document.body);
|
|
271
|
+
|
|
272
|
+
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('Do not trigger onChange if clicked on the same option', async () => {
|
|
276
|
+
const { user, mockOnChange, getByRole, getByTestId } = setup({
|
|
277
|
+
selectedItems: [items[2]],
|
|
278
|
+
label: placeholder,
|
|
279
|
+
isMultiple: false,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const dropdownEl = getByTestId('dropdown');
|
|
283
|
+
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
284
|
+
|
|
285
|
+
await user.click(dropdownToggleEl);
|
|
286
|
+
|
|
287
|
+
const listItemEls = within(getByRole('listbox')).getAllByRole('button');
|
|
288
|
+
|
|
289
|
+
await user.click(listItemEls[2]);
|
|
290
|
+
|
|
291
|
+
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
292
|
+
|
|
293
|
+
await user.click(dropdownToggleEl);
|
|
294
|
+
await user.click(listItemEls[2]);
|
|
295
|
+
|
|
296
|
+
expect(mockOnChange).toHaveBeenCalledTimes(0);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('Renders with a custom placeholder', () => {
|
|
300
|
+
const { getByTestId } = setup({
|
|
301
|
+
label: 'Strategy',
|
|
302
|
+
placeholder: 'Choose at least one option',
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
const dropdownToggleEl = within(getByTestId('dropdown')).getByRole(
|
|
306
|
+
'combobox',
|
|
307
|
+
);
|
|
308
|
+
expect(dropdownToggleEl).toHaveTextContent('Choose at least one option');
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('Renders with a hidden placeholder', () => {
|
|
312
|
+
const { getByTestId } = setup({
|
|
313
|
+
label: 'Strategy',
|
|
314
|
+
showPlaceholder: false,
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
const dropdownToggleEl = within(getByTestId('dropdown')).getByRole(
|
|
318
|
+
'combobox',
|
|
319
|
+
);
|
|
320
|
+
expect(dropdownToggleEl).toHaveTextContent('StrategyCarrot down');
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('Renders in the disabled state', async () => {
|
|
324
|
+
const { user, mockOnChange, queryByRole, getByTestId } = setup({
|
|
325
|
+
isDisabled: true,
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
const dropdownEl = getByTestId('dropdown');
|
|
329
|
+
|
|
330
|
+
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
331
|
+
expect(dropdownToggleEl).toHaveTextContent('Select something');
|
|
332
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-expanded', 'false');
|
|
333
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-haspopup', 'listbox');
|
|
334
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-controls');
|
|
335
|
+
expect(dropdownToggleEl).toHaveAttribute('aria-labelledby');
|
|
336
|
+
expect(dropdownToggleEl).toHaveAttribute('disabled');
|
|
337
|
+
await within(dropdownToggleEl).findByTitle('Carrot down');
|
|
338
|
+
|
|
339
|
+
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
340
|
+
|
|
341
|
+
await user.click(dropdownToggleEl);
|
|
342
|
+
|
|
343
|
+
expect(mockOnChange).not.toBeCalled();
|
|
344
|
+
|
|
345
|
+
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
346
|
+
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
347
|
+
expect(dropdownToggleEl).not.toHaveFocus();
|
|
348
|
+
expect(dropdownToggleEl).toHaveTextContent('Select something');
|
|
349
|
+
expect(dropdownToggleEl).toHaveAttribute('disabled');
|
|
350
|
+
await within(dropdownToggleEl).findByTitle('Carrot down');
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('Closes when changes state to disabled', async () => {
|
|
354
|
+
const { rerender, user, queryByRole, getByTestId } = setup();
|
|
355
|
+
|
|
356
|
+
const dropdownToggleEl = within(getByTestId('dropdown')).getByRole(
|
|
357
|
+
'combobox',
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
await user.click(dropdownToggleEl);
|
|
361
|
+
|
|
362
|
+
expect(queryByRole('listbox')).toBeInTheDocument();
|
|
363
|
+
|
|
364
|
+
rerender(
|
|
365
|
+
<MultipleDropdown isMultiple isDisabled>
|
|
366
|
+
{items.map((item, index) => (
|
|
367
|
+
<DropdownOption key={index} value={item.value}>
|
|
368
|
+
{item.label}
|
|
369
|
+
</DropdownOption>
|
|
370
|
+
))}
|
|
371
|
+
</MultipleDropdown>,
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
expect(queryByRole('listbox')).not.toBeInTheDocument();
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('Renders opened', () => {
|
|
378
|
+
const { queryByRole } = setup({ isOpen: true });
|
|
379
|
+
|
|
380
|
+
expect(queryByRole('listbox')).toBeInTheDocument();
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('New item should be rendered correctly', async () => {
|
|
384
|
+
const args = {
|
|
385
|
+
isDisabled: false,
|
|
386
|
+
isMultiple: true,
|
|
387
|
+
selectedItems: [],
|
|
388
|
+
label: 'Strategy',
|
|
389
|
+
};
|
|
390
|
+
const mockOnChange = jest.fn();
|
|
391
|
+
const { getByTestId, getByText, getByRole } = render(
|
|
392
|
+
<DynamicallyChangedItems {...args} />,
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
expect(mockOnChange).not.toBeCalled();
|
|
396
|
+
|
|
397
|
+
const dropdownEl = getByTestId('dropdown');
|
|
398
|
+
|
|
399
|
+
let dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
400
|
+
await userEvent.click(dropdownToggleEl);
|
|
401
|
+
|
|
402
|
+
let listItemEls = within(getByRole('listbox')).getAllByRole('button');
|
|
403
|
+
expect(listItemEls.length).toEqual(3);
|
|
404
|
+
|
|
405
|
+
const updateItemsButton = getByText('Update items');
|
|
406
|
+
await userEvent.click(updateItemsButton);
|
|
407
|
+
|
|
408
|
+
dropdownToggleEl = within(dropdownEl).getByRole('combobox');
|
|
409
|
+
await userEvent.click(dropdownToggleEl);
|
|
410
|
+
|
|
411
|
+
listItemEls = within(getByRole('listbox')).getAllByRole('button');
|
|
412
|
+
expect(listItemEls.length).toEqual(4);
|
|
413
|
+
});
|
|
414
|
+
});
|