@dxc-technology/halstack-react 0.0.0-ebb089f → 0.0.0-ec06b53
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 +294 -0
- package/accordion/Accordion.d.ts +4 -0
- package/accordion/Accordion.js +245 -0
- package/accordion/Accordion.stories.tsx +306 -0
- package/accordion/Accordion.test.js +71 -0
- package/accordion/types.d.ts +69 -0
- package/accordion/types.js +5 -0
- package/accordion-group/AccordionGroup.d.ts +7 -0
- package/accordion-group/AccordionGroup.js +149 -0
- package/accordion-group/AccordionGroup.stories.tsx +251 -0
- package/accordion-group/AccordionGroup.test.js +126 -0
- package/accordion-group/types.d.ts +79 -0
- package/accordion-group/types.js +5 -0
- package/alert/Alert.d.ts +4 -0
- package/{dist/alert → alert}/Alert.js +44 -154
- 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 +44 -0
- package/box/types.js +5 -0
- package/bulleted-list/BulletedList.d.ts +7 -0
- package/bulleted-list/BulletedList.js +123 -0
- package/bulleted-list/BulletedList.stories.tsx +200 -0
- package/bulleted-list/types.d.ts +11 -0
- package/bulleted-list/types.js +5 -0
- package/button/Button.d.ts +4 -0
- package/button/Button.js +156 -0
- package/button/Button.stories.tsx +283 -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 +68 -0
- package/card/types.js +5 -0
- package/checkbox/Checkbox.d.ts +4 -0
- package/checkbox/Checkbox.js +250 -0
- package/checkbox/Checkbox.stories.tsx +208 -0
- package/checkbox/Checkbox.test.js +155 -0
- package/checkbox/types.d.ts +68 -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 +363 -425
- package/date-input/Calendar.d.ts +4 -0
- package/date-input/Calendar.js +258 -0
- package/date-input/DateInput.d.ts +4 -0
- package/date-input/DateInput.js +227 -0
- package/date-input/DateInput.stories.tsx +151 -0
- package/date-input/DateInput.test.js +752 -0
- package/date-input/DatePicker.d.ts +4 -0
- package/date-input/DatePicker.js +160 -0
- package/date-input/YearPicker.d.ts +4 -0
- package/date-input/YearPicker.js +115 -0
- package/date-input/types.d.ts +160 -0
- package/date-input/types.js +5 -0
- package/dialog/Dialog.d.ts +4 -0
- package/dialog/Dialog.js +162 -0
- package/dialog/Dialog.stories.tsx +267 -0
- package/dialog/Dialog.test.js +70 -0
- package/dialog/types.d.ts +44 -0
- package/dialog/types.js +5 -0
- package/dropdown/Dropdown.d.ts +4 -0
- package/dropdown/Dropdown.js +391 -0
- package/dropdown/Dropdown.stories.tsx +312 -0
- package/dropdown/Dropdown.test.js +585 -0
- package/dropdown/DropdownMenu.d.ts +4 -0
- package/dropdown/DropdownMenu.js +80 -0
- package/dropdown/DropdownMenuItem.d.ts +4 -0
- package/dropdown/DropdownMenuItem.js +92 -0
- package/dropdown/types.d.ts +100 -0
- package/dropdown/types.js +5 -0
- package/file-input/FileInput.d.ts +4 -0
- package/file-input/FileInput.js +551 -0
- package/file-input/FileInput.stories.tsx +535 -0
- package/file-input/FileInput.test.js +498 -0
- package/file-input/FileItem.d.ts +4 -0
- package/file-input/FileItem.js +161 -0
- package/file-input/types.d.ts +129 -0
- package/file-input/types.js +5 -0
- package/flex/Flex.d.ts +4 -0
- package/flex/Flex.js +69 -0
- package/flex/Flex.stories.tsx +103 -0
- package/flex/types.d.ts +32 -0
- package/flex/types.js +5 -0
- package/footer/Footer.d.ts +4 -0
- package/footer/Footer.js +185 -0
- package/footer/Footer.stories.tsx +137 -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 +66 -0
- package/footer/types.js +5 -0
- package/header/Header.d.ts +7 -0
- package/header/Header.js +305 -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 +9 -34
- package/header/types.d.ts +48 -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/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 +20 -0
- package/layout/ApplicationLayout.js +171 -0
- package/layout/ApplicationLayout.stories.tsx +162 -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 +42 -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 +193 -0
- package/link/Link.test.js +83 -0
- package/link/types.d.ts +54 -0
- package/link/types.js +5 -0
- package/main.d.ts +44 -0
- package/{dist/main.js → main.js} +114 -104
- 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 +542 -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 +36 -33
- 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/paragraph/Paragraph.d.ts +6 -0
- package/paragraph/Paragraph.js +38 -0
- package/paragraph/Paragraph.stories.tsx +44 -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 +181 -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/progress-bar/ProgressBar.js +176 -0
- package/progress-bar/ProgressBar.stories.jsx +60 -0
- package/progress-bar/ProgressBar.test.js +110 -0
- package/progress-bar/types.d.ts +36 -0
- package/progress-bar/types.js +5 -0
- package/quick-nav/QuickNav.d.ts +4 -0
- package/quick-nav/QuickNav.js +117 -0
- package/quick-nav/QuickNav.stories.tsx +342 -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 +156 -0
- package/radio-group/RadioGroup.d.ts +4 -0
- package/radio-group/RadioGroup.js +283 -0
- package/radio-group/RadioGroup.stories.tsx +101 -0
- package/radio-group/RadioGroup.test.js +722 -0
- package/radio-group/types.d.ts +114 -0
- package/radio-group/types.js +5 -0
- package/resultsetTable/Icons.d.ts +7 -0
- package/resultsetTable/Icons.js +51 -0
- package/resultsetTable/ResultsetTable.d.ts +4 -0
- package/resultsetTable/ResultsetTable.js +195 -0
- package/resultsetTable/ResultsetTable.stories.tsx +300 -0
- package/resultsetTable/ResultsetTable.test.js +330 -0
- package/resultsetTable/types.d.ts +67 -0
- package/resultsetTable/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 +198 -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 +645 -0
- package/select/Select.stories.tsx +627 -0
- package/select/Select.test.js +2233 -0
- package/select/types.d.ts +210 -0
- package/select/types.js +5 -0
- package/sidenav/Sidenav.d.ts +10 -0
- package/sidenav/Sidenav.js +268 -0
- package/sidenav/Sidenav.stories.tsx +180 -0
- package/sidenav/Sidenav.test.js +44 -0
- package/sidenav/types.d.ts +73 -0
- package/sidenav/types.js +5 -0
- package/slider/Slider.d.ts +4 -0
- package/slider/Slider.js +343 -0
- package/slider/Slider.stories.tsx +183 -0
- package/slider/Slider.test.js +250 -0
- package/slider/types.d.ts +86 -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/switch/Switch.d.ts +4 -0
- package/switch/Switch.js +262 -0
- package/switch/Switch.stories.tsx +138 -0
- package/switch/Switch.test.js +225 -0
- package/switch/types.d.ts +66 -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/Tab.d.ts +4 -0
- package/tabs/Tab.js +135 -0
- package/tabs/Tabs.d.ts +4 -0
- package/tabs/Tabs.js +467 -0
- package/tabs/Tabs.stories.tsx +186 -0
- package/tabs/Tabs.test.js +351 -0
- package/tabs/types.d.ts +92 -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 +130 -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-input/Icons.d.ts +8 -0
- package/text-input/Icons.js +60 -0
- package/text-input/Suggestion.d.ts +4 -0
- package/text-input/Suggestion.js +57 -0
- package/text-input/Suggestions.d.ts +4 -0
- package/text-input/Suggestions.js +134 -0
- package/text-input/TextInput.d.ts +4 -0
- package/text-input/TextInput.js +677 -0
- package/text-input/TextInput.stories.tsx +481 -0
- package/text-input/TextInput.test.js +1624 -0
- package/text-input/types.d.ts +197 -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/typography/Typography.d.ts +4 -0
- package/typography/Typography.js +131 -0
- package/typography/Typography.stories.tsx +198 -0
- package/typography/types.d.ts +18 -0
- package/typography/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 +285 -0
- package/wizard/Wizard.stories.tsx +233 -0
- package/wizard/Wizard.test.js +141 -0
- package/wizard/types.d.ts +65 -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.js +0 -238
- 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/Checkbox.js +0 -299
- 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/DateInput.js +0 -400
- 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/Dropdown.js +0 -544
- 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/ProgressBar.js +0 -242
- 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/ResultsetTable.js +0 -358
- 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/Slider.js +0 -404
- 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/TextInput.js +0 -974
- 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/DateInput.test.js
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
4
|
-
|
|
5
|
-
import DxcDateInput from "../src/date-input/DateInput";
|
|
6
|
-
|
|
7
|
-
describe("DateInput component tests", () => {
|
|
8
|
-
test("Renders with correct label, helper text, optional, placeholder and clearable action", () => {
|
|
9
|
-
const { getByText, getByRole, getAllByRole } = render(
|
|
10
|
-
<DxcDateInput label="Example label" helperText="Example of helper text" placeholder optional clearable />
|
|
11
|
-
);
|
|
12
|
-
const input = getByRole("textbox");
|
|
13
|
-
expect(getByText("Example label")).toBeTruthy();
|
|
14
|
-
expect(getByText("Example of helper text")).toBeTruthy();
|
|
15
|
-
expect(getByText("(Optional)")).toBeTruthy();
|
|
16
|
-
expect(input.getAttribute("placeholder")).toBe("DD-MM-YYYY");
|
|
17
|
-
userEvent.type(input, "10/10/2010");
|
|
18
|
-
const closeAction = getAllByRole("button")[0];
|
|
19
|
-
userEvent.click(closeAction);
|
|
20
|
-
expect(input.value).toBe("");
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test("Renders with personalized error", () => {
|
|
24
|
-
const { getByText } = render(<DxcDateInput error="Personalized error." />);
|
|
25
|
-
expect(getByText("Personalized error.")).toBeTruthy();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test("Renders with correct format: user typed date but it's invalid, onBlur error", () => {
|
|
29
|
-
const onBlur = jest.fn(({ value, error }) => {
|
|
30
|
-
expect(value).toBe("10/90/2010");
|
|
31
|
-
expect(error).toBe("Invalid date.");
|
|
32
|
-
});
|
|
33
|
-
const { getByRole } = render(<DxcDateInput label="With format MM/dd/yyyy" format="MM/dd/yyyy" onBlur={onBlur} />);
|
|
34
|
-
const input = getByRole("textbox");
|
|
35
|
-
|
|
36
|
-
userEvent.type(input, "10/90/2010");
|
|
37
|
-
fireEvent.blur(input);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test("Renders with correct format: user typed date but it's invalid, onChange error", () => {
|
|
41
|
-
const onChange = jest.fn();
|
|
42
|
-
const { getByRole } = render(
|
|
43
|
-
<DxcDateInput label="With format MM/dd/yyyy" format="MM/dd/yyyy" onChange={onChange} />
|
|
44
|
-
);
|
|
45
|
-
const input = getByRole("textbox");
|
|
46
|
-
|
|
47
|
-
userEvent.type(input, "10/90/2010");
|
|
48
|
-
expect(onChange).toHaveBeenCalledTimes(10);
|
|
49
|
-
expect(onChange).toHaveBeenCalledWith({ value: "10/90/2010", error: "Invalid date.", date: null });
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("Calendar renders with correct date: today's date", () => {
|
|
53
|
-
const { getByText, getByRole } = render(<DxcDateInput />);
|
|
54
|
-
const calendarAction = getByRole("button");
|
|
55
|
-
const d = new Date();
|
|
56
|
-
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
57
|
-
|
|
58
|
-
userEvent.click(calendarAction);
|
|
59
|
-
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("Calendar renders with correct date: value prop", () => {
|
|
63
|
-
const { getByText, getByRole } = render(<DxcDateInput value="20-10-2019" />);
|
|
64
|
-
const calendarAction = getByRole("button");
|
|
65
|
-
const d = new Date(2019, 9, 20);
|
|
66
|
-
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
67
|
-
|
|
68
|
-
userEvent.click(calendarAction);
|
|
69
|
-
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("Calendar renders with correct date: user typed value", () => {
|
|
73
|
-
const { getByText, getByRole } = render(<DxcDateInput />);
|
|
74
|
-
const calendarAction = getByRole("button");
|
|
75
|
-
const d = new Date(2010, 0, 1);
|
|
76
|
-
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
77
|
-
const input = getByRole("textbox");
|
|
78
|
-
|
|
79
|
-
userEvent.type(input, "01-01-2010");
|
|
80
|
-
userEvent.click(calendarAction);
|
|
81
|
-
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test("Calendar renders with correct date: invalid date, renders with today's date", () => {
|
|
85
|
-
const onBlur = jest.fn();
|
|
86
|
-
const { getByText, getByRole } = render(<DxcDateInput onBlur={onBlur} />);
|
|
87
|
-
const calendarAction = getByRole("button");
|
|
88
|
-
const d = new Date();
|
|
89
|
-
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
90
|
-
const input = getByRole("textbox");
|
|
91
|
-
|
|
92
|
-
userEvent.type(input, "01-01-xxxx");
|
|
93
|
-
fireEvent.blur(input);
|
|
94
|
-
expect(onBlur).toHaveBeenCalled();
|
|
95
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "01-01-xxxx", error: "Invalid date.", date: null });
|
|
96
|
-
userEvent.click(calendarAction);
|
|
97
|
-
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("Selecting a date from the calendar with an specific format", () => {
|
|
101
|
-
const { getByText, getByRole } = render(<DxcDateInput label="With format M-dd-yyyy" format="M-dd-yyyy" />);
|
|
102
|
-
const input = getByRole("textbox");
|
|
103
|
-
const calendarAction = getByRole("button");
|
|
104
|
-
userEvent.click(calendarAction);
|
|
105
|
-
const dayButton = getByText("10").closest("button");
|
|
106
|
-
fireEvent.click(dayButton);
|
|
107
|
-
const d = new Date();
|
|
108
|
-
d.setDate(10);
|
|
109
|
-
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
110
|
-
expect(getByText(d.toLocaleString("en-US", options))).toBeTruthy();
|
|
111
|
-
fireEvent.keyDown(document, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
112
|
-
expect(input.value).toBe(`${d.getMonth() + 1}-10-${d.getFullYear()}`);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test("Selecting a date from the calendar (using keyboard presses)", () => {
|
|
116
|
-
const { getByRole } = render(<DxcDateInput />);
|
|
117
|
-
const calendarAction = getByRole("button");
|
|
118
|
-
const input = getByRole("textbox");
|
|
119
|
-
|
|
120
|
-
userEvent.type(input, "01-01-2010");
|
|
121
|
-
userEvent.click(calendarAction);
|
|
122
|
-
fireEvent.keyDown(document, { key: "ArrowRight", code: "ArrowRight", keyCode: 39, charCode: 39 });
|
|
123
|
-
fireEvent.keyDown(document, { key: "ArrowRight", code: "ArrowRight", keyCode: 39, charCode: 39 });
|
|
124
|
-
fireEvent.keyDown(document, { key: "ArrowRight", code: "ArrowRight", keyCode: 39, charCode: 39 });
|
|
125
|
-
fireEvent.keyDown(document, { key: "ArrowLeft", code: "ArrowLeft", keyCode: 37, charCode: 37 });
|
|
126
|
-
fireEvent.keyDown(document, { key: "Esc", code: "Esc", keyCode: 27, charCode: 27 });
|
|
127
|
-
expect(input.value).toBe("03-01-2010");
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("onChange & onBlur functions are called correctly", () => {
|
|
131
|
-
const onBlur = jest.fn();
|
|
132
|
-
const onChange = jest.fn();
|
|
133
|
-
const { getByRole } = render(<DxcDateInput onChange={onChange} onBlur={onBlur} />);
|
|
134
|
-
const input = getByRole("textbox");
|
|
135
|
-
const d = new Date(2011, 9, 10);
|
|
136
|
-
|
|
137
|
-
userEvent.type(input, "10-10-2011");
|
|
138
|
-
expect(input.value).toBe("10-10-2011");
|
|
139
|
-
expect(onChange).toHaveBeenCalledTimes(10);
|
|
140
|
-
expect(onChange).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
141
|
-
fireEvent.blur(input);
|
|
142
|
-
expect(onBlur).toHaveBeenCalled();
|
|
143
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-2011", error: null, date: d });
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test("onChange & onBlur functions are called correctly, also with errors", () => {
|
|
147
|
-
const onBlur = jest.fn();
|
|
148
|
-
const onChange = jest.fn();
|
|
149
|
-
const { getByRole } = render(<DxcDateInput onChange={onChange} onBlur={onBlur} />);
|
|
150
|
-
const input = getByRole("textbox");
|
|
151
|
-
|
|
152
|
-
userEvent.type(input, "10-10-");
|
|
153
|
-
expect(input.value).toBe("10-10-");
|
|
154
|
-
expect(onChange).toHaveBeenCalledTimes(6);
|
|
155
|
-
expect(onChange).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
156
|
-
fireEvent.blur(input);
|
|
157
|
-
expect(onBlur).toHaveBeenCalled();
|
|
158
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "10-10-", error: "Invalid date.", date: null });
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
test("onBlur function removes the error when it is fixed", () => {
|
|
162
|
-
const onBlur = jest.fn();
|
|
163
|
-
const { getByRole } = render(<DxcDateInput onBlur={onBlur} />);
|
|
164
|
-
const input = getByRole("textbox");
|
|
165
|
-
const d = new Date(2002, 1, 20);
|
|
166
|
-
|
|
167
|
-
userEvent.type(input, "test");
|
|
168
|
-
expect(input.value).toBe("test");
|
|
169
|
-
fireEvent.blur(input);
|
|
170
|
-
expect(onBlur).toHaveBeenCalled();
|
|
171
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Invalid date.", date: null });
|
|
172
|
-
userEvent.clear(input);
|
|
173
|
-
userEvent.type(input, "20-02-2002");
|
|
174
|
-
expect(input.value).toBe("20-02-2002");
|
|
175
|
-
fireEvent.blur(input);
|
|
176
|
-
expect(onBlur).toHaveBeenCalled();
|
|
177
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "20-02-2002", error: null, date: d });
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test("onBlur function removes the error when the input is empty", () => {
|
|
181
|
-
const onBlur = jest.fn();
|
|
182
|
-
const { getByRole } = render(<DxcDateInput onBlur={onBlur} optional />);
|
|
183
|
-
const input = getByRole("textbox");
|
|
184
|
-
|
|
185
|
-
userEvent.type(input, "test");
|
|
186
|
-
expect(input.value).toBe("test");
|
|
187
|
-
fireEvent.blur(input);
|
|
188
|
-
expect(onBlur).toHaveBeenCalled();
|
|
189
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "test", error: "Invalid date.", date: null });
|
|
190
|
-
userEvent.clear(input);
|
|
191
|
-
fireEvent.blur(input);
|
|
192
|
-
expect(onBlur).toHaveBeenCalled();
|
|
193
|
-
expect(onBlur).toHaveBeenCalledWith({ value: "", error: null, date: null });
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
test("onBlur & onChange functions error: required field (not optional)", () => {
|
|
197
|
-
const onBlur = jest.fn();
|
|
198
|
-
const onChange = jest.fn();
|
|
199
|
-
const { getByRole } = render(<DxcDateInput onBlur={onBlur} onChange={onChange} />);
|
|
200
|
-
const date = getByRole("textbox");
|
|
201
|
-
|
|
202
|
-
userEvent.type(date, "t");
|
|
203
|
-
expect(date.value).toBe("t");
|
|
204
|
-
userEvent.clear(date);
|
|
205
|
-
fireEvent.blur(date);
|
|
206
|
-
expect(onBlur).toHaveBeenCalled();
|
|
207
|
-
expect(onBlur).toHaveBeenCalledWith({
|
|
208
|
-
value: "",
|
|
209
|
-
error: "This field is required. Please, enter a value.",
|
|
210
|
-
date: null,
|
|
211
|
-
});
|
|
212
|
-
expect(onChange).toHaveBeenCalled();
|
|
213
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
214
|
-
value: "",
|
|
215
|
-
error: "This field is required. Please, enter a value.",
|
|
216
|
-
date: null,
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
test("Disabled date input (calendar action must be shown but not clickable)", () => {
|
|
221
|
-
const { getByRole, queryByText } = render(<DxcDateInput disabled />);
|
|
222
|
-
const calendarAction = getByRole("button");
|
|
223
|
-
const d = new Date();
|
|
224
|
-
const options = { weekday: "short", month: "short", day: "numeric" };
|
|
225
|
-
|
|
226
|
-
expect(getByRole("textbox").disabled).toBeTruthy();
|
|
227
|
-
userEvent.click(calendarAction);
|
|
228
|
-
expect(queryByText(d.toLocaleString("en-US", options))).toBeFalsy();
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test("Input has correct accesibility attributes", () => {
|
|
232
|
-
const { getByRole } = render(<DxcDateInput label="Date input label" />);
|
|
233
|
-
const input = getByRole("textbox");
|
|
234
|
-
expect(input.getAttribute("aria-autocomplete")).toBeNull();
|
|
235
|
-
expect(input.getAttribute("aria-controls")).toBeNull();
|
|
236
|
-
expect(input.getAttribute("aria-expanded")).toBeNull();
|
|
237
|
-
const calendarAction = getByRole("button");
|
|
238
|
-
userEvent.click(calendarAction);
|
|
239
|
-
const datePicker = getByRole("dialog");
|
|
240
|
-
expect(datePicker.getAttribute("aria-modal")).toBe("true");
|
|
241
|
-
});
|
|
242
|
-
});
|
package/test/Dialog.test.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { render, fireEvent } from "@testing-library/react";
|
|
3
|
-
import DxcDialog from "../src/dialog/Dialog";
|
|
4
|
-
|
|
5
|
-
describe("Dialog component tests", () => {
|
|
6
|
-
test("Dialog renders with correct text", () => {
|
|
7
|
-
const { getByText } = render(<DxcDialog>dialog-text</DxcDialog>);
|
|
8
|
-
expect(getByText("dialog-text")).toBeTruthy();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test("Dialog renders without close button", () => {
|
|
12
|
-
const { queryByRole } = render(<DxcDialog isCloseVisible={false}>dialog-text</DxcDialog>);
|
|
13
|
-
expect(queryByRole("button")).toBeFalsy();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test("Calls correct function onCloseClick", () => {
|
|
17
|
-
const onCloseClick = jest.fn();
|
|
18
|
-
const { getByRole } = render(<DxcDialog onCloseClick={onCloseClick}>dialog-text</DxcDialog>);
|
|
19
|
-
const closeButton = getByRole("button");
|
|
20
|
-
fireEvent.click(closeButton);
|
|
21
|
-
expect(onCloseClick).toHaveBeenCalled();
|
|
22
|
-
});
|
|
23
|
-
});
|
package/test/Dropdown.test.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { render, fireEvent, act } from "@testing-library/react";
|
|
3
|
-
import DxcDropdown from "../src/dropdown/Dropdown";
|
|
4
|
-
|
|
5
|
-
global.document.createRange = () => ({
|
|
6
|
-
setStart: () => {},
|
|
7
|
-
setEnd: () => {},
|
|
8
|
-
commonAncestorContainer: {
|
|
9
|
-
nodeName: "BODY",
|
|
10
|
-
ownerDocument: document,
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe("Dropdown component tests", () => {
|
|
15
|
-
test("Dropdown renders with correct label", () => {
|
|
16
|
-
const { getByText } = render(<DxcDropdown label="dropdown-test"></DxcDropdown>);
|
|
17
|
-
expect(getByText("dropdown-test")).toBeTruthy();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test("Dropdown renders with correct icon before", () => {
|
|
21
|
-
const { getAllByRole } = render(<DxcDropdown iconSrc="/testIcon" label="dropdown-test"></DxcDropdown>);
|
|
22
|
-
const image = getAllByRole("img")[0];
|
|
23
|
-
expect(image.getAttribute("src")).toEqual("/testIcon");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("Dropdown renders with correct icon after", () => {
|
|
27
|
-
const { getAllByRole } = render(
|
|
28
|
-
<DxcDropdown iconSrc="/testIcon" iconPosition="after" label="dropdown-test"></DxcDropdown>
|
|
29
|
-
);
|
|
30
|
-
const image = getAllByRole("img")[0];
|
|
31
|
-
expect(image.getAttribute("src")).toEqual("/testIcon");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("onClick shows and hides option", () => {
|
|
35
|
-
const options = [
|
|
36
|
-
{
|
|
37
|
-
value: 1,
|
|
38
|
-
label: "option-test",
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
const { queryByText } = render(<DxcDropdown options={options} label="dropdown-test"></DxcDropdown>);
|
|
42
|
-
const dropdown = queryByText("dropdown-test");
|
|
43
|
-
//Before clicked is not showed
|
|
44
|
-
expect(queryByText("option-test")).toBeFalsy();
|
|
45
|
-
act(() => {
|
|
46
|
-
fireEvent.click(dropdown);
|
|
47
|
-
});
|
|
48
|
-
expect(queryByText("option-test")).toBeTruthy();
|
|
49
|
-
});
|
|
50
|
-
test("Disabled dropdown is not clickable", () => {
|
|
51
|
-
const options = [
|
|
52
|
-
{
|
|
53
|
-
value: 1,
|
|
54
|
-
label: "option-test",
|
|
55
|
-
},
|
|
56
|
-
];
|
|
57
|
-
const { queryByText } = render(<DxcDropdown options={options} disabled label="dropdown-test"></DxcDropdown>);
|
|
58
|
-
const dropdown = queryByText("dropdown-test");
|
|
59
|
-
expect(queryByText("option-test")).toBeFalsy();
|
|
60
|
-
act(() => {
|
|
61
|
-
fireEvent.click(dropdown);
|
|
62
|
-
});
|
|
63
|
-
expect(queryByText("option-test")).toBeFalsy();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("Dropdown renders with correct icon before option", () => {
|
|
67
|
-
const options = [
|
|
68
|
-
{
|
|
69
|
-
value: 1,
|
|
70
|
-
label: "option-test",
|
|
71
|
-
iconSrc: "/testIcon",
|
|
72
|
-
},
|
|
73
|
-
];
|
|
74
|
-
const { getByText, getByRole } = render(<DxcDropdown options={options} label="dropdown-test"></DxcDropdown>);
|
|
75
|
-
const dropdown = getByText("dropdown-test");
|
|
76
|
-
act(() => {
|
|
77
|
-
fireEvent.click(dropdown);
|
|
78
|
-
});
|
|
79
|
-
expect(getByRole("img").getAttribute("src")).toEqual("/testIcon");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("Dropdown renders with correct icon after option", () => {
|
|
83
|
-
const options = [
|
|
84
|
-
{
|
|
85
|
-
value: 1,
|
|
86
|
-
label: "option-test",
|
|
87
|
-
iconSrc: "/testIcon",
|
|
88
|
-
},
|
|
89
|
-
];
|
|
90
|
-
const { getByText, getByRole } = render(
|
|
91
|
-
<DxcDropdown options={options} optionsIconPosition="after" label="dropdown-test"></DxcDropdown>
|
|
92
|
-
);
|
|
93
|
-
const dropdown = getByText("dropdown-test");
|
|
94
|
-
act(() => {
|
|
95
|
-
fireEvent.click(dropdown);
|
|
96
|
-
});
|
|
97
|
-
expect(getByRole("img").getAttribute("src")).toEqual("/testIcon");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("Dropdown renders with caret hidden", () => {
|
|
101
|
-
const { queryByRole } = render(<DxcDropdown caretHidden={true} label="dropdown-test"></DxcDropdown>);
|
|
102
|
-
expect(queryByRole("img")).toBeFalsy();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test("onSelectOption fuction is called correctly", () => {
|
|
106
|
-
const onSelectOption = jest.fn((i) => i);
|
|
107
|
-
const options = [
|
|
108
|
-
{
|
|
109
|
-
value: 1,
|
|
110
|
-
label: "option-test",
|
|
111
|
-
},
|
|
112
|
-
];
|
|
113
|
-
const { getByText } = render(
|
|
114
|
-
<DxcDropdown options={options} onSelectOption={onSelectOption} label="dropdown-test"></DxcDropdown>
|
|
115
|
-
);
|
|
116
|
-
const dropdown = getByText("dropdown-test");
|
|
117
|
-
act(() => {
|
|
118
|
-
fireEvent.click(dropdown);
|
|
119
|
-
});
|
|
120
|
-
const option = getByText("option-test");
|
|
121
|
-
act(() => {
|
|
122
|
-
fireEvent.click(option);
|
|
123
|
-
});
|
|
124
|
-
expect(onSelectOption).toHaveBeenCalledWith(1);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test("expandOnHover shows and hides the option correctly", () => {
|
|
128
|
-
const options = [
|
|
129
|
-
{
|
|
130
|
-
value: 1,
|
|
131
|
-
label: "option-test",
|
|
132
|
-
},
|
|
133
|
-
];
|
|
134
|
-
const { queryByText } = render(
|
|
135
|
-
<DxcDropdown options={options} expandOnHover={true} label="dropdown-test"></DxcDropdown>
|
|
136
|
-
);
|
|
137
|
-
const dropdown = queryByText("dropdown-test");
|
|
138
|
-
//Verify that is not showed before
|
|
139
|
-
expect(queryByText("option-test")).toBeFalsy();
|
|
140
|
-
act(() => {
|
|
141
|
-
fireEvent.mouseOver(dropdown);
|
|
142
|
-
});
|
|
143
|
-
expect(queryByText("option-test")).toBeTruthy();
|
|
144
|
-
});
|
|
145
|
-
});
|
package/test/FileInput.test.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { render, fireEvent, waitFor } from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
4
|
-
|
|
5
|
-
import DxcFileInput from "../src/file-input/FileInput";
|
|
6
|
-
|
|
7
|
-
describe("FileInput component tests", () => {
|
|
8
|
-
const file1 = new File(["file1"], "file1.png", { type: "image/png" });
|
|
9
|
-
const file2 = new File(["file2"], "file2.txt", {
|
|
10
|
-
type: "text/plain",
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const files = [
|
|
14
|
-
{
|
|
15
|
-
error: null,
|
|
16
|
-
preview: null,
|
|
17
|
-
file: file1,
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
error: "Error message",
|
|
21
|
-
preview: null,
|
|
22
|
-
file: file2,
|
|
23
|
-
},
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
test("Renders with correct labels and helper text in file mode", () => {
|
|
27
|
-
const { getByText } = render(<DxcFileInput label="File input label" helperText="File input helper text" />);
|
|
28
|
-
expect(getByText("File input label")).toBeTruthy();
|
|
29
|
-
expect(getByText("File input helper text")).toBeTruthy();
|
|
30
|
-
});
|
|
31
|
-
test("Renders with correct button label in file mode", () => {
|
|
32
|
-
const { getByText } = render(<DxcFileInput label="File input label" helperText="File input helper text" />);
|
|
33
|
-
expect(getByText("Select files")).toBeTruthy();
|
|
34
|
-
});
|
|
35
|
-
test("Renders with correct labels in filedrop mode", () => {
|
|
36
|
-
const { getByText } = render(
|
|
37
|
-
<DxcFileInput label="File input label" helperText="File input helper text" mode="filedrop" />
|
|
38
|
-
);
|
|
39
|
-
expect(getByText("Select")).toBeTruthy();
|
|
40
|
-
expect(getByText("or drop files")).toBeTruthy();
|
|
41
|
-
});
|
|
42
|
-
test("Renders with correct labels in dropzone mode", () => {
|
|
43
|
-
const { getByText } = render(
|
|
44
|
-
<DxcFileInput label="File input label" helperText="File input helper text" mode="dropzone" />
|
|
45
|
-
);
|
|
46
|
-
expect(getByText("Select")).toBeTruthy();
|
|
47
|
-
expect(getByText("or drop files")).toBeTruthy();
|
|
48
|
-
});
|
|
49
|
-
test("Disabled file input", () => {
|
|
50
|
-
const { getByText, getByRole } = render(
|
|
51
|
-
<DxcFileInput label="File input label" helperText="File input helper text" disabled />
|
|
52
|
-
);
|
|
53
|
-
expect(getByText("Select files")).toBeTruthy();
|
|
54
|
-
const button = getByRole("button");
|
|
55
|
-
expect(button.disabled).toBeTruthy();
|
|
56
|
-
});
|
|
57
|
-
test("Renders file items passed in value when multiple file input", () => {
|
|
58
|
-
const callbackFile = jest.fn();
|
|
59
|
-
const { getByText } = render(
|
|
60
|
-
<DxcFileInput
|
|
61
|
-
label="File input label"
|
|
62
|
-
helperText="File input helper text"
|
|
63
|
-
value={files}
|
|
64
|
-
callbackFile={callbackFile}
|
|
65
|
-
/>
|
|
66
|
-
);
|
|
67
|
-
expect(getByText("file1.png")).toBeTruthy();
|
|
68
|
-
expect(getByText("file2.txt")).toBeTruthy();
|
|
69
|
-
expect(getByText("Error message")).toBeTruthy();
|
|
70
|
-
});
|
|
71
|
-
test("Renders file items when single file input", () => {
|
|
72
|
-
const callbackFile = jest.fn();
|
|
73
|
-
const { getByText } = render(
|
|
74
|
-
<DxcFileInput
|
|
75
|
-
label="File input label"
|
|
76
|
-
helperText="File input helper text"
|
|
77
|
-
multiple={false}
|
|
78
|
-
value={files}
|
|
79
|
-
callbackFile={callbackFile}
|
|
80
|
-
/>
|
|
81
|
-
);
|
|
82
|
-
expect(getByText("file1.png")).toBeTruthy();
|
|
83
|
-
expect(getByText("file2.txt")).toBeTruthy();
|
|
84
|
-
expect(getByText("Error message")).toBeTruthy();
|
|
85
|
-
});
|
|
86
|
-
test("Add file item when single file input", async () => {
|
|
87
|
-
const newFile = new File(["newFile"], "newFile.pdf", { type: "pdf" });
|
|
88
|
-
const callbackFile = jest.fn();
|
|
89
|
-
const { getByText, getByLabelText } = render(
|
|
90
|
-
<DxcFileInput
|
|
91
|
-
label="File input label"
|
|
92
|
-
helperText="File input helper text"
|
|
93
|
-
value={files}
|
|
94
|
-
callbackFile={callbackFile}
|
|
95
|
-
multiple={false}
|
|
96
|
-
/>
|
|
97
|
-
);
|
|
98
|
-
expect(getByText("file1.png")).toBeTruthy();
|
|
99
|
-
expect(getByText("file2.txt")).toBeTruthy();
|
|
100
|
-
expect(getByText("Error message")).toBeTruthy();
|
|
101
|
-
const inputFile = getByLabelText("File input label", { hidden: true });
|
|
102
|
-
fireEvent.change(inputFile, { target: { files: [newFile] } });
|
|
103
|
-
await waitFor(() => {
|
|
104
|
-
expect(callbackFile).toHaveBeenCalledWith([
|
|
105
|
-
{
|
|
106
|
-
error: undefined,
|
|
107
|
-
file: newFile,
|
|
108
|
-
preview: (
|
|
109
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
|
110
|
-
<path fill="none" d="M0 0h24v24H0V0z" />
|
|
111
|
-
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z" />
|
|
112
|
-
</svg>
|
|
113
|
-
),
|
|
114
|
-
},
|
|
115
|
-
]);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
test("Renders file items and delete one file", async () => {
|
|
119
|
-
const callbackFile = jest.fn();
|
|
120
|
-
const { getByText, getAllByRole } = render(
|
|
121
|
-
<DxcFileInput
|
|
122
|
-
label="File input label"
|
|
123
|
-
helperText="File input helper text"
|
|
124
|
-
value={files}
|
|
125
|
-
callbackFile={callbackFile}
|
|
126
|
-
/>
|
|
127
|
-
);
|
|
128
|
-
expect(getByText("file1.png")).toBeTruthy();
|
|
129
|
-
expect(getByText("file2.txt")).toBeTruthy();
|
|
130
|
-
expect(getByText("Error message")).toBeTruthy();
|
|
131
|
-
const removeBtn = getAllByRole("button")[1];
|
|
132
|
-
userEvent.click(removeBtn);
|
|
133
|
-
await waitFor(() => {
|
|
134
|
-
expect(callbackFile).toHaveBeenCalledWith([{ error: "Error message", file: file2, preview: null }]);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test("CallbackFile is correctly called", async () => {
|
|
139
|
-
const newFile = new File(["newFile"], "newFile.pdf", { type: "pdf" });
|
|
140
|
-
const callbackFile = jest.fn();
|
|
141
|
-
const { getByLabelText } = render(
|
|
142
|
-
<DxcFileInput
|
|
143
|
-
label="File input label"
|
|
144
|
-
helperText="File input helper text"
|
|
145
|
-
value={files}
|
|
146
|
-
callbackFile={callbackFile}
|
|
147
|
-
/>
|
|
148
|
-
);
|
|
149
|
-
const inputFile = getByLabelText("File input label", { hidden: true });
|
|
150
|
-
fireEvent.change(inputFile, { target: { files: [newFile] } });
|
|
151
|
-
await waitFor(() => {
|
|
152
|
-
expect(callbackFile).toHaveBeenCalledWith([
|
|
153
|
-
{ error: null, preview: null, file: file1 },
|
|
154
|
-
{ error: "Error message", preview: null, file: file2 },
|
|
155
|
-
{
|
|
156
|
-
error: undefined,
|
|
157
|
-
file: newFile,
|
|
158
|
-
preview: (
|
|
159
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
|
160
|
-
<path fill="none" d="M0 0h24v24H0V0z" />
|
|
161
|
-
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z" />
|
|
162
|
-
</svg>
|
|
163
|
-
),
|
|
164
|
-
},
|
|
165
|
-
]);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
test("Callback called correctly when a file size does not comply minSize or maxSize", async () => {
|
|
170
|
-
const newFile = new File(["newFile"], "newFile.pdf", { type: "pdf" });
|
|
171
|
-
const callbackFile = jest.fn();
|
|
172
|
-
const { getByLabelText } = render(
|
|
173
|
-
<DxcFileInput
|
|
174
|
-
label="File input label"
|
|
175
|
-
helperText="File input helper text"
|
|
176
|
-
minSize={1000}
|
|
177
|
-
maxSize={20000}
|
|
178
|
-
value={files}
|
|
179
|
-
callbackFile={callbackFile}
|
|
180
|
-
/>
|
|
181
|
-
);
|
|
182
|
-
const inputFile = getByLabelText("File input label", { hidden: true });
|
|
183
|
-
fireEvent.change(inputFile, { target: { files: [newFile] } });
|
|
184
|
-
await waitFor(() => {
|
|
185
|
-
expect(callbackFile).toHaveBeenCalledWith([
|
|
186
|
-
{ error: null, preview: null, file: file1 },
|
|
187
|
-
{ error: "Error message", preview: null, file: file2 },
|
|
188
|
-
{
|
|
189
|
-
error: "File size must be greater than min size.",
|
|
190
|
-
file: newFile,
|
|
191
|
-
preview: (
|
|
192
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
|
|
193
|
-
<path fill="none" d="M0 0h24v24H0V0z" />
|
|
194
|
-
<path d="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6z" />
|
|
195
|
-
</svg>
|
|
196
|
-
),
|
|
197
|
-
},
|
|
198
|
-
]);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
});
|