@sqrzro/admin 1.0.0-beta.1
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 +4 -0
- package/.gitattributes +1 -0
- package/.prettierrc +9 -0
- package/.storybook/main.js +40 -0
- package/.storybook/manager.js +4 -0
- package/.storybook/postcss.config.js +3 -0
- package/.storybook/preview.js +11 -0
- package/.storybook/theme.js +7 -0
- package/.stylelintrc +9 -0
- package/LICENSE +5 -0
- package/README.md +9 -0
- package/__mocks__/squarezero-utility.ts +40 -0
- package/assets/logo-horizontal-dark.svg +21 -0
- package/assets/logo-horizontal-white.svg +21 -0
- package/assets/logo-vertical-dark.svg +21 -0
- package/assets/logo-vertical-white.svg +21 -0
- package/dist/index.css +3554 -0
- package/dist/index.js +5099 -0
- package/dist/index.js.map +1 -0
- package/dist/types/components/Alert/index.d.ts +10 -0
- package/dist/types/components/Allow/index.d.ts +13 -0
- package/dist/types/components/App/index.d.ts +19 -0
- package/dist/types/components/AutoSuggest/index.d.ts +60 -0
- package/dist/types/components/Button/index.d.ts +36 -0
- package/dist/types/components/CalendarInput/index.d.ts +10 -0
- package/dist/types/components/CheckboxList/index.d.ts +4 -0
- package/dist/types/components/ConnectedDropdown/index.d.ts +8 -0
- package/dist/types/components/ConnectedList/index.d.ts +4 -0
- package/dist/types/components/ConnectedScene/index.d.ts +11 -0
- package/dist/types/components/ConnectedTable/index.d.ts +4 -0
- package/dist/types/components/ContentBlock/index.d.ts +6 -0
- package/dist/types/components/DateInput/index.d.ts +7 -0
- package/dist/types/components/Document/index.d.ts +6 -0
- package/dist/types/components/Dropdown/index.d.ts +14 -0
- package/dist/types/components/Fieldset/index.d.ts +11 -0
- package/dist/types/components/FileInput/index.d.ts +4 -0
- package/dist/types/components/FilterLink/index.d.ts +7 -0
- package/dist/types/components/Form/index.d.ts +11 -0
- package/dist/types/components/FormActions/index.d.ts +9 -0
- package/dist/types/components/FormField/index.d.ts +27 -0
- package/dist/types/components/FormRepeater/index.d.ts +8 -0
- package/dist/types/components/ImageInput/index.d.ts +4 -0
- package/dist/types/components/InfoPanel/index.d.ts +8 -0
- package/dist/types/components/Link/__mocks__/index.d.ts +6 -0
- package/dist/types/components/Link/index.d.ts +13 -0
- package/dist/types/components/List/index.d.ts +23 -0
- package/dist/types/components/ListActions/index.d.ts +9 -0
- package/dist/types/components/LoginForm/index.d.ts +3 -0
- package/dist/types/components/Message/index.d.ts +7 -0
- package/dist/types/components/ModalActions/index.d.ts +11 -0
- package/dist/types/components/MoneyInput/index.d.ts +10 -0
- package/dist/types/components/PasswordForm/index.d.ts +3 -0
- package/dist/types/components/PasswordInput/index.d.ts +8 -0
- package/dist/types/components/RadioList/index.d.ts +4 -0
- package/dist/types/components/Scene/index.d.ts +10 -0
- package/dist/types/components/SummaryList/index.d.ts +8 -0
- package/dist/types/components/Switch/index.d.ts +9 -0
- package/dist/types/components/Table/index.d.ts +13 -0
- package/dist/types/components/Tag/index.d.ts +8 -0
- package/dist/types/components/TextArea/index.d.ts +4 -0
- package/dist/types/components/TextInput/index.d.ts +17 -0
- package/dist/types/components/WebsiteInput/index.d.ts +10 -0
- package/dist/types/components/WeekCalendar/index.d.ts +12 -0
- package/dist/types/core/AppHeader/index.d.ts +3 -0
- package/dist/types/core/AppLogo/index.d.ts +6 -0
- package/dist/types/core/AppLogoImage/index.d.ts +3 -0
- package/dist/types/core/AppLogoPlaceholder/index.d.ts +3 -0
- package/dist/types/core/Assistive/index.d.ts +6 -0
- package/dist/types/core/Banner/index.d.ts +3 -0
- package/dist/types/core/BuildModal/index.d.ts +3 -0
- package/dist/types/core/Calendar/index.d.ts +11 -0
- package/dist/types/core/CalendarDay/index.d.ts +16 -0
- package/dist/types/core/CalendarMonth/index.d.ts +12 -0
- package/dist/types/core/CalendarNavigation/index.d.ts +9 -0
- package/dist/types/core/CalendarWeek/index.d.ts +14 -0
- package/dist/types/core/ChkRad/index.d.ts +10 -0
- package/dist/types/core/ChkRadIcon/index.d.ts +7 -0
- package/dist/types/core/ChkRadList/index.d.ts +15 -0
- package/dist/types/core/CloseButton/index.d.ts +9 -0
- package/dist/types/core/ConfirmModal/index.d.ts +3 -0
- package/dist/types/core/ConnectedRepeater/index.d.ts +26 -0
- package/dist/types/core/ConnectedRepeaterComponent/index.d.ts +24 -0
- package/dist/types/core/Container/index.d.ts +7 -0
- package/dist/types/core/DropdownPanel/index.d.ts +18 -0
- package/dist/types/core/EmptyMessage/index.d.ts +12 -0
- package/dist/types/core/ErrorBoundary/index.d.ts +15 -0
- package/dist/types/core/ErrorMessage/index.d.ts +8 -0
- package/dist/types/core/FilterItem/index.d.ts +10 -0
- package/dist/types/core/Filters/index.d.ts +11 -0
- package/dist/types/core/FixedActions/index.d.ts +12 -0
- package/dist/types/core/FormError/index.d.ts +6 -0
- package/dist/types/core/FormLabel/index.d.ts +8 -0
- package/dist/types/core/FormLegend/index.d.ts +6 -0
- package/dist/types/core/Header/index.d.ts +8 -0
- package/dist/types/core/Icon/index.d.ts +7 -0
- package/dist/types/core/IconButton/Icon/index.d.ts +7 -0
- package/dist/types/core/IconButton/index.d.ts +11 -0
- package/dist/types/core/InputPanel/index.d.ts +8 -0
- package/dist/types/core/ListItem/index.d.ts +16 -0
- package/dist/types/core/ListItemAction/index.d.ts +4 -0
- package/dist/types/core/ListItemActions/index.d.ts +8 -0
- package/dist/types/core/ListItemMetaItem/index.d.ts +10 -0
- package/dist/types/core/ListItemTitle/index.d.ts +9 -0
- package/dist/types/core/Loader/index.d.ts +6 -0
- package/dist/types/core/MeActions/index.d.ts +3 -0
- package/dist/types/core/MePanel/index.d.ts +9 -0
- package/dist/types/core/Modal/index.d.ts +12 -0
- package/dist/types/core/Navigation/index.d.ts +3 -0
- package/dist/types/core/NavigationDivider/index.d.ts +3 -0
- package/dist/types/core/NavigationItem/index.d.ts +7 -0
- package/dist/types/core/Pagination/index.d.ts +7 -0
- package/dist/types/core/PaginationItem/index.d.ts +7 -0
- package/dist/types/core/Panel/index.d.ts +8 -0
- package/dist/types/core/RadialProgress/index.d.ts +8 -0
- package/dist/types/core/StaticTextInput/index.d.ts +12 -0
- package/dist/types/core/Styled/index.d.ts +6 -0
- package/dist/types/core/SummaryListItem/index.d.ts +15 -0
- package/dist/types/core/TableActionsCell/index.d.ts +8 -0
- package/dist/types/core/TableCell/index.d.ts +8 -0
- package/dist/types/core/TableHead/index.d.ts +8 -0
- package/dist/types/core/TableRow/index.d.ts +13 -0
- package/dist/types/core/Tabs/index.d.ts +11 -0
- package/dist/types/core/TextInputAncillary/index.d.ts +11 -0
- package/dist/types/core/Toast/index.d.ts +3 -0
- package/dist/types/core/WeekCalendarDay/index.d.ts +14 -0
- package/dist/types/filters/BooleanFilter/index.d.ts +5 -0
- package/dist/types/filters/DateFilter/index.d.ts +5 -0
- package/dist/types/filters/DropdownFilter/index.d.ts +5 -0
- package/dist/types/filters/QuickDateFilter/index.d.ts +5 -0
- package/dist/types/filters/interfaces.d.ts +36 -0
- package/dist/types/hooks/useAccessiblePanel.d.ts +13 -0
- package/dist/types/hooks/useAppContext.d.ts +37 -0
- package/dist/types/hooks/useClickOutside.d.ts +3 -0
- package/dist/types/hooks/useConnectedList.d.ts +7 -0
- package/dist/types/hooks/useFilters.d.ts +3 -0
- package/dist/types/hooks/useForm.d.ts +26 -0
- package/dist/types/hooks/useFormData.d.ts +9 -0
- package/dist/types/hooks/useLayout.d.ts +6 -0
- package/dist/types/hooks/useModal.d.ts +12 -0
- package/dist/types/hooks/useVariant.d.ts +6 -0
- package/dist/types/index.d.ts +187 -0
- package/dist/types/scenes/Error404Scene.d.ts +3 -0
- package/dist/types/services/BuildService.d.ts +5 -0
- package/dist/types/services/ConfirmService.d.ts +12 -0
- package/dist/types/services/DateService.d.ts +17 -0
- package/dist/types/services/DownloadService.d.ts +5 -0
- package/dist/types/services/FilterComponentService.d.ts +8 -0
- package/dist/types/services/FilterService.d.ts +13 -0
- package/dist/types/services/FormatService.d.ts +7 -0
- package/dist/types/services/ToastService.d.ts +5 -0
- package/dist/types/utility/MockRouter/index.d.ts +2 -0
- package/dist/types/utility/StorybookPanel/index.d.ts +7 -0
- package/dist/types/utility/TestChangeHandler/index.d.ts +8 -0
- package/dist/types/utility/create-app.d.ts +4 -0
- package/dist/types/utility/interfaces.d.ts +72 -0
- package/dist/types/utility/prop-types.d.ts +40 -0
- package/docs/guides/01-installation.story.mdx +33 -0
- package/docs/guides/02-configuration.story.mdx +80 -0
- package/docs/guides/03-pages.story.mdx +18 -0
- package/docs/guides/04-integration.story.mdx +33 -0
- package/docs/guides/a11y.story.mdx +7 -0
- package/docs/guides/theming.story.mdx +7 -0
- package/docs/introduction.story.mdx +17 -0
- package/jest.config.js +19 -0
- package/package.json +101 -0
- package/postcss.config.js +3 -0
- package/rollup.config.js +36 -0
- package/scripts/create-exports.js +74 -0
- package/scripts/update-license.js +8 -0
- package/squarezero.config.js +5 -0
- package/src/components/Alert/Alert.module.css +50 -0
- package/src/components/Alert/Alert.spec.tsx +63 -0
- package/src/components/Alert/Alert.story.tsx +23 -0
- package/src/components/Alert/index.tsx +67 -0
- package/src/components/Allow/Allow.spec.tsx +37 -0
- package/src/components/Allow/index.tsx +42 -0
- package/src/components/App/App.module.css +22 -0
- package/src/components/App/App.spec.tsx +128 -0
- package/src/components/App/index.tsx +108 -0
- package/src/components/AutoSuggest/AutoSuggest.module.css +8 -0
- package/src/components/AutoSuggest/AutoSuggest.spec.tsx +211 -0
- package/src/components/AutoSuggest/AutoSuggest.story.tsx +30 -0
- package/src/components/AutoSuggest/index.tsx +216 -0
- package/src/components/Button/Button.module.css +95 -0
- package/src/components/Button/Button.spec.tsx +69 -0
- package/src/components/Button/Button.story.tsx +39 -0
- package/src/components/Button/index.tsx +99 -0
- package/src/components/CalendarInput/CalendarInput.module.css +8 -0
- package/src/components/CalendarInput/CalendarInput.spec.tsx +206 -0
- package/src/components/CalendarInput/CalendarInput.story.tsx +62 -0
- package/src/components/CalendarInput/index.tsx +122 -0
- package/src/components/CheckboxList/CheckboxList.spec.tsx +83 -0
- package/src/components/CheckboxList/index.tsx +53 -0
- package/src/components/ConnectedDropdown/index.tsx +56 -0
- package/src/components/ConnectedList/index.tsx +15 -0
- package/src/components/ConnectedScene/index.tsx +95 -0
- package/src/components/ConnectedTable/index.tsx +17 -0
- package/src/components/ContentBlock/ContentBlock.module.css +8 -0
- package/src/components/ContentBlock/ContentBlock.spec.tsx +15 -0
- package/src/components/ContentBlock/index.tsx +16 -0
- package/src/components/DateInput/DateInput.module.css +15 -0
- package/src/components/DateInput/DateInput.spec.tsx +91 -0
- package/src/components/DateInput/index.tsx +149 -0
- package/src/components/Document/index.tsx +20 -0
- package/src/components/Dropdown/Dropdown.module.css +8 -0
- package/src/components/Dropdown/Dropdown.spec.tsx +286 -0
- package/src/components/Dropdown/Dropdown.story.tsx +53 -0
- package/src/components/Dropdown/index.tsx +224 -0
- package/src/components/Fieldset/Fieldset.spec.tsx +22 -0
- package/src/components/Fieldset/Fieldset.story.tsx +21 -0
- package/src/components/Fieldset/index.tsx +30 -0
- package/src/components/FileInput/FileInput.module.css +18 -0
- package/src/components/FileInput/FileInput.spec.tsx +42 -0
- package/src/components/FileInput/FileInput.story.tsx +6 -0
- package/src/components/FileInput/index.tsx +72 -0
- package/src/components/FilterLink/FilterLink.module.css +9 -0
- package/src/components/FilterLink/FilterLink.spec.tsx +20 -0
- package/src/components/FilterLink/index.tsx +31 -0
- package/src/components/Form/Form.spec.tsx +68 -0
- package/src/components/Form/index.tsx +87 -0
- package/src/components/FormActions/FormActions.spec.tsx +10 -0
- package/src/components/FormActions/FormActions.story.tsx +23 -0
- package/src/components/FormActions/index.tsx +31 -0
- package/src/components/FormField/FormField.module.css +71 -0
- package/src/components/FormField/FormField.spec.tsx +137 -0
- package/src/components/FormField/FormField.story.tsx +22 -0
- package/src/components/FormField/index.tsx +162 -0
- package/src/components/FormRepeater/FormRepeater.module.css +3 -0
- package/src/components/FormRepeater/FormRepeater.spec.tsx +127 -0
- package/src/components/FormRepeater/index.tsx +118 -0
- package/src/components/ImageInput/ImageInput.module.css +74 -0
- package/src/components/ImageInput/ImageInput.spec.tsx +45 -0
- package/src/components/ImageInput/ImageInput.story.tsx +6 -0
- package/src/components/ImageInput/index.tsx +91 -0
- package/src/components/InfoPanel/InfoPanel.module.css +18 -0
- package/src/components/InfoPanel/InfoPanel.spec.tsx +15 -0
- package/src/components/InfoPanel/InfoPanel.story.tsx +32 -0
- package/src/components/InfoPanel/index.tsx +25 -0
- package/src/components/Link/Link.spec.tsx +62 -0
- package/src/components/Link/__mocks__/index.tsx +24 -0
- package/src/components/Link/index.tsx +51 -0
- package/src/components/List/List.module.css +9 -0
- package/src/components/List/List.spec.tsx +311 -0
- package/src/components/List/List.story.tsx +92 -0
- package/src/components/List/index.tsx +79 -0
- package/src/components/ListActions/ListActions.spec.tsx +10 -0
- package/src/components/ListActions/ListActions.story.tsx +6 -0
- package/src/components/ListActions/index.tsx +31 -0
- package/src/components/LoginForm/LoginForm.module.css +21 -0
- package/src/components/LoginForm/LoginForm.spec.tsx +63 -0
- package/src/components/LoginForm/index.tsx +102 -0
- package/src/components/Message/Message.module.css +14 -0
- package/src/components/Message/Message.spec.tsx +20 -0
- package/src/components/Message/index.tsx +27 -0
- package/src/components/ModalActions/ModalActions.module.css +5 -0
- package/src/components/ModalActions/ModalActions.spec.tsx +53 -0
- package/src/components/ModalActions/ModalActions.story.tsx +6 -0
- package/src/components/ModalActions/index.tsx +47 -0
- package/src/components/MoneyInput/MoneyInput.spec.tsx +17 -0
- package/src/components/MoneyInput/MoneyInput.story.tsx +6 -0
- package/src/components/MoneyInput/index.tsx +16 -0
- package/src/components/PasswordForm/PasswordForm.module.css +21 -0
- package/src/components/PasswordForm/index.tsx +94 -0
- package/src/components/PasswordInput/PasswordInput.module.css +23 -0
- package/src/components/PasswordInput/PasswordInput.spec.tsx +31 -0
- package/src/components/PasswordInput/PasswordInput.story.tsx +16 -0
- package/src/components/PasswordInput/index.tsx +27 -0
- package/src/components/RadioList/RadioList.spec.tsx +45 -0
- package/src/components/RadioList/index.tsx +10 -0
- package/src/components/Scene/Scene.spec.tsx +123 -0
- package/src/components/Scene/Scene.story.tsx +6 -0
- package/src/components/Scene/index.tsx +58 -0
- package/src/components/SummaryList/SummaryList.module.css +16 -0
- package/src/components/SummaryList/SummaryList.spec.tsx +77 -0
- package/src/components/SummaryList/SummaryList.story.tsx +11 -0
- package/src/components/SummaryList/index.tsx +37 -0
- package/src/components/Switch/Switch.module.css +86 -0
- package/src/components/Switch/Switch.spec.tsx +64 -0
- package/src/components/Switch/index.tsx +85 -0
- package/src/components/Table/Table.module.css +14 -0
- package/src/components/Table/Table.spec.tsx +128 -0
- package/src/components/Table/Table.story.tsx +101 -0
- package/src/components/Table/index.tsx +114 -0
- package/src/components/Tag/Tag.module.css +37 -0
- package/src/components/Tag/Tag.spec.tsx +10 -0
- package/src/components/Tag/Tag.story.tsx +55 -0
- package/src/components/Tag/index.tsx +27 -0
- package/src/components/TextArea/TextArea.module.css +23 -0
- package/src/components/TextArea/TextArea.spec.tsx +77 -0
- package/src/components/TextArea/index.tsx +59 -0
- package/src/components/TextInput/TextInput.module.css +57 -0
- package/src/components/TextInput/TextInput.spec.tsx +134 -0
- package/src/components/TextInput/TextInput.story.tsx +24 -0
- package/src/components/TextInput/index.tsx +146 -0
- package/src/components/WebsiteInput/WebsiteInput.spec.tsx +17 -0
- package/src/components/WebsiteInput/index.tsx +16 -0
- package/src/components/WeekCalendar/WeekCalendar.module.css +19 -0
- package/src/components/WeekCalendar/index.tsx +80 -0
- package/src/core/AppHeader/index.tsx +23 -0
- package/src/core/AppLogo/AppLogo.module.css +19 -0
- package/src/core/AppLogo/index.tsx +33 -0
- package/src/core/AppLogoImage/index.tsx +19 -0
- package/src/core/AppLogoPlaceholder/index.tsx +26 -0
- package/src/core/Assistive/Assistive.module.css +10 -0
- package/src/core/Assistive/index.tsx +18 -0
- package/src/core/Banner/Banner.module.css +36 -0
- package/src/core/Banner/index.tsx +25 -0
- package/src/core/BuildModal/index.tsx +119 -0
- package/src/core/Calendar/index.tsx +116 -0
- package/src/core/CalendarDay/CalendarDay.module.css +61 -0
- package/src/core/CalendarDay/index.tsx +82 -0
- package/src/core/CalendarMonth/CalendarMonth.module.css +13 -0
- package/src/core/CalendarMonth/index.tsx +101 -0
- package/src/core/CalendarNavigation/CalendarNavigation.module.css +26 -0
- package/src/core/CalendarNavigation/index.tsx +56 -0
- package/src/core/CalendarWeek/index.tsx +95 -0
- package/src/core/ChkRad/ChkRad.module.css +31 -0
- package/src/core/ChkRad/ChkRad.spec.tsx +72 -0
- package/src/core/ChkRad/index.tsx +80 -0
- package/src/core/ChkRadIcon/ChkRadIcon.module.css +28 -0
- package/src/core/ChkRadIcon/index.tsx +33 -0
- package/src/core/ChkRadList/ChkRadList.module.css +10 -0
- package/src/core/ChkRadList/index.tsx +85 -0
- package/src/core/CloseButton/CloseButton.spec.tsx +36 -0
- package/src/core/CloseButton/index.tsx +31 -0
- package/src/core/ConfirmModal/ConfirmModal.spec.tsx +88 -0
- package/src/core/ConfirmModal/index.tsx +51 -0
- package/src/core/ConnectedRepeater/index.tsx +248 -0
- package/src/core/ConnectedRepeaterComponent/index.tsx +66 -0
- package/src/core/Container/Container.module.css +12 -0
- package/src/core/Container/index.tsx +35 -0
- package/src/core/DropdownPanel/DropdownPanel.module.css +68 -0
- package/src/core/DropdownPanel/index.tsx +92 -0
- package/src/core/EmptyMessage/EmptyMessage.module.css +18 -0
- package/src/core/EmptyMessage/index.tsx +31 -0
- package/src/core/ErrorBoundary/ErrorBoundary.spec.tsx +33 -0
- package/src/core/ErrorBoundary/index.tsx +42 -0
- package/src/core/ErrorMessage/ErrorMessage.module.css +25 -0
- package/src/core/ErrorMessage/ErrorMessage.spec.tsx +31 -0
- package/src/core/ErrorMessage/index.tsx +37 -0
- package/src/core/FilterItem/FilterItem.module.css +104 -0
- package/src/core/FilterItem/index.tsx +164 -0
- package/src/core/Filters/Filters.module.css +86 -0
- package/src/core/Filters/Filters.spec.tsx +533 -0
- package/src/core/Filters/index.tsx +158 -0
- package/src/core/FixedActions/FixedActions.module.css +24 -0
- package/src/core/FixedActions/index.tsx +52 -0
- package/src/core/FormError/FormError.module.css +7 -0
- package/src/core/FormError/index.tsx +18 -0
- package/src/core/FormLabel/FormLabel.module.css +15 -0
- package/src/core/FormLabel/index.tsx +25 -0
- package/src/core/FormLegend/FormLegend.module.css +13 -0
- package/src/core/FormLegend/index.tsx +18 -0
- package/src/core/Header/Header.module.css +35 -0
- package/src/core/Header/index.tsx +37 -0
- package/src/core/Icon/Icon.spec.tsx +31 -0
- package/src/core/Icon/index.tsx +64 -0
- package/src/core/IconButton/Icon/Icon.spec.tsx +31 -0
- package/src/core/IconButton/Icon/index.tsx +64 -0
- package/src/core/IconButton/IconButton.module.css +32 -0
- package/src/core/IconButton/index.tsx +55 -0
- package/src/core/InputPanel/InputPanel.module.css +70 -0
- package/src/core/InputPanel/index.tsx +28 -0
- package/src/core/ListItem/ListItem.module.css +28 -0
- package/src/core/ListItem/ListItem.story.tsx +28 -0
- package/src/core/ListItem/index.tsx +99 -0
- package/src/core/ListItemAction/ListItemAction.module.css +28 -0
- package/src/core/ListItemAction/index.tsx +30 -0
- package/src/core/ListItemActions/ListItemActions.module.css +94 -0
- package/src/core/ListItemActions/index.tsx +55 -0
- package/src/core/ListItemMetaItem/ListItemMetaItem.module.css +18 -0
- package/src/core/ListItemMetaItem/index.tsx +54 -0
- package/src/core/ListItemTitle/ListItemTitle.module.css +14 -0
- package/src/core/ListItemTitle/ListItemTitle.spec.tsx +33 -0
- package/src/core/ListItemTitle/index.tsx +72 -0
- package/src/core/Loader/Loader.module.css +57 -0
- package/src/core/Loader/Loader.story.tsx +8 -0
- package/src/core/Loader/index.tsx +27 -0
- package/src/core/MeActions/MeActions.module.css +45 -0
- package/src/core/MeActions/index.tsx +46 -0
- package/src/core/MePanel/MePanel.module.css +75 -0
- package/src/core/MePanel/index.tsx +45 -0
- package/src/core/Modal/Modal.module.css +84 -0
- package/src/core/Modal/Modal.spec.tsx +51 -0
- package/src/core/Modal/index.tsx +66 -0
- package/src/core/Navigation/Navigation.module.css +83 -0
- package/src/core/Navigation/Navigation.spec.tsx +101 -0
- package/src/core/Navigation/index.tsx +109 -0
- package/src/core/NavigationDivider/NavigationDivider.module.css +18 -0
- package/src/core/NavigationDivider/index.tsx +13 -0
- package/src/core/NavigationItem/NavigationItem.module.css +51 -0
- package/src/core/NavigationItem/index.tsx +59 -0
- package/src/core/Pagination/Pagination.module.css +15 -0
- package/src/core/Pagination/index.tsx +100 -0
- package/src/core/PaginationItem/PaginationItem.module.css +33 -0
- package/src/core/PaginationItem/index.tsx +46 -0
- package/src/core/Panel/Panel.module.css +15 -0
- package/src/core/Panel/index.tsx +31 -0
- package/src/core/RadialProgress/RadialProgress.module.css +78 -0
- package/src/core/RadialProgress/index.tsx +52 -0
- package/src/core/StaticTextInput/StaticTextInput.module.css +79 -0
- package/src/core/StaticTextInput/StaticTextInput.spec.tsx +133 -0
- package/src/core/StaticTextInput/index.tsx +114 -0
- package/src/core/Styled/Styled.spec.tsx +38 -0
- package/src/core/Styled/Styled.story.tsx +10 -0
- package/src/core/Styled/index.tsx +62 -0
- package/src/core/SummaryListItem/SummaryListItem.module.css +28 -0
- package/src/core/SummaryListItem/index.tsx +60 -0
- package/src/core/TableActionsCell/TableActionsCell.module.css +3 -0
- package/src/core/TableActionsCell/index.tsx +37 -0
- package/src/core/TableCell/TableCell.module.css +16 -0
- package/src/core/TableCell/index.tsx +39 -0
- package/src/core/TableHead/TableHead.module.css +12 -0
- package/src/core/TableHead/index.tsx +48 -0
- package/src/core/TableRow/index.tsx +64 -0
- package/src/core/Tabs/Tabs.module.css +50 -0
- package/src/core/Tabs/index.tsx +94 -0
- package/src/core/TextInputAncillary/TextInputAncillary.module.css +64 -0
- package/src/core/TextInputAncillary/index.tsx +72 -0
- package/src/core/Toast/Toast.module.css +55 -0
- package/src/core/Toast/Toast.spec.tsx +78 -0
- package/src/core/Toast/index.tsx +81 -0
- package/src/core/WeekCalendarDay/WeekCalendarDay.module.css +32 -0
- package/src/core/WeekCalendarDay/index.tsx +68 -0
- package/src/filters/BooleanFilter/index.tsx +46 -0
- package/src/filters/DateFilter/index.tsx +36 -0
- package/src/filters/DropdownFilter/index.tsx +53 -0
- package/src/filters/QuickDateFilter/index.tsx +74 -0
- package/src/filters/interfaces.ts +40 -0
- package/src/hooks/useAccessiblePanel.spec.tsx +88 -0
- package/src/hooks/useAccessiblePanel.ts +74 -0
- package/src/hooks/useAppContext.ts +77 -0
- package/src/hooks/useClickOutside.ts +49 -0
- package/src/hooks/useConnectedList.ts +26 -0
- package/src/hooks/useFilters.ts +26 -0
- package/src/hooks/useForm.spec.ts +126 -0
- package/src/hooks/useForm.ts +99 -0
- package/src/hooks/useFormData.spec.ts +40 -0
- package/src/hooks/useFormData.ts +27 -0
- package/src/hooks/useLayout.spec.ts +55 -0
- package/src/hooks/useLayout.ts +29 -0
- package/src/hooks/useModal.spec.tsx +63 -0
- package/src/hooks/useModal.ts +60 -0
- package/src/hooks/useVariant.spec.ts +14 -0
- package/src/hooks/useVariant.ts +34 -0
- package/src/index.ts +194 -0
- package/src/scenes/Error404Scene.tsx +5 -0
- package/src/services/BuildService.spec.ts +56 -0
- package/src/services/BuildService.ts +34 -0
- package/src/services/ConfirmService.ts +21 -0
- package/src/services/DateService.spec.ts +87 -0
- package/src/services/DateService.ts +137 -0
- package/src/services/DownloadService.spec.ts +29 -0
- package/src/services/DownloadService.ts +14 -0
- package/src/services/FilterComponentService.tsx +46 -0
- package/src/services/FilterService.spec.ts +87 -0
- package/src/services/FilterService.ts +58 -0
- package/src/services/FormatService.spec.ts +83 -0
- package/src/services/FormatService.ts +55 -0
- package/src/services/ToastService.spec.ts +44 -0
- package/src/services/ToastService.ts +19 -0
- package/src/styles/layout.css +64 -0
- package/src/styles/variables.css +85 -0
- package/src/typings.d.ts +4 -0
- package/src/utility/MockRouter/index.ts +45 -0
- package/src/utility/StorybookPanel/StorybookPanel.module.css +9 -0
- package/src/utility/StorybookPanel/index.tsx +25 -0
- package/src/utility/TestChangeHandler/TestChangeHandler.module.css +7 -0
- package/src/utility/TestChangeHandler/TestChangeHandler.spec.tsx +24 -0
- package/src/utility/TestChangeHandler/index.tsx +54 -0
- package/src/utility/create-app.tsx +29 -0
- package/src/utility/interfaces.ts +119 -0
- package/src/utility/prop-types.ts +67 -0
- package/tests/setupFilesAfterEnv.js +10 -0
- package/tsconfig.json +26 -0
- package/tsconfig.types.json +9 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { Fragment } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import useAppContext from '@hooks/useAppContext';
|
|
5
|
+
import type { Me } from '@hooks/useAppContext';
|
|
6
|
+
|
|
7
|
+
interface AllowProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
permission?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const hasPermission = (me: Me, permission?: string): boolean => {
|
|
13
|
+
if (!me.permissions || !permission) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return me.permissions.includes(permission);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The `Allow` component is essentially a wrappy that lets a developer display or hide child content
|
|
21
|
+
* based on the permissions a particular user has.
|
|
22
|
+
*
|
|
23
|
+
* By default, the
|
|
24
|
+
*/
|
|
25
|
+
const Allow: React.FunctionComponent<AllowProps> = ({ children, permission }) => {
|
|
26
|
+
const { me } = useAppContext();
|
|
27
|
+
|
|
28
|
+
if (!me || !hasPermission(me, permission)) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Use the `Fragment` here to get around TS complaining about FunctionComponent
|
|
33
|
+
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
34
|
+
return <Fragment>{children}</Fragment>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
Allow.propTypes = {
|
|
38
|
+
children: PropTypes.node.isRequired,
|
|
39
|
+
permission: PropTypes.string,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default Allow;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
min-height: 100%;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.loader {
|
|
8
|
+
align-items: center;
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
height: 100vh;
|
|
12
|
+
justify-content: center;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.main {
|
|
16
|
+
display: block;
|
|
17
|
+
padding-left: var(--banner-width);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.mainTopbar {
|
|
21
|
+
padding-left: 0;
|
|
22
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
|
|
5
|
+
import { ApiService } from '@sqrzro/utility';
|
|
6
|
+
|
|
7
|
+
import Scene from '@components/Scene';
|
|
8
|
+
import { createMockRouter } from '@utility/MockRouter';
|
|
9
|
+
|
|
10
|
+
import App from './index';
|
|
11
|
+
|
|
12
|
+
const Component = (): React.ReactElement => <div>Component</div>;
|
|
13
|
+
|
|
14
|
+
const ComponentWithoutLayout = (): React.ReactElement => <div>ComponentWithoutLayout</div>;
|
|
15
|
+
ComponentWithoutLayout.hasLayout = false;
|
|
16
|
+
|
|
17
|
+
const ComponentWithLayout = (): React.ReactElement => <div>ComponentWithLayout</div>;
|
|
18
|
+
const Layout = (): React.ReactElement => <div>Layout</div>;
|
|
19
|
+
ComponentWithLayout.Layout = Layout;
|
|
20
|
+
|
|
21
|
+
const SceneComponent = (): React.ReactElement => <Scene title="Scene Title">Scene Content</Scene>;
|
|
22
|
+
|
|
23
|
+
const Logo = (): React.ReactElement => <div>Logo</div>;
|
|
24
|
+
|
|
25
|
+
const config = { name: 'Lorem', navigation: [], paths: {} };
|
|
26
|
+
const router = createMockRouter('lorem');
|
|
27
|
+
|
|
28
|
+
describe('App', () => {
|
|
29
|
+
it('should render', () => {
|
|
30
|
+
render(<App Component={Component} config={config} router={router} />);
|
|
31
|
+
expect(screen.getByText('Loading...')).toBeInTheDocument();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should render me', async () => {
|
|
35
|
+
// @ts-expect-error APIResponse not being available
|
|
36
|
+
jest.spyOn(ApiService, 'get').mockImplementation(() => ({
|
|
37
|
+
data: {
|
|
38
|
+
name: 'Lorem',
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
render(<App Component={Component} config={config} router={router} />);
|
|
43
|
+
|
|
44
|
+
await waitFor(() => {
|
|
45
|
+
expect(screen.getByText('Component')).toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(screen.getByTestId('me-panel-title')).toHaveTextContent('Lorem');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should render without layout', async () => {
|
|
52
|
+
render(<App Component={ComponentWithoutLayout} config={config} router={router} />);
|
|
53
|
+
|
|
54
|
+
await waitFor(() => {
|
|
55
|
+
expect(screen.getByText('ComponentWithoutLayout')).toBeInTheDocument();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(screen.queryByTestId('me-panel-title')).not.toBeInTheDocument();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should render with layout', async () => {
|
|
62
|
+
render(<App Component={ComponentWithLayout} config={config} router={router} />);
|
|
63
|
+
|
|
64
|
+
await waitFor(() => {
|
|
65
|
+
expect(screen.getByText('Layout')).toBeInTheDocument();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should render logo', async () => {
|
|
70
|
+
render(<App Component={Component} Logo={Logo} config={config} router={router} />);
|
|
71
|
+
|
|
72
|
+
await waitFor(() => {
|
|
73
|
+
expect(screen.getByText('Logo')).toBeInTheDocument();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should render brand', async () => {
|
|
78
|
+
const configWithBrand = { ...config, style: { brand: '#000' } };
|
|
79
|
+
|
|
80
|
+
render(<App Component={Component} config={configWithBrand} router={router} />);
|
|
81
|
+
|
|
82
|
+
await waitFor(() => {
|
|
83
|
+
expect(screen.getByTestId('app-brand')).toBeInTheDocument();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should render brand without layout', async () => {
|
|
88
|
+
const configWithBrand = { ...config, style: { brand: '#000' } };
|
|
89
|
+
|
|
90
|
+
render(<App Component={ComponentWithoutLayout} config={configWithBrand} router={router} />);
|
|
91
|
+
|
|
92
|
+
await waitFor(() => {
|
|
93
|
+
expect(screen.getByTestId('app-brand')).toBeInTheDocument();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should render brand topbar', async () => {
|
|
98
|
+
const configWithLayout = { ...config, style: { layout: 'topbar' } };
|
|
99
|
+
|
|
100
|
+
render(<App Component={Component} config={configWithLayout} router={router} />);
|
|
101
|
+
|
|
102
|
+
await waitFor(() => {
|
|
103
|
+
expect(screen.getByRole('main')).toHaveClass('main mainTopbar');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should render scene', async () => {
|
|
108
|
+
render(<App Component={SceneComponent} config={config} router={router} />);
|
|
109
|
+
|
|
110
|
+
await waitFor(() => {
|
|
111
|
+
expect(screen.getByTestId('header-title')).toHaveTextContent('Scene Title');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
expect(screen.getByText('Scene Content')).toBeInTheDocument();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should open mepanel', async () => {
|
|
118
|
+
render(<App Component={Component} Logo={Logo} config={config} router={router} />);
|
|
119
|
+
|
|
120
|
+
await waitFor(() => {
|
|
121
|
+
expect(screen.getByRole('button', { name: 'Lorem' })).toBeInTheDocument();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
expect(screen.getByTestId('me-panel-root')).not.toHaveClass('rootIsOpen');
|
|
125
|
+
userEvent.click(screen.getByRole('button', { name: 'Lorem' }));
|
|
126
|
+
expect(screen.getByTestId('me-panel-root')).toHaveClass('rootIsOpen');
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import type { AppContext, AppInitialProps } from 'next/app';
|
|
3
|
+
import type { NextRouter } from 'next/router';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
|
|
6
|
+
import { ApiService } from '@sqrzro/utility';
|
|
7
|
+
|
|
8
|
+
import { AppContextProvider } from '@hooks/useAppContext';
|
|
9
|
+
import type { Config, Me } from '@hooks/useAppContext';
|
|
10
|
+
|
|
11
|
+
import AppHeader from '@core/AppHeader';
|
|
12
|
+
import Banner from '@core/Banner';
|
|
13
|
+
import ConfirmModal from '@core/ConfirmModal';
|
|
14
|
+
import Loader from '@core/Loader';
|
|
15
|
+
import Toast from '@core/Toast';
|
|
16
|
+
|
|
17
|
+
import 'modern-normalize';
|
|
18
|
+
import '../../styles/variables.css';
|
|
19
|
+
import '../../styles/layout.css';
|
|
20
|
+
|
|
21
|
+
import type { SceneComponentType } from '@utility/interfaces';
|
|
22
|
+
import { AppPropTypes } from '@utility/prop-types';
|
|
23
|
+
|
|
24
|
+
import styles from './App.module.css';
|
|
25
|
+
|
|
26
|
+
const AUTH_ROUTE = '/auth/';
|
|
27
|
+
|
|
28
|
+
export interface AppProps {
|
|
29
|
+
Component: SceneComponentType;
|
|
30
|
+
Logo?: React.ComponentType | null;
|
|
31
|
+
config?: Config;
|
|
32
|
+
router: NextRouter;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type AppType = React.FunctionComponent<AppProps> & {
|
|
36
|
+
getInitialProps: (context: AppContext) => Promise<AppInitialProps>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
40
|
+
const App: React.FunctionComponent<AppProps> = ({
|
|
41
|
+
Component,
|
|
42
|
+
config,
|
|
43
|
+
Logo,
|
|
44
|
+
router,
|
|
45
|
+
...pageProps
|
|
46
|
+
}) => {
|
|
47
|
+
const [me, setMe] = useState<Me>();
|
|
48
|
+
|
|
49
|
+
const getMe = async (): Promise<void> => {
|
|
50
|
+
try {
|
|
51
|
+
const response = await ApiService.get('me');
|
|
52
|
+
setMe({ name: '', ...response.data } as Me);
|
|
53
|
+
} catch (err) {} // eslint-disable-line no-empty
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
void getMe();
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
if (!config || (!me && !router.route.startsWith(AUTH_ROUTE))) {
|
|
61
|
+
return (
|
|
62
|
+
<div className={styles.loader}>
|
|
63
|
+
<Loader />
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const { brand, layout } = config.style || {};
|
|
69
|
+
|
|
70
|
+
if (Component.hasLayout === false) {
|
|
71
|
+
return (
|
|
72
|
+
<AppContextProvider value={{ ...config, Logo, me }}>
|
|
73
|
+
{typeof brand !== 'undefined' && (
|
|
74
|
+
<style data-testid="app-brand">{`:root { --clr-brand: ${brand} }`}</style>
|
|
75
|
+
)}
|
|
76
|
+
<Component router={router} {...pageProps} />
|
|
77
|
+
<Toast />
|
|
78
|
+
</AppContextProvider>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<AppContextProvider value={{ ...config, Logo, me }}>
|
|
84
|
+
{typeof brand !== 'undefined' && (
|
|
85
|
+
<style data-testid="app-brand">{`:root { --clr-brand: ${brand} }`}</style>
|
|
86
|
+
)}
|
|
87
|
+
<div className={styles.root}>
|
|
88
|
+
<Banner />
|
|
89
|
+
<main className={classNames(styles.main, layout === 'topbar' && styles.mainTopbar)}>
|
|
90
|
+
<AppHeader />
|
|
91
|
+
{Component.Layout ? (
|
|
92
|
+
<Component.Layout>
|
|
93
|
+
<Component router={router} {...pageProps} />
|
|
94
|
+
</Component.Layout>
|
|
95
|
+
) : (
|
|
96
|
+
<Component router={router} {...pageProps} />
|
|
97
|
+
)}
|
|
98
|
+
</main>
|
|
99
|
+
</div>
|
|
100
|
+
<ConfirmModal />
|
|
101
|
+
<Toast />
|
|
102
|
+
</AppContextProvider>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
App.propTypes = AppPropTypes;
|
|
107
|
+
|
|
108
|
+
export default App;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import fetch from 'jest-fetch-mock';
|
|
5
|
+
|
|
6
|
+
import { ApiService } from '@sqrzro/utility';
|
|
7
|
+
|
|
8
|
+
import TestChangeHandler from '@utility/TestChangeHandler';
|
|
9
|
+
|
|
10
|
+
import AutoSuggest from './index';
|
|
11
|
+
|
|
12
|
+
const mockData = ['apple', 'banana', 'bandana', 'carrot'];
|
|
13
|
+
const mockObjectData = [
|
|
14
|
+
{ id: 1, name: 'apple', meta: 'lorem' },
|
|
15
|
+
{ id: 2, name: 'banana', meta: 'ipsum' },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
describe('AutoSuggest', () => {
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
fetch.resetMocks();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should render', () => {
|
|
24
|
+
render(<AutoSuggest name="lorem" />);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should handle opening (and clickoutside)', async () => {
|
|
28
|
+
render(
|
|
29
|
+
<TestChangeHandler>
|
|
30
|
+
<AutoSuggest data={mockData} name="lorem" />
|
|
31
|
+
<div>[DOM]</div>
|
|
32
|
+
</TestChangeHandler>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const input = screen.getByRole('textbox');
|
|
36
|
+
|
|
37
|
+
expect(screen.queryAllByRole('option')).toHaveLength(0);
|
|
38
|
+
|
|
39
|
+
userEvent.type(input, 'ban');
|
|
40
|
+
|
|
41
|
+
await waitFor(() => {
|
|
42
|
+
expect(screen.queryAllByRole('option')).toHaveLength(2);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
userEvent.click(screen.getByText('[DOM]'));
|
|
46
|
+
await waitForElementToBeRemoved(screen.queryAllByRole('option'));
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should handle an error getting data', async () => {
|
|
50
|
+
jest.spyOn(ApiService, 'get').mockImplementationOnce(() => {
|
|
51
|
+
throw new Error('lorem');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
render(<AutoSuggest name="lorem" remote="data" />);
|
|
55
|
+
|
|
56
|
+
const input = screen.getByRole('textbox');
|
|
57
|
+
userEvent.type(input, 'ban');
|
|
58
|
+
|
|
59
|
+
await waitFor(() => {
|
|
60
|
+
expect(screen.getByText(/^Something's gone wrong/u)).toBeInTheDocument();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should handle remote suggestions', async () => {
|
|
65
|
+
const mockFn = fetch.mockResponse(JSON.stringify({ data: ['banana', 'bandana'] }));
|
|
66
|
+
|
|
67
|
+
render(
|
|
68
|
+
<TestChangeHandler>
|
|
69
|
+
<AutoSuggest name="lorem" remote="data" />
|
|
70
|
+
</TestChangeHandler>
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const input = screen.getByRole('textbox');
|
|
74
|
+
userEvent.type(input, 'ban');
|
|
75
|
+
|
|
76
|
+
await waitFor(() => {
|
|
77
|
+
expect(mockFn).toHaveBeenCalledTimes(3);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(mockFn).toHaveBeenLastCalledWith(
|
|
81
|
+
'/data?search=ban',
|
|
82
|
+
expect.objectContaining({ method: 'get' })
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
await waitFor(() => {
|
|
86
|
+
expect(screen.queryAllByRole('option')).toHaveLength(2);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(screen.queryAllByRole('option')[0]).toHaveTextContent(/^bananaSelect$/u);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should handle suggestion objects', async () => {
|
|
93
|
+
render(
|
|
94
|
+
<TestChangeHandler>
|
|
95
|
+
<AutoSuggest data={mockObjectData} name="lorem" />
|
|
96
|
+
</TestChangeHandler>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const input = screen.getByRole('textbox');
|
|
100
|
+
userEvent.type(input, 'ban');
|
|
101
|
+
|
|
102
|
+
await waitFor(() => {
|
|
103
|
+
expect(screen.queryAllByRole('option')).toHaveLength(1);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
expect(screen.queryAllByRole('option')[0]).toHaveTextContent(/^bananaipsumSelect$/u);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should handle remote suggestion objects', async () => {
|
|
110
|
+
fetch.mockResponse(JSON.stringify({ data: [mockObjectData[0]] }));
|
|
111
|
+
|
|
112
|
+
render(
|
|
113
|
+
<TestChangeHandler>
|
|
114
|
+
<AutoSuggest name="lorem" remote="data" />
|
|
115
|
+
</TestChangeHandler>
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const input = screen.getByRole('textbox');
|
|
119
|
+
userEvent.type(input, 'app');
|
|
120
|
+
|
|
121
|
+
await waitFor(() => {
|
|
122
|
+
expect(screen.queryAllByRole('option')).toHaveLength(1);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
expect(screen.queryAllByRole('option')[0]).toHaveTextContent(/^appleloremSelect$/u);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should handle no suggestions', async () => {
|
|
129
|
+
fetch.mockResponseOnce(JSON.stringify({ data: null }));
|
|
130
|
+
|
|
131
|
+
render(
|
|
132
|
+
<TestChangeHandler>
|
|
133
|
+
<AutoSuggest name="lorem" remote="data" />
|
|
134
|
+
</TestChangeHandler>
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const input = screen.getByRole('textbox');
|
|
138
|
+
userEvent.type(input, 'ban');
|
|
139
|
+
|
|
140
|
+
await waitFor(() => {
|
|
141
|
+
expect(screen.queryAllByRole('option')).toHaveLength(0);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should handle change if no data or remote', () => {
|
|
146
|
+
render(<AutoSuggest name="lorem" />);
|
|
147
|
+
|
|
148
|
+
const input = screen.getByRole('textbox');
|
|
149
|
+
|
|
150
|
+
expect(screen.queryAllByRole('option')).toHaveLength(0);
|
|
151
|
+
|
|
152
|
+
userEvent.type(input, 'ban');
|
|
153
|
+
expect(screen.queryAllByRole('option')).toHaveLength(0);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('should handle onChange (through typing)', () => {
|
|
157
|
+
render(
|
|
158
|
+
<TestChangeHandler>
|
|
159
|
+
<AutoSuggest name="lorem" />
|
|
160
|
+
</TestChangeHandler>
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
userEvent.type(screen.getByRole('textbox'), 'ban');
|
|
164
|
+
|
|
165
|
+
expect(screen.getByRole('textbox')).toHaveValue('ban');
|
|
166
|
+
expect(screen.getByTestId('test-change-handler-value')).toHaveTextContent('ban');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should handle onChange (through suggestion)', () => {
|
|
170
|
+
render(
|
|
171
|
+
<TestChangeHandler>
|
|
172
|
+
<AutoSuggest data={mockData} name="lorem" />
|
|
173
|
+
</TestChangeHandler>
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
userEvent.type(screen.getByRole('textbox'), 'ban');
|
|
177
|
+
|
|
178
|
+
expect(screen.getByRole('textbox')).toHaveValue('ban');
|
|
179
|
+
expect(screen.getByTestId('test-change-handler-value')).toHaveTextContent('ban');
|
|
180
|
+
|
|
181
|
+
userEvent.click(screen.queryAllByRole('button')[0]);
|
|
182
|
+
|
|
183
|
+
expect(screen.getByRole('textbox')).toHaveValue('banana');
|
|
184
|
+
expect(screen.getByTestId('test-change-handler-value')).toHaveTextContent('banana');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('should close if value is deleted', async () => {
|
|
188
|
+
render(
|
|
189
|
+
<TestChangeHandler>
|
|
190
|
+
<AutoSuggest data={mockData} name="lorem" />
|
|
191
|
+
</TestChangeHandler>
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
userEvent.type(screen.getByRole('textbox'), 'a');
|
|
195
|
+
|
|
196
|
+
await waitFor(() => {
|
|
197
|
+
expect(screen.queryAllByRole('option')).toHaveLength(1);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
userEvent.type(screen.getByRole('textbox'), '{backspace}');
|
|
201
|
+
|
|
202
|
+
await waitFor(() => {
|
|
203
|
+
expect(screen.queryAllByRole('option')).toHaveLength(0);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('should pass a form error through', () => {
|
|
208
|
+
render(<AutoSuggest name="lorem" hasError />);
|
|
209
|
+
expect(screen.getByRole('textbox')).toHaveClass('input inputHasError');
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import AutoSuggest from './index';
|
|
3
|
+
|
|
4
|
+
import TestChangeHandler from '@utility/TestChangeHandler';
|
|
5
|
+
import StorybookPanel from '@utility/StorybookPanel';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Components/AutoSuggest',
|
|
9
|
+
component: AutoSuggest,
|
|
10
|
+
decorators: [
|
|
11
|
+
(storyFn: () => React.ReactElement): React.ReactElement => (
|
|
12
|
+
<StorybookPanel>
|
|
13
|
+
<TestChangeHandler>{storyFn()}</TestChangeHandler>
|
|
14
|
+
</StorybookPanel>
|
|
15
|
+
),
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const data = ['apple', 'banana', 'bandana', 'carrot', 'dessert'];
|
|
20
|
+
const objectData = [
|
|
21
|
+
{ id: 1, name: 'apple' },
|
|
22
|
+
{ id: 2, name: 'banana' },
|
|
23
|
+
{ id: 3, name: 'carrot' },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
export const Basic = (): React.ReactElement => <AutoSuggest data={data} name="lorem" />;
|
|
27
|
+
|
|
28
|
+
export const WithObjectArray = (): React.ReactElement => (
|
|
29
|
+
<AutoSuggest data={objectData} name="lorem" />
|
|
30
|
+
);
|