@pautena/react-design-system 0.12.0 → 0.12.2
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/.eslintrc.cjs +40 -0
- package/.prettierrc.cjs +5 -0
- package/package.json +1 -1
- package/src/components/alerts/alerts.stories.mdx +0 -10
- package/src/components/alerts/expandable-alert/expandable-alert.stories.tsx +0 -96
- package/src/components/alerts/expandable-alert/expandable-alert.test.tsx +0 -137
- package/src/components/alerts/expandable-alert/expandable-alert.tsx +0 -78
- package/src/components/alerts/expandable-alert/index.ts +0 -1
- package/src/components/alerts/index.ts +0 -1
- package/src/components/components.stories.mdx +0 -20
- package/src/components/containers/center-container/center-container.stories.tsx +0 -52
- package/src/components/containers/center-container/center-container.test.tsx +0 -16
- package/src/components/containers/center-container/center-container.tsx +0 -32
- package/src/components/containers/center-container/index.ts +0 -1
- package/src/components/containers/containers.stories.mdx +0 -12
- package/src/components/containers/content/content.stories.tsx +0 -20
- package/src/components/containers/content/content.test.tsx +0 -26
- package/src/components/containers/content/content.tsx +0 -11
- package/src/components/containers/content/content.types.ts +0 -5
- package/src/components/containers/content/index.ts +0 -2
- package/src/components/containers/index.ts +0 -3
- package/src/components/containers/list-panel/index.ts +0 -2
- package/src/components/containers/list-panel/list-panel-panel.tsx +0 -17
- package/src/components/containers/list-panel/list-panel.context.tsx +0 -5
- package/src/components/containers/list-panel/list-panel.mocks.tsx +0 -117
- package/src/components/containers/list-panel/list-panel.stories.tsx +0 -38
- package/src/components/containers/list-panel/list-panel.test.tsx +0 -65
- package/src/components/containers/list-panel/list-panel.tsx +0 -88
- package/src/components/data-display/board/board.stories.tsx +0 -58
- package/src/components/data-display/board/board.test.tsx +0 -118
- package/src/components/data-display/board/board.tsx +0 -80
- package/src/components/data-display/board/index.ts +0 -1
- package/src/components/data-display/bullet/bullet.stories.tsx +0 -47
- package/src/components/data-display/bullet/bullet.test.tsx +0 -24
- package/src/components/data-display/bullet/bullet.tsx +0 -35
- package/src/components/data-display/bullet/index.ts +0 -1
- package/src/components/data-display/data-display.stories.mdx +0 -15
- package/src/components/data-display/header/header-title.tsx +0 -51
- package/src/components/data-display/header/header.dummy.ts +0 -56
- package/src/components/data-display/header/header.stories.tsx +0 -212
- package/src/components/data-display/header/header.test.tsx +0 -299
- package/src/components/data-display/header/header.tsx +0 -144
- package/src/components/data-display/header/header.types.ts +0 -96
- package/src/components/data-display/header/index.ts +0 -3
- package/src/components/data-display/index.ts +0 -5
- package/src/components/data-display/label/index.ts +0 -1
- package/src/components/data-display/label/label.stories.tsx +0 -53
- package/src/components/data-display/label/label.test.tsx +0 -30
- package/src/components/data-display/label/label.tsx +0 -93
- package/src/components/data-display/link-card/index.ts +0 -0
- package/src/components/data-display/link-card/link-card.stories.tsx +0 -59
- package/src/components/data-display/link-card/link-card.test.tsx +0 -43
- package/src/components/data-display/link-card/link-card.tsx +0 -52
- package/src/components/data-display/markdown/index.ts +0 -1
- package/src/components/data-display/markdown/markdown.stories.tsx +0 -25
- package/src/components/data-display/markdown/markdown.test.tsx +0 -64
- package/src/components/data-display/markdown/markdown.tsx +0 -38
- package/src/components/dialogs/bootstrap-dialog/bootstrap-dialog.stories.tsx +0 -86
- package/src/components/dialogs/bootstrap-dialog/bootstrap-dialog.test.tsx +0 -268
- package/src/components/dialogs/bootstrap-dialog/bootstrap-dialog.tsx +0 -97
- package/src/components/dialogs/bootstrap-dialog/index.ts +0 -1
- package/src/components/dialogs/confirm-dialog/confirm-dialog.stories.tsx +0 -58
- package/src/components/dialogs/confirm-dialog/confirm-dialog.test.tsx +0 -186
- package/src/components/dialogs/confirm-dialog/confirm-dialog.tsx +0 -67
- package/src/components/dialogs/confirm-dialog/index.ts +0 -1
- package/src/components/dialogs/dialog-hooks/index.ts +0 -1
- package/src/components/dialogs/dialog-hooks/use-dialog.ts +0 -10
- package/src/components/dialogs/dialog.types.ts +0 -29
- package/src/components/dialogs/dialogs.stories.mdx +0 -12
- package/src/components/dialogs/form-dialog/form-dialog.stories.tsx +0 -54
- package/src/components/dialogs/form-dialog/form-dialog.test.tsx +0 -165
- package/src/components/dialogs/form-dialog/form-dialog.tsx +0 -63
- package/src/components/dialogs/form-dialog/index.ts +0 -1
- package/src/components/dialogs/index.ts +0 -5
- package/src/components/drawers/drawer/drawer.stories.tsx +0 -35
- package/src/components/drawers/drawer/drawer.test.tsx +0 -83
- package/src/components/drawers/drawer/drawer.tsx +0 -94
- package/src/components/drawers/drawer/index.ts +0 -1
- package/src/components/drawers/drawer-app-bar/drawer-app-bar.stories.tsx +0 -26
- package/src/components/drawers/drawer-app-bar/drawer-app-bar.test.tsx +0 -83
- package/src/components/drawers/drawer-app-bar/drawer-app-bar.tsx +0 -87
- package/src/components/drawers/drawer-app-bar/index.ts +0 -1
- package/src/components/drawers/drawer-content/drawer-content.stories.tsx +0 -48
- package/src/components/drawers/drawer-content/drawer-content.test.tsx +0 -64
- package/src/components/drawers/drawer-content/drawer-content.tsx +0 -19
- package/src/components/drawers/drawer-content/index.ts +0 -1
- package/src/components/drawers/drawer-demo.stories.tsx +0 -94
- package/src/components/drawers/drawer-item/drawer-item-link.tsx +0 -149
- package/src/components/drawers/drawer-item/drawer-item.stories.tsx +0 -148
- package/src/components/drawers/drawer-item/drawer-item.test.tsx +0 -270
- package/src/components/drawers/drawer-item/drawer-item.tsx +0 -53
- package/src/components/drawers/drawer-item/drawer-menu-item.tsx +0 -137
- package/src/components/drawers/drawer-item/index.ts +0 -3
- package/src/components/drawers/drawer-main/drawer-main.tsx +0 -42
- package/src/components/drawers/drawer-main/index.ts +0 -1
- package/src/components/drawers/drawer-provider/drawer-context.test.tsx +0 -24
- package/src/components/drawers/drawer-provider/drawer-context.ts +0 -28
- package/src/components/drawers/drawer-provider/drawer-mixins.test.tsx +0 -25
- package/src/components/drawers/drawer-provider/drawer-mixins.ts +0 -24
- package/src/components/drawers/drawer-provider/drawer-provider.test.tsx +0 -165
- package/src/components/drawers/drawer-provider/drawer.provider.tsx +0 -64
- package/src/components/drawers/drawer-provider/index.ts +0 -3
- package/src/components/drawers/drawer-section/drawer-section.stories.tsx +0 -55
- package/src/components/drawers/drawer-section/drawer-section.test.tsx +0 -88
- package/src/components/drawers/drawer-section/drawer-section.tsx +0 -49
- package/src/components/drawers/drawer-section/index.ts +0 -1
- package/src/components/drawers/drawer-subheader/drawer-subheader.stories.tsx +0 -27
- package/src/components/drawers/drawer-subheader/drawer-subheader.tsx +0 -15
- package/src/components/drawers/drawer-subheader/index.ts +0 -1
- package/src/components/drawers/drawer.mock.tsx +0 -195
- package/src/components/drawers/drawer.types.ts +0 -78
- package/src/components/drawers/drawers.stories.mdx +0 -15
- package/src/components/drawers/index.ts +0 -8
- package/src/components/feedback/feedback.stories.mdx +0 -13
- package/src/components/feedback/index.ts +0 -2
- package/src/components/feedback/loading-area/index.ts +0 -1
- package/src/components/feedback/loading-area/loading-area.stories.tsx +0 -15
- package/src/components/feedback/loading-area/loading-area.test.tsx +0 -12
- package/src/components/feedback/loading-area/loading-area.tsx +0 -13
- package/src/components/feedback/query-container/index.ts +0 -1
- package/src/components/feedback/query-container/query-container.stories.tsx +0 -87
- package/src/components/feedback/query-container/query-container.test.tsx +0 -144
- package/src/components/feedback/query-container/query-container.tsx +0 -86
- package/src/components/index.ts +0 -11
- package/src/components/inputs/action/action-header.test.tsx +0 -11
- package/src/components/inputs/action/action-header.tsx +0 -37
- package/src/components/inputs/action/action.stories.tsx +0 -77
- package/src/components/inputs/action/action.test.tsx +0 -97
- package/src/components/inputs/action/action.tsx +0 -88
- package/src/components/inputs/action/index.ts +0 -2
- package/src/components/inputs/autocomplete/autocomplete.stories.tsx +0 -123
- package/src/components/inputs/autocomplete/autocomplete.test.tsx +0 -75
- package/src/components/inputs/autocomplete/autocomplete.tsx +0 -68
- package/src/components/inputs/autocomplete/index.ts +0 -1
- package/src/components/inputs/date-range-calendar/date-range-calendar.stories.tsx +0 -19
- package/src/components/inputs/date-range-calendar/date-range-calendar.test.tsx +0 -150
- package/src/components/inputs/date-range-calendar/date-range-calendar.tsx +0 -118
- package/src/components/inputs/date-range-calendar/index.ts +0 -1
- package/src/components/inputs/date-range-picker/date-range-picker.stories.tsx +0 -32
- package/src/components/inputs/date-range-picker/date-range-picker.test.tsx +0 -165
- package/src/components/inputs/date-range-picker/date-range-picker.tsx +0 -67
- package/src/components/inputs/date-range-picker/index.ts +0 -1
- package/src/components/inputs/index.ts +0 -7
- package/src/components/inputs/inputs.stories.mdx +0 -17
- package/src/components/inputs/search-input/index.ts +0 -1
- package/src/components/inputs/search-input/search-input.stories.tsx +0 -60
- package/src/components/inputs/search-input/search-input.test.tsx +0 -166
- package/src/components/inputs/search-input/search-input.tsx +0 -218
- package/src/components/inputs/select/index.ts +0 -1
- package/src/components/inputs/select/select.stories.tsx +0 -107
- package/src/components/inputs/select/select.test.tsx +0 -96
- package/src/components/inputs/select/select.tsx +0 -108
- package/src/components/inputs/sign-in/index.ts +0 -1
- package/src/components/inputs/sign-in/sign-in.stories.tsx +0 -37
- package/src/components/inputs/sign-in/sign-in.test.tsx +0 -97
- package/src/components/inputs/sign-in/sign-in.tsx +0 -97
- package/src/components/inputs/text-field/index.ts +0 -1
- package/src/components/inputs/text-field/text-field.stories.tsx +0 -136
- package/src/components/inputs/text-field/text-field.test.tsx +0 -64
- package/src/components/inputs/text-field/text-field.tsx +0 -101
- package/src/components/navigation/index.ts +0 -2
- package/src/components/navigation/link/index.ts +0 -1
- package/src/components/navigation/link/link.tsx +0 -17
- package/src/components/navigation/navigation.stories.mdx +0 -10
- package/src/components/navigation/tab-card/index.ts +0 -2
- package/src/components/navigation/tab-card/tab-card-panel.tsx +0 -19
- package/src/components/navigation/tab-card/tab-card.context.tsx +0 -7
- package/src/components/navigation/tab-card/tab-card.dummy.tsx +0 -34
- package/src/components/navigation/tab-card/tab-card.stories.tsx +0 -21
- package/src/components/navigation/tab-card/tab-card.test.tsx +0 -74
- package/src/components/navigation/tab-card/tab-card.tsx +0 -81
- package/src/components/navigation/tab-panel/index.ts +0 -1
- package/src/components/navigation/tab-panel/tab-panel.test.tsx +0 -26
- package/src/components/navigation/tab-panel/tab-panel.tsx +0 -27
- package/src/components/placeholders/content-placeholder/content-placeholder.stories.tsx +0 -13
- package/src/components/placeholders/content-placeholder/content-placeholder.tsx +0 -17
- package/src/components/placeholders/content-placeholder/index.ts +0 -1
- package/src/components/placeholders/index.ts +0 -5
- package/src/components/placeholders/lorem-ipsum-placeholder/index.ts +0 -1
- package/src/components/placeholders/lorem-ipsum-placeholder/lorem-ipsum-placeholder.stories.tsx +0 -13
- package/src/components/placeholders/lorem-ipsum-placeholder/lorem-ipsum-placeholder.tsx +0 -26
- package/src/components/placeholders/placeholder/index.ts +0 -1
- package/src/components/placeholders/placeholder/placeholder.mock.ts +0 -15
- package/src/components/placeholders/placeholder/placeholder.stories.tsx +0 -45
- package/src/components/placeholders/placeholder/placeholder.test.tsx +0 -78
- package/src/components/placeholders/placeholder/placeholder.tsx +0 -77
- package/src/components/placeholders/placeholders.stories.mdx +0 -14
- package/src/components/placeholders/skeleton-card/index.ts +0 -1
- package/src/components/placeholders/skeleton-card/skeleton-card.stories.tsx +0 -17
- package/src/components/placeholders/skeleton-card/skeleton-card.tsx +0 -17
- package/src/components/placeholders/skeleton-grid/index.ts +0 -1
- package/src/components/placeholders/skeleton-grid/skeleton-grid.stories.tsx +0 -13
- package/src/components/placeholders/skeleton-grid/skeleton-grid.tsx +0 -20
- package/src/components/tables/enhanced-remote-table/enhanced-remote-table.mock.tsx +0 -28
- package/src/components/tables/enhanced-remote-table/enhanced-remote-table.stories.tsx +0 -22
- package/src/components/tables/enhanced-remote-table/enhanced-remote-table.test.tsx +0 -78
- package/src/components/tables/enhanced-remote-table/enhanced-remote-table.tsx +0 -74
- package/src/components/tables/enhanced-remote-table/index.ts +0 -1
- package/src/components/tables/enhanced-table/enhanced-table-head.tsx +0 -63
- package/src/components/tables/enhanced-table/enhanced-table.mock.tsx +0 -99
- package/src/components/tables/enhanced-table/enhanced-table.stories.tsx +0 -20
- package/src/components/tables/enhanced-table/enhanced-table.test.tsx +0 -108
- package/src/components/tables/enhanced-table/enhanced-table.tsx +0 -136
- package/src/components/tables/enhanced-table/index.ts +0 -2
- package/src/components/tables/index.ts +0 -2
- package/src/components/tables/table.stories.mdx +0 -11
- package/src/components/value-displays/group-value-card/group-value-card.mock.tsx +0 -61
- package/src/components/value-displays/group-value-card/group-value-card.stories.tsx +0 -76
- package/src/components/value-displays/group-value-card/group-value-card.test.tsx +0 -61
- package/src/components/value-displays/group-value-card/group-value-card.tsx +0 -60
- package/src/components/value-displays/group-value-card/index.ts +0 -1
- package/src/components/value-displays/index.ts +0 -10
- package/src/components/value-displays/value-base/index.ts +0 -2
- package/src/components/value-displays/value-base/value-displays.types.ts +0 -36
- package/src/components/value-displays/value-base/value-edit.test.tsx +0 -88
- package/src/components/value-displays/value-base/value-edit.tsx +0 -81
- package/src/components/value-displays/value-boolean/index.ts +0 -1
- package/src/components/value-displays/value-boolean/value-boolean.stories.tsx +0 -49
- package/src/components/value-displays/value-boolean/value-boolean.test.tsx +0 -133
- package/src/components/value-displays/value-boolean/value-boolean.tsx +0 -66
- package/src/components/value-displays/value-card/index.ts +0 -1
- package/src/components/value-displays/value-card/value-card.stories.tsx +0 -22
- package/src/components/value-displays/value-card/value-card.test.tsx +0 -18
- package/src/components/value-displays/value-card/value-card.tsx +0 -12
- package/src/components/value-displays/value-content/index.ts +0 -1
- package/src/components/value-displays/value-content/value-content.stories.tsx +0 -27
- package/src/components/value-displays/value-content/value-content.test.tsx +0 -64
- package/src/components/value-displays/value-content/value-content.tsx +0 -81
- package/src/components/value-displays/value-datetime/index.ts +0 -1
- package/src/components/value-displays/value-datetime/value-datetime.stories.tsx +0 -86
- package/src/components/value-displays/value-datetime/value-datetime.test.tsx +0 -141
- package/src/components/value-displays/value-datetime/value-datetime.tsx +0 -99
- package/src/components/value-displays/value-displays.stories.mdx +0 -39
- package/src/components/value-displays/value-image/index.ts +0 -1
- package/src/components/value-displays/value-image/value-image.stories.tsx +0 -37
- package/src/components/value-displays/value-image/value-image.test.tsx +0 -22
- package/src/components/value-displays/value-image/value-image.tsx +0 -26
- package/src/components/value-displays/value-item/index.ts +0 -1
- package/src/components/value-displays/value-item/value-item.stories.tsx +0 -45
- package/src/components/value-displays/value-item/value-item.test.tsx +0 -20
- package/src/components/value-displays/value-item/value-item.tsx +0 -54
- package/src/components/value-displays/value-label/index.ts +0 -1
- package/src/components/value-displays/value-label/value-label.stories.tsx +0 -78
- package/src/components/value-displays/value-label/value-label.test.tsx +0 -72
- package/src/components/value-displays/value-label/value-label.tsx +0 -45
- package/src/components/value-displays/value-rating/index.ts +0 -1
- package/src/components/value-displays/value-rating/value-rating.stories.tsx +0 -55
- package/src/components/value-displays/value-rating/value-rating.test.tsx +0 -105
- package/src/components/value-displays/value-rating/value-rating.tsx +0 -48
- package/src/components/value-displays/value-text/index.ts +0 -1
- package/src/components/value-displays/value-text/value-text.stories.tsx +0 -72
- package/src/components/value-displays/value-text/value-text.test.tsx +0 -129
- package/src/components/value-displays/value-text/value-text.tsx +0 -67
- package/src/generators/generators.mock.ts +0 -298
- package/src/generators/generators.model.test.ts +0 -79
- package/src/generators/generators.model.ts +0 -180
- package/src/generators/generators.stories.mdx +0 -13
- package/src/generators/index.ts +0 -5
- package/src/generators/model-form/index.ts +0 -1
- package/src/generators/model-form/model-form-field.tsx +0 -269
- package/src/generators/model-form/model-form.stories.tsx +0 -40
- package/src/generators/model-form/model-form.test.tsx +0 -133
- package/src/generators/model-form/model-form.tsx +0 -62
- package/src/generators/model-router/index.ts +0 -2
- package/src/generators/model-router/model-router.test.tsx +0 -1104
- package/src/generators/model-router/model-router.tsx +0 -30
- package/src/generators/model-router/model-router.types.ts +0 -18
- package/src/generators/model-router/screens/add-screen.tsx +0 -67
- package/src/generators/model-router/screens/details-screen.tsx +0 -64
- package/src/generators/model-router/screens/index.ts +0 -4
- package/src/generators/model-router/screens/list-screen.tsx +0 -143
- package/src/generators/model-router/screens/screens.types.ts +0 -38
- package/src/generators/model-router/screens/update-screen.tsx +0 -105
- package/src/generators/model-router/stories/details-screen.stories.tsx +0 -39
- package/src/generators/model-router/stories/list-screen.stories.tsx +0 -102
- package/src/generators/model-router/stories/model-router.stories.tsx +0 -229
- package/src/generators/model-router/stories/templates.tsx +0 -33
- package/src/generators/object-details/index.ts +0 -1
- package/src/generators/object-details/object-details.stories.tsx +0 -30
- package/src/generators/object-details/object-details.test.tsx +0 -22
- package/src/generators/object-details/object-details.tsx +0 -169
- package/src/generators/table-list/index.ts +0 -1
- package/src/generators/table-list/table-list.stories.tsx +0 -91
- package/src/generators/table-list/table-list.test.tsx +0 -297
- package/src/generators/table-list/table-list.tsx +0 -138
- package/src/hooks/index.ts +0 -1
- package/src/hooks/routing/index.ts +0 -1
- package/src/hooks/routing/routing.hooks.ts +0 -23
- package/src/hooks/routing/routing.test.tsx +0 -83
- package/src/index.ts +0 -5
- package/src/layouts/drawer-layout/drawer-layout.stories.tsx +0 -57
- package/src/layouts/drawer-layout/drawer-layout.test.tsx +0 -41
- package/src/layouts/drawer-layout/drawer-layout.tsx +0 -26
- package/src/layouts/drawer-layout/index.ts +0 -1
- package/src/layouts/header-layout/header-layout.stories.tsx +0 -245
- package/src/layouts/header-layout/header-layout.test.tsx +0 -102
- package/src/layouts/header-layout/header-layout.tsx +0 -49
- package/src/layouts/header-layout/index.ts +0 -1
- package/src/layouts/index.ts +0 -2
- package/src/layouts/layouts.stories.mdx +0 -11
- package/src/providers/index.ts +0 -2
- package/src/providers/notification-center/index.ts +0 -3
- package/src/providers/notification-center/notification-center.context.ts +0 -31
- package/src/providers/notification-center/notification-center.hooks.ts +0 -23
- package/src/providers/notification-center/notification-center.provider.tsx +0 -51
- package/src/providers/notification-center/notification-center.stories.tsx +0 -52
- package/src/providers/notification-center/notification-center.test.tsx +0 -198
- package/src/providers/tab-provider/index.ts +0 -2
- package/src/providers/tab-provider/tab-provider.context.ts +0 -8
- package/src/providers/tab-provider/tab-provider.provider.tsx +0 -13
- package/src/stories/Introduction.stories.mdx +0 -33
- package/src/stories/assets/code-brackets.svg +0 -1
- package/src/stories/assets/colors.svg +0 -1
- package/src/stories/assets/comments.svg +0 -1
- package/src/stories/assets/direction.svg +0 -1
- package/src/stories/assets/flow.svg +0 -1
- package/src/stories/assets/plugin.svg +0 -1
- package/src/stories/assets/repo.svg +0 -1
- package/src/stories/assets/stackalt.svg +0 -1
- package/src/stories/assets/work-in-progress.jpg +0 -0
- package/src/stories/getting-started.stories.mdx +0 -23
- package/src/storybook.tsx +0 -139
- package/src/tests/actions.ts +0 -48
- package/src/tests/assertions.ts +0 -206
- package/src/tests/datatable-placeholder/datatable-placeholder.stories.tsx +0 -13
- package/src/tests/datatable-placeholder/datatable-placeholder.tsx +0 -38
- package/src/tests/datatable-placeholder/index.ts +0 -1
- package/src/tests/file-mock.ts +0 -1
- package/src/tests/mocks/markdown.mock.ts +0 -25
- package/src/tests/mocks.ts +0 -23
- package/src/tests/testing-library.tsx +0 -79
- package/src/types/index.d.ts +0 -10
- package/src/types.d.ts +0 -4
- package/src/utils/arrays.test.ts +0 -9
- package/src/utils/arrays.ts +0 -7
- package/src/utils/breakpoints.test.ts +0 -42
- package/src/utils/breakpoints.ts +0 -62
- package/src/utils/forms.ts +0 -11
- package/src/utils/index.ts +0 -4
- package/src/utils/theme.ts +0 -11
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { render, screen } from "~/tests/testing-library";
|
|
2
|
-
import { Autocomplete } from "./autocomplete";
|
|
3
|
-
import { faker } from "@faker-js/faker";
|
|
4
|
-
import React from "react";
|
|
5
|
-
import { selectOption } from "~/tests/actions";
|
|
6
|
-
import userEvents from "@testing-library/user-event";
|
|
7
|
-
import { expectProgressIndicator } from "~/tests/assertions";
|
|
8
|
-
import { vi } from "vitest";
|
|
9
|
-
|
|
10
|
-
const options: string[] = [...faker.definitions.vehicle.model];
|
|
11
|
-
|
|
12
|
-
describe("Autocomplete", () => {
|
|
13
|
-
const renderComponent = ({
|
|
14
|
-
value,
|
|
15
|
-
loading,
|
|
16
|
-
fetching,
|
|
17
|
-
}: { value?: string; loading?: boolean; fetching?: boolean } = {}) => {
|
|
18
|
-
const onChangeValue = vi.fn();
|
|
19
|
-
render(
|
|
20
|
-
<Autocomplete
|
|
21
|
-
label="Car model"
|
|
22
|
-
loading={loading}
|
|
23
|
-
fetching={fetching}
|
|
24
|
-
value={value}
|
|
25
|
-
options={options}
|
|
26
|
-
onChangeValue={onChangeValue}
|
|
27
|
-
/>,
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
return { onChangeValue };
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
it("should render a label", () => {
|
|
34
|
-
renderComponent();
|
|
35
|
-
|
|
36
|
-
expect(screen.getByRole("combobox", { name: /car model/i })).toBeVisible();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should render the value if is defined", () => {
|
|
40
|
-
const value = options[3];
|
|
41
|
-
renderComponent({ value });
|
|
42
|
-
|
|
43
|
-
expect(screen.getByRole("combobox")).toHaveValue(value);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("should call onChange when the selected value changes", async () => {
|
|
47
|
-
const { onChangeValue } = renderComponent();
|
|
48
|
-
|
|
49
|
-
await selectOption(screen.getByRole("combobox"), "Model T");
|
|
50
|
-
|
|
51
|
-
expect(onChangeValue).toHaveBeenCalledTimes(1);
|
|
52
|
-
expect(onChangeValue).toHaveBeenCalledWith("Model T");
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("should filter the options if the user enters a search", async () => {
|
|
56
|
-
renderComponent();
|
|
57
|
-
|
|
58
|
-
await userEvents.type(screen.getByRole("combobox"), "Rang");
|
|
59
|
-
|
|
60
|
-
expect(screen.getByRole("option", { name: "Durango" })).toBeVisible();
|
|
61
|
-
expect(screen.getByRole("option", { name: "Wrangler" })).toBeVisible();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("should render a loading indicator if is fetching", () => {
|
|
65
|
-
renderComponent({ loading: true });
|
|
66
|
-
|
|
67
|
-
expectProgressIndicator();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("should render a loading indicator if is loading", () => {
|
|
71
|
-
renderComponent({ fetching: true });
|
|
72
|
-
|
|
73
|
-
expectProgressIndicator();
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Autocomplete as MuiAutocomplete,
|
|
3
|
-
AutocompleteProps as MuiAutocompleteProps,
|
|
4
|
-
ChipTypeMap,
|
|
5
|
-
} from "@mui/material";
|
|
6
|
-
import React from "react";
|
|
7
|
-
import { TextField } from "../text-field";
|
|
8
|
-
|
|
9
|
-
export interface AutocompleteProps<
|
|
10
|
-
T,
|
|
11
|
-
Multiple extends boolean | undefined,
|
|
12
|
-
DisableClearable extends boolean | undefined,
|
|
13
|
-
FreeSolo extends boolean | undefined,
|
|
14
|
-
ChipComponent extends React.ElementType = ChipTypeMap["defaultComponent"],
|
|
15
|
-
> extends Omit<
|
|
16
|
-
MuiAutocompleteProps<T, Multiple, DisableClearable, FreeSolo, ChipComponent>,
|
|
17
|
-
"renderInput" | "onChange" | "color"
|
|
18
|
-
> {
|
|
19
|
-
label: string;
|
|
20
|
-
helperText?: string;
|
|
21
|
-
color?: string;
|
|
22
|
-
fetching?: boolean;
|
|
23
|
-
onChangeValue?: (value: T) => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const Autocomplete = <
|
|
27
|
-
T,
|
|
28
|
-
Multiple extends boolean | undefined,
|
|
29
|
-
DisableClearable extends boolean | undefined,
|
|
30
|
-
FreeSolo extends boolean | undefined,
|
|
31
|
-
ChipComponent extends React.ElementType = ChipTypeMap["defaultComponent"],
|
|
32
|
-
>(
|
|
33
|
-
props: AutocompleteProps<T, Multiple, DisableClearable, FreeSolo, ChipComponent>,
|
|
34
|
-
) => {
|
|
35
|
-
const {
|
|
36
|
-
label,
|
|
37
|
-
loading,
|
|
38
|
-
fetching,
|
|
39
|
-
options,
|
|
40
|
-
helperText,
|
|
41
|
-
color,
|
|
42
|
-
onChangeValue = () => null,
|
|
43
|
-
sx,
|
|
44
|
-
...rest
|
|
45
|
-
} = props;
|
|
46
|
-
const loadingOrFetching = loading || fetching;
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<MuiAutocomplete
|
|
50
|
-
loading={loadingOrFetching}
|
|
51
|
-
options={fetching ? [] : options}
|
|
52
|
-
onChange={(_, value) => onChangeValue(value as T)}
|
|
53
|
-
{...(rest as any)}
|
|
54
|
-
renderInput={(params) => (
|
|
55
|
-
<TextField
|
|
56
|
-
{...params}
|
|
57
|
-
label={label}
|
|
58
|
-
fullWidth
|
|
59
|
-
fetching={fetching}
|
|
60
|
-
loading={loading}
|
|
61
|
-
hexColor={color}
|
|
62
|
-
helperText={helperText}
|
|
63
|
-
/>
|
|
64
|
-
)}
|
|
65
|
-
sx={sx}
|
|
66
|
-
/>
|
|
67
|
-
);
|
|
68
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./autocomplete";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Meta, StoryObj } from "@storybook/react";
|
|
2
|
-
import { withContainer, withLocalizationProvider } from "~/storybook";
|
|
3
|
-
import { DateRangeCalendar } from "./date-range-calendar";
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: "Components/Inputs/DateRangeCalendar",
|
|
7
|
-
component: DateRangeCalendar,
|
|
8
|
-
decorators: [withLocalizationProvider],
|
|
9
|
-
parameters: {
|
|
10
|
-
layout: "centered",
|
|
11
|
-
},
|
|
12
|
-
} satisfies Meta<typeof DateRangeCalendar>;
|
|
13
|
-
type Story = StoryObj<typeof DateRangeCalendar>;
|
|
14
|
-
|
|
15
|
-
export const Default: Story = {
|
|
16
|
-
args: {
|
|
17
|
-
defaultValue: [new Date(2023, 4, 2), new Date(2023, 4, 24)],
|
|
18
|
-
},
|
|
19
|
-
};
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { fireEvent, render, screen, waitFor } from "~/tests/testing-library";
|
|
2
|
-
import { DateRangeCalendar } from "./date-range-calendar";
|
|
3
|
-
import { vi } from "vitest";
|
|
4
|
-
import React from "react";
|
|
5
|
-
import { differenceInCalendarDays, format, addDays, subDays } from "date-fns";
|
|
6
|
-
|
|
7
|
-
describe("DateRangeCalendar", () => {
|
|
8
|
-
const renderComponent = () => {
|
|
9
|
-
const onValueChange = vi.fn();
|
|
10
|
-
const startDate = new Date(2023, 4, 2);
|
|
11
|
-
const endDate = new Date(2023, 4, 24);
|
|
12
|
-
render(<DateRangeCalendar defaultValue={[startDate, endDate]} onValueChange={onValueChange} />);
|
|
13
|
-
return { startDate, endDate, onValueChange };
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
vi.useFakeTimers();
|
|
18
|
-
vi.setSystemTime(new Date(2023, 4, 26));
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
vi.useRealTimers();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("should mark the dates between the start and the end as selected", () => {
|
|
26
|
-
const { startDate, endDate } = renderComponent();
|
|
27
|
-
|
|
28
|
-
const days = differenceInCalendarDays(endDate, startDate);
|
|
29
|
-
|
|
30
|
-
for (let i = 0; i < days; ++i) {
|
|
31
|
-
const date = addDays(startDate, i);
|
|
32
|
-
expect(
|
|
33
|
-
screen.getByRole("gridcell", {
|
|
34
|
-
name: format(date, "yyyy-MM-dd"),
|
|
35
|
-
selected: true,
|
|
36
|
-
}),
|
|
37
|
-
).toBeVisible();
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("should not mark as selected the date before and after the range", () => {
|
|
42
|
-
const { startDate, endDate } = renderComponent();
|
|
43
|
-
|
|
44
|
-
expect(
|
|
45
|
-
screen.getByRole("gridcell", {
|
|
46
|
-
name: format(subDays(startDate, 1), "yyyy-MM-dd"),
|
|
47
|
-
selected: false,
|
|
48
|
-
}),
|
|
49
|
-
).toBeVisible();
|
|
50
|
-
expect(
|
|
51
|
-
screen.getByRole("gridcell", {
|
|
52
|
-
name: format(addDays(endDate, 1), "yyyy-MM-dd"),
|
|
53
|
-
selected: false,
|
|
54
|
-
}),
|
|
55
|
-
).toBeVisible();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe("onValueChange", () => {
|
|
59
|
-
it("should call onValueChange when the first date is selected with the first value changed", () => {
|
|
60
|
-
const { endDate, onValueChange } = renderComponent();
|
|
61
|
-
|
|
62
|
-
fireEvent.click(
|
|
63
|
-
screen.getByRole("gridcell", {
|
|
64
|
-
name: "4",
|
|
65
|
-
}),
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
expect(onValueChange).toHaveBeenCalledTimes(1);
|
|
69
|
-
expect(onValueChange).toHaveBeenCalledWith([new Date(2023, 4, 4), endDate], 0);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should call onValueChange when the second date is selected with the second value changed", () => {
|
|
73
|
-
const { onValueChange } = renderComponent();
|
|
74
|
-
|
|
75
|
-
fireEvent.click(
|
|
76
|
-
screen.getByRole("gridcell", {
|
|
77
|
-
name: "4",
|
|
78
|
-
}),
|
|
79
|
-
);
|
|
80
|
-
fireEvent.click(
|
|
81
|
-
screen.getByRole("gridcell", {
|
|
82
|
-
name: "12",
|
|
83
|
-
}),
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
expect(onValueChange).toHaveBeenCalledTimes(2);
|
|
87
|
-
expect(onValueChange).toHaveBeenLastCalledWith(
|
|
88
|
-
[new Date(2023, 4, 4), new Date(2023, 4, 12)],
|
|
89
|
-
1,
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("should call onValueChange when the third date is selected with the first value changed", () => {
|
|
94
|
-
const { onValueChange } = renderComponent();
|
|
95
|
-
|
|
96
|
-
fireEvent.click(
|
|
97
|
-
screen.getByRole("gridcell", {
|
|
98
|
-
name: "4",
|
|
99
|
-
}),
|
|
100
|
-
);
|
|
101
|
-
fireEvent.click(
|
|
102
|
-
screen.getByRole("gridcell", {
|
|
103
|
-
name: "12",
|
|
104
|
-
}),
|
|
105
|
-
);
|
|
106
|
-
fireEvent.click(
|
|
107
|
-
screen.getByRole("gridcell", {
|
|
108
|
-
name: "2",
|
|
109
|
-
}),
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
expect(onValueChange).toHaveBeenCalledTimes(3);
|
|
113
|
-
expect(onValueChange).toHaveBeenLastCalledWith(
|
|
114
|
-
[new Date(2023, 4, 2), new Date(2023, 4, 12)],
|
|
115
|
-
0,
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("should call onValueChange when a second date minor than the initial date is selected changing the first value", () => {
|
|
120
|
-
const { onValueChange } = renderComponent();
|
|
121
|
-
|
|
122
|
-
fireEvent.click(
|
|
123
|
-
screen.getByRole("gridcell", {
|
|
124
|
-
name: "12",
|
|
125
|
-
}),
|
|
126
|
-
);
|
|
127
|
-
fireEvent.click(
|
|
128
|
-
screen.getByRole("gridcell", {
|
|
129
|
-
name: "6",
|
|
130
|
-
}),
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
expect(onValueChange).toHaveBeenCalledTimes(2);
|
|
134
|
-
expect(onValueChange).toHaveBeenLastCalledWith([new Date(2023, 4, 6), undefined], 0);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it("should call onValueChange when the first date is bigger than the end date with the end date as undefined", () => {
|
|
138
|
-
const { onValueChange } = renderComponent();
|
|
139
|
-
|
|
140
|
-
fireEvent.click(
|
|
141
|
-
screen.getByRole("gridcell", {
|
|
142
|
-
name: "28",
|
|
143
|
-
}),
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
expect(onValueChange).toHaveBeenCalledTimes(1);
|
|
147
|
-
expect(onValueChange).toHaveBeenCalledWith([new Date(2023, 4, 28), undefined], 0);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
});
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { Box, BoxProps, styled } from "@mui/material";
|
|
2
|
-
import { DateCalendar, PickersDay, PickersDayProps } from "@mui/x-date-pickers";
|
|
3
|
-
import { endOfWeek, format, isAfter, isSameDay, startOfWeek } from "date-fns";
|
|
4
|
-
import { isBefore } from "date-fns/esm";
|
|
5
|
-
import React, { useState } from "react";
|
|
6
|
-
|
|
7
|
-
type DateRange = [Date, Date | undefined];
|
|
8
|
-
|
|
9
|
-
interface CustomPickerDayProps extends BoxProps {
|
|
10
|
-
dayIsBetween: boolean;
|
|
11
|
-
isFirstDay: boolean;
|
|
12
|
-
isLastDay: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const CustomPickersDayBackground = styled(Box, {
|
|
16
|
-
shouldForwardProp: (prop) =>
|
|
17
|
-
prop !== "dayIsBetween" &&
|
|
18
|
-
prop !== "isFirstDay" &&
|
|
19
|
-
prop !== "isLastDay" &&
|
|
20
|
-
prop !== "isStartOfWeek" &&
|
|
21
|
-
prop !== "isEndOfWeek",
|
|
22
|
-
})<CustomPickerDayProps>(({ theme, dayIsBetween, isFirstDay, isLastDay }) => {
|
|
23
|
-
return {
|
|
24
|
-
...((isFirstDay || isLastDay || dayIsBetween) && {
|
|
25
|
-
borderRadius: 0,
|
|
26
|
-
backgroundColor: `${theme.palette.primary.light}40`,
|
|
27
|
-
margin: 0,
|
|
28
|
-
}),
|
|
29
|
-
...(isFirstDay && {
|
|
30
|
-
borderTopLeftRadius: "50%",
|
|
31
|
-
borderBottomLeftRadius: "50%",
|
|
32
|
-
}),
|
|
33
|
-
...(isLastDay && {
|
|
34
|
-
borderTopRightRadius: "50%",
|
|
35
|
-
borderBottomRightRadius: "50%",
|
|
36
|
-
}),
|
|
37
|
-
};
|
|
38
|
-
}) as React.ComponentType<CustomPickerDayProps>;
|
|
39
|
-
|
|
40
|
-
const Day = (props: PickersDayProps<Date> & { dateRange?: DateRange | null }) => {
|
|
41
|
-
const { day, dateRange, ...other } = props;
|
|
42
|
-
|
|
43
|
-
if (dateRange == null) {
|
|
44
|
-
return <PickersDay day={day} {...other} />;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const [start, end] = dateRange;
|
|
48
|
-
|
|
49
|
-
const dayIsBetween = !!end && isAfter(day, start) && isBefore(day, end);
|
|
50
|
-
const isFirstDay = isSameDay(day, start);
|
|
51
|
-
const isLastDay = !!end && isSameDay(day, end);
|
|
52
|
-
const isStartOfWeek = isSameDay(day, startOfWeek(day));
|
|
53
|
-
const isEndOfWeek = isSameDay(day, endOfWeek(day));
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<CustomPickersDayBackground
|
|
57
|
-
dayIsBetween={dayIsBetween}
|
|
58
|
-
isFirstDay={isFirstDay || (dayIsBetween && isStartOfWeek)}
|
|
59
|
-
isLastDay={isLastDay || (dayIsBetween && isEndOfWeek)}
|
|
60
|
-
aria-label={format(day, "yyyy-MM-dd")}
|
|
61
|
-
aria-selected={dayIsBetween || isFirstDay || isLastDay}
|
|
62
|
-
role="gridcell"
|
|
63
|
-
>
|
|
64
|
-
<PickersDay {...other} day={day} selected={isFirstDay || isLastDay} />
|
|
65
|
-
</CustomPickersDayBackground>
|
|
66
|
-
);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export interface DateRangeCalendarProps {
|
|
70
|
-
defaultValue: DateRange;
|
|
71
|
-
onValueChange: (value: DateRange, updatedIndex: number) => void;
|
|
72
|
-
}
|
|
73
|
-
export const DateRangeCalendar = ({ defaultValue, onValueChange }: DateRangeCalendarProps) => {
|
|
74
|
-
const [value, setValue] = useState(defaultValue);
|
|
75
|
-
const [index, setIndex] = useState(0);
|
|
76
|
-
|
|
77
|
-
const setValueRange = (newRange: DateRange, index: number, newIndex: number) => {
|
|
78
|
-
setValue(newRange);
|
|
79
|
-
onValueChange(newRange, index);
|
|
80
|
-
setIndex(newIndex);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const handleChange = (newValue: Date | null) => {
|
|
84
|
-
if (!newValue) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// If is the end date and is minor than the start date
|
|
89
|
-
if (index === 1 && newValue < value[0]) {
|
|
90
|
-
return setValueRange([newValue, undefined], 0, 1);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// If is the start date and is bigger than the end date
|
|
94
|
-
if (index === 0 && value[1] && newValue > value[1]) {
|
|
95
|
-
return setValueRange([newValue, undefined], 0, 1);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Default case
|
|
99
|
-
setValueRange(
|
|
100
|
-
[index === 0 ? newValue : value[0], index === 1 ? newValue : value[1]],
|
|
101
|
-
index,
|
|
102
|
-
index === 0 ? 1 : 0,
|
|
103
|
-
);
|
|
104
|
-
};
|
|
105
|
-
return (
|
|
106
|
-
<DateCalendar
|
|
107
|
-
value={null}
|
|
108
|
-
onChange={handleChange}
|
|
109
|
-
slots={{ day: Day }}
|
|
110
|
-
slotProps={{
|
|
111
|
-
day: {
|
|
112
|
-
dateRange: value,
|
|
113
|
-
} as any,
|
|
114
|
-
}}
|
|
115
|
-
aria-label="calendar range picker"
|
|
116
|
-
/>
|
|
117
|
-
);
|
|
118
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./date-range-calendar";
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Meta, StoryObj } from "@storybook/react";
|
|
2
|
-
import { withContainer, withLocalizationProvider } from "~/storybook";
|
|
3
|
-
import { DateRangePicker } from "./date-range-picker";
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: "Components/Inputs/DateRangePicker",
|
|
7
|
-
component: DateRangePicker,
|
|
8
|
-
decorators: [withLocalizationProvider, withContainer({ width: 300 })],
|
|
9
|
-
parameters: {
|
|
10
|
-
layout: "centered",
|
|
11
|
-
},
|
|
12
|
-
} satisfies Meta<typeof DateRangePicker>;
|
|
13
|
-
type Story = StoryObj<typeof DateRangePicker>;
|
|
14
|
-
|
|
15
|
-
export const Default: Story = {
|
|
16
|
-
args: {
|
|
17
|
-
label: "Select your date range",
|
|
18
|
-
defaultValue: [new Date(2023, 4, 9), new Date(2023, 4, 18)],
|
|
19
|
-
format: "yyyy/MM/dd",
|
|
20
|
-
fullWidth: true,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const Small: Story = {
|
|
25
|
-
args: {
|
|
26
|
-
label: "Select your date range",
|
|
27
|
-
defaultValue: [new Date(2023, 4, 9), new Date(2023, 4, 18)],
|
|
28
|
-
format: "yyyy/MM/dd",
|
|
29
|
-
fullWidth: true,
|
|
30
|
-
size: "small",
|
|
31
|
-
},
|
|
32
|
-
};
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fireEvent,
|
|
3
|
-
render,
|
|
4
|
-
screen,
|
|
5
|
-
waitFor,
|
|
6
|
-
waitForElementToBeRemoved,
|
|
7
|
-
} from "~/tests/testing-library";
|
|
8
|
-
import { DateRangePicker } from "./date-range-picker";
|
|
9
|
-
import { vi } from "vitest";
|
|
10
|
-
import React from "react";
|
|
11
|
-
import userEvent from "@testing-library/user-event";
|
|
12
|
-
|
|
13
|
-
describe("DateRangePicker", () => {
|
|
14
|
-
const renderComponent = () => {
|
|
15
|
-
const onValueChange = vi.fn();
|
|
16
|
-
const startDate = new Date(2023, 4, 2);
|
|
17
|
-
const endDate = new Date(2023, 4, 24);
|
|
18
|
-
render(
|
|
19
|
-
<DateRangePicker
|
|
20
|
-
label="lorem ipsum"
|
|
21
|
-
format="yyyy-MM-dd"
|
|
22
|
-
defaultValue={[startDate, endDate]}
|
|
23
|
-
onValueChange={onValueChange}
|
|
24
|
-
/>,
|
|
25
|
-
);
|
|
26
|
-
return { startDate, endDate, onValueChange };
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
vi.useFakeTimers();
|
|
31
|
-
vi.setSystemTime(new Date(2023, 4, 26));
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
afterEach(() => {
|
|
35
|
-
vi.useRealTimers();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should render an input with a label", () => {
|
|
39
|
-
renderComponent();
|
|
40
|
-
|
|
41
|
-
expect(screen.getByRole("textbox", { name: /lorem ipsum/i })).toBeVisible();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should render the value inside the input with the correct format", () => {
|
|
45
|
-
renderComponent();
|
|
46
|
-
|
|
47
|
-
expect(screen.getByRole("textbox")).toHaveValue("2023-05-02 - 2023-05-24");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should open a date selector if the calendar icon is clicked", () => {
|
|
51
|
-
renderComponent();
|
|
52
|
-
|
|
53
|
-
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
54
|
-
|
|
55
|
-
expect(screen.getByLabelText(/calendar range picker/i)).toBeVisible();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe("date selection", () => {
|
|
59
|
-
it("should call onValueChange when the first date is selected with the first value changed", () => {
|
|
60
|
-
const { endDate, onValueChange } = renderComponent();
|
|
61
|
-
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
62
|
-
|
|
63
|
-
fireEvent.click(
|
|
64
|
-
screen.getByRole("gridcell", {
|
|
65
|
-
name: "4",
|
|
66
|
-
}),
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
expect(onValueChange).toHaveBeenCalledTimes(1);
|
|
70
|
-
expect(onValueChange).toHaveBeenCalledWith([new Date(2023, 4, 4), endDate], 0);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe("second value selected", () => {
|
|
74
|
-
it("should call onValueChange when the second date is selected with the second value changed", () => {
|
|
75
|
-
const { onValueChange } = renderComponent();
|
|
76
|
-
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
77
|
-
|
|
78
|
-
fireEvent.click(
|
|
79
|
-
screen.getByRole("gridcell", {
|
|
80
|
-
name: "4",
|
|
81
|
-
}),
|
|
82
|
-
);
|
|
83
|
-
fireEvent.click(
|
|
84
|
-
screen.getByRole("gridcell", {
|
|
85
|
-
name: "12",
|
|
86
|
-
}),
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
expect(onValueChange).toHaveBeenCalledTimes(2);
|
|
90
|
-
expect(onValueChange).toHaveBeenLastCalledWith(
|
|
91
|
-
[new Date(2023, 4, 4), new Date(2023, 4, 12)],
|
|
92
|
-
1,
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe(" when a second date minor than the initial date", () => {
|
|
98
|
-
it("should call onValueChange changing the first value with end date as undefined", () => {
|
|
99
|
-
const { onValueChange } = renderComponent();
|
|
100
|
-
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
101
|
-
|
|
102
|
-
fireEvent.click(
|
|
103
|
-
screen.getByRole("gridcell", {
|
|
104
|
-
name: "12",
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
fireEvent.click(
|
|
108
|
-
screen.getByRole("gridcell", {
|
|
109
|
-
name: "6",
|
|
110
|
-
}),
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
expect(onValueChange).toHaveBeenCalledTimes(2);
|
|
114
|
-
expect(onValueChange).toHaveBeenLastCalledWith([new Date(2023, 4, 6), undefined], 0);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it("should show the date format as end date", () => {
|
|
118
|
-
renderComponent();
|
|
119
|
-
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
120
|
-
|
|
121
|
-
fireEvent.click(
|
|
122
|
-
screen.getByRole("gridcell", {
|
|
123
|
-
name: "12",
|
|
124
|
-
}),
|
|
125
|
-
);
|
|
126
|
-
fireEvent.click(
|
|
127
|
-
screen.getByRole("gridcell", {
|
|
128
|
-
name: "6",
|
|
129
|
-
}),
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
expect(screen.getByRole("textbox")).toHaveValue("2023-05-06 - YYYY-MM-DD");
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe("when the first date is bigger than the end date", () => {
|
|
137
|
-
it("should call onValueChange changing the firest value with the end date as undefined", () => {
|
|
138
|
-
const { onValueChange } = renderComponent();
|
|
139
|
-
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
140
|
-
|
|
141
|
-
fireEvent.click(
|
|
142
|
-
screen.getByRole("gridcell", {
|
|
143
|
-
name: "28",
|
|
144
|
-
}),
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
expect(onValueChange).toHaveBeenCalledTimes(1);
|
|
148
|
-
expect(onValueChange).toHaveBeenCalledWith([new Date(2023, 4, 28), undefined], 0);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("should show the date format as end date", () => {
|
|
152
|
-
renderComponent();
|
|
153
|
-
fireEvent.click(screen.getByRole("button", { name: /open calendar/i }));
|
|
154
|
-
|
|
155
|
-
fireEvent.click(
|
|
156
|
-
screen.getByRole("gridcell", {
|
|
157
|
-
name: "28",
|
|
158
|
-
}),
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
expect(screen.getByRole("textbox")).toHaveValue("2023-05-28 - YYYY-MM-DD");
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
2
|
-
import { format } from "date-fns";
|
|
3
|
-
import {
|
|
4
|
-
Box,
|
|
5
|
-
Button,
|
|
6
|
-
Collapse,
|
|
7
|
-
Grid,
|
|
8
|
-
IconButton,
|
|
9
|
-
InputAdornment,
|
|
10
|
-
Paper,
|
|
11
|
-
TextField,
|
|
12
|
-
} from "@mui/material";
|
|
13
|
-
import EventIcon from "@mui/icons-material/Event";
|
|
14
|
-
import { DateRangeCalendar } from "../date-range-calendar";
|
|
15
|
-
|
|
16
|
-
type DateRange = [Date, Date | undefined];
|
|
17
|
-
export interface DateRangePickerProps {
|
|
18
|
-
label: string;
|
|
19
|
-
defaultValue: DateRange;
|
|
20
|
-
format: string;
|
|
21
|
-
fullWidth?: boolean;
|
|
22
|
-
size?: "small" | "medium";
|
|
23
|
-
onValueChange: (value: DateRange, index: number) => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const DateRangePicker = ({
|
|
27
|
-
defaultValue,
|
|
28
|
-
format: fmt,
|
|
29
|
-
label,
|
|
30
|
-
fullWidth,
|
|
31
|
-
onValueChange,
|
|
32
|
-
size = "medium",
|
|
33
|
-
}: DateRangePickerProps) => {
|
|
34
|
-
const [isPopoverOpened, setIsPopoverOpened] = useState(false);
|
|
35
|
-
const [value, setValue] = useState(defaultValue);
|
|
36
|
-
|
|
37
|
-
const handleValueChange = (newValue: DateRange, index: number) => {
|
|
38
|
-
setValue(newValue);
|
|
39
|
-
onValueChange(newValue, index);
|
|
40
|
-
setIsPopoverOpened(index < 1);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<>
|
|
45
|
-
<TextField
|
|
46
|
-
label={label}
|
|
47
|
-
fullWidth={fullWidth}
|
|
48
|
-
size={size}
|
|
49
|
-
value={`${format(value[0], fmt)} - ${value[1] ? format(value[1], fmt) : fmt.toUpperCase()}`}
|
|
50
|
-
InputProps={{
|
|
51
|
-
endAdornment: (
|
|
52
|
-
<InputAdornment position="end">
|
|
53
|
-
<IconButton onClick={() => setIsPopoverOpened((o) => !o)} aria-label="open calendar">
|
|
54
|
-
<EventIcon />
|
|
55
|
-
</IconButton>
|
|
56
|
-
</InputAdornment>
|
|
57
|
-
),
|
|
58
|
-
}}
|
|
59
|
-
/>
|
|
60
|
-
<Paper>
|
|
61
|
-
<Collapse in={isPopoverOpened} aria-label="calendar collapse">
|
|
62
|
-
<DateRangeCalendar defaultValue={defaultValue} onValueChange={handleValueChange} />
|
|
63
|
-
</Collapse>
|
|
64
|
-
</Paper>
|
|
65
|
-
</>
|
|
66
|
-
);
|
|
67
|
-
};
|