@dxc-technology/halstack-react 0.0.0-ebb089f → 0.0.0-ebf4fe2
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/BackgroundColorContext.d.ts +10 -0
- package/BackgroundColorContext.js +47 -0
- package/HalstackContext.d.ts +12 -0
- package/HalstackContext.js +295 -0
- package/accordion/Accordion.d.ts +4 -0
- package/accordion/Accordion.js +226 -0
- package/accordion/Accordion.stories.tsx +307 -0
- package/accordion/Accordion.test.js +72 -0
- package/accordion/types.d.ts +68 -0
- package/accordion/types.js +5 -0
- package/accordion-group/AccordionGroup.d.ts +7 -0
- package/accordion-group/AccordionGroup.js +169 -0
- package/accordion-group/AccordionGroup.stories.tsx +225 -0
- package/accordion-group/AccordionGroup.test.js +151 -0
- package/accordion-group/types.d.ts +72 -0
- package/accordion-group/types.js +5 -0
- package/alert/Alert.d.ts +4 -0
- package/{dist/alert → alert}/Alert.js +43 -153
- package/alert/Alert.stories.tsx +170 -0
- package/alert/Alert.test.js +92 -0
- package/alert/types.d.ts +49 -0
- package/alert/types.js +5 -0
- package/badge/Badge.d.ts +4 -0
- package/badge/Badge.js +61 -0
- package/badge/types.d.ts +5 -0
- package/badge/types.js +5 -0
- package/bleed/Bleed.d.ts +3 -0
- package/bleed/Bleed.js +51 -0
- package/bleed/Bleed.stories.tsx +341 -0
- package/bleed/types.d.ts +37 -0
- package/bleed/types.js +5 -0
- package/box/Box.d.ts +4 -0
- package/box/Box.js +116 -0
- package/box/Box.stories.tsx +132 -0
- package/box/Box.test.js +18 -0
- package/box/types.d.ts +43 -0
- package/box/types.js +5 -0
- package/button/Button.d.ts +4 -0
- package/{dist/button → button}/Button.js +33 -97
- package/button/Button.stories.tsx +274 -0
- package/button/Button.test.js +35 -0
- package/button/types.d.ts +53 -0
- package/button/types.js +5 -0
- package/card/Card.d.ts +4 -0
- package/card/Card.js +161 -0
- package/card/Card.stories.tsx +201 -0
- package/card/Card.test.js +50 -0
- package/card/ice-cream.jpg +0 -0
- package/card/types.d.ts +67 -0
- package/card/types.js +5 -0
- package/checkbox/Checkbox.d.ts +4 -0
- package/{dist/checkbox → checkbox}/Checkbox.js +52 -94
- package/checkbox/Checkbox.stories.tsx +188 -0
- package/checkbox/Checkbox.test.js +78 -0
- package/checkbox/types.d.ts +64 -0
- package/checkbox/types.js +5 -0
- package/chip/Chip.d.ts +4 -0
- package/chip/Chip.js +161 -0
- package/chip/Chip.stories.tsx +119 -0
- package/chip/Chip.test.js +56 -0
- package/chip/types.d.ts +45 -0
- package/chip/types.js +5 -0
- package/{dist/common → common}/OpenSans.css +0 -0
- package/{dist/common → common}/RequiredComponent.js +3 -11
- package/{dist/common → common}/fonts/OpenSans-Bold.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-BoldItalic.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-ExtraBold.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-ExtraBoldItalic.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-Italic.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-Light.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-LightItalic.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-Regular.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-SemiBold.ttf +0 -0
- package/{dist/common → common}/fonts/OpenSans-SemiBoldItalic.ttf +0 -0
- package/{dist/common → common}/utils.js +0 -0
- package/{dist/common → common}/variables.js +302 -406
- package/date-input/DateInput.d.ts +4 -0
- package/{dist/date-input → date-input}/DateInput.js +80 -108
- package/date-input/DateInput.stories.tsx +138 -0
- package/date-input/DateInput.test.js +479 -0
- package/date-input/types.d.ts +107 -0
- package/date-input/types.js +5 -0
- package/dialog/Dialog.d.ts +4 -0
- package/dialog/Dialog.js +138 -0
- package/dialog/Dialog.stories.tsx +212 -0
- package/dialog/Dialog.test.js +40 -0
- package/dialog/types.d.ts +43 -0
- package/dialog/types.js +5 -0
- package/dropdown/Dropdown.d.ts +4 -0
- package/{dist/dropdown → dropdown}/Dropdown.js +54 -207
- package/dropdown/Dropdown.stories.tsx +249 -0
- package/dropdown/Dropdown.test.js +189 -0
- package/dropdown/types.d.ts +80 -0
- package/dropdown/types.js +5 -0
- package/file-input/FileInput.d.ts +4 -0
- package/file-input/FileInput.js +593 -0
- package/file-input/FileInput.stories.tsx +507 -0
- package/file-input/FileInput.test.js +457 -0
- package/file-input/FileItem.d.ts +14 -0
- package/file-input/FileItem.js +186 -0
- package/file-input/types.d.ts +112 -0
- package/file-input/types.js +5 -0
- package/footer/Footer.d.ts +4 -0
- package/footer/Footer.js +185 -0
- package/footer/Footer.stories.tsx +130 -0
- package/footer/Footer.test.js +109 -0
- package/footer/Icons.d.ts +2 -0
- package/{dist/footer → footer}/Icons.js +16 -16
- package/footer/types.d.ts +65 -0
- package/footer/types.js +5 -0
- package/header/Header.d.ts +7 -0
- package/header/Header.js +303 -0
- package/header/Header.stories.tsx +172 -0
- package/header/Header.test.js +79 -0
- package/header/Icons.d.ts +2 -0
- package/{dist/header → header}/Icons.js +7 -32
- package/header/types.d.ts +47 -0
- package/header/types.js +5 -0
- package/heading/Heading.d.ts +4 -0
- package/{dist/heading → heading}/Heading.js +25 -96
- package/heading/Heading.stories.tsx +54 -0
- package/heading/Heading.test.js +186 -0
- package/heading/types.d.ts +33 -0
- package/heading/types.js +5 -0
- package/inline/Inline.d.ts +4 -0
- package/inline/Inline.js +60 -0
- package/inline/Inline.stories.tsx +305 -0
- package/inline/types.d.ts +36 -0
- package/inline/types.js +5 -0
- package/inset/Inset.d.ts +3 -0
- package/inset/Inset.js +51 -0
- package/inset/Inset.stories.tsx +229 -0
- package/inset/types.d.ts +37 -0
- package/inset/types.js +5 -0
- package/layout/ApplicationLayout.d.ts +11 -0
- package/layout/ApplicationLayout.js +199 -0
- package/layout/ApplicationLayout.stories.tsx +126 -0
- package/layout/Icons.d.ts +5 -0
- package/{dist/layout → layout}/Icons.js +19 -8
- package/layout/SidenavContext.d.ts +5 -0
- package/layout/SidenavContext.js +19 -0
- package/layout/types.d.ts +52 -0
- package/layout/types.js +5 -0
- package/link/Link.d.ts +4 -0
- package/link/Link.js +136 -0
- package/link/Link.stories.tsx +186 -0
- package/link/Link.test.js +83 -0
- package/link/types.d.ts +54 -0
- package/link/types.js +5 -0
- package/list/List.d.ts +4 -0
- package/list/List.js +47 -0
- package/list/List.stories.tsx +89 -0
- package/list/types.d.ts +7 -0
- package/list/types.js +5 -0
- package/main.d.ts +48 -0
- package/{dist/main.js → main.js} +138 -96
- package/number-input/NumberInput.d.ts +4 -0
- package/number-input/NumberInput.js +76 -0
- package/number-input/NumberInput.stories.tsx +115 -0
- package/number-input/NumberInput.test.js +506 -0
- package/number-input/NumberInputContext.d.ts +4 -0
- package/{dist/number-input → number-input}/NumberInputContext.js +5 -2
- package/number-input/numberInputContextTypes.d.ts +19 -0
- package/number-input/numberInputContextTypes.js +5 -0
- package/number-input/types.d.ts +124 -0
- package/number-input/types.js +5 -0
- package/package.json +27 -20
- package/{dist/paginator → paginator}/Icons.js +9 -9
- package/paginator/Paginator.d.ts +4 -0
- package/paginator/Paginator.js +171 -0
- package/paginator/Paginator.stories.tsx +63 -0
- package/paginator/Paginator.test.js +308 -0
- package/paginator/types.d.ts +38 -0
- package/paginator/types.js +5 -0
- package/password-input/PasswordInput.d.ts +4 -0
- package/{dist/password-input → password-input}/PasswordInput.js +40 -77
- package/password-input/PasswordInput.stories.tsx +131 -0
- package/password-input/PasswordInput.test.js +180 -0
- package/password-input/types.d.ts +110 -0
- package/password-input/types.js +5 -0
- package/progress-bar/ProgressBar.d.ts +4 -0
- package/{dist/progress-bar → progress-bar}/ProgressBar.js +23 -95
- package/progress-bar/ProgressBar.stories.jsx +58 -0
- package/progress-bar/ProgressBar.test.js +65 -0
- package/progress-bar/types.d.ts +37 -0
- package/progress-bar/types.js +5 -0
- package/quick-nav/QuickNav.d.ts +4 -0
- package/quick-nav/QuickNav.js +116 -0
- package/quick-nav/QuickNav.stories.tsx +237 -0
- package/quick-nav/types.d.ts +21 -0
- package/quick-nav/types.js +5 -0
- package/radio-group/Radio.d.ts +4 -0
- package/radio-group/Radio.js +141 -0
- package/radio-group/RadioGroup.d.ts +4 -0
- package/radio-group/RadioGroup.js +282 -0
- package/radio-group/RadioGroup.stories.tsx +100 -0
- package/radio-group/RadioGroup.test.js +695 -0
- package/radio-group/types.d.ts +114 -0
- package/radio-group/types.js +5 -0
- package/resultsetTable/ResultsetTable.d.ts +4 -0
- package/{dist/resultsetTable → resultsetTable}/ResultsetTable.js +43 -147
- package/resultsetTable/ResultsetTable.stories.tsx +275 -0
- package/resultsetTable/ResultsetTable.test.js +348 -0
- package/resultsetTable/types.d.ts +67 -0
- package/resultsetTable/types.js +5 -0
- package/row/Row.d.ts +3 -0
- package/row/Row.js +127 -0
- package/row/Row.stories.tsx +237 -0
- package/row/types.d.ts +28 -0
- package/row/types.js +5 -0
- package/select/Icons.d.ts +10 -0
- package/select/Icons.js +93 -0
- package/select/Listbox.d.ts +4 -0
- package/select/Listbox.js +175 -0
- package/select/Option.d.ts +4 -0
- package/select/Option.js +110 -0
- package/select/Select.d.ts +4 -0
- package/select/Select.js +660 -0
- package/select/Select.stories.tsx +626 -0
- package/select/Select.test.js +2162 -0
- package/select/types.d.ts +212 -0
- package/select/types.js +5 -0
- package/sidenav/Sidenav.d.ts +9 -0
- package/sidenav/Sidenav.js +147 -0
- package/sidenav/Sidenav.stories.tsx +182 -0
- package/sidenav/Sidenav.test.js +56 -0
- package/sidenav/types.d.ts +50 -0
- package/sidenav/types.js +5 -0
- package/slider/Slider.d.ts +4 -0
- package/{dist/slider → slider}/Slider.js +76 -162
- package/slider/Slider.stories.tsx +177 -0
- package/slider/Slider.test.js +150 -0
- package/slider/types.d.ts +82 -0
- package/slider/types.js +5 -0
- package/spinner/Spinner.d.ts +4 -0
- package/spinner/Spinner.js +250 -0
- package/spinner/Spinner.stories.jsx +103 -0
- package/spinner/Spinner.test.js +64 -0
- package/spinner/types.d.ts +32 -0
- package/spinner/types.js +5 -0
- package/stack/Stack.d.ts +4 -0
- package/stack/Stack.js +52 -0
- package/stack/Stack.stories.tsx +225 -0
- package/stack/types.d.ts +28 -0
- package/stack/types.js +5 -0
- package/switch/Switch.d.ts +4 -0
- package/switch/Switch.js +195 -0
- package/switch/Switch.stories.tsx +160 -0
- package/switch/Switch.test.js +98 -0
- package/switch/types.d.ts +62 -0
- package/switch/types.js +5 -0
- package/table/Table.d.ts +4 -0
- package/{dist/table → table}/Table.js +12 -26
- package/table/Table.stories.jsx +277 -0
- package/table/Table.test.js +26 -0
- package/table/types.d.ts +21 -0
- package/table/types.js +5 -0
- package/tabs/Tabs.d.ts +4 -0
- package/tabs/Tabs.js +211 -0
- package/tabs/Tabs.stories.tsx +112 -0
- package/tabs/Tabs.test.js +140 -0
- package/tabs/types.d.ts +82 -0
- package/tabs/types.js +5 -0
- package/tabs-nav/NavTabs.d.ts +8 -0
- package/tabs-nav/NavTabs.js +125 -0
- package/tabs-nav/NavTabs.stories.tsx +170 -0
- package/tabs-nav/NavTabs.test.js +82 -0
- package/tabs-nav/Tab.d.ts +4 -0
- package/tabs-nav/Tab.js +132 -0
- package/tabs-nav/types.d.ts +53 -0
- package/tabs-nav/types.js +5 -0
- package/tag/Tag.d.ts +4 -0
- package/tag/Tag.js +183 -0
- package/tag/Tag.stories.tsx +142 -0
- package/tag/Tag.test.js +60 -0
- package/tag/types.d.ts +69 -0
- package/tag/types.js +5 -0
- package/text/Text.d.ts +7 -0
- package/text/Text.js +30 -0
- package/text/Text.stories.tsx +19 -0
- package/text-input/Suggestion.d.ts +4 -0
- package/text-input/Suggestion.js +55 -0
- package/text-input/TextInput.d.ts +4 -0
- package/{dist/text-input → text-input}/TextInput.js +282 -486
- package/text-input/TextInput.stories.tsx +474 -0
- package/text-input/TextInput.test.js +1712 -0
- package/text-input/types.d.ts +178 -0
- package/text-input/types.js +5 -0
- package/textarea/Textarea.d.ts +4 -0
- package/{dist/textarea → textarea}/Textarea.js +50 -142
- package/textarea/Textarea.stories.jsx +157 -0
- package/textarea/Textarea.test.js +437 -0
- package/textarea/types.d.ts +137 -0
- package/textarea/types.js +5 -0
- package/toggle-group/ToggleGroup.d.ts +4 -0
- package/{dist/toggle-group → toggle-group}/ToggleGroup.js +36 -148
- package/toggle-group/ToggleGroup.stories.tsx +173 -0
- package/toggle-group/ToggleGroup.test.js +156 -0
- package/toggle-group/types.d.ts +105 -0
- package/toggle-group/types.js +5 -0
- package/useTheme.d.ts +2 -0
- package/{dist/useTheme.js → useTheme.js} +2 -2
- package/useTranslatedLabels.d.ts +2 -0
- package/useTranslatedLabels.js +20 -0
- package/wizard/Wizard.d.ts +4 -0
- package/wizard/Wizard.js +292 -0
- package/wizard/Wizard.stories.tsx +214 -0
- package/wizard/Wizard.test.js +141 -0
- package/wizard/types.d.ts +64 -0
- package/wizard/types.js +5 -0
- package/README.md +0 -66
- package/babel.config.js +0 -7
- package/dist/BackgroundColorContext.js +0 -46
- package/dist/ThemeContext.js +0 -250
- package/dist/V3Select/V3Select.js +0 -549
- package/dist/V3Select/index.d.ts +0 -27
- package/dist/V3Textarea/V3Textarea.js +0 -264
- package/dist/V3Textarea/index.d.ts +0 -27
- package/dist/accordion/Accordion.js +0 -353
- package/dist/accordion/index.d.ts +0 -28
- package/dist/accordion-group/AccordionGroup.js +0 -186
- package/dist/accordion-group/index.d.ts +0 -16
- package/dist/alert/index.d.ts +0 -51
- package/dist/badge/Badge.js +0 -63
- package/dist/box/Box.js +0 -156
- package/dist/box/index.d.ts +0 -25
- package/dist/button/Button.stories.js +0 -27
- package/dist/button/index.d.ts +0 -24
- package/dist/card/Card.js +0 -254
- package/dist/card/index.d.ts +0 -22
- package/dist/checkbox/index.d.ts +0 -24
- package/dist/chip/Chip.js +0 -265
- package/dist/chip/index.d.ts +0 -22
- package/dist/date/Date.js +0 -379
- package/dist/date/index.d.ts +0 -27
- package/dist/date-input/index.d.ts +0 -95
- package/dist/dialog/Dialog.js +0 -218
- package/dist/dialog/index.d.ts +0 -18
- package/dist/dropdown/index.d.ts +0 -26
- package/dist/file-input/FileInput.js +0 -644
- package/dist/file-input/FileItem.js +0 -287
- package/dist/file-input/index.d.ts +0 -81
- package/dist/footer/Footer.js +0 -421
- package/dist/footer/index.d.ts +0 -25
- package/dist/header/Header.js +0 -470
- package/dist/header/index.d.ts +0 -25
- package/dist/heading/index.d.ts +0 -17
- package/dist/input-text/Icons.js +0 -22
- package/dist/input-text/InputText.js +0 -705
- package/dist/input-text/index.d.ts +0 -36
- package/dist/layout/ApplicationLayout.js +0 -327
- package/dist/link/Link.js +0 -237
- package/dist/link/index.d.ts +0 -23
- package/dist/main.d.ts +0 -40
- package/dist/number-input/NumberInput.js +0 -136
- package/dist/number-input/index.d.ts +0 -113
- package/dist/paginator/Paginator.js +0 -305
- package/dist/paginator/index.d.ts +0 -20
- package/dist/password-input/index.d.ts +0 -94
- package/dist/progress-bar/index.d.ts +0 -18
- package/dist/radio/Radio.js +0 -209
- package/dist/radio/index.d.ts +0 -23
- package/dist/resultsetTable/index.d.ts +0 -19
- package/dist/select/Select.js +0 -1137
- package/dist/select/index.d.ts +0 -131
- package/dist/sidenav/Sidenav.js +0 -179
- package/dist/sidenav/index.d.ts +0 -13
- package/dist/slider/index.d.ts +0 -29
- package/dist/spinner/Spinner.js +0 -381
- package/dist/spinner/index.d.ts +0 -17
- package/dist/switch/Switch.js +0 -222
- package/dist/switch/index.d.ts +0 -24
- package/dist/table/index.d.ts +0 -13
- package/dist/tabs/Tabs.js +0 -343
- package/dist/tabs/index.d.ts +0 -19
- package/dist/tag/Tag.js +0 -282
- package/dist/tag/index.d.ts +0 -24
- package/dist/text-input/index.d.ts +0 -135
- package/dist/textarea/index.d.ts +0 -117
- package/dist/toggle/Toggle.js +0 -220
- package/dist/toggle/index.d.ts +0 -21
- package/dist/toggle-group/index.d.ts +0 -21
- package/dist/upload/Upload.js +0 -205
- package/dist/upload/buttons-upload/ButtonsUpload.js +0 -135
- package/dist/upload/buttons-upload/Icons.js +0 -40
- package/dist/upload/dragAndDropArea/DragAndDropArea.js +0 -329
- package/dist/upload/dragAndDropArea/Icons.js +0 -39
- package/dist/upload/file-upload/FileToUpload.js +0 -189
- package/dist/upload/file-upload/Icons.js +0 -66
- package/dist/upload/files-upload/FilesToUpload.js +0 -123
- package/dist/upload/index.d.ts +0 -15
- package/dist/upload/transaction/Icons.js +0 -160
- package/dist/upload/transaction/Transaction.js +0 -148
- package/dist/upload/transactions/Transactions.js +0 -138
- package/dist/wizard/Icons.js +0 -65
- package/dist/wizard/Wizard.js +0 -405
- package/dist/wizard/index.d.ts +0 -18
- package/test/Accordion.test.js +0 -33
- package/test/AccordionGroup.test.js +0 -125
- package/test/Alert.test.js +0 -53
- package/test/Box.test.js +0 -10
- package/test/Button.test.js +0 -18
- package/test/Card.test.js +0 -30
- package/test/Checkbox.test.js +0 -45
- package/test/Chip.test.js +0 -25
- package/test/Date.test.js +0 -395
- package/test/DateInput.test.js +0 -242
- package/test/Dialog.test.js +0 -23
- package/test/Dropdown.test.js +0 -145
- package/test/FileInput.test.js +0 -201
- package/test/Footer.test.js +0 -94
- package/test/Header.test.js +0 -34
- package/test/Heading.test.js +0 -83
- package/test/InputText.test.js +0 -239
- package/test/Link.test.js +0 -43
- package/test/NumberInput.test.js +0 -259
- package/test/Paginator.test.js +0 -181
- package/test/PasswordInput.test.js +0 -83
- package/test/ProgressBar.test.js +0 -35
- package/test/Radio.test.js +0 -37
- package/test/ResultsetTable.test.js +0 -330
- package/test/Select.test.js +0 -928
- package/test/Sidenav.test.js +0 -45
- package/test/Slider.test.js +0 -74
- package/test/Spinner.test.js +0 -32
- package/test/Switch.test.js +0 -45
- package/test/Table.test.js +0 -36
- package/test/Tabs.test.js +0 -109
- package/test/Tag.test.js +0 -32
- package/test/TextInput.test.js +0 -731
- package/test/Textarea.test.js +0 -193
- package/test/ToggleGroup.test.js +0 -85
- package/test/Upload.test.js +0 -60
- package/test/V3Select.test.js +0 -212
- package/test/V3TextArea.test.js +0 -51
- package/test/Wizard.test.js +0 -130
- package/test/mocks/pngMock.js +0 -1
- package/test/mocks/svgMock.js +0 -1
package/test/Select.test.js
DELETED
|
@@ -1,928 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import DxcSelect from "../src/select/Select";
|
|
3
|
-
import { render, fireEvent } from "@testing-library/react";
|
|
4
|
-
import userEvent from "@testing-library/user-event";
|
|
5
|
-
|
|
6
|
-
const single_options = [
|
|
7
|
-
{ label: "Option 01", value: "1" },
|
|
8
|
-
{ label: "Option 02", value: "2" },
|
|
9
|
-
{ label: "Option 03", value: "3" },
|
|
10
|
-
{ label: "Option 04", value: "4" },
|
|
11
|
-
{ label: "Option 05", value: "5" },
|
|
12
|
-
{ label: "Option 06", value: "6" },
|
|
13
|
-
{ label: "Option 07", value: "7" },
|
|
14
|
-
{ label: "Option 08", value: "8" },
|
|
15
|
-
{ label: "Option 09", value: "9" },
|
|
16
|
-
{ label: "Option 10", value: "10" },
|
|
17
|
-
{ label: "Option 11", value: "11" },
|
|
18
|
-
{ label: "Option 12", value: "12" },
|
|
19
|
-
{ label: "Option 13", value: "13" },
|
|
20
|
-
{ label: "Option 14", value: "14" },
|
|
21
|
-
{ label: "Option 15", value: "15" },
|
|
22
|
-
{ label: "Option 16", value: "16" },
|
|
23
|
-
{ label: "Option 17", value: "17" },
|
|
24
|
-
{ label: "Option 18", value: "18" },
|
|
25
|
-
{ label: "Option 19", value: "19" },
|
|
26
|
-
{ label: "Option 20", value: "20" },
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
const svg_icon_options = [
|
|
30
|
-
{
|
|
31
|
-
label: "3G Mobile",
|
|
32
|
-
value: "1",
|
|
33
|
-
icon: (
|
|
34
|
-
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
|
35
|
-
<g>
|
|
36
|
-
<path d="M0,0h24v24H0V0z" fill="none" />
|
|
37
|
-
</g>
|
|
38
|
-
<g>
|
|
39
|
-
<g>
|
|
40
|
-
<path d="M3,7v2h5v2H4v2h4v2H3v2h5c1.1,0,2-0.9,2-2v-1.5c0-0.83-0.67-1.5-1.5-1.5c0.83,0,1.5-0.67,1.5-1.5V9c0-1.1-0.9-2-2-2H3z M21,11v4c0,1.1-0.9,2-2,2h-5c-1.1,0-2-0.9-2-2V9c0-1.1,0.9-2,2-2h5c1.1,0,2,0.9,2,2h-7v6h5v-2h-2.5v-2H21z" />
|
|
41
|
-
</g>
|
|
42
|
-
</g>
|
|
43
|
-
</svg>
|
|
44
|
-
),
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
label: "Ethernet",
|
|
48
|
-
value: "2",
|
|
49
|
-
icon: (
|
|
50
|
-
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
|
51
|
-
<path d="M0 0h24v24H0V0z" fill="none" />
|
|
52
|
-
<path d="M7.77 6.76L6.23 5.48.82 12l5.41 6.52 1.54-1.28L3.42 12l4.35-5.24zM7 13h2v-2H7v2zm10-2h-2v2h2v-2zm-6 2h2v-2h-2v2zm6.77-7.52l-1.54 1.28L20.58 12l-4.35 5.24 1.54 1.28L23.18 12l-5.41-6.52z" />
|
|
53
|
-
</svg>
|
|
54
|
-
),
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
label: "Wi-fi",
|
|
58
|
-
value: "3",
|
|
59
|
-
icon: (
|
|
60
|
-
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
|
61
|
-
<path d="M0 0h24v24H0V0zm0 0h24v24H0V0z" fill="none" />
|
|
62
|
-
<path d="M1 9l2 2c4.97-4.97 13.03-4.97 18 0l2-2C16.93 2.93 7.08 2.93 1 9zm8 8l3 3 3-3c-1.65-1.66-4.34-1.66-6 0zm-4-4l2 2c2.76-2.76 7.24-2.76 10 0l2-2C15.14 9.14 8.87 9.14 5 13z" />
|
|
63
|
-
</svg>
|
|
64
|
-
),
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
label: "Settings backup restore (just for previous configuration)",
|
|
68
|
-
value: "4",
|
|
69
|
-
icon: (
|
|
70
|
-
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
|
71
|
-
<path d="M0 0h24v24H0V0z" fill="none" />
|
|
72
|
-
<path d="M14 12c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2zm-2-9c-4.97 0-9 4.03-9 9H0l4 4 4-4H5c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.51 0-2.91-.49-4.06-1.3l-1.42 1.44C8.04 20.3 9.94 21 12 21c4.97 0 9-4.03 9-9s-4.03-9-9-9z" />
|
|
73
|
-
</svg>
|
|
74
|
-
),
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
label: "Regular",
|
|
78
|
-
value: "Regular",
|
|
79
|
-
},
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
const url_icon_options = [
|
|
83
|
-
{
|
|
84
|
-
label: "Instagram",
|
|
85
|
-
value: "1",
|
|
86
|
-
icon: "https://cdn.icon-icons.com/icons2/2518/PNG/512/brand_instagram_icon_151534.png",
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
label: "Twitter",
|
|
90
|
-
value: "2",
|
|
91
|
-
icon: "https://cdn-icons-png.flaticon.com/512/81/81609.png",
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
label: "Snapchat",
|
|
95
|
-
value: "3",
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
label: "Facebook",
|
|
99
|
-
value: "4",
|
|
100
|
-
icon: "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/2021_Facebook_icon.svg/2048px-2021_Facebook_icon.svg.png",
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
label: "Pinterest",
|
|
104
|
-
value: "5",
|
|
105
|
-
icon: "https://cdn-icons-png.flaticon.com/512/145/145808.png",
|
|
106
|
-
},
|
|
107
|
-
];
|
|
108
|
-
|
|
109
|
-
const group_options = [
|
|
110
|
-
{
|
|
111
|
-
label: "Colores",
|
|
112
|
-
options: [
|
|
113
|
-
{ label: "Azul", value: "azul" },
|
|
114
|
-
{ label: "Rojo", value: "rojo" },
|
|
115
|
-
{ label: "Rosa", value: "rosa" },
|
|
116
|
-
{ label: "Verde", value: "verde" },
|
|
117
|
-
{ label: "Amarillo", value: "amarillo" },
|
|
118
|
-
{ label: "Blanco", value: "blanco" },
|
|
119
|
-
{ label: "Negro", value: "negro" },
|
|
120
|
-
],
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
label: "Ciudades españolas",
|
|
124
|
-
options: [
|
|
125
|
-
{ label: "Madrid", value: "madrid" },
|
|
126
|
-
{ label: "Oviedo", value: "oviedo" },
|
|
127
|
-
{ label: "Sevilla", value: "sevilla" },
|
|
128
|
-
{ label: "Bilbao", value: "bilbao" },
|
|
129
|
-
{ label: "Barcelona", value: "barcelona" },
|
|
130
|
-
],
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
label: "Ríos españoles",
|
|
134
|
-
options: [
|
|
135
|
-
{ label: "Miño", value: "miño" },
|
|
136
|
-
{ label: "Duero", value: "duero" },
|
|
137
|
-
{ label: "Tajo", value: "tajo" },
|
|
138
|
-
{ label: "Guadiana", value: "guadiana" },
|
|
139
|
-
{ label: "Guadalquivir", value: "guadalquivir" },
|
|
140
|
-
{ label: "Ebro", value: "ebro" },
|
|
141
|
-
],
|
|
142
|
-
},
|
|
143
|
-
];
|
|
144
|
-
|
|
145
|
-
const grouped_icon_options = [
|
|
146
|
-
{
|
|
147
|
-
label: "Social Media",
|
|
148
|
-
options: [
|
|
149
|
-
{
|
|
150
|
-
label: "Instagram",
|
|
151
|
-
value: "1",
|
|
152
|
-
icon: "https://cdn.icon-icons.com/icons2/2518/PNG/512/brand_instagram_icon_151534.png",
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
label: "Twitter",
|
|
156
|
-
value: "2",
|
|
157
|
-
icon: "https://cdn-icons-png.flaticon.com/512/81/81609.png",
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
label: "Facebook",
|
|
161
|
-
value: "3",
|
|
162
|
-
icon: "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/2021_Facebook_icon.svg/2048px-2021_Facebook_icon.svg.png",
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
label: "Pinterest",
|
|
166
|
-
value: "4",
|
|
167
|
-
icon: "https://cdn-icons-png.flaticon.com/512/145/145808.png",
|
|
168
|
-
},
|
|
169
|
-
],
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
label: "Group 2",
|
|
173
|
-
options: [
|
|
174
|
-
{ label: "Option 4", value: "5" },
|
|
175
|
-
{ label: "Option 5", value: "6" },
|
|
176
|
-
{ label: "Option 6", value: "7" },
|
|
177
|
-
],
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
label: "Group 3",
|
|
181
|
-
options: [
|
|
182
|
-
{ label: "Option 7", value: "8" },
|
|
183
|
-
{ label: "Option 8", value: "9" },
|
|
184
|
-
{ label: "Option 9", value: "10" },
|
|
185
|
-
],
|
|
186
|
-
},
|
|
187
|
-
];
|
|
188
|
-
|
|
189
|
-
describe("Select component tests", () => {
|
|
190
|
-
test("Renders with correct label", () => {
|
|
191
|
-
const { getByText, getByRole } = render(
|
|
192
|
-
<DxcSelect label="test-select-label" helperText="test-select-helper-text" placeholder="Example text" />
|
|
193
|
-
);
|
|
194
|
-
const select = getByRole("combobox");
|
|
195
|
-
const label = getByText("test-select-label");
|
|
196
|
-
|
|
197
|
-
expect(label).toBeTruthy();
|
|
198
|
-
userEvent.click(label);
|
|
199
|
-
expect(document.activeElement).toEqual(select);
|
|
200
|
-
});
|
|
201
|
-
test("Renders with correct helper text and placeholder", () => {
|
|
202
|
-
const { getByText } = render(
|
|
203
|
-
<DxcSelect label="test-select-label" helperText="test-select-helper-text" placeholder="Example text" />
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
expect(getByText("test-select-helper-text")).toBeTruthy();
|
|
207
|
-
expect(getByText("Example text")).toBeTruthy();
|
|
208
|
-
});
|
|
209
|
-
test("Renders with correct optional label", () => {
|
|
210
|
-
const { getByText } = render(<DxcSelect label="test-select-label" optional />);
|
|
211
|
-
|
|
212
|
-
expect(getByText("test-select-label")).toBeTruthy();
|
|
213
|
-
expect(getByText("(Optional)")).toBeTruthy();
|
|
214
|
-
});
|
|
215
|
-
test("Renders with error message", () => {
|
|
216
|
-
const { getByText, getByRole } = render(<DxcSelect label="test-select-label" error="Error message." />);
|
|
217
|
-
const select = getByRole("combobox");
|
|
218
|
-
|
|
219
|
-
expect(getByText("Error message.")).toBeTruthy();
|
|
220
|
-
expect(select.getAttribute("aria-invalid")).toBe("true");
|
|
221
|
-
});
|
|
222
|
-
test("Disabled select - Clear all options action must be shown but not clickable", () => {
|
|
223
|
-
const { getByRole, getByText, queryByRole } = render(
|
|
224
|
-
<DxcSelect label="test-select-label" value={["1", "2"]} options={single_options} disabled searchable multiple />
|
|
225
|
-
);
|
|
226
|
-
const select = getByRole("combobox");
|
|
227
|
-
|
|
228
|
-
userEvent.click(select);
|
|
229
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
230
|
-
userEvent.click(getByRole("button"));
|
|
231
|
-
expect(getByText("Option 01, Option 02")).toBeTruthy();
|
|
232
|
-
});
|
|
233
|
-
test("Focused select does not open the listbox", () => {
|
|
234
|
-
const { getByRole, queryByRole } = render(
|
|
235
|
-
<DxcSelect label="test-select-label" value={["1", "2"]} options={single_options} disabled searchable multiple />
|
|
236
|
-
);
|
|
237
|
-
const select = getByRole("combobox");
|
|
238
|
-
|
|
239
|
-
fireEvent.focus(select);
|
|
240
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
241
|
-
});
|
|
242
|
-
test("Controlled - Not optional constraint", () => {
|
|
243
|
-
const onChange = jest.fn();
|
|
244
|
-
const onBlur = jest.fn();
|
|
245
|
-
const { getByRole, getAllByRole } = render(
|
|
246
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} onBlur={onBlur} />
|
|
247
|
-
);
|
|
248
|
-
const select = getByRole("combobox");
|
|
249
|
-
|
|
250
|
-
expect(select.getAttribute("aria-required")).toBe("true");
|
|
251
|
-
fireEvent.focus(select);
|
|
252
|
-
fireEvent.blur(select);
|
|
253
|
-
expect(onBlur).toHaveBeenCalled();
|
|
254
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "", error: "This field is required. Please, enter a value." });
|
|
255
|
-
userEvent.click(select);
|
|
256
|
-
userEvent.click(getAllByRole("option")[0]);
|
|
257
|
-
expect(onChange).toHaveBeenCalled();
|
|
258
|
-
expect(onChange).toHaveBeenCalledWith({ value: "1", error: null });
|
|
259
|
-
fireEvent.focus(select);
|
|
260
|
-
fireEvent.blur(select);
|
|
261
|
-
expect(onBlur).toHaveBeenCalled();
|
|
262
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "1", error: null });
|
|
263
|
-
});
|
|
264
|
-
test("Controlled - Optional constraint", () => {
|
|
265
|
-
const onChange = jest.fn();
|
|
266
|
-
const onBlur = jest.fn();
|
|
267
|
-
const { getByRole } = render(
|
|
268
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} onBlur={onBlur} optional />
|
|
269
|
-
);
|
|
270
|
-
const select = getByRole("combobox");
|
|
271
|
-
|
|
272
|
-
expect(select.getAttribute("aria-required")).toBe("false");
|
|
273
|
-
fireEvent.focus(select);
|
|
274
|
-
fireEvent.blur(select);
|
|
275
|
-
expect(onBlur).toHaveBeenCalled();
|
|
276
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "", error: null });
|
|
277
|
-
expect(select.getAttribute("aria-invalid")).toBe("false");
|
|
278
|
-
});
|
|
279
|
-
test("Non-Grouped Options - Opens listbox and renders correctly or closes it with a click on select", () => {
|
|
280
|
-
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
281
|
-
<DxcSelect label="test-select-label" options={single_options} />
|
|
282
|
-
);
|
|
283
|
-
const select = getByRole("combobox");
|
|
284
|
-
|
|
285
|
-
userEvent.click(select);
|
|
286
|
-
expect(getByRole("listbox")).toBeTruthy();
|
|
287
|
-
expect(select.getAttribute("aria-expanded")).toBe("true");
|
|
288
|
-
expect(getByText("Option 01")).toBeTruthy();
|
|
289
|
-
expect(getByText("Option 02")).toBeTruthy();
|
|
290
|
-
expect(getByText("Option 08")).toBeTruthy();
|
|
291
|
-
expect(getByText("Option 09")).toBeTruthy();
|
|
292
|
-
expect(getAllByRole("option").length).toBe(20);
|
|
293
|
-
userEvent.click(select);
|
|
294
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
295
|
-
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
296
|
-
});
|
|
297
|
-
test("Non-Grouped Options - If an empty list of options is passed, the select is rendered but doestn't open the listbox", () => {
|
|
298
|
-
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={[]} />);
|
|
299
|
-
const select = getByRole("combobox");
|
|
300
|
-
|
|
301
|
-
userEvent.click(select);
|
|
302
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
303
|
-
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
304
|
-
});
|
|
305
|
-
test("Non-Grouped Options - Click in an option selects it and closes the listbox", () => {
|
|
306
|
-
const onChange = jest.fn();
|
|
307
|
-
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
308
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} />
|
|
309
|
-
);
|
|
310
|
-
const select = getByRole("combobox");
|
|
311
|
-
|
|
312
|
-
userEvent.click(select);
|
|
313
|
-
userEvent.click(getAllByRole("option")[2]);
|
|
314
|
-
expect(onChange).toHaveBeenCalledWith({ value: "3", error: null });
|
|
315
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
316
|
-
expect(getByText("Option 03")).toBeTruthy();
|
|
317
|
-
userEvent.click(select);
|
|
318
|
-
expect(getAllByRole("option")[2].getAttribute("aria-selected")).toBe("true");
|
|
319
|
-
});
|
|
320
|
-
test("Non-Grouped Options - Optional renders an empty first option with the placeholder as its label", () => {
|
|
321
|
-
const onChange = jest.fn();
|
|
322
|
-
const { getByRole, getAllByRole, getAllByText } = render(
|
|
323
|
-
<DxcSelect
|
|
324
|
-
label="test-select-label"
|
|
325
|
-
placeholder="Choose an option"
|
|
326
|
-
options={single_options}
|
|
327
|
-
onChange={onChange}
|
|
328
|
-
optional
|
|
329
|
-
/>
|
|
330
|
-
);
|
|
331
|
-
const select = getByRole("combobox");
|
|
332
|
-
|
|
333
|
-
userEvent.click(select);
|
|
334
|
-
expect(getAllByText("Choose an option").length).toBe(2);
|
|
335
|
-
expect(getAllByRole("option")[0].getAttribute("aria-selected")).toBe("true");
|
|
336
|
-
userEvent.click(getAllByRole("option")[0]);
|
|
337
|
-
expect(onChange).toHaveBeenCalledWith({ value: "", error: null });
|
|
338
|
-
expect(getAllByText("Choose an option").length).toBe(1);
|
|
339
|
-
|
|
340
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
341
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
342
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
343
|
-
expect(onChange).toHaveBeenCalledWith({ value: "", error: null });
|
|
344
|
-
expect(getAllByText("Choose an option").length).toBe(1);
|
|
345
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
346
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
347
|
-
});
|
|
348
|
-
test("Non-Grouped Options - Renders SVG icons correctly when passed with options", () => {
|
|
349
|
-
const { getByRole, getAllByRole } = render(<DxcSelect label="test-select-label" options={svg_icon_options} />);
|
|
350
|
-
const select = getByRole("combobox");
|
|
351
|
-
|
|
352
|
-
userEvent.click(select);
|
|
353
|
-
expect(getByRole("listbox").querySelectorAll("[role='img']").length).toBe(4);
|
|
354
|
-
expect(getAllByRole("option").length).toBe(5);
|
|
355
|
-
});
|
|
356
|
-
test("Non-Grouped Options - Renders string url icons correctly when passed with options", () => {
|
|
357
|
-
const { getByRole, getAllByRole } = render(
|
|
358
|
-
<DxcSelect label="test-select-label" options={url_icon_options} optional />
|
|
359
|
-
);
|
|
360
|
-
const select = getByRole("combobox");
|
|
361
|
-
|
|
362
|
-
userEvent.click(select);
|
|
363
|
-
expect(getByRole("listbox").querySelectorAll("img").length).toBe(4);
|
|
364
|
-
expect(getAllByRole("option").length).toBe(6);
|
|
365
|
-
});
|
|
366
|
-
test("Non-Grouped Options: Arrow up key - Opens the listbox and visually focus the last option", () => {
|
|
367
|
-
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={single_options} />);
|
|
368
|
-
const select = getByRole("combobox");
|
|
369
|
-
|
|
370
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
371
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
372
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-19");
|
|
373
|
-
});
|
|
374
|
-
test("Non-Grouped Options: Arrow up key - Puts the focus in last option when the first one is visually focused", () => {
|
|
375
|
-
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={single_options} />);
|
|
376
|
-
const select = getByRole("combobox");
|
|
377
|
-
|
|
378
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
379
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
380
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
381
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-19");
|
|
382
|
-
});
|
|
383
|
-
test("Non-Grouped Options: Arrow down key - Opens the listbox and visually focus the first option", () => {
|
|
384
|
-
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={single_options} />);
|
|
385
|
-
const select = getByRole("combobox");
|
|
386
|
-
|
|
387
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
388
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
389
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
390
|
-
});
|
|
391
|
-
test("Non-Grouped Options: Arrow down key - Puts the focus in the first option when the last one is visually focused", () => {
|
|
392
|
-
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={single_options} />);
|
|
393
|
-
const select = getByRole("combobox");
|
|
394
|
-
|
|
395
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
396
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
397
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
398
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
399
|
-
});
|
|
400
|
-
test("Non-Grouped Options: Enter key - Selects the visually focused option and closes the listbox", () => {
|
|
401
|
-
const onChange = jest.fn();
|
|
402
|
-
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
403
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} optional />
|
|
404
|
-
);
|
|
405
|
-
const select = getByRole("combobox");
|
|
406
|
-
|
|
407
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
408
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
409
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
410
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
411
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
412
|
-
expect(onChange).toHaveBeenCalledWith({ value: "20", error: null });
|
|
413
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
414
|
-
expect(getByText("Option 20")).toBeTruthy();
|
|
415
|
-
userEvent.click(select);
|
|
416
|
-
expect(getAllByRole("option")[20].getAttribute("aria-selected")).toBe("true");
|
|
417
|
-
});
|
|
418
|
-
test("Non-Grouped Options: Searchable - Displays an input for filtering the list of options", () => {
|
|
419
|
-
const onChange = jest.fn();
|
|
420
|
-
const { container, getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
421
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
422
|
-
);
|
|
423
|
-
const select = getByRole("combobox");
|
|
424
|
-
const searchInput = container.querySelectorAll("input")[1];
|
|
425
|
-
|
|
426
|
-
userEvent.click(select);
|
|
427
|
-
expect(getByRole("listbox")).toBeTruthy();
|
|
428
|
-
userEvent.type(searchInput, "08");
|
|
429
|
-
userEvent.click(getByRole("option"));
|
|
430
|
-
expect(onChange).toHaveBeenCalledWith({ value: "8", error: null });
|
|
431
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
432
|
-
expect(getByText("Option 08")).toBeTruthy();
|
|
433
|
-
expect(searchInput.value).toBe("");
|
|
434
|
-
userEvent.click(select);
|
|
435
|
-
expect(getAllByRole("option")[7].getAttribute("aria-selected")).toBe("true");
|
|
436
|
-
});
|
|
437
|
-
test("Non-Grouped Options: Searchable - Displays 'No matches found' when there are no filtering results", () => {
|
|
438
|
-
const onChange = jest.fn();
|
|
439
|
-
const { container, getByText, getByRole } = render(
|
|
440
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
441
|
-
);
|
|
442
|
-
const select = getByRole("combobox");
|
|
443
|
-
const searchInput = container.querySelectorAll("input")[1];
|
|
444
|
-
|
|
445
|
-
userEvent.click(select);
|
|
446
|
-
expect(getByRole("listbox")).toBeTruthy();
|
|
447
|
-
userEvent.type(searchInput, "abc");
|
|
448
|
-
expect(getByText("No matches found")).toBeTruthy();
|
|
449
|
-
});
|
|
450
|
-
test("Non-Grouped Options: Searchable - Clicking the select, when the list is open, clears the search value", () => {
|
|
451
|
-
const onChange = jest.fn();
|
|
452
|
-
const { container, getByText, getByRole, getAllByRole } = render(
|
|
453
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
454
|
-
);
|
|
455
|
-
const select = getByRole("combobox");
|
|
456
|
-
const searchInput = container.querySelectorAll("input")[1];
|
|
457
|
-
|
|
458
|
-
userEvent.click(select);
|
|
459
|
-
expect(getByRole("listbox")).toBeTruthy();
|
|
460
|
-
userEvent.type(searchInput, "2");
|
|
461
|
-
expect(getByText("Option 02")).toBeTruthy();
|
|
462
|
-
expect(getByText("Option 12")).toBeTruthy();
|
|
463
|
-
expect(getByText("Option 20")).toBeTruthy();
|
|
464
|
-
expect(getAllByRole("option").length).toBe(3);
|
|
465
|
-
userEvent.click(select);
|
|
466
|
-
expect(searchInput.value).toBe("");
|
|
467
|
-
});
|
|
468
|
-
test("Non-Grouped Options: Searchable - Writing displays the listbox, if it was not open", () => {
|
|
469
|
-
const onChange = jest.fn();
|
|
470
|
-
const { container, getByRole, queryByRole } = render(
|
|
471
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
472
|
-
);
|
|
473
|
-
const select = getByRole("combobox");
|
|
474
|
-
const searchInput = container.querySelectorAll("input")[1];
|
|
475
|
-
|
|
476
|
-
userEvent.click(select);
|
|
477
|
-
userEvent.click(select);
|
|
478
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
479
|
-
userEvent.type(searchInput, "2");
|
|
480
|
-
expect(getByRole("listbox")).toBeTruthy();
|
|
481
|
-
});
|
|
482
|
-
test("Non-Grouped Options: Searchable - Key Esc cleans the search value and closes the options", () => {
|
|
483
|
-
const onChange = jest.fn();
|
|
484
|
-
const { container, getByRole, queryByRole } = render(
|
|
485
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
486
|
-
);
|
|
487
|
-
const select = getByRole("combobox");
|
|
488
|
-
const searchInput = container.querySelectorAll("input")[1];
|
|
489
|
-
|
|
490
|
-
userEvent.type(searchInput, "Option 02");
|
|
491
|
-
fireEvent.keyDown(select, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
492
|
-
expect(searchInput.value).toBe("");
|
|
493
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
494
|
-
});
|
|
495
|
-
test("Non-Grouped Options: Searchable - While user types, a clear action is displayed for cleaning the search value", () => {
|
|
496
|
-
const onChange = jest.fn();
|
|
497
|
-
const { container, getByRole, getAllByRole } = render(
|
|
498
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} searchable />
|
|
499
|
-
);
|
|
500
|
-
const searchInput = container.querySelectorAll("input")[1];
|
|
501
|
-
|
|
502
|
-
userEvent.type(searchInput, "Option 02");
|
|
503
|
-
expect(getAllByRole("option").length).toBe(1);
|
|
504
|
-
const clearAction = getByRole("button");
|
|
505
|
-
expect(clearAction).toBeTruthy();
|
|
506
|
-
userEvent.click(clearAction);
|
|
507
|
-
expect(getByRole("listbox")).toBeTruthy();
|
|
508
|
-
expect(getAllByRole("option").length).toBe(20);
|
|
509
|
-
});
|
|
510
|
-
test("Non-Grouped Options: Multiple selection - Displays a checkbox per option and enables the multi-selection", () => {
|
|
511
|
-
const onChange = jest.fn();
|
|
512
|
-
const { getByText, getAllByText, getByRole, getAllByRole, queryByRole } = render(
|
|
513
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} multiple />
|
|
514
|
-
);
|
|
515
|
-
const select = getByRole("combobox");
|
|
516
|
-
|
|
517
|
-
userEvent.click(select);
|
|
518
|
-
expect(getByRole("listbox").getAttribute("aria-multiselectable")).toBe("true");
|
|
519
|
-
userEvent.click(getAllByRole("option")[10]);
|
|
520
|
-
// expect(onChange).toHaveBeenCalledWith({ value: ["11"], error: null });
|
|
521
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
522
|
-
expect(getAllByText("Option 11").length).toBe(2);
|
|
523
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
524
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
525
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
526
|
-
// expect(onChange).toHaveBeenCalledWith({ value: ["11", "19"], error: null });
|
|
527
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
528
|
-
expect(getByText("Option 11, Option 19")).toBeTruthy();
|
|
529
|
-
expect(getAllByRole("option")[10].getAttribute("aria-selected")).toBe("true");
|
|
530
|
-
expect(getAllByRole("option")[18].getAttribute("aria-selected")).toBe("true");
|
|
531
|
-
});
|
|
532
|
-
test("Non-Grouped Options: Multiple selection - Clear action and selection indicator", () => {
|
|
533
|
-
const onChange = jest.fn();
|
|
534
|
-
const { getByText, queryByText, getByRole, getAllByRole, queryByRole, getByTitle, queryByTitle } = render(
|
|
535
|
-
<DxcSelect label="test-select-label" options={single_options} onChange={onChange} multiple />
|
|
536
|
-
);
|
|
537
|
-
const select = getByRole("combobox");
|
|
538
|
-
|
|
539
|
-
userEvent.click(select);
|
|
540
|
-
userEvent.click(getAllByRole("option")[5]);
|
|
541
|
-
userEvent.click(getAllByRole("option")[8]);
|
|
542
|
-
userEvent.click(getAllByRole("option")[13]);
|
|
543
|
-
// expect(onChange).toHaveBeenCalledWith({ value: ["6", "9", "14"], error: null });
|
|
544
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
545
|
-
expect(getByText("Option 06, Option 09, Option 14")).toBeTruthy();
|
|
546
|
-
expect(getByText("3", { exact: true })).toBeTruthy();
|
|
547
|
-
userEvent.click(getByTitle("Clear selected options"));
|
|
548
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
549
|
-
expect(queryByText("Option 06, Option 09, Option 14")).toBeFalsy();
|
|
550
|
-
expect(queryByText("3")).toBeFalsy();
|
|
551
|
-
expect(queryByTitle("Clear selected options")).toBeFalsy();
|
|
552
|
-
});
|
|
553
|
-
test("Non-Grouped Options: Multiple selection - Optional option should not be added when the select is marked as multiple", () => {
|
|
554
|
-
const onChange = jest.fn();
|
|
555
|
-
const { getByText, getAllByText, getByRole, getAllByRole } = render(
|
|
556
|
-
<DxcSelect
|
|
557
|
-
label="test-select-label"
|
|
558
|
-
placeholder="Choose an option"
|
|
559
|
-
options={single_options}
|
|
560
|
-
onChange={onChange}
|
|
561
|
-
multiple
|
|
562
|
-
optional
|
|
563
|
-
/>
|
|
564
|
-
);
|
|
565
|
-
const select = getByRole("combobox");
|
|
566
|
-
|
|
567
|
-
expect(getByText("(Optional)")).toBeTruthy();
|
|
568
|
-
userEvent.click(select);
|
|
569
|
-
expect(getAllByText("Choose an option").length).toBe(1);
|
|
570
|
-
expect(getAllByRole("option")[0].getAttribute("aria-selected")).toBe("false");
|
|
571
|
-
userEvent.click(getAllByRole("option")[0]);
|
|
572
|
-
// expect(onChange).toHaveBeenCalledWith({ value: ["1"], error: null });
|
|
573
|
-
expect(getAllByText("Option 01").length).toBe(2);
|
|
574
|
-
});
|
|
575
|
-
test("Non-Grouped Options - If an options was previously selected when its opened (by key press), the visual focus appears always in the selected option", () => {
|
|
576
|
-
const { getByText, getByRole, getAllByRole } = render(
|
|
577
|
-
<DxcSelect label="test-select-label" options={single_options} />
|
|
578
|
-
);
|
|
579
|
-
const select = getByRole("combobox");
|
|
580
|
-
|
|
581
|
-
userEvent.click(select);
|
|
582
|
-
userEvent.click(getAllByRole("option")[4]);
|
|
583
|
-
expect(getByText("Option 05")).toBeTruthy();
|
|
584
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
585
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-4");
|
|
586
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
587
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
588
|
-
expect(getByText("Option 04")).toBeTruthy();
|
|
589
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
590
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-3");
|
|
591
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
592
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
593
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
594
|
-
expect(getByText("Option 06")).toBeTruthy();
|
|
595
|
-
});
|
|
596
|
-
test("Non-Grouped Options - If an options was previously selected when its opened (by click and key press), the visual focus appears always in the selected option", () => {
|
|
597
|
-
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
598
|
-
<DxcSelect label="test-select-label" options={single_options} />
|
|
599
|
-
);
|
|
600
|
-
const select = getByRole("combobox");
|
|
601
|
-
|
|
602
|
-
userEvent.click(select);
|
|
603
|
-
userEvent.click(getAllByRole("option")[15]);
|
|
604
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
605
|
-
expect(getByText("Option 16")).toBeTruthy();
|
|
606
|
-
userEvent.click(select);
|
|
607
|
-
expect(select.getAttribute("aria-activedescendant")).toBeNull();
|
|
608
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
609
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-15");
|
|
610
|
-
userEvent.click(select);
|
|
611
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
612
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
613
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-15");
|
|
614
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
615
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
616
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
617
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
618
|
-
expect(getByText("Option 17")).toBeTruthy();
|
|
619
|
-
});
|
|
620
|
-
test("Grouped Options - Opens listbox and renders it correctly or closes it with a click on select", () => {
|
|
621
|
-
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
622
|
-
<DxcSelect label="test-select-label" options={group_options} />
|
|
623
|
-
);
|
|
624
|
-
const select = getByRole("combobox");
|
|
625
|
-
|
|
626
|
-
userEvent.click(select);
|
|
627
|
-
expect(getByRole("listbox")).toBeTruthy();
|
|
628
|
-
expect(select.getAttribute("aria-expanded")).toBe("true");
|
|
629
|
-
expect(getByText("Colores")).toBeTruthy();
|
|
630
|
-
expect(getByText("Azul")).toBeTruthy();
|
|
631
|
-
expect(getByText("Negro")).toBeTruthy();
|
|
632
|
-
expect(getByText("Ciudades españolas")).toBeTruthy();
|
|
633
|
-
expect(getByText("Madrid")).toBeTruthy();
|
|
634
|
-
expect(getAllByRole("group").length).toBe(3);
|
|
635
|
-
expect(getAllByRole("presentation").length).toBe(3);
|
|
636
|
-
expect(getAllByRole("option").length).toBe(18);
|
|
637
|
-
userEvent.click(select);
|
|
638
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
639
|
-
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
640
|
-
});
|
|
641
|
-
test("Grouped Options - If an empty list of options in a group is passed, the select is rendered but doestn't open the listbox", () => {
|
|
642
|
-
const { getByRole, queryByRole } = render(
|
|
643
|
-
<DxcSelect
|
|
644
|
-
label="test-select-label"
|
|
645
|
-
options={[
|
|
646
|
-
{
|
|
647
|
-
label: "Group 1",
|
|
648
|
-
options: [],
|
|
649
|
-
},
|
|
650
|
-
]}
|
|
651
|
-
/>
|
|
652
|
-
);
|
|
653
|
-
const select = getByRole("combobox");
|
|
654
|
-
|
|
655
|
-
userEvent.click(select);
|
|
656
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
657
|
-
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
658
|
-
});
|
|
659
|
-
test("Grouped Options - Click in an option selects it and closes the listbox", () => {
|
|
660
|
-
const onChange = jest.fn();
|
|
661
|
-
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
662
|
-
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} />
|
|
663
|
-
);
|
|
664
|
-
const select = getByRole("combobox");
|
|
665
|
-
|
|
666
|
-
userEvent.click(select);
|
|
667
|
-
userEvent.click(getAllByRole("option")[8]);
|
|
668
|
-
expect(onChange).toHaveBeenCalledWith({ value: "oviedo", error: null });
|
|
669
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
670
|
-
expect(getByText("Oviedo")).toBeTruthy();
|
|
671
|
-
userEvent.click(select);
|
|
672
|
-
expect(getAllByRole("option")[8].getAttribute("aria-selected")).toBe("true");
|
|
673
|
-
});
|
|
674
|
-
test("Grouped Options - Optional renders an empty first option (out of any group) with the placeholder as its label", () => {
|
|
675
|
-
const onChange = jest.fn();
|
|
676
|
-
const { getByRole, getAllByRole, getAllByText } = render(
|
|
677
|
-
<DxcSelect
|
|
678
|
-
label="test-select-label"
|
|
679
|
-
placeholder="Placeholder example"
|
|
680
|
-
options={group_options}
|
|
681
|
-
onChange={onChange}
|
|
682
|
-
optional
|
|
683
|
-
/>
|
|
684
|
-
);
|
|
685
|
-
const select = getByRole("combobox");
|
|
686
|
-
|
|
687
|
-
userEvent.click(select);
|
|
688
|
-
expect(getAllByText("Placeholder example").length).toBe(2);
|
|
689
|
-
expect(getAllByRole("option")[0].getAttribute("aria-selected")).toBe("true");
|
|
690
|
-
userEvent.click(getAllByRole("option")[0]);
|
|
691
|
-
expect(onChange).toHaveBeenCalledWith({ value: "", error: null });
|
|
692
|
-
expect(getAllByText("Placeholder example").length).toBe(1);
|
|
693
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
694
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
695
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
696
|
-
expect(onChange).toHaveBeenCalledWith({ value: "", error: null });
|
|
697
|
-
expect(getAllByText("Placeholder example").length).toBe(1);
|
|
698
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
699
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
700
|
-
});
|
|
701
|
-
test("Grouped Options - Renders icons correctly when passed with group options", () => {
|
|
702
|
-
const { getByRole, getAllByRole } = render(
|
|
703
|
-
<DxcSelect label="test-select-label" options={grouped_icon_options} optional />
|
|
704
|
-
);
|
|
705
|
-
const select = getByRole("combobox");
|
|
706
|
-
|
|
707
|
-
userEvent.click(select);
|
|
708
|
-
expect(getByRole("listbox").querySelectorAll("img").length).toBe(4);
|
|
709
|
-
expect(getAllByRole("option").length).toBe(11);
|
|
710
|
-
});
|
|
711
|
-
test("Grouped Options: Arrow up key - Opens the listbox and visually focus the last option", () => {
|
|
712
|
-
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={group_options} />);
|
|
713
|
-
const select = getByRole("combobox");
|
|
714
|
-
|
|
715
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
716
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
717
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-17");
|
|
718
|
-
});
|
|
719
|
-
test("Grouped Options: Arrow up key - Puts the focus in last option when the first one is visually focused", () => {
|
|
720
|
-
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={group_options} />);
|
|
721
|
-
const select = getByRole("combobox");
|
|
722
|
-
|
|
723
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
724
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
725
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
726
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-17");
|
|
727
|
-
});
|
|
728
|
-
test("Grouped Options: Arrow down key - Opens the listbox and visually focus the first option", () => {
|
|
729
|
-
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={group_options} />);
|
|
730
|
-
const select = getByRole("combobox");
|
|
731
|
-
|
|
732
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
733
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
734
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
735
|
-
});
|
|
736
|
-
test("Grouped Options: Arrow down key - Puts the focus in the first option when the last one is visually focused", () => {
|
|
737
|
-
const { getByRole, queryByRole } = render(<DxcSelect label="test-select-label" options={group_options} />);
|
|
738
|
-
const select = getByRole("combobox");
|
|
739
|
-
|
|
740
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
741
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
742
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
743
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-0");
|
|
744
|
-
});
|
|
745
|
-
test("Grouped Options: Enter key - Selects the visually focused option and closes the listbox", () => {
|
|
746
|
-
const onChange = jest.fn();
|
|
747
|
-
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
748
|
-
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} optional />
|
|
749
|
-
);
|
|
750
|
-
const select = getByRole("combobox");
|
|
751
|
-
|
|
752
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
753
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
754
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
755
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
756
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
757
|
-
expect(onChange).toHaveBeenCalledWith({ value: "ebro", error: null });
|
|
758
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
759
|
-
expect(getByText("Ebro")).toBeTruthy();
|
|
760
|
-
userEvent.click(select);
|
|
761
|
-
expect(getAllByRole("option")[18].getAttribute("aria-selected")).toBe("true");
|
|
762
|
-
});
|
|
763
|
-
test("Grouped Options: Searchable - Displays an input for filtering the list of options", () => {
|
|
764
|
-
const onChange = jest.fn();
|
|
765
|
-
const { container, getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
766
|
-
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} searchable />
|
|
767
|
-
);
|
|
768
|
-
const select = getByRole("combobox");
|
|
769
|
-
const searchInput = container.querySelectorAll("input")[1];
|
|
770
|
-
|
|
771
|
-
userEvent.click(select);
|
|
772
|
-
expect(getByRole("listbox")).toBeTruthy();
|
|
773
|
-
userEvent.type(searchInput, "ro");
|
|
774
|
-
expect(getAllByRole("group").length).toBe(2);
|
|
775
|
-
expect(getAllByRole("presentation").length).toBe(2);
|
|
776
|
-
expect(getAllByRole("option").length).toBe(5);
|
|
777
|
-
expect(getByText("Colores")).toBeTruthy();
|
|
778
|
-
expect(getByText("Ríos españoles")).toBeTruthy();
|
|
779
|
-
userEvent.click(getAllByRole("option")[4]);
|
|
780
|
-
expect(onChange).toHaveBeenCalledWith({ value: "ebro", error: null });
|
|
781
|
-
expect(queryByRole("listbox")).toBeFalsy();
|
|
782
|
-
expect(getByText("Ebro")).toBeTruthy();
|
|
783
|
-
expect(searchInput.value).toBe("");
|
|
784
|
-
userEvent.click(select);
|
|
785
|
-
expect(getAllByRole("option")[17].getAttribute("aria-selected")).toBe("true");
|
|
786
|
-
});
|
|
787
|
-
test("Grouped Options: Searchable - Displays 'No matches found' when there are no filtering results", () => {
|
|
788
|
-
const onChange = jest.fn();
|
|
789
|
-
const { container, getByText, getByRole } = render(
|
|
790
|
-
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} searchable />
|
|
791
|
-
);
|
|
792
|
-
const select = getByRole("combobox");
|
|
793
|
-
const searchInput = container.querySelectorAll("input")[1];
|
|
794
|
-
|
|
795
|
-
userEvent.click(select);
|
|
796
|
-
expect(getByRole("listbox")).toBeTruthy();
|
|
797
|
-
userEvent.type(searchInput, "very long string");
|
|
798
|
-
expect(getByText("No matches found")).toBeTruthy();
|
|
799
|
-
});
|
|
800
|
-
test("Grouped Options: Multiple selection - Displays a checkbox per option and enables the multi-selection", () => {
|
|
801
|
-
const onChange = jest.fn();
|
|
802
|
-
const { getByText, getAllByText, getByRole, getAllByRole, queryByRole } = render(
|
|
803
|
-
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} multiple />
|
|
804
|
-
);
|
|
805
|
-
const select = getByRole("combobox");
|
|
806
|
-
|
|
807
|
-
userEvent.click(select);
|
|
808
|
-
expect(getByRole("listbox").getAttribute("aria-multiselectable")).toBe("true");
|
|
809
|
-
userEvent.click(getAllByRole("option")[10]);
|
|
810
|
-
// expect(onChange).toHaveBeenCalledWith({ value: ["bilbao"], error: null });
|
|
811
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
812
|
-
expect(getAllByText("Bilbao").length).toBe(2);
|
|
813
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
814
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
815
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
816
|
-
// expect(onChange).toHaveBeenCalledWith({ value: ["bilbao", "guadalquivir"], error: null });
|
|
817
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
818
|
-
expect(getByText("Bilbao, Guadalquivir")).toBeTruthy();
|
|
819
|
-
expect(getAllByRole("option")[10].getAttribute("aria-selected")).toBe("true");
|
|
820
|
-
expect(getAllByRole("option")[16].getAttribute("aria-selected")).toBe("true");
|
|
821
|
-
});
|
|
822
|
-
test("Grouped Options: Multiple selection - Clear action and selection indicator", () => {
|
|
823
|
-
const onChange = jest.fn();
|
|
824
|
-
const { getByText, queryByText, getByRole, getAllByRole, queryByRole, getByTitle, queryByTitle } = render(
|
|
825
|
-
<DxcSelect label="test-select-label" options={group_options} onChange={onChange} multiple />
|
|
826
|
-
);
|
|
827
|
-
const select = getByRole("combobox");
|
|
828
|
-
|
|
829
|
-
userEvent.click(select);
|
|
830
|
-
userEvent.click(getAllByRole("option")[5]);
|
|
831
|
-
userEvent.click(getAllByRole("option")[8]);
|
|
832
|
-
userEvent.click(getAllByRole("option")[13]);
|
|
833
|
-
userEvent.click(getAllByRole("option")[17]);
|
|
834
|
-
// expect(onChange).toHaveBeenCalledWith({ value: ["blanco", "oviedo", "duero", "ebro"], error: null });
|
|
835
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
836
|
-
expect(getByText("Blanco, Oviedo, Duero, Ebro")).toBeTruthy();
|
|
837
|
-
expect(getByText("4", { exact: true })).toBeTruthy();
|
|
838
|
-
userEvent.click(getByTitle("Clear selected options"));
|
|
839
|
-
expect(queryByRole("listbox")).toBeTruthy();
|
|
840
|
-
expect(queryByText("Blanco, Oviedo, Duero, Ebro")).toBeFalsy();
|
|
841
|
-
expect(queryByText("4")).toBeFalsy();
|
|
842
|
-
expect(queryByTitle("Clear selected options")).toBeFalsy();
|
|
843
|
-
});
|
|
844
|
-
test("Grouped Options: Multiple selection - Optional option should not be added when the select is marked as multiple", () => {
|
|
845
|
-
const onChange = jest.fn();
|
|
846
|
-
const { getByText, getAllByText, getByRole, getAllByRole } = render(
|
|
847
|
-
<DxcSelect
|
|
848
|
-
label="test-select-label"
|
|
849
|
-
placeholder="Choose an option"
|
|
850
|
-
options={group_options}
|
|
851
|
-
onChange={onChange}
|
|
852
|
-
multiple
|
|
853
|
-
optional
|
|
854
|
-
/>
|
|
855
|
-
);
|
|
856
|
-
const select = getByRole("combobox");
|
|
857
|
-
|
|
858
|
-
expect(getByText("(Optional)")).toBeTruthy();
|
|
859
|
-
userEvent.click(select);
|
|
860
|
-
expect(getAllByText("Choose an option").length).toBe(1);
|
|
861
|
-
expect(getAllByRole("option")[0].getAttribute("aria-selected")).toBe("false");
|
|
862
|
-
userEvent.click(getAllByRole("option")[0]);
|
|
863
|
-
// expect(onChange).toHaveBeenCalledWith({ value: ["azul"], error: null });
|
|
864
|
-
expect(getAllByText("Azul").length).toBe(2);
|
|
865
|
-
});
|
|
866
|
-
test("Grouped Options - If an options was previously selected when its opened (by key press), the visual focus appears always in the selected option", () => {
|
|
867
|
-
const { getByText, getByRole, getAllByRole } = render(
|
|
868
|
-
<DxcSelect label="test-select-label" options={group_options} />
|
|
869
|
-
);
|
|
870
|
-
const select = getByRole("combobox");
|
|
871
|
-
|
|
872
|
-
userEvent.click(select);
|
|
873
|
-
userEvent.click(getAllByRole("option")[2]);
|
|
874
|
-
expect(getByText("Rosa")).toBeTruthy();
|
|
875
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
876
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-2");
|
|
877
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
878
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
879
|
-
expect(getByText("Rojo")).toBeTruthy();
|
|
880
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
881
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-1");
|
|
882
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
883
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
884
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
885
|
-
expect(getByText("Verde")).toBeTruthy();
|
|
886
|
-
});
|
|
887
|
-
test("Grouped Options - If an options was previously selected when its opened (by click and key press), the visual focus appears always in the selected option", () => {
|
|
888
|
-
const { getByText, getByRole, getAllByRole, queryByRole } = render(
|
|
889
|
-
<DxcSelect label="test-select-label" options={group_options} />
|
|
890
|
-
);
|
|
891
|
-
const select = getByRole("combobox");
|
|
892
|
-
|
|
893
|
-
userEvent.click(select);
|
|
894
|
-
userEvent.click(getAllByRole("option")[17]);
|
|
895
|
-
expect(getByText("Ebro")).toBeTruthy();
|
|
896
|
-
userEvent.click(select);
|
|
897
|
-
expect(select.getAttribute("aria-activedescendant")).toBeNull();
|
|
898
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
899
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-17");
|
|
900
|
-
userEvent.click(select);
|
|
901
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
902
|
-
expect(select.getAttribute("aria-activedescendant")).toBe("option-17");
|
|
903
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
904
|
-
fireEvent.keyDown(select, { key: "ArrowDown", code: "ArrowDown", keyCode: 40, charCode: 40 });
|
|
905
|
-
fireEvent.keyDown(select, { key: "ArrowUp", code: "ArrowUp", keyCode: 38, charCode: 38 });
|
|
906
|
-
fireEvent.keyDown(select, { key: "Enter", code: "Enter", keyCode: 13, charCode: 13 });
|
|
907
|
-
expect(getByText("Azul")).toBeTruthy();
|
|
908
|
-
});
|
|
909
|
-
test("Renders with correct aria attributes", () => {
|
|
910
|
-
const { getByText, getByRole } = render(
|
|
911
|
-
<DxcSelect label="test-select-label" placeholder="Example" options={single_options} />
|
|
912
|
-
);
|
|
913
|
-
const select = getByRole("combobox");
|
|
914
|
-
const label = getByText("test-select-label");
|
|
915
|
-
|
|
916
|
-
expect(select.getAttribute("aria-haspopup")).toBe("listbox");
|
|
917
|
-
expect(select.getAttribute("aria-expanded")).toBe("false");
|
|
918
|
-
expect(select.getAttribute("aria-required")).toBe("true");
|
|
919
|
-
expect(select.getAttribute("aria-labelledby")).toBe(label.id);
|
|
920
|
-
expect(select.getAttribute("aria-activedescendant")).toBeNull();
|
|
921
|
-
expect(select.getAttribute("aria-invalid")).toBe("false");
|
|
922
|
-
userEvent.click(select);
|
|
923
|
-
const list = getByRole("listbox");
|
|
924
|
-
expect(select.getAttribute("aria-controls")).toBe(list.id);
|
|
925
|
-
expect(list.getAttribute("aria-multiselectable")).toBe("false");
|
|
926
|
-
expect(list.getAttribute("aria-labelledby")).toBe(label.id);
|
|
927
|
-
});
|
|
928
|
-
});
|