@nypl/design-system-react-components 1.0.2 → 1.0.4

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.
Files changed (309) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +171 -135
  3. package/dist/__tests__/mediaMatchMock.d.ts +79 -0
  4. package/dist/components/Card/Card.d.ts +8 -6
  5. package/dist/components/Heading/Heading.d.ts +6 -0
  6. package/dist/components/Icons/Icon.d.ts +1 -1
  7. package/dist/components/Icons/IconSvgs.d.ts +10 -0
  8. package/dist/components/Logo/Logo.d.ts +1 -1
  9. package/dist/components/Logo/LogoSvgs.d.ts +3 -0
  10. package/dist/components/Slider/Slider.d.ts +1 -2
  11. package/dist/components/Table/Table.d.ts +3 -2
  12. package/dist/components/Text/Text.d.ts +6 -0
  13. package/dist/components/TextInput/TextInput.d.ts +2 -1
  14. package/dist/design-system-react-components.cjs.development.js +1700 -878
  15. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  16. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  17. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  18. package/dist/design-system-react-components.esm.js +1672 -881
  19. package/dist/design-system-react-components.esm.js.map +1 -1
  20. package/dist/hooks/{tests → __tests__}/useCarouselStyles.test.d.ts +0 -0
  21. package/dist/hooks/__tests__/useNYPLBreakpoints.test.d.ts +1 -0
  22. package/dist/hooks/useNYPLBreakpoints.d.ts +13 -0
  23. package/dist/index.d.ts +2 -1
  24. package/dist/resources.scss +0 -4
  25. package/dist/styles.css +3 -2
  26. package/dist/theme/components/button.d.ts +7 -2
  27. package/dist/theme/components/checkbox.d.ts +1 -0
  28. package/dist/theme/components/customTable.d.ts +522 -34
  29. package/dist/theme/components/datePicker.d.ts +1 -0
  30. package/dist/theme/components/global.d.ts +5 -2
  31. package/dist/theme/components/heading.d.ts +5 -1
  32. package/dist/theme/components/image.d.ts +18 -0
  33. package/dist/theme/components/radio.d.ts +9 -0
  34. package/dist/theme/components/searchBar.d.ts +6 -0
  35. package/dist/theme/components/select.d.ts +4 -5
  36. package/dist/theme/components/structuredContent.d.ts +117 -17
  37. package/dist/theme/components/template.d.ts +4 -1
  38. package/dist/theme/components/text.d.ts +5 -1
  39. package/dist/theme/components/textInput.d.ts +4 -0
  40. package/dist/theme/components/toggle.d.ts +1 -0
  41. package/dist/theme/provider.d.ts +2 -1
  42. package/package.json +16 -16
  43. package/src/__tests__/fileMock.ts +0 -6
  44. package/src/__tests__/setup.ts +0 -27
  45. package/src/__tests__/utils/utils.test.ts +0 -18
  46. package/src/components/AccessibilityGuide/SkipNavigation.stories.mdx +0 -42
  47. package/src/components/Accordion/Accordion.stories.mdx +0 -333
  48. package/src/components/Accordion/Accordion.test.tsx +0 -237
  49. package/src/components/Accordion/Accordion.tsx +0 -137
  50. package/src/components/Accordion/__snapshots__/Accordion.test.tsx.snap +0 -734
  51. package/src/components/Autosuggest/Autosuggest.stories.mdx +0 -75
  52. package/src/components/Autosuggest/Autosuggest.stories.tsx +0 -211
  53. package/src/components/Autosuggest/_Autosuggest.scss +0 -51
  54. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +0 -231
  55. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +0 -144
  56. package/src/components/Breadcrumbs/Breadcrumbs.tsx +0 -98
  57. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +0 -695
  58. package/src/components/Button/Button.stories.mdx +0 -320
  59. package/src/components/Button/Button.test.tsx +0 -184
  60. package/src/components/Button/Button.tsx +0 -95
  61. package/src/components/Button/__snapshots__/Button.test.tsx.snap +0 -106
  62. package/src/components/ButtonGroup/ButtonGroup.stories.mdx +0 -178
  63. package/src/components/ButtonGroup/ButtonGroup.test.tsx +0 -141
  64. package/src/components/ButtonGroup/ButtonGroup.tsx +0 -100
  65. package/src/components/ButtonGroup/__snapshots__/ButtonGroup.test.tsx.snap +0 -117
  66. package/src/components/Card/Card.stories.mdx +0 -1041
  67. package/src/components/Card/Card.test.tsx +0 -388
  68. package/src/components/Card/Card.tsx +0 -346
  69. package/src/components/Card/__snapshots__/Card.test.tsx.snap +0 -568
  70. package/src/components/Chakra/Box.stories.mdx +0 -52
  71. package/src/components/Chakra/Center.stories.mdx +0 -96
  72. package/src/components/Chakra/Flex.stories.mdx +0 -111
  73. package/src/components/Chakra/Grid.stories.mdx +0 -89
  74. package/src/components/Chakra/Stack.stories.mdx +0 -109
  75. package/src/components/Checkbox/Checkbox.stories.mdx +0 -243
  76. package/src/components/Checkbox/Checkbox.test.tsx +0 -350
  77. package/src/components/Checkbox/Checkbox.tsx +0 -152
  78. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +0 -661
  79. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +0 -462
  80. package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +0 -492
  81. package/src/components/CheckboxGroup/CheckboxGroup.tsx +0 -173
  82. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +0 -1842
  83. package/src/components/ComponentWrapper/ComponentWrapper.test.tsx +0 -163
  84. package/src/components/ComponentWrapper/ComponentWrapper.tsx +0 -76
  85. package/src/components/ComponentWrapper/__snapshots__/ComponentWrapper.test.tsx.snap +0 -103
  86. package/src/components/DatePicker/DatePicker.stories.mdx +0 -452
  87. package/src/components/DatePicker/DatePicker.test.tsx +0 -940
  88. package/src/components/DatePicker/DatePicker.tsx +0 -450
  89. package/src/components/DatePicker/_DatePicker.scss +0 -100
  90. package/src/components/DatePicker/__snapshots__/DatePicker.test.tsx.snap +0 -908
  91. package/src/components/Fieldset/Fieldset.stories.mdx +0 -96
  92. package/src/components/Fieldset/Fieldset.test.tsx +0 -155
  93. package/src/components/Fieldset/Fieldset.tsx +0 -55
  94. package/src/components/Fieldset/__snapshots__/Fieldset.test.tsx.snap +0 -89
  95. package/src/components/Form/Form.stories.mdx +0 -426
  96. package/src/components/Form/Form.test.tsx +0 -234
  97. package/src/components/Form/Form.tsx +0 -124
  98. package/src/components/Form/__snapshots__/Form.test.tsx.snap +0 -115
  99. package/src/components/Grid/SimpleGrid.stories.mdx +0 -336
  100. package/src/components/Grid/SimpleGrid.test.tsx +0 -79
  101. package/src/components/Grid/SimpleGrid.tsx +0 -49
  102. package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +0 -23
  103. package/src/components/Heading/Heading.stories.mdx +0 -187
  104. package/src/components/Heading/Heading.test.tsx +0 -171
  105. package/src/components/Heading/Heading.tsx +0 -104
  106. package/src/components/Heading/__snapshots__/Heading.test.tsx.snap +0 -90
  107. package/src/components/HelperErrorText/HelperErrorText.stories.mdx +0 -172
  108. package/src/components/HelperErrorText/HelperErrorText.test.tsx +0 -114
  109. package/src/components/HelperErrorText/HelperErrorText.tsx +0 -62
  110. package/src/components/HelperErrorText/__snapshots__/HelperErrorText.test.tsx.snap +0 -93
  111. package/src/components/Hero/Hero.stories.mdx +0 -378
  112. package/src/components/Hero/Hero.test.tsx +0 -611
  113. package/src/components/Hero/Hero.tsx +0 -203
  114. package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +0 -379
  115. package/src/components/HorizontalRule/HorizontalRule.stories.mdx +0 -73
  116. package/src/components/HorizontalRule/HorizontalRule.test.tsx +0 -54
  117. package/src/components/HorizontalRule/HorizontalRule.tsx +0 -27
  118. package/src/components/HorizontalRule/__snapshots__/HorizontalRule.test.tsx.snap +0 -44
  119. package/src/components/Icons/Icon.stories.mdx +0 -413
  120. package/src/components/Icons/Icon.test.tsx +0 -120
  121. package/src/components/Icons/Icon.tsx +0 -187
  122. package/src/components/Icons/IconSvgs.tsx +0 -64
  123. package/src/components/Icons/__snapshots__/Icon.test.tsx.snap +0 -129
  124. package/src/components/Image/Image.stories.mdx +0 -332
  125. package/src/components/Image/Image.test.tsx +0 -155
  126. package/src/components/Image/Image.tsx +0 -171
  127. package/src/components/Image/__snapshots__/Image.test.tsx.snap +0 -269
  128. package/src/components/Label/Label.stories.mdx +0 -100
  129. package/src/components/Label/Label.test.tsx +0 -116
  130. package/src/components/Label/Label.tsx +0 -55
  131. package/src/components/Label/__snapshots__/Label.test.tsx.snap +0 -45
  132. package/src/components/Link/Link.stories.mdx +0 -249
  133. package/src/components/Link/Link.test.tsx +0 -224
  134. package/src/components/Link/Link.tsx +0 -178
  135. package/src/components/Link/__snapshots__/Link.test.tsx.snap +0 -286
  136. package/src/components/List/List.stories.mdx +0 -393
  137. package/src/components/List/List.test.tsx +0 -265
  138. package/src/components/List/List.tsx +0 -156
  139. package/src/components/List/__snapshots__/List.test.tsx.snap +0 -213
  140. package/src/components/Logo/Logo.stories.mdx +0 -295
  141. package/src/components/Logo/Logo.test.tsx +0 -116
  142. package/src/components/Logo/Logo.tsx +0 -151
  143. package/src/components/Logo/LogoSvgs.tsx +0 -90
  144. package/src/components/Logo/__snapshots__/Logo.test.tsx.snap +0 -142
  145. package/src/components/Modal/Modal.stories.mdx +0 -294
  146. package/src/components/Modal/Modal.test.tsx +0 -157
  147. package/src/components/Modal/Modal.tsx +0 -154
  148. package/src/components/Modal/__snapshots__/Modal.test.tsx.snap +0 -25
  149. package/src/components/Notification/Notification.stories.mdx +0 -358
  150. package/src/components/Notification/Notification.test.tsx +0 -279
  151. package/src/components/Notification/Notification.tsx +0 -224
  152. package/src/components/Notification/__snapshots__/Notification.test.tsx.snap +0 -525
  153. package/src/components/Pagination/Pagination.stories.mdx +0 -184
  154. package/src/components/Pagination/Pagination.test.tsx +0 -419
  155. package/src/components/Pagination/Pagination.tsx +0 -269
  156. package/src/components/Pagination/__snapshots__/Pagination.test.tsx.snap +0 -544
  157. package/src/components/Placeholder/Placeholder.tsx +0 -19
  158. package/src/components/ProgressIndicator/ProgressIndicator.stories.mdx +0 -360
  159. package/src/components/ProgressIndicator/ProgressIndicator.test.tsx +0 -298
  160. package/src/components/ProgressIndicator/ProgressIndicator.tsx +0 -132
  161. package/src/components/ProgressIndicator/__snapshots__/ProgressIndicator.test.tsx.snap +0 -434
  162. package/src/components/Radio/Radio.stories.mdx +0 -216
  163. package/src/components/Radio/Radio.test.tsx +0 -247
  164. package/src/components/Radio/Radio.tsx +0 -119
  165. package/src/components/Radio/__snapshots__/Radio.test.tsx.snap +0 -451
  166. package/src/components/RadioGroup/RadioGroup.stories.mdx +0 -479
  167. package/src/components/RadioGroup/RadioGroup.test.tsx +0 -471
  168. package/src/components/RadioGroup/RadioGroup.tsx +0 -171
  169. package/src/components/RadioGroup/__snapshots__/RadioGroup.test.tsx.snap +0 -1550
  170. package/src/components/SearchBar/SearchBar.stories.mdx +0 -518
  171. package/src/components/SearchBar/SearchBar.test.tsx +0 -435
  172. package/src/components/SearchBar/SearchBar.tsx +0 -210
  173. package/src/components/SearchBar/__snapshots__/SearchBar.test.tsx.snap +0 -1049
  174. package/src/components/Select/Select.stories.mdx +0 -439
  175. package/src/components/Select/Select.test.tsx +0 -358
  176. package/src/components/Select/Select.tsx +0 -183
  177. package/src/components/Select/__snapshots__/Select.test.tsx.snap +0 -895
  178. package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +0 -142
  179. package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +0 -116
  180. package/src/components/SkeletonLoader/SkeletonLoader.tsx +0 -123
  181. package/src/components/SkeletonLoader/__snapshots__/SkeletonLoader.test.tsx.snap +0 -898
  182. package/src/components/SkipNavigation/SkipNavigation.stories.mdx +0 -90
  183. package/src/components/SkipNavigation/SkipNavigation.test.tsx +0 -63
  184. package/src/components/SkipNavigation/SkipNavigation.tsx +0 -51
  185. package/src/components/SkipNavigation/__snapshots__/SkipNavigation.test.tsx.snap +0 -130
  186. package/src/components/Slider/Slider.stories.mdx +0 -628
  187. package/src/components/Slider/Slider.test.tsx +0 -736
  188. package/src/components/Slider/Slider.tsx +0 -322
  189. package/src/components/Slider/__snapshots__/Slider.test.tsx.snap +0 -2186
  190. package/src/components/StatusBadge/StatusBadge.stories.mdx +0 -109
  191. package/src/components/StatusBadge/StatusBadge.test.tsx +0 -70
  192. package/src/components/StatusBadge/StatusBadge.tsx +0 -35
  193. package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +0 -47
  194. package/src/components/StructuredContent/StructuredContent.stories.mdx +0 -567
  195. package/src/components/StructuredContent/StructuredContent.test.tsx +0 -435
  196. package/src/components/StructuredContent/StructuredContent.tsx +0 -139
  197. package/src/components/StructuredContent/__snapshots__/StructuredContent.test.tsx.snap +0 -368
  198. package/src/components/StyleGuide/Bidirectionality.stories.mdx +0 -206
  199. package/src/components/StyleGuide/Breakpoints.stories.mdx +0 -55
  200. package/src/components/StyleGuide/Buttons.stories.mdx +0 -194
  201. package/src/components/StyleGuide/ColorCard.tsx +0 -43
  202. package/src/components/StyleGuide/Colors.stories.mdx +0 -201
  203. package/src/components/StyleGuide/DesignTokens.stories.mdx +0 -193
  204. package/src/components/StyleGuide/Forms.stories.mdx +0 -94
  205. package/src/components/StyleGuide/Iconography.stories.mdx +0 -142
  206. package/src/components/StyleGuide/Spacing.stories.mdx +0 -116
  207. package/src/components/StyleGuide/Typography.stories.mdx +0 -419
  208. package/src/components/Table/Table.stories.mdx +0 -272
  209. package/src/components/Table/Table.test.tsx +0 -241
  210. package/src/components/Table/Table.tsx +0 -152
  211. package/src/components/Table/__snapshots__/Table.test.tsx.snap +0 -1703
  212. package/src/components/Tabs/Tabs.stories.mdx +0 -338
  213. package/src/components/Tabs/Tabs.test.tsx +0 -298
  214. package/src/components/Tabs/Tabs.tsx +0 -264
  215. package/src/components/Tabs/__snapshots__/Tabs.test.tsx.snap +0 -584
  216. package/src/components/Template/Template.stories.mdx +0 -695
  217. package/src/components/Template/Template.test.tsx +0 -309
  218. package/src/components/Template/Template.tsx +0 -326
  219. package/src/components/Template/__snapshots__/Template.test.tsx.snap +0 -342
  220. package/src/components/Text/Text.stories.mdx +0 -103
  221. package/src/components/Text/Text.test.tsx +0 -63
  222. package/src/components/Text/Text.tsx +0 -50
  223. package/src/components/Text/__snapshots__/Text.test.tsx.snap +0 -50
  224. package/src/components/TextInput/TextInput.stories.mdx +0 -268
  225. package/src/components/TextInput/TextInput.test.tsx +0 -451
  226. package/src/components/TextInput/TextInput.tsx +0 -240
  227. package/src/components/TextInput/__snapshots__/TextInput.test.tsx.snap +0 -274
  228. package/src/components/Toggle/Toggle.stories.mdx +0 -237
  229. package/src/components/Toggle/Toggle.test.tsx +0 -170
  230. package/src/components/Toggle/Toggle.tsx +0 -128
  231. package/src/components/Toggle/__snapshots__/Toggle.test.tsx.snap +0 -470
  232. package/src/components/VideoPlayer/VideoPlayer.stories.mdx +0 -212
  233. package/src/components/VideoPlayer/VideoPlayer.test.tsx +0 -308
  234. package/src/components/VideoPlayer/VideoPlayer.tsx +0 -188
  235. package/src/components/VideoPlayer/__snapshots__/VideoPlayer.test.tsx.snap +0 -192
  236. package/src/docs/Chakra.stories.mdx +0 -563
  237. package/src/docs/Welcome.stories.mdx +0 -148
  238. package/src/helpers/types.ts +0 -1
  239. package/src/hooks/tests/useCarouselStyles.test.ts +0 -140
  240. package/src/hooks/tests/useNYPLTheme.test.tsx +0 -36
  241. package/src/hooks/useCarouselStyles.stories.mdx +0 -30
  242. package/src/hooks/useCarouselStyles.ts +0 -35
  243. package/src/hooks/useNYPLTheme.stories.mdx +0 -98
  244. package/src/hooks/useNYPLTheme.ts +0 -91
  245. package/src/hooks/useWindowSize.stories.mdx +0 -23
  246. package/src/hooks/useWindowSize.ts +0 -40
  247. package/src/index.ts +0 -136
  248. package/src/resources.scss +0 -6
  249. package/src/styles/base/_01-breakpoints.scss +0 -27
  250. package/src/styles/base/_02-mixins.scss +0 -103
  251. package/src/styles/base/_place-holder.scss +0 -33
  252. package/src/styles/space/_space-inline.scss +0 -79
  253. package/src/styles/space/_space-inset.scss +0 -57
  254. package/src/styles/space/_space-stack.scss +0 -116
  255. package/src/styles.scss +0 -23
  256. package/src/theme/components/accordion.ts +0 -25
  257. package/src/theme/components/breadcrumb.ts +0 -94
  258. package/src/theme/components/button.ts +0 -133
  259. package/src/theme/components/buttonGroup.ts +0 -10
  260. package/src/theme/components/card.ts +0 -237
  261. package/src/theme/components/checkbox.ts +0 -110
  262. package/src/theme/components/checkboxGroup.ts +0 -10
  263. package/src/theme/components/componentWrapper.ts +0 -14
  264. package/src/theme/components/customTable.ts +0 -77
  265. package/src/theme/components/datePicker.ts +0 -17
  266. package/src/theme/components/fieldset.ts +0 -23
  267. package/src/theme/components/global.ts +0 -91
  268. package/src/theme/components/globalMixins.ts +0 -24
  269. package/src/theme/components/heading.ts +0 -79
  270. package/src/theme/components/helperErrorText.ts +0 -14
  271. package/src/theme/components/hero.ts +0 -238
  272. package/src/theme/components/horizontalRule.ts +0 -17
  273. package/src/theme/components/icon.ts +0 -88
  274. package/src/theme/components/image.ts +0 -136
  275. package/src/theme/components/label.ts +0 -15
  276. package/src/theme/components/link.ts +0 -63
  277. package/src/theme/components/list.ts +0 -88
  278. package/src/theme/components/logo.ts +0 -58
  279. package/src/theme/components/notification.ts +0 -132
  280. package/src/theme/components/pagination.ts +0 -17
  281. package/src/theme/components/progressIndicator.ts +0 -67
  282. package/src/theme/components/radio.ts +0 -103
  283. package/src/theme/components/radioGroup.ts +0 -10
  284. package/src/theme/components/searchBar.ts +0 -19
  285. package/src/theme/components/select.ts +0 -72
  286. package/src/theme/components/skeletonLoader.ts +0 -113
  287. package/src/theme/components/skipNavigation.ts +0 -29
  288. package/src/theme/components/slider.ts +0 -95
  289. package/src/theme/components/statusBadge.ts +0 -26
  290. package/src/theme/components/structuredContent.ts +0 -149
  291. package/src/theme/components/tabs.ts +0 -109
  292. package/src/theme/components/template.ts +0 -114
  293. package/src/theme/components/text.ts +0 -38
  294. package/src/theme/components/textInput.ts +0 -65
  295. package/src/theme/components/toggle.ts +0 -109
  296. package/src/theme/components/videoPlayer.ts +0 -47
  297. package/src/theme/foundations/breakpoints.ts +0 -24
  298. package/src/theme/foundations/colors.ts +0 -212
  299. package/src/theme/foundations/global.ts +0 -43
  300. package/src/theme/foundations/radii.ts +0 -7
  301. package/src/theme/foundations/shadows.ts +0 -5
  302. package/src/theme/foundations/spacing.ts +0 -136
  303. package/src/theme/foundations/typography.ts +0 -107
  304. package/src/theme/index.ts +0 -131
  305. package/src/theme/provider.tsx +0 -9
  306. package/src/theme/types.ts +0 -1
  307. package/src/utils/componentCategories.ts +0 -152
  308. package/src/utils/interfaces.ts +0 -5
  309. package/src/utils/utils.ts +0 -84
@@ -1,940 +0,0 @@
1
- import * as React from "react";
2
- import { render, screen } from "@testing-library/react";
3
- import { axe } from "jest-axe";
4
- import userEvent from "@testing-library/user-event";
5
- import renderer from "react-test-renderer";
6
-
7
- import DatePicker, { DatePickerTypes, FullDateType } from "./DatePicker";
8
- import { TextInputRefType } from "../TextInput/TextInput";
9
-
10
- /** This adds a "0" padding for date values under "10". */
11
- const strPad = (n: number) => String("0" + n).slice(-2);
12
- const monthArray: string[] = [
13
- "January",
14
- "February",
15
- "March",
16
- "April",
17
- "May",
18
- "June",
19
- "July",
20
- "August",
21
- "September",
22
- "October",
23
- "November",
24
- "December",
25
- ];
26
-
27
- describe("DatePicker Accessibility", () => {
28
- it("passes axe accessibility for a single date input", async () => {
29
- const { container } = render(
30
- <DatePicker
31
- id="datePicker"
32
- labelText="Select the date you want to visit NYPL"
33
- />
34
- );
35
- expect(await axe(container)).toHaveNoViolations();
36
- });
37
-
38
- it("passes axe accessibility for a date range", async () => {
39
- const { container } = render(
40
- <DatePicker
41
- id="datePicker"
42
- labelText="Select the date range you want to visit NYPL"
43
- isDateRange
44
- />
45
- );
46
- expect(await axe(container)).toHaveNoViolations();
47
- });
48
- });
49
-
50
- describe("DatePicker", () => {
51
- const todaysDate = new Date();
52
- /** Returns today's year, month, and day values. */
53
- const getTodaysValues = () => {
54
- const year = todaysDate.getFullYear();
55
- const month = strPad(todaysDate.getMonth() + 1);
56
- const day = strPad(todaysDate.getDate());
57
- return [year, month, day];
58
- };
59
- /** Returns today's date in string format based on the DatePicker type. */
60
- const getTodaysDateDisplay = (type?: DatePickerTypes) => {
61
- const [year, month, day] = getTodaysValues();
62
- if ("year" === type) {
63
- return `${year}`;
64
- } else if ("month" === type) {
65
- return `${month}-${year}`;
66
- }
67
- return `${year}-${month}-${day}`;
68
- };
69
-
70
- describe("Single input", () => {
71
- it("should render the basic date input field including a date", () => {
72
- render(
73
- <DatePicker
74
- id="datePicker"
75
- labelText="Select the full date you want to visit NYPL"
76
- />
77
- );
78
- const [year, month, day] = getTodaysValues();
79
- const date = getTodaysDateDisplay();
80
- const input = screen.getByLabelText(
81
- /Select the full date you want to visit NYPL/i
82
- );
83
-
84
- expect(input).toBeInTheDocument();
85
- expect(input).not.toHaveAttribute("aria-label");
86
- // Date format based on component specification yyyy-mm-dd.
87
- expect(date).toEqual(`${year}-${month}-${day}`);
88
- expect(screen.getByDisplayValue(date)).toBeInTheDocument();
89
- });
90
-
91
- it("should render with an initial date", () => {
92
- render(
93
- <DatePicker
94
- id="datePicker"
95
- labelText="Select the full date you want to visit NYPL"
96
- initialDate="1/2/1988"
97
- />
98
- );
99
- const date = screen.getByDisplayValue("1988-01-02");
100
-
101
- expect(date).toBeInTheDocument();
102
- });
103
-
104
- it("should render the 'month' DatePicker type", () => {
105
- render(
106
- <DatePicker
107
- id="datePicker"
108
- dateType="month"
109
- labelText="Select the month you want to visit NYPL"
110
- />
111
- );
112
- const [year, month] = getTodaysValues();
113
- const date = getTodaysDateDisplay("month");
114
-
115
- expect(
116
- screen.getByLabelText(/Select the month you want to visit NYPL/i)
117
- ).toBeInTheDocument();
118
- // Date format based on component specification mm-yyyy.
119
- expect(date).toEqual(`${month}-${year}`);
120
- expect(screen.getByDisplayValue(date)).toBeInTheDocument();
121
- });
122
-
123
- it("should render the 'year' DatePicker type", () => {
124
- render(
125
- <DatePicker
126
- id="datePicker"
127
- dateType="year"
128
- labelText="Select the month you want to visit NYPL"
129
- />
130
- );
131
- const [year] = getTodaysValues();
132
- const date = getTodaysDateDisplay("year");
133
-
134
- expect(
135
- screen.getByLabelText(/Select the month you want to visit NYPL/i)
136
- ).toBeInTheDocument();
137
- // Date format based on component specification yyyy.
138
- expect(date).toEqual(`${year}`);
139
- expect(screen.getByDisplayValue(date)).toBeInTheDocument();
140
- });
141
-
142
- it("should render a custom date format", () => {
143
- const customDateFormat1 = "yyyy/dd/MM";
144
- const customDateFormat2 = "MM/dd/yyyy";
145
- const { rerender } = render(
146
- <DatePicker
147
- id="datePicker"
148
- labelText="Select the date you want to visit NYPL"
149
- dateFormat={customDateFormat1}
150
- />
151
- );
152
- const [year, month, day] = getTodaysValues();
153
- const dateFormat1 = `${year}/${day}/${month}`;
154
-
155
- expect(screen.getByDisplayValue(dateFormat1)).toBeInTheDocument();
156
-
157
- const dateFormat2 = `${month}/${day}/${year}`;
158
- rerender(
159
- <DatePicker
160
- id="datePicker"
161
- labelText="Select the date you want to visit NYPL"
162
- dateFormat={customDateFormat2}
163
- />
164
- );
165
- expect(screen.getByDisplayValue(dateFormat2)).toBeInTheDocument();
166
- });
167
-
168
- it("should hide the input label but add an aria-label", () => {
169
- render(
170
- <DatePicker
171
- id="datePicker"
172
- labelText="Select the date you want to visit NYPL"
173
- showLabel={false}
174
- />
175
- );
176
- const input = screen.getByLabelText(
177
- /Select the date you want to visit NYPL/i
178
- );
179
-
180
- expect(
181
- screen.queryByDisplayValue(/Select the date you want to visit NYPL/i)
182
- ).not.toBeInTheDocument();
183
- expect(input).toHaveAttribute("aria-label");
184
- });
185
-
186
- it("should render with helper text and error text", () => {
187
- const { rerender } = render(
188
- <DatePicker
189
- id="datePicker"
190
- labelText="Select the date you want to visit NYPL"
191
- helperText="Note that the Library may be closed on Sundays."
192
- invalidText="Please select a valid date."
193
- />
194
- );
195
-
196
- // When not errored, we expect only the helper text to appear.
197
- expect(
198
- screen.getByLabelText(/Select the date you want to visit NYPL/i)
199
- ).toBeInTheDocument();
200
- expect(
201
- screen.getByText("Note that the Library may be closed on Sundays.")
202
- ).toBeInTheDocument();
203
- expect(
204
- screen.queryByText("Please select a valid date.")
205
- ).not.toBeInTheDocument();
206
-
207
- rerender(
208
- <DatePicker
209
- id="datePicker"
210
- labelText="Select the date you want to visit NYPL"
211
- helperText="Note that the Library may be closed on Sundays."
212
- invalidText="Please select a valid date."
213
- isInvalid
214
- />
215
- );
216
- // When errored, we expect only the error text to appear.
217
- expect(
218
- screen.queryByText("Note that the Library may be closed on Sundays.")
219
- ).not.toBeInTheDocument();
220
- expect(
221
- screen.getByText("Please select a valid date.")
222
- ).toBeInTheDocument();
223
- });
224
-
225
- it("should not render the helper text or invalid text when 'showHelperInvalidText' is false", () => {
226
- const { rerender } = render(
227
- <DatePicker
228
- id="datePicker"
229
- labelText="Select the date you want to visit NYPL"
230
- helperText="Note that the Library may be closed on Sundays."
231
- invalidText="Please select a valid date."
232
- showHelperInvalidText={false}
233
- />
234
- );
235
- expect(
236
- screen.queryByText("Note that the Library may be closed on Sundays.")
237
- ).not.toBeInTheDocument();
238
- expect(
239
- screen.queryByText("Please select a valid date.")
240
- ).not.toBeInTheDocument();
241
-
242
- rerender(
243
- <DatePicker
244
- id="datePicker"
245
- labelText="Select the date you want to visit NYPL"
246
- helperText="Note that the Library may be closed on Sundays."
247
- invalidText="Please select a valid date."
248
- showHelperInvalidText={false}
249
- isInvalid
250
- />
251
- );
252
- expect(
253
- screen.queryByText("Note that the Library may be closed on Sundays.")
254
- ).not.toBeInTheDocument();
255
- expect(
256
- screen.queryByText("Please select a valid date.")
257
- ).not.toBeInTheDocument();
258
- });
259
-
260
- it("should render a disabled input field", () => {
261
- render(
262
- <DatePicker
263
- id="datePicker"
264
- labelText="Select the date you want to visit NYPL"
265
- helperText="Note that the Library may be closed on Sundays."
266
- isDisabled
267
- />
268
- );
269
-
270
- expect(
271
- screen.getByLabelText(/Select the date you want to visit NYPL/i)
272
- ).toHaveAttribute("disabled");
273
- });
274
-
275
- it("should render a required label", () => {
276
- render(
277
- <DatePicker
278
- id="datePicker"
279
- labelText="Select the date you want to visit NYPL"
280
- helperText="Note that the Library may be closed on Sundays."
281
- isRequired
282
- />
283
- );
284
-
285
- expect(screen.getByText(/required/i)).toBeInTheDocument();
286
- });
287
-
288
- it("should hide the (Required) text in the label with `showRequiredLabel`", () => {
289
- const { rerender } = render(
290
- <DatePicker
291
- id="datePicker"
292
- labelText="Select the date you want to visit NYPL"
293
- />
294
- );
295
- expect(screen.queryByText(/Required/i)).not.toBeInTheDocument();
296
-
297
- rerender(
298
- <DatePicker
299
- id="datePicker"
300
- labelText="Select the date you want to visit NYPL"
301
- isRequired
302
- />
303
- );
304
- expect(screen.getByText(/Required/i)).toBeInTheDocument();
305
-
306
- rerender(
307
- <DatePicker
308
- id="datePicker"
309
- labelText="Select the date you want to visit NYPL"
310
- showRequiredLabel={false}
311
- isRequired
312
- />
313
- );
314
- expect(screen.queryByText(/Required/i)).not.toBeInTheDocument();
315
- });
316
-
317
- it("should pass the value to the `onChange` function", () => {
318
- let dateObject: FullDateType = {
319
- startDate: new Date(),
320
- endDate: new Date(),
321
- };
322
- const onChange = (data: FullDateType) => {
323
- dateObject = data;
324
- };
325
- render(
326
- <DatePicker
327
- id="datePicker"
328
- labelText="Select the date you want to visit NYPL"
329
- helperText="Note that the Library may be closed on Sundays."
330
- onChange={onChange}
331
- isRequired
332
- />
333
- );
334
-
335
- const input = screen.getByLabelText(
336
- /Select the date you want to visit NYPL/i
337
- );
338
- const date = getTodaysDateDisplay();
339
- const midMonthDay = "15";
340
-
341
- // Let's select a new day.
342
- userEvent.click(input);
343
- // The popup displays.
344
- userEvent.click(screen.getByText(midMonthDay));
345
-
346
- const newDayValue = date.slice(0, -2) + midMonthDay;
347
- expect(screen.getByDisplayValue(newDayValue)).toBeInTheDocument();
348
-
349
- const { startDate } = dateObject;
350
- const valueFromOnChange = `${startDate.getFullYear()}-${strPad(
351
- startDate.getMonth() + 1
352
- )}-${strPad(startDate.getDate())}`;
353
- expect(newDayValue).toEqual(valueFromOnChange);
354
- });
355
-
356
- it("should throw a warning when refs are used but not `name` props", () => {
357
- const warn = jest.spyOn(console, "warn");
358
- const ref = React.createRef<TextInputRefType>();
359
- render(
360
- <DatePicker
361
- id="datePicker"
362
- labelText="Select the date you want to visit NYPL"
363
- ref={ref}
364
- />
365
- );
366
- expect(warn).toHaveBeenCalledWith(
367
- "NYPL Reservoir DatePicker: A `ref` or `refTo` prop was passed but " +
368
- "not the equivalent `nameFrom` or `nameTo` prop."
369
- );
370
- });
371
-
372
- it("should throw a warning when `onChange` is passed as well as a `ref` prop.", () => {
373
- const warn = jest.spyOn(console, "warn");
374
- const ref = React.createRef<TextInputRefType>();
375
- const onChange = (_data: {}) => {};
376
- render(
377
- <DatePicker
378
- id="datePicker"
379
- labelText="Select the date you want to visit NYPL"
380
- ref={ref}
381
- nameFrom="start-date"
382
- onChange={onChange}
383
- />
384
- );
385
- expect(warn).toHaveBeenCalledWith(
386
- "NYPL Reservoir DatePicker: A `ref`, `refTo`, `nameFrom`, or `nameTo` " +
387
- "prop was passed and an `onChange` prop as well. Use whichever is best " +
388
- "for your app but not both."
389
- );
390
- });
391
-
392
- // Note: Have to add an initial date so that the snapshot tests always
393
- // pass. Otherwise, it'll use the _current_ date which changes
394
- // based on the day it is tested and is not what we want.
395
- it("renders the UI snapshot correctly", () => {
396
- const basic = renderer
397
- .create(
398
- <DatePicker
399
- id="basic"
400
- labelText="Select the full date you want to visit NYPL"
401
- initialDate="1/2/1988"
402
- />
403
- )
404
- .toJSON();
405
- const withoutLabel = renderer
406
- .create(
407
- <DatePicker
408
- id="no-label"
409
- labelText="Select the date you want to visit NYPL"
410
- initialDate="1/2/1988"
411
- showLabel={false}
412
- />
413
- )
414
- .toJSON();
415
- const withCustomFormat = renderer
416
- .create(
417
- <DatePicker
418
- id="custom-format"
419
- labelText="Select the date you want to visit NYPL"
420
- dateFormat="yyyy/dd/MM"
421
- initialDate="1/2/1988"
422
- />
423
- )
424
- .toJSON();
425
- const invalid = renderer
426
- .create(
427
- <DatePicker
428
- id="invalid"
429
- labelText="Select the date you want to visit NYPL"
430
- helperText="Note that the Library may be closed on Sundays."
431
- invalidText="Please select a valid date."
432
- initialDate="1/2/1988"
433
- isInvalid
434
- />
435
- )
436
- .toJSON();
437
- const disabled = renderer
438
- .create(
439
- <DatePicker
440
- id="disabled"
441
- labelText="Select the date you want to visit NYPL"
442
- helperText="Note that the Library may be closed on Sundays."
443
- invalidText="Please select a valid date."
444
- initialDate="1/2/1988"
445
- isDisabled
446
- />
447
- )
448
- .toJSON();
449
- const withChakraProps = renderer
450
- .create(
451
- <DatePicker
452
- id="chakra"
453
- labelText="Select the date you want to visit NYPL"
454
- helperText="Note that the Library may be closed on Sundays."
455
- invalidText="Please select a valid date."
456
- initialDate="1/2/1988"
457
- p="20px"
458
- color="ui.error.primary"
459
- />
460
- )
461
- .toJSON();
462
- const withOtherProps = renderer
463
- .create(
464
- <DatePicker
465
- id="props"
466
- labelText="Select the date you want to visit NYPL"
467
- helperText="Note that the Library may be closed on Sundays."
468
- invalidText="Please select a valid date."
469
- initialDate="1/2/1988"
470
- data-testid="datepicker"
471
- />
472
- )
473
- .toJSON();
474
-
475
- expect(basic).toMatchSnapshot();
476
- expect(withoutLabel).toMatchSnapshot();
477
- expect(withCustomFormat).toMatchSnapshot();
478
- expect(invalid).toMatchSnapshot();
479
- expect(disabled).toMatchSnapshot();
480
- expect(withChakraProps).toMatchSnapshot();
481
- expect(withOtherProps).toMatchSnapshot();
482
- });
483
- });
484
-
485
- describe("Date Range", () => {
486
- it("should render the date range with two input fields", () => {
487
- render(
488
- <DatePicker
489
- id="datePicker"
490
- labelText="Select the date range you want to visit NYPL"
491
- isDateRange
492
- />
493
- );
494
- const [year, month, day] = getTodaysValues();
495
- const date = getTodaysDateDisplay();
496
-
497
- expect(
498
- screen.getByText(/Select the date range you want to visit NYPL/i)
499
- ).toBeInTheDocument();
500
- // Date format based on component specification yyyy-mm-dd.
501
- expect(date).toEqual(`${year}-${month}-${day}`);
502
- // There are two input fields with the date displaying.
503
- expect(screen.getAllByDisplayValue(date)).toHaveLength(2);
504
- });
505
-
506
- it("should render the initial dates", () => {
507
- render(
508
- <DatePicker
509
- id="datePicker"
510
- labelText="Select the full date you want to visit NYPL"
511
- isDateRange
512
- initialDate="1/2/1988"
513
- initialDateTo="3/4/1990"
514
- />
515
- );
516
- const dateFrom = screen.getByDisplayValue("1988-01-02");
517
- const dateTo = screen.getByDisplayValue("1990-03-04");
518
-
519
- expect(dateFrom).toBeInTheDocument();
520
- expect(dateTo).toBeInTheDocument();
521
- });
522
-
523
- it("should render two input labels and three separate helper text", () => {
524
- render(
525
- <DatePicker
526
- id="datePicker"
527
- labelText="Select the date range you want to visit NYPL"
528
- helperText="Note that the Library may be closed on Sundays."
529
- helperTextFrom="Note for the 'from' field."
530
- helperTextTo="Note for the 'to' field."
531
- invalidText="Please select a valid date range."
532
- isDateRange
533
- />
534
- );
535
- // There are two labels for each input.
536
- expect(screen.getByText("From")).toBeInTheDocument();
537
- expect(screen.getByText("To")).toBeInTheDocument();
538
- // Helper text for the component
539
- expect(
540
- screen.getByText(/Note that the Library may be closed on Sundays./i)
541
- ).toBeInTheDocument();
542
- // Helper text for the "From" input
543
- expect(
544
- screen.getByText(/Note for the 'from' field./i)
545
- ).toBeInTheDocument();
546
- // Helper text for the "To" input
547
- expect(screen.getByText(/Note for the 'to' field./i)).toBeInTheDocument();
548
- });
549
-
550
- it("should render different states based on respective props", () => {
551
- const { rerender } = render(
552
- <DatePicker
553
- id="datePicker"
554
- labelText="Select the date range you want to visit NYPL"
555
- helperText="Note that the Library may be closed on Sundays."
556
- helperTextTo="Note for the 'to' field."
557
- invalidText="Please select a valid date range."
558
- isDateRange
559
- isInvalid
560
- />
561
- );
562
-
563
- // The invalid text displays under each input field.
564
- expect(
565
- screen.getAllByText("Please select a valid date range.")
566
- ).toHaveLength(2);
567
-
568
- rerender(
569
- <DatePicker
570
- id="datePicker"
571
- labelText="Select the date range you want to visit NYPL"
572
- helperText="Note that the Library may be closed on Sundays."
573
- helperTextTo="Note for the 'to' field."
574
- invalidText="Please select a valid date range."
575
- isDisabled
576
- isDateRange
577
- />
578
- );
579
- // Both input fields are disabled.
580
- expect(screen.getByLabelText(/From/i)).toHaveAttribute("disabled");
581
- expect(screen.getByLabelText(/To/i)).toHaveAttribute("disabled");
582
-
583
- rerender(
584
- <DatePicker
585
- id="datePicker"
586
- labelText="Select the date range you want to visit NYPL"
587
- helperText="Note that the Library may be closed on Sundays."
588
- helperTextTo="Note for the 'to' field."
589
- invalidText="Please select a valid date range."
590
- isRequired
591
- isDateRange
592
- />
593
- );
594
- // Both input fields are required.
595
- // The "Required" text is only displayed once in the `legend`.
596
- expect(screen.getAllByText(/Required/i)).toHaveLength(1);
597
- expect(screen.getByLabelText(/From/i)).toHaveAttribute("required");
598
- expect(screen.getByLabelText(/To/i)).toHaveAttribute("required");
599
- });
600
-
601
- // Note: Have to add initial dates so that the snapshot tests always
602
- // pass. Otherwise, it'll use the _current_ date which changes
603
- // based on the day it is tested and is not what we want.
604
- it("renders the UI snapshot correctly", () => {
605
- const basic = renderer
606
- .create(
607
- <DatePicker
608
- id="basic"
609
- labelText="Select the full date you want to visit NYPL"
610
- initialDate="1/2/1988"
611
- initialDateTo="2/2/1988"
612
- isDateRange
613
- />
614
- )
615
- .toJSON();
616
- const withoutLabel = renderer
617
- .create(
618
- <DatePicker
619
- id="no-label"
620
- labelText="Select the date you want to visit NYPL"
621
- showLabel={false}
622
- initialDate="1/2/1988"
623
- initialDateTo="2/2/1988"
624
- isDateRange
625
- />
626
- )
627
- .toJSON();
628
- const withCustomFormat = renderer
629
- .create(
630
- <DatePicker
631
- id="custom-format"
632
- labelText="Select the date you want to visit NYPL"
633
- dateFormat="yyyy/dd/MM"
634
- initialDate="1/2/1988"
635
- initialDateTo="2/2/1988"
636
- isDateRange
637
- />
638
- )
639
- .toJSON();
640
- const invalid = renderer
641
- .create(
642
- <DatePicker
643
- id="invalid"
644
- labelText="Select the date you want to visit NYPL"
645
- helperText="Note that the Library may be closed on Sundays."
646
- invalidText="Please select a valid date."
647
- initialDate="1/2/1988"
648
- initialDateTo="2/2/1988"
649
- isInvalid
650
- isDateRange
651
- />
652
- )
653
- .toJSON();
654
- const disabled = renderer
655
- .create(
656
- <DatePicker
657
- id="disabled"
658
- labelText="Select the date you want to visit NYPL"
659
- helperText="Note that the Library may be closed on Sundays."
660
- invalidText="Please select a valid date."
661
- initialDate="1/2/1988"
662
- initialDateTo="2/2/1988"
663
- isDisabled
664
- isDateRange
665
- />
666
- )
667
- .toJSON();
668
- expect(basic).toMatchSnapshot();
669
- expect(withoutLabel).toMatchSnapshot();
670
- expect(withCustomFormat).toMatchSnapshot();
671
- expect(invalid).toMatchSnapshot();
672
- expect(disabled).toMatchSnapshot();
673
- });
674
-
675
- it("should select two new dates", () => {
676
- render(
677
- <DatePicker
678
- id="datePicker"
679
- initialDate="3/2/1988"
680
- initialDateTo="3/28/1988"
681
- isDateRange
682
- labelText="Select the date range you want to visit NYPL"
683
- />
684
- );
685
- const fromInput = screen.getByLabelText(/From/i);
686
- const toInput = screen.getByLabelText(/To/i);
687
-
688
- expect(fromInput).toHaveValue("1988-03-02");
689
- expect(toInput).toHaveValue("1988-03-28");
690
- // expect(screen.getAllByDisplayValue(date)).toHaveLength(2);
691
-
692
- // Let's select a new day.
693
- userEvent.click(fromInput);
694
- // The popup displays. Select a new day.
695
- const newDateFrom = 5;
696
- const newDateTo = 25;
697
- userEvent.click(screen.getByText(newDateFrom));
698
-
699
- // We selected a new day but kept everything else the same.
700
- // Example: 2021-03-02 -> 5 is selected -> 2021-03-05
701
- expect(screen.getByDisplayValue("1988-03-05")).toBeInTheDocument();
702
- // The "To" input should only have the older value now.
703
- // expect(screen.getAllByDisplayValue(date)).toHaveLength(1);
704
-
705
- // Now select the "To" date.
706
- userEvent.click(toInput);
707
- // The popup displays.
708
- userEvent.click(screen.getByText(newDateTo));
709
-
710
- expect(screen.getByDisplayValue("1988-03-25")).toBeInTheDocument();
711
- // The original date values are no longer in display.
712
- expect(screen.queryByDisplayValue("1988-03-02")).not.toBeInTheDocument();
713
- expect(screen.queryByDisplayValue("1988-03-28")).not.toBeInTheDocument();
714
- // The "From" date value wasn't affected by this!
715
- expect(screen.getByDisplayValue("1988-03-05")).toBeInTheDocument();
716
- });
717
- });
718
-
719
- describe("Popup Calendar", () => {
720
- it("should render a popup calendar for the full date", () => {
721
- render(
722
- <DatePicker
723
- id="datePicker"
724
- labelText="Select the date you want to visit NYPL"
725
- />
726
- );
727
- const input = screen.getByLabelText(
728
- /Select the date you want to visit NYPL/i
729
- );
730
- const [year] = getTodaysValues();
731
- const monthFullName = monthArray[todaysDate.getMonth()];
732
-
733
- expect(
734
- screen.queryByText(`${monthFullName} ${year}`)
735
- ).not.toBeInTheDocument();
736
- expect(screen.queryByText("Su")).not.toBeInTheDocument();
737
-
738
- userEvent.click(input);
739
-
740
- // In the display, the calendar displays "Month Year" such as
741
- // "August 2021" for example.
742
- expect(screen.getByText(`${monthFullName} ${year}`)).toBeInTheDocument();
743
- // This calendar displays columns with the days of the week.
744
- expect(screen.getByText("Su")).toBeInTheDocument();
745
- expect(screen.getByText("Mo")).toBeInTheDocument();
746
- expect(screen.getByText("Tu")).toBeInTheDocument();
747
- expect(screen.getByText("We")).toBeInTheDocument();
748
- expect(screen.getByText("Th")).toBeInTheDocument();
749
- expect(screen.getByText("Fr")).toBeInTheDocument();
750
- expect(screen.getByText("Sa")).toBeInTheDocument();
751
- });
752
-
753
- it("should select a new date from the calendar", () => {
754
- render(
755
- <DatePicker
756
- id="datePicker"
757
- labelText="Select the date you want to visit NYPL"
758
- initialDate="08/01/2021"
759
- />
760
- );
761
- const input = screen.getByLabelText(
762
- /Select the date you want to visit NYPL/i
763
- );
764
- const date = "2021-08-01";
765
- const midMonthDay = "15";
766
-
767
- expect(screen.getByDisplayValue(date)).toBeInTheDocument();
768
-
769
- // Let's select a new day.
770
- userEvent.click(input);
771
- // The popup displays.
772
- userEvent.click(screen.getByText(midMonthDay));
773
-
774
- // We selected a new day but kept everything else the same. So we just
775
- // need to remove the older day with the new "15" selected date.
776
- // Example: 2021-08-01 -> 15 is selected -> 2021-08-15
777
- const newDayValue = date.slice(0, -2) + midMonthDay;
778
- expect(screen.getByDisplayValue(newDayValue)).toBeInTheDocument();
779
-
780
- // Let's select a new month
781
- userEvent.click(input);
782
- // The popup displays. We are currently on 08/15/2021.
783
- expect(
784
- screen.getByText(monthArray["7"], { exact: false })
785
- ).toBeInTheDocument();
786
- userEvent.click(screen.getByLabelText("Next Month"));
787
- userEvent.click(screen.getByLabelText("Next Month"));
788
-
789
- // We are two months ahead but still selecting the midmonth day.
790
- userEvent.click(screen.getByText(midMonthDay));
791
- // So only the month should change accordingly.
792
- const newMonthValue = `${newDayValue.substr(0, 5)}${strPad(
793
- 10
794
- )}${newDayValue.substr(7)}`;
795
- expect(screen.getByDisplayValue(newMonthValue)).toBeInTheDocument();
796
- });
797
-
798
- it("should render a popup calendar for the month date", () => {
799
- render(
800
- <DatePicker
801
- id="datePicker"
802
- dateType="month"
803
- labelText="Select the month you want to visit NYPL"
804
- />
805
- );
806
- const input = screen.getByLabelText(
807
- /Select the month you want to visit NYPL/i
808
- );
809
- const [year] = getTodaysValues();
810
-
811
- expect(screen.queryByText(year)).not.toBeInTheDocument();
812
- expect(screen.queryByText("Jan")).not.toBeInTheDocument();
813
-
814
- userEvent.click(input);
815
-
816
- // In the display, the calendar displays "Year" such as "2021".
817
- expect(screen.getByText(year)).toBeInTheDocument();
818
- // This calendar displays all 12 months but only the first three
819
- // characters such as "Jan", "Feb", and so on.
820
- monthArray.forEach((month) => {
821
- expect(screen.getByText(month.slice(0, 3))).toBeInTheDocument();
822
- });
823
- });
824
-
825
- it("should select a new month from the calendar", () => {
826
- render(
827
- <DatePicker
828
- id="datePicker"
829
- dateType="month"
830
- initialDate="4/1/1988"
831
- labelText="Select the month you want to visit NYPL"
832
- />
833
- );
834
- const input = screen.getByLabelText(
835
- /Select the month you want to visit NYPL/i
836
- );
837
- // In the "month" format.
838
- const date = "04-1988";
839
- // Let's select May as the new month.
840
- let currentMonthSelected = monthArray[4];
841
- let currentMonthSelectedDisplay = currentMonthSelected.slice(0, 3);
842
-
843
- // We start off with April being displayed as "4-1988".
844
- expect(screen.getByDisplayValue(date)).toBeInTheDocument();
845
- expect(
846
- screen.queryByText(currentMonthSelectedDisplay)
847
- ).not.toBeInTheDocument();
848
-
849
- // Let's select a new day by first clicking on the input to open
850
- // the calendar popup.
851
- userEvent.click(input);
852
-
853
- // Now "May" appears as the next month in the calendar popup.
854
- expect(screen.getByText(currentMonthSelectedDisplay)).toBeInTheDocument();
855
-
856
- userEvent.click(screen.getByText(currentMonthSelectedDisplay));
857
-
858
- // We selected a new month but kept the year the same.
859
- // Example: 04-2021 -> "May" -> 05-2021
860
- expect(
861
- screen.getByDisplayValue(`05-${date.substr(3)}`)
862
- ).toBeInTheDocument();
863
- });
864
-
865
- it("should render a popup calendar for the year date", () => {
866
- render(
867
- <DatePicker
868
- id="datePicker"
869
- dateType="year"
870
- labelText="Select the year you want to visit NYPL"
871
- />
872
- );
873
- const input = screen.getByLabelText(
874
- /Select the year you want to visit NYPL/i
875
- );
876
- const mockYear = 2021;
877
-
878
- expect(
879
- screen.queryByText(
880
- `${(mockYear as any) - 4} - ${(mockYear as any) + 7}`
881
- )
882
- ).not.toBeInTheDocument();
883
-
884
- userEvent.click(input);
885
-
886
- // In the display, the calendar displays a date range from four years
887
- // before the current year to seven years after the current year. For year
888
- // 2021, it will display 2017 - 2028.
889
- expect(
890
- screen.getByText(`${(mockYear as any) - 4} - ${(mockYear as any) + 7}`)
891
- ).toBeInTheDocument();
892
- // This calendar displays 12 years to select from.
893
- // It should display the four previous years from the current year.
894
- for (let i = 4; i > 0; i--) {
895
- expect(screen.getByText((mockYear as any) - i)).toBeInTheDocument();
896
- }
897
- // It should display the eight next years from the current year.
898
- for (let i = 0; i < 8; i++) {
899
- expect(screen.getByText((mockYear as any) + i)).toBeInTheDocument();
900
- }
901
- });
902
-
903
- it("should select a new year from the calendar", () => {
904
- render(
905
- <DatePicker
906
- id="datePicker"
907
- dateType="year"
908
- labelText="Select the year you want to visit NYPL"
909
- />
910
- );
911
- const input = screen.getByLabelText(
912
- /Select the year you want to visit NYPL/i
913
- );
914
- const [year] = getTodaysValues();
915
-
916
- expect(screen.getByDisplayValue(year)).toBeInTheDocument();
917
-
918
- // Let's select a new day.
919
- userEvent.click(input);
920
- // The popup displays.
921
-
922
- // Select a new year
923
- userEvent.click(screen.getByText("2024"));
924
-
925
- expect(screen.getByDisplayValue("2024")).toBeInTheDocument();
926
- });
927
-
928
- it("logs a warning when there is no `id` passed", () => {
929
- const warn = jest.spyOn(console, "warn");
930
- render(
931
- // @ts-ignore: Typescript complains when a required prop is not passed, but
932
- // here we don't want to pass the required prop to make sure the warning appears.
933
- <DatePicker labelText="Select the year you want to visit NYPL" />
934
- );
935
- expect(warn).toHaveBeenCalledWith(
936
- "NYPL Reservoir DatePicker: This component's required `id` prop was not passed."
937
- );
938
- });
939
- });
940
- });