@nypl/design-system-react-components 0.25.0 → 0.25.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.
Files changed (236) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/components/Accordion/Accordion.d.ts +14 -14
  3. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +11 -14
  4. package/dist/components/Breadcrumbs/BreadcrumbsTypes.d.ts +6 -0
  5. package/dist/components/Button/ButtonTypes.d.ts +2 -1
  6. package/dist/components/Card/Card.d.ts +1 -1
  7. package/dist/components/Card/CardTypes.d.ts +2 -2
  8. package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +43 -0
  9. package/dist/components/CheckboxGroup/CheckboxGroupLayoutTypes.d.ts +4 -0
  10. package/dist/components/DatePicker/DatePicker.d.ts +3 -3
  11. package/dist/components/Form/Form.d.ts +13 -8
  12. package/dist/components/Form/FormTypes.d.ts +2 -8
  13. package/dist/components/Grid/GridTypes.d.ts +9 -0
  14. package/dist/components/Grid/SimpleGrid.d.ts +14 -0
  15. package/dist/components/Heading/Heading.d.ts +4 -4
  16. package/dist/components/Hero/Hero.d.ts +19 -14
  17. package/dist/components/Hero/HeroTypes.d.ts +10 -5
  18. package/dist/components/Icons/Icon.d.ts +13 -16
  19. package/dist/components/Icons/IconTypes.d.ts +78 -64
  20. package/dist/components/Label/Label.d.ts +5 -17
  21. package/dist/components/Link/Link.d.ts +8 -12
  22. package/dist/components/SearchBar/SearchBar.d.ts +45 -27
  23. package/dist/components/Select/Select.d.ts +32 -35
  24. package/dist/components/Select/SelectTypes.d.ts +4 -0
  25. package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +1 -1
  26. package/dist/components/SkeletonLoader/SkeletonLoaderTypes.d.ts +2 -2
  27. package/dist/components/StatusBadge/StatusBadge.d.ts +8 -6
  28. package/dist/components/StatusBadge/StatusBadgeTypes.d.ts +5 -0
  29. package/dist/components/Template/Template.d.ts +91 -0
  30. package/dist/components/Text/Text.d.ts +16 -0
  31. package/dist/components/Text/TextTypes.d.ts +6 -0
  32. package/dist/components/TextInput/TextInput.d.ts +32 -31
  33. package/dist/components/TextInput/TextInputTypes.d.ts +5 -0
  34. package/dist/design-system-react-components.cjs.development.js +2597 -1170
  35. package/dist/design-system-react-components.cjs.development.js.map +1 -1
  36. package/dist/design-system-react-components.cjs.production.min.js +1 -1
  37. package/dist/design-system-react-components.cjs.production.min.js.map +1 -1
  38. package/dist/design-system-react-components.esm.js +2580 -1173
  39. package/dist/design-system-react-components.esm.js.map +1 -1
  40. package/dist/index.d.ts +8 -1
  41. package/dist/styles.css +1 -1
  42. package/dist/theme/components/accordion.d.ts +25 -0
  43. package/dist/theme/components/breadcrumb.d.ts +90 -0
  44. package/dist/theme/components/button.d.ts +17 -7
  45. package/dist/theme/components/checkbox.d.ts +7 -7
  46. package/dist/theme/components/customCheckboxGroup.d.ts +18 -0
  47. package/dist/theme/components/customRadioGroup.d.ts +4 -3
  48. package/dist/theme/components/global.d.ts +55 -0
  49. package/dist/theme/components/globalMixins.d.ts +15 -0
  50. package/dist/theme/components/heading.d.ts +50 -20
  51. package/dist/theme/components/hero.d.ts +492 -0
  52. package/dist/theme/components/icon.d.ts +13 -0
  53. package/dist/theme/components/label.d.ts +16 -0
  54. package/dist/theme/components/link.d.ts +45 -0
  55. package/dist/theme/components/radio.d.ts +8 -7
  56. package/dist/theme/components/searchBar.d.ts +20 -0
  57. package/dist/theme/components/select.d.ts +58 -0
  58. package/dist/theme/components/statusBadge.d.ts +25 -0
  59. package/dist/theme/components/tabs.d.ts +9 -9
  60. package/dist/theme/components/template.d.ts +105 -0
  61. package/dist/theme/components/text.d.ts +20 -0
  62. package/dist/theme/components/textInput.d.ts +105 -0
  63. package/dist/theme/foundations/global.d.ts +3 -0
  64. package/dist/theme/foundations/shadows.d.ts +4 -0
  65. package/dist/utils/utils.d.ts +6 -0
  66. package/package.json +3 -2
  67. package/src/components/Accordion/Accordion.stories.mdx +227 -33
  68. package/src/components/Accordion/Accordion.test.tsx +135 -19
  69. package/src/components/Accordion/Accordion.tsx +81 -56
  70. package/src/components/Autosuggest/Autosuggest.stories.mdx +1 -1
  71. package/src/components/Autosuggest/Autosuggest.stories.tsx +1 -1
  72. package/src/components/Autosuggest/_Autosuggest.scss +2 -2
  73. package/src/components/Breadcrumbs/Breadcrumbs.stories.mdx +46 -52
  74. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +31 -25
  75. package/src/components/Breadcrumbs/Breadcrumbs.tsx +71 -73
  76. package/src/components/Breadcrumbs/BreadcrumbsTypes.tsx +6 -0
  77. package/src/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.tsx.snap +100 -0
  78. package/src/components/Button/Button.stories.mdx +31 -27
  79. package/src/components/Button/Button.test.tsx +17 -5
  80. package/src/components/Button/ButtonTypes.tsx +1 -0
  81. package/src/components/Button/_Button.scss +3 -27
  82. package/src/components/Button/__snapshots__/Button.test.tsx.snap +11 -0
  83. package/src/components/Card/Card.stories.mdx +24 -20
  84. package/src/components/Card/Card.test.tsx +13 -19
  85. package/src/components/Card/Card.tsx +1 -1
  86. package/src/components/Card/CardTypes.tsx +2 -2
  87. package/src/components/Card/_Card.scss +1 -1
  88. package/src/components/CardEdition/CardEdition.stories.tsx +11 -6
  89. package/src/components/CardEdition/CardEdition.test.tsx +23 -31
  90. package/src/components/CardEdition/_CardEdition.scss +2 -2
  91. package/src/components/Chakra/Center.stories.mdx +31 -14
  92. package/src/components/Chakra/Grid.stories.mdx +79 -0
  93. package/src/components/Chakra/Stack.stories.mdx +4 -4
  94. package/src/components/Checkbox/Checkbox.tsx +9 -12
  95. package/src/components/Checkbox/__snapshots__/Checkbox.test.tsx.snap +2 -5
  96. package/src/components/CheckboxGroup/CheckboxGroup.stories.mdx +249 -0
  97. package/src/components/CheckboxGroup/CheckboxGroup.test.tsx +345 -0
  98. package/src/components/CheckboxGroup/CheckboxGroup.tsx +148 -0
  99. package/src/components/CheckboxGroup/CheckboxGroupLayoutTypes.tsx +4 -0
  100. package/src/components/CheckboxGroup/__snapshots__/CheckboxGroup.test.tsx.snap +1360 -0
  101. package/src/components/DatePicker/DatePicker.test.tsx +4 -4
  102. package/src/components/DatePicker/DatePicker.tsx +13 -13
  103. package/src/components/DatePicker/_DatePicker.scss +1 -0
  104. package/src/components/Form/Form.stories.mdx +46 -21
  105. package/src/components/Form/Form.test.tsx +58 -45
  106. package/src/components/Form/Form.tsx +49 -21
  107. package/src/components/Form/FormTypes.tsx +3 -8
  108. package/src/components/Form/__snapshots__/Form.test.tsx.snap +24 -14
  109. package/src/components/Grid/GridTypes.tsx +9 -0
  110. package/src/components/Grid/SimpleGrid.stories.mdx +275 -0
  111. package/src/components/Grid/SimpleGrid.test.tsx +66 -0
  112. package/src/components/Grid/SimpleGrid.tsx +37 -0
  113. package/src/components/Grid/__snapshots__/SimpleGrid.test.tsx.snap +8 -0
  114. package/src/components/Heading/Heading.stories.mdx +1 -0
  115. package/src/components/Heading/Heading.tsx +12 -6
  116. package/src/components/HelperErrorText/_HelperErrorText.scss +1 -1
  117. package/src/components/Hero/Hero.stories.mdx +188 -121
  118. package/src/components/Hero/Hero.test.tsx +537 -107
  119. package/src/components/Hero/Hero.tsx +79 -92
  120. package/src/components/Hero/HeroTypes.tsx +17 -5
  121. package/src/components/Hero/__snapshots__/Hero.test.tsx.snap +307 -0
  122. package/src/components/HorizontalRule/_HorizontalRule.scss +1 -1
  123. package/src/components/Icons/Icon.stories.mdx +83 -74
  124. package/src/components/Icons/Icon.test.tsx +30 -22
  125. package/src/components/Icons/Icon.tsx +63 -61
  126. package/src/components/Icons/IconTypes.tsx +80 -64
  127. package/src/components/Input/_Input.scss +2 -2
  128. package/src/components/Label/Label.stories.mdx +28 -7
  129. package/src/components/Label/Label.test.tsx +43 -12
  130. package/src/components/Label/Label.tsx +21 -34
  131. package/src/components/Label/__snapshots__/Label.test.tsx.snap +41 -0
  132. package/src/components/Link/Link.stories.mdx +41 -41
  133. package/src/components/Link/Link.test.tsx +33 -44
  134. package/src/components/Link/Link.tsx +114 -100
  135. package/src/components/List/List.stories.mdx +0 -2
  136. package/src/components/List/List.stories.tsx +5 -5
  137. package/src/components/List/_List.scss +3 -3
  138. package/src/components/Modal/_Modal.scss +1 -1
  139. package/src/components/Notification/Notification.stories.mdx +12 -1
  140. package/src/components/Notification/Notification.test.tsx +3 -16
  141. package/src/components/Notification/Notification.tsx +9 -10
  142. package/src/components/Notification/_Notification.scss +4 -4
  143. package/src/components/Pagination/Pagination.test.tsx +16 -10
  144. package/src/components/RadioGroup/RadioGroup.stories.mdx +1 -1
  145. package/src/components/RadioGroup/RadioGroup.tsx +2 -10
  146. package/src/components/SearchBar/SearchBar.Test.tsx +151 -16
  147. package/src/components/SearchBar/SearchBar.stories.mdx +189 -219
  148. package/src/components/SearchBar/SearchBar.tsx +151 -46
  149. package/src/components/Select/Select.stories.mdx +188 -170
  150. package/src/components/Select/Select.test.tsx +125 -380
  151. package/src/components/Select/Select.tsx +118 -165
  152. package/src/components/Select/SelectTypes.tsx +4 -0
  153. package/src/components/SkeletonLoader/SkeletonLoader.stories.mdx +13 -25
  154. package/src/components/SkeletonLoader/SkeletonLoader.test.tsx +7 -7
  155. package/src/components/SkeletonLoader/SkeletonLoader.tsx +4 -2
  156. package/src/components/SkeletonLoader/SkeletonLoaderTypes.tsx +2 -2
  157. package/src/components/SkeletonLoader/_SkeletonLoader.scss +3 -3
  158. package/src/components/StatusBadge/StatusBadge.stories.mdx +91 -0
  159. package/src/components/StatusBadge/StatusBadge.test.tsx +35 -7
  160. package/src/components/StatusBadge/StatusBadge.tsx +24 -25
  161. package/src/components/StatusBadge/StatusBadgeTypes.tsx +5 -0
  162. package/src/components/StatusBadge/__snapshots__/StatusBadge.test.tsx.snap +28 -0
  163. package/src/components/StyleGuide/Bidirectionality.stories.mdx +16 -16
  164. package/src/components/StyleGuide/Buttons.stories.mdx +15 -15
  165. package/src/components/StyleGuide/Colors.stories.mdx +336 -0
  166. package/src/components/StyleGuide/Iconography.stories.mdx +88 -90
  167. package/src/components/StyleGuide/UIDocCard.tsx +1 -1
  168. package/src/components/Tabs/Tabs.tsx +7 -9
  169. package/src/components/Template/Template.stories.mdx +574 -0
  170. package/src/components/Template/Template.test.tsx +124 -0
  171. package/src/components/Template/Template.tsx +226 -0
  172. package/src/components/Text/Text.stories.mdx +70 -0
  173. package/src/components/Text/Text.test.tsx +63 -0
  174. package/src/components/Text/Text.tsx +55 -0
  175. package/src/components/Text/TextTypes.tsx +6 -0
  176. package/src/components/Text/__snapshots__/Text.test.tsx.snap +33 -0
  177. package/src/components/TextInput/TextInput.stories.mdx +89 -90
  178. package/src/components/TextInput/TextInput.test.tsx +65 -86
  179. package/src/components/TextInput/TextInput.tsx +101 -95
  180. package/src/components/TextInput/TextInputTypes.tsx +6 -0
  181. package/src/components/VideoPlayer/_VideoPlayer.scss +1 -1
  182. package/src/docs/Chakra.stories.mdx +4 -4
  183. package/src/docs/Intro.stories.mdx +15 -13
  184. package/src/index.ts +20 -0
  185. package/src/styles/01-colors/_colors-brand.scss +6 -0
  186. package/src/styles/01-colors/_colors-utility.scss +14 -12
  187. package/src/styles/base/_04-base.scss +2 -1
  188. package/src/styles/base/_place-holder.scss +1 -1
  189. package/src/styles.scss +10 -12
  190. package/src/theme/components/accordion.ts +30 -0
  191. package/src/theme/components/breadcrumb.ts +77 -0
  192. package/src/theme/components/button.ts +77 -63
  193. package/src/theme/components/checkbox.ts +15 -27
  194. package/src/theme/components/customCheckboxGroup.ts +12 -0
  195. package/src/theme/components/customRadioGroup.ts +4 -10
  196. package/src/theme/components/global.ts +71 -0
  197. package/src/theme/components/globalMixins.ts +16 -0
  198. package/src/theme/components/heading.ts +15 -8
  199. package/src/theme/components/hero.ts +239 -0
  200. package/src/theme/components/icon.ts +79 -0
  201. package/src/theme/components/label.ts +17 -0
  202. package/src/theme/components/link.ts +47 -0
  203. package/src/theme/components/radio.ts +20 -31
  204. package/src/theme/components/searchBar.ts +21 -0
  205. package/src/theme/components/select.ts +50 -0
  206. package/src/theme/components/statusBadge.ts +27 -0
  207. package/src/theme/components/tabs.ts +72 -69
  208. package/src/theme/components/template.ts +114 -0
  209. package/src/theme/components/text.ts +31 -0
  210. package/src/theme/components/textInput.ts +61 -0
  211. package/src/theme/foundations/colors.ts +29 -13
  212. package/src/theme/foundations/global.ts +3 -0
  213. package/src/theme/foundations/shadows.ts +5 -0
  214. package/src/theme/index.ts +37 -7
  215. package/src/utils/componentCategories.ts +8 -2
  216. package/src/utils/utils.ts +13 -0
  217. package/dist/components/Accordion/Accordion.stories.d.ts +0 -6
  218. package/dist/components/StatusBadge/StatusBadge.stories.d.ts +0 -8
  219. package/dist/components/StyleGuide/Colors.stories.d.ts +0 -25
  220. package/dist/components/Template/Template.stories.d.ts +0 -30
  221. package/src/components/Accordion/Accordion.stories.tsx +0 -66
  222. package/src/components/Accordion/_Accordion.scss +0 -81
  223. package/src/components/Breadcrumbs/_Breadcrumbs.scss +0 -97
  224. package/src/components/Form/_Form.scss +0 -67
  225. package/src/components/Hero/_Hero.scss +0 -256
  226. package/src/components/Icons/_Icons.scss +0 -116
  227. package/src/components/Label/_Label.scss +0 -22
  228. package/src/components/Link/_Link.scss +0 -73
  229. package/src/components/SearchBar/_SearchBar.scss +0 -16
  230. package/src/components/Select/_Select.scss +0 -82
  231. package/src/components/StatusBadge/StatusBadge.stories.tsx +0 -34
  232. package/src/components/StatusBadge/_StatusBadge.scss +0 -23
  233. package/src/components/StyleGuide/Colors.stories.tsx +0 -289
  234. package/src/components/Template/Template.stories.tsx +0 -86
  235. package/src/components/Template/_Template.scss +0 -63
  236. package/src/components/TextInput/_TextInput.scss +0 -59
@@ -1,6 +1,7 @@
1
1
  import * as React from "react";
2
- import { render } from "@testing-library/react";
2
+ import { render, screen } from "@testing-library/react";
3
3
  import { axe } from "jest-axe";
4
+ import renderer from "react-test-renderer";
4
5
 
5
6
  import Image from "../Image/Image";
6
7
  import Heading from "../Heading/Heading";
@@ -8,27 +9,108 @@ import { HeadingLevels } from "../Heading/HeadingTypes";
8
9
  import { HeroTypes } from "./HeroTypes";
9
10
  import Hero from "./Hero";
10
11
 
11
- describe("Hero Component", () => {
12
- it("passes axe accessibility test", async () => {
13
- const { container } = render(
14
- <Hero
15
- heroType={HeroTypes.Primary}
16
- heading={
17
- <Heading
18
- level={HeadingLevels.One}
19
- id="a11y-hero"
20
- text="Hero Primary"
21
- blockName="hero"
22
- />
23
- }
24
- backgroundImageSrc="https://placeimg.com/1600/800/arch"
25
- />
26
- );
27
- expect(await axe(container)).toHaveNoViolations();
12
+ export const subHeaderText = (
13
+ <>
14
+ Explore our collection of hundreds of online resources and databases. Use
15
+ our free online content to help with your research, whether it's finding a
16
+ single article, tracing a family tree, learning a new language, or anything
17
+ in between.
18
+ </>
19
+ );
20
+ export const otherSubHeaderText =
21
+ "With 92 locations across the Bronx, Manhattan, and Staten Island, The New York Public Library is an essential part of neighborhoods across the city. Visit us today.";
22
+ export const image = (
23
+ <Image src="https://placeimg.com/800/400/animals" alt="Image example" />
24
+ );
25
+
26
+ describe("Hero", () => {
27
+ describe("axe accessbility tests", () => {
28
+ it("passes for type Primary", async () => {
29
+ const { container } = render(
30
+ <Hero
31
+ heroType={HeroTypes.Primary}
32
+ heading={
33
+ <Heading
34
+ level={HeadingLevels.One}
35
+ id="a11y-hero"
36
+ text="Hero Primary"
37
+ />
38
+ }
39
+ subHeaderText="Example Subtitle"
40
+ backgroundImageSrc="https://placeimg.com/1600/800/arch"
41
+ />
42
+ );
43
+ expect(await axe(container)).toHaveNoViolations();
44
+ });
45
+
46
+ it("passes for type Secondary", async () => {
47
+ const { container } = render(
48
+ <Hero
49
+ heroType={HeroTypes.Secondary}
50
+ heading={
51
+ <Heading
52
+ level={HeadingLevels.One}
53
+ id="a11y-hero"
54
+ text="Hero Secondary"
55
+ />
56
+ }
57
+ subHeaderText={subHeaderText}
58
+ image={image}
59
+ />
60
+ );
61
+ expect(await axe(container)).toHaveNoViolations();
62
+ });
63
+
64
+ it("passes for type Tertiary", async () => {
65
+ const { container } = render(
66
+ <Hero
67
+ heroType={HeroTypes.Tertiary}
68
+ heading={
69
+ <Heading
70
+ level={HeadingLevels.One}
71
+ id="a11y-hero"
72
+ text="Hero Tertiary"
73
+ />
74
+ }
75
+ subHeaderText={otherSubHeaderText}
76
+ />
77
+ );
78
+ expect(await axe(container)).toHaveNoViolations();
79
+ });
80
+
81
+ it("passes for type Campaign", async () => {
82
+ const { container } = render(
83
+ <Hero
84
+ heroType={HeroTypes.Campaign}
85
+ heading={
86
+ <Heading
87
+ level={HeadingLevels.One}
88
+ id="a11y-hero"
89
+ text="Hero Campaign"
90
+ />
91
+ }
92
+ subHeaderText={otherSubHeaderText}
93
+ backgroundImageSrc="https://placeimg.com/2400/800/nature/grayscale"
94
+ image={image}
95
+ />
96
+ );
97
+ expect(await axe(container)).toHaveNoViolations();
98
+ });
99
+
100
+ it("passes for type FiftyFifty", async () => {
101
+ const { container } = render(
102
+ <Hero
103
+ heroType={HeroTypes.FiftyFifty}
104
+ subHeaderText={otherSubHeaderText}
105
+ image={image}
106
+ />
107
+ );
108
+ expect(await axe(container)).toHaveNoViolations();
109
+ });
28
110
  });
29
111
 
30
- it("renders Primary Hero with background image", () => {
31
- const utils = render(
112
+ it("renders Primary Hero", () => {
113
+ render(
32
114
  <Hero
33
115
  heroType={HeroTypes.Primary}
34
116
  heading={
@@ -36,21 +118,23 @@ describe("Hero Component", () => {
36
118
  level={HeadingLevels.One}
37
119
  id="primary-hero"
38
120
  text="Hero Primary"
39
- blockName="hero"
40
121
  />
41
122
  }
123
+ subHeaderText="Example Subtitle"
42
124
  backgroundImageSrc="https://placeimg.com/1600/800/arch"
43
125
  />
44
126
  );
45
- expect(utils.container.querySelector(".hero--primary")).toBeInTheDocument();
46
- expect(utils.container.querySelector(".hero")).toHaveAttribute(
127
+
128
+ expect(screen.getByText("Hero Primary")).toBeInTheDocument();
129
+ expect(screen.getByText("Example Subtitle")).toBeInTheDocument();
130
+ expect(screen.getByTestId("hero")).toHaveAttribute(
47
131
  "style",
48
132
  "background-image: url(https://placeimg.com/1600/800/arch);"
49
133
  );
50
134
  });
51
135
 
52
- it("renders Secondary Hero with foreground image", () => {
53
- const utils = render(
136
+ it("renders Secondary Hero", () => {
137
+ render(
54
138
  <Hero
55
139
  heroType={HeroTypes.Secondary}
56
140
  heading={
@@ -58,29 +142,24 @@ describe("Hero Component", () => {
58
142
  level={HeadingLevels.One}
59
143
  id="secondary-hero"
60
144
  text="Hero Secondary"
61
- blockName="hero"
62
- />
63
- }
64
- image={
65
- <Image
66
- src="https://placeimg.com/800/400/arch"
67
- blockName="hero"
68
- alt="Image alt text."
69
145
  />
70
146
  }
147
+ subHeaderText={subHeaderText}
148
+ image={image}
71
149
  />
72
150
  );
73
- expect(
74
- utils.container.querySelector(".hero--secondary")
75
- ).toBeInTheDocument();
76
- expect(utils.container.querySelector(".hero__image ")).toHaveAttribute(
151
+
152
+ expect(screen.getByText("Hero Secondary")).toBeInTheDocument();
153
+ expect(screen.getByText(/Explore our collection of/i)).toBeInTheDocument();
154
+ expect(screen.getByRole("img")).toBeInTheDocument();
155
+ expect(screen.getByRole("img")).toHaveAttribute(
77
156
  "src",
78
- "https://placeimg.com/800/400/arch"
157
+ "https://placeimg.com/800/400/animals"
79
158
  );
80
159
  });
81
160
 
82
- it("renders Tertiary Hero without any images", () => {
83
- const utils = render(
161
+ it("renders Tertiary Hero", () => {
162
+ render(
84
163
  <Hero
85
164
  heroType={HeroTypes.Tertiary}
86
165
  heading={
@@ -88,95 +167,73 @@ describe("Hero Component", () => {
88
167
  level={HeadingLevels.One}
89
168
  id="tertiary-hero"
90
169
  text="Hero Tertiary"
91
- blockName="hero"
92
170
  />
93
171
  }
172
+ subHeaderText={otherSubHeaderText}
94
173
  />
95
174
  );
96
- expect(
97
- utils.container.querySelector(".hero--tertiary")
98
- ).toBeInTheDocument();
99
- expect(
100
- utils.container.querySelector(".hero--tertiary")
101
- ).not.toHaveAttribute("style");
102
- expect(
103
- utils.container.querySelector(".hero__image ")
104
- ).not.toBeInTheDocument();
175
+
176
+ expect(screen.getByText("Hero Tertiary")).toBeInTheDocument();
177
+ expect(screen.getByText(/With 92 locations across/i)).toBeInTheDocument();
178
+ expect(screen.queryByRole("img")).not.toBeInTheDocument();
105
179
  });
106
180
 
107
- it("renders Fifty-Fifty Hero with foreground image", () => {
108
- const utils = render(
181
+ it("renders Campaign Hero", () => {
182
+ render(
109
183
  <Hero
110
- heroType={HeroTypes.FiftyFifty}
184
+ heroType={HeroTypes.Campaign}
111
185
  heading={
112
186
  <Heading
113
187
  level={HeadingLevels.One}
114
- id="fifty-fifty-hero"
115
- text="Hero Fifty-Fifty"
116
- blockName="hero"
117
- />
118
- }
119
- image={
120
- <Image
121
- src="https://placeimg.com/600/200/arch"
122
- blockName="hero"
123
- alt="Image alt text."
188
+ id="campaign-hero"
189
+ text="Hero Campaign"
124
190
  />
125
191
  }
192
+ subHeaderText={otherSubHeaderText}
193
+ backgroundImageSrc="https://placeimg.com/2400/800/nature/grayscale"
194
+ image={image}
126
195
  />
127
196
  );
128
- expect(utils.container.querySelector(".hero--50-50")).toBeInTheDocument();
129
- expect(utils.container.querySelector(".hero__image ")).toHaveAttribute(
197
+
198
+ expect(screen.getByText("Hero Campaign")).toBeInTheDocument();
199
+ expect(screen.getByText(/With 92 locations across/i)).toBeInTheDocument();
200
+ expect(screen.getByTestId("hero")).toHaveAttribute(
201
+ "style",
202
+ "background-image: url(https://placeimg.com/2400/800/nature/grayscale);"
203
+ );
204
+ expect(screen.getByRole("img")).toBeInTheDocument();
205
+ expect(screen.getByRole("img")).toHaveAttribute(
130
206
  "src",
131
- "https://placeimg.com/600/200/arch"
207
+ "https://placeimg.com/800/400/animals"
132
208
  );
133
209
  });
134
210
 
135
- it("renders Campaign Hero with background and foreground images", () => {
136
- const utils = render(
211
+ it("renders Fifty-Fifty Hero", () => {
212
+ render(
137
213
  <Hero
138
- heroType={HeroTypes.Campaign}
139
- heading={
140
- <Heading
141
- level={HeadingLevels.One}
142
- id="campaign-hero"
143
- text="Hero campaign"
144
- blockName="hero"
145
- />
146
- }
147
- backgroundImageSrc="https://placeimg.com/1600/800/arch"
148
- image={
149
- <Image
150
- src="https://placeimg.com/800/400/arch"
151
- blockName="hero"
152
- alt="Image alt text."
153
- />
154
- }
214
+ heroType={HeroTypes.FiftyFifty}
215
+ subHeaderText={otherSubHeaderText}
216
+ image={image}
155
217
  />
156
218
  );
157
- expect(
158
- utils.container.querySelector(".hero--campaign")
159
- ).toBeInTheDocument();
160
- expect(utils.container.querySelector(".hero")).toHaveAttribute(
161
- "style",
162
- "background-image: url(https://placeimg.com/1600/800/arch);"
163
- );
164
- expect(utils.container.querySelector(".hero__image ")).toHaveAttribute(
219
+
220
+ expect(screen.getByText(/With 92 locations across/i)).toBeInTheDocument();
221
+ expect(screen.getByRole("img")).toBeInTheDocument();
222
+ expect(screen.getByRole("img")).toHaveAttribute(
165
223
  "src",
166
- "https://placeimg.com/800/400/arch"
224
+ "https://placeimg.com/800/400/animals"
167
225
  );
168
226
  });
169
227
 
170
- it("renders custom background and foreground colors", () => {
171
- const utils = render(
228
+ it("renders custom background and foreground colors for all but the Secondary type", () => {
229
+ const { rerender } = render(
172
230
  <Hero
173
231
  heroType={HeroTypes.Primary}
174
232
  heading={
175
233
  <Heading
176
234
  level={HeadingLevels.One}
177
235
  id="custom-colors-hero"
178
- text="Hero with Cusotm Colors"
179
- blockName="hero"
236
+ text="Hero with Custom Colors"
180
237
  />
181
238
  }
182
239
  backgroundImageSrc="https://placeimg.com/1600/800/arch"
@@ -184,26 +241,399 @@ describe("Hero Component", () => {
184
241
  backgroundColor="#654321"
185
242
  />
186
243
  );
187
- expect(utils.container.querySelector(".hero__content")).toHaveAttribute(
244
+
245
+ expect(screen.getByTestId("hero-content")).toHaveAttribute(
188
246
  "style",
189
247
  "color: rgb(18, 52, 86); background-color: rgb(101, 67, 33);"
190
248
  );
191
- });
192
249
 
193
- it("renders Hero with warnings in browser console", () => {
194
- const utils = render(
250
+ rerender(
195
251
  <Hero
196
- heroType={HeroTypes.Primary}
252
+ heroType={HeroTypes.FiftyFifty}
253
+ subHeaderText={otherSubHeaderText}
254
+ image={image}
255
+ foregroundColor="#123456"
256
+ backgroundColor="#654321"
257
+ />
258
+ );
259
+
260
+ expect(screen.getByTestId("hero-content")).toHaveAttribute(
261
+ "style",
262
+ "color: rgb(18, 52, 86); background-color: rgb(101, 67, 33);"
263
+ );
264
+
265
+ rerender(
266
+ <Hero
267
+ heroType={HeroTypes.Secondary}
197
268
  heading={
198
269
  <Heading
199
270
  level={HeadingLevels.One}
200
- id="hero-errors"
201
- text="Hero with Error Warnings"
202
- blockName="hero"
271
+ id="secondary-hero"
272
+ text="Hero Secondary"
203
273
  />
204
274
  }
275
+ subHeaderText={subHeaderText}
276
+ image={image}
277
+ foregroundColor="#123456"
278
+ backgroundColor="#654321"
279
+ />
280
+ );
281
+
282
+ expect(screen.getByTestId("hero-content")).not.toHaveAttribute(
283
+ "style",
284
+ "color: rgb(18, 52, 86); background-color: rgb(101, 67, 33);"
285
+ );
286
+ });
287
+
288
+ it("renders Primary Hero with warnings in browser console", () => {
289
+ const warn = jest.spyOn(console, "warn");
290
+ const heading = (
291
+ <Heading
292
+ level={HeadingLevels.One}
293
+ id="hero-errors"
294
+ text="Hero with Error Warnings"
295
+ />
296
+ );
297
+ const { rerender } = render(
298
+ <Hero heroType={HeroTypes.Primary} heading={heading} />
299
+ );
300
+ expect(warn).toHaveBeenCalledWith(
301
+ `Warning: it is recommended to use the "backgroundImageSrc" prop for PRIMARY hero.`
302
+ );
303
+
304
+ rerender(
305
+ <Hero
306
+ heroType={HeroTypes.Primary}
307
+ heading={heading}
308
+ backgroundImageSrc="https://placeimg.com/1600/800/arch"
309
+ image={image}
205
310
  />
206
311
  );
207
- expect(utils.container.querySelector(".hero--warning")).toBeInTheDocument();
312
+ expect(warn).toHaveBeenCalledWith(
313
+ `Warning: the "image" prop has been passed, but PRIMARY hero will not use it.`
314
+ );
315
+ });
316
+
317
+ it("renders Secondary Hero with warnings in browser console", () => {
318
+ const warn = jest.spyOn(console, "warn");
319
+ const heading = (
320
+ <Heading
321
+ level={HeadingLevels.One}
322
+ id="hero-errors"
323
+ text="Hero with Error Warnings"
324
+ />
325
+ );
326
+ const { rerender } = render(
327
+ <Hero
328
+ heroType={HeroTypes.Secondary}
329
+ heading={heading}
330
+ subHeaderText={subHeaderText}
331
+ image={image}
332
+ locationDetails={<>Some location details.</>}
333
+ />
334
+ );
335
+ expect(warn).toHaveBeenCalledWith(
336
+ `Warning: Please provide "locationDetails" only to PRIMARY hero.`
337
+ );
338
+
339
+ rerender(
340
+ <Hero
341
+ heroType={HeroTypes.Secondary}
342
+ heading={heading}
343
+ subHeaderText={subHeaderText}
344
+ image={image}
345
+ backgroundImageSrc="https://placeimg.com/1600/800/arch"
346
+ />
347
+ );
348
+ expect(warn).toHaveBeenCalledWith(
349
+ `Warning: the "backgroundImageSrc" prop has been passed, but SECONDARY hero will not use it.`
350
+ );
351
+
352
+ rerender(
353
+ <Hero
354
+ heroType={HeroTypes.Secondary}
355
+ heading={heading}
356
+ subHeaderText={subHeaderText}
357
+ image={image}
358
+ foregroundColor="#123456"
359
+ backgroundColor="#654321"
360
+ />
361
+ );
362
+ expect(warn).toHaveBeenCalledWith(
363
+ `Warning: the "foregroundColor" and/or "backgroundColor" props have been passed, but SECONDARY Hero will not use them.`
364
+ );
365
+ });
366
+
367
+ it("renders Tertiary Hero with warnings in browser console", () => {
368
+ const warn = jest.spyOn(console, "warn");
369
+ const heading = (
370
+ <Heading
371
+ level={HeadingLevels.One}
372
+ id="hero-errors"
373
+ text="Hero with Error Warnings"
374
+ />
375
+ );
376
+ const { rerender } = render(
377
+ <Hero
378
+ heroType={HeroTypes.Tertiary}
379
+ heading={heading}
380
+ subHeaderText={otherSubHeaderText}
381
+ locationDetails={<>Some location details.</>}
382
+ />
383
+ );
384
+ expect(warn).toHaveBeenCalledWith(
385
+ `Warning: Please provide "locationDetails" only to PRIMARY hero.`
386
+ );
387
+
388
+ rerender(
389
+ <Hero
390
+ heroType={HeroTypes.Tertiary}
391
+ heading={heading}
392
+ subHeaderText={otherSubHeaderText}
393
+ image={image}
394
+ />
395
+ );
396
+ expect(warn).toHaveBeenCalledWith(
397
+ `Warning: TERTIARY hero will not use any of the image props.`
398
+ );
399
+
400
+ rerender(
401
+ <Hero
402
+ heroType={HeroTypes.Tertiary}
403
+ heading={heading}
404
+ subHeaderText={otherSubHeaderText}
405
+ backgroundImageSrc="https://placeimg.com/1600/800/arch"
406
+ />
407
+ );
408
+ expect(warn).toHaveBeenCalledWith(
409
+ `Warning: TERTIARY hero will not use any of the image props.`
410
+ );
411
+ });
412
+
413
+ it("renders Campaign Hero with warnings in browser console", () => {
414
+ const warn = jest.spyOn(console, "warn");
415
+ const heading = (
416
+ <Heading
417
+ level={HeadingLevels.One}
418
+ id="hero-errors"
419
+ text="Hero with Error Warnings"
420
+ />
421
+ );
422
+ const { rerender } = render(
423
+ <Hero
424
+ heroType={HeroTypes.Campaign}
425
+ heading={heading}
426
+ subHeaderText={otherSubHeaderText}
427
+ backgroundImageSrc="https://placeimg.com/2400/800/nature/grayscale"
428
+ image={image}
429
+ locationDetails={<>Some location details.</>}
430
+ />
431
+ );
432
+ expect(warn).toHaveBeenCalledWith(
433
+ `Warning: Please provide "locationDetails" only to PRIMARY hero.`
434
+ );
435
+
436
+ rerender(
437
+ <Hero
438
+ heroType={HeroTypes.Campaign}
439
+ heading={heading}
440
+ subHeaderText={otherSubHeaderText}
441
+ image={image}
442
+ locationDetails={<>Some location details.</>}
443
+ />
444
+ );
445
+ expect(warn).toHaveBeenCalledWith(
446
+ `Warning: it is recommended to use both "backgroundImageSrc" and "image" props for CAMPAIGN hero.`
447
+ );
448
+
449
+ rerender(
450
+ <Hero
451
+ heroType={HeroTypes.Campaign}
452
+ heading={heading}
453
+ subHeaderText={otherSubHeaderText}
454
+ backgroundImageSrc="https://placeimg.com/2400/800/nature/grayscale"
455
+ locationDetails={<>Some location details.</>}
456
+ />
457
+ );
458
+ expect(warn).toHaveBeenCalledWith(
459
+ `Warning: it is recommended to use both "backgroundImageSrc" and "image" props for CAMPAIGN hero.`
460
+ );
461
+ });
462
+
463
+ it("renders FiftyFifty Hero with warnings in browser console", () => {
464
+ const warn = jest.spyOn(console, "warn");
465
+ const { rerender } = render(
466
+ <Hero
467
+ heroType={HeroTypes.FiftyFifty}
468
+ subHeaderText={otherSubHeaderText}
469
+ image={image}
470
+ locationDetails={<>Some location details.</>}
471
+ />
472
+ );
473
+ expect(warn).toHaveBeenCalledWith(
474
+ `Warning: Please provide "locationDetails" only to PRIMARY hero.`
475
+ );
476
+
477
+ rerender(
478
+ <Hero
479
+ heroType={HeroTypes.FiftyFifty}
480
+ subHeaderText={otherSubHeaderText}
481
+ image={image}
482
+ backgroundImageSrc="https://placeimg.com/2400/800/nature/grayscale"
483
+ />
484
+ );
485
+ expect(warn).toHaveBeenCalledWith(
486
+ `Warning: the "backgroundImageSrc" prop has been passed, but FIFTYFIFTY hero will not use it.`
487
+ );
488
+ });
489
+
490
+ it("Renders the UI snapshot correctly", () => {
491
+ const primary = renderer
492
+ .create(
493
+ <Hero
494
+ heroType={HeroTypes.Primary}
495
+ heading={
496
+ <Heading
497
+ level={HeadingLevels.One}
498
+ id="primary-hero"
499
+ text="Hero Primary"
500
+ />
501
+ }
502
+ subHeaderText="Example Subtitle"
503
+ backgroundImageSrc="https://placeimg.com/1600/800/arch"
504
+ />
505
+ )
506
+ .toJSON();
507
+ const secondary = renderer
508
+ .create(
509
+ <Hero
510
+ heroType={HeroTypes.Secondary}
511
+ heading={
512
+ <Heading
513
+ level={HeadingLevels.One}
514
+ id="secondary-hero"
515
+ text="Hero Secondary"
516
+ />
517
+ }
518
+ subHeaderText={subHeaderText}
519
+ image={image}
520
+ />
521
+ )
522
+ .toJSON();
523
+ const secondaryBooksAndMore = renderer
524
+ .create(
525
+ <Hero
526
+ heroType={HeroTypes.SecondaryBooksAndMore}
527
+ heading={
528
+ <Heading
529
+ level={HeadingLevels.One}
530
+ id="secondary-hero"
531
+ text="Hero Secondary Books and More"
532
+ />
533
+ }
534
+ subHeaderText={subHeaderText}
535
+ image={image}
536
+ />
537
+ )
538
+ .toJSON();
539
+ const secondaryLocations = renderer
540
+ .create(
541
+ <Hero
542
+ heroType={HeroTypes.SecondaryLocations}
543
+ heading={
544
+ <Heading
545
+ level={HeadingLevels.One}
546
+ id="secondary-hero"
547
+ text="Hero Secondary Locations"
548
+ />
549
+ }
550
+ subHeaderText={subHeaderText}
551
+ image={image}
552
+ />
553
+ )
554
+ .toJSON();
555
+ const secondaryResearch = renderer
556
+ .create(
557
+ <Hero
558
+ heroType={HeroTypes.SecondaryResearch}
559
+ heading={
560
+ <Heading
561
+ level={HeadingLevels.One}
562
+ id="secondary-hero"
563
+ text="Hero Secondary"
564
+ />
565
+ }
566
+ subHeaderText={subHeaderText}
567
+ image={image}
568
+ />
569
+ )
570
+ .toJSON();
571
+ const secondaryWhatsOn = renderer
572
+ .create(
573
+ <Hero
574
+ heroType={HeroTypes.SecondaryWhatsOn}
575
+ heading={
576
+ <Heading
577
+ level={HeadingLevels.One}
578
+ id="secondary-hero"
579
+ text="Hero Secondary What's On"
580
+ />
581
+ }
582
+ subHeaderText={subHeaderText}
583
+ image={image}
584
+ />
585
+ )
586
+ .toJSON();
587
+ const campaign = renderer
588
+ .create(
589
+ <Hero
590
+ heroType={HeroTypes.Campaign}
591
+ heading={
592
+ <Heading
593
+ level={HeadingLevels.One}
594
+ id="campaign-hero"
595
+ text="Hero Campaign"
596
+ />
597
+ }
598
+ subHeaderText={otherSubHeaderText}
599
+ backgroundImageSrc="https://placeimg.com/2400/800/nature/grayscale"
600
+ image={image}
601
+ />
602
+ )
603
+ .toJSON();
604
+ const tertiary = renderer
605
+ .create(
606
+ <Hero
607
+ heroType={HeroTypes.Tertiary}
608
+ heading={
609
+ <Heading
610
+ level={HeadingLevels.One}
611
+ id="tertiary-hero"
612
+ text="Hero Tertiary"
613
+ />
614
+ }
615
+ subHeaderText={otherSubHeaderText}
616
+ />
617
+ )
618
+ .toJSON();
619
+ const fiftyFifty = renderer
620
+ .create(
621
+ <Hero
622
+ heroType={HeroTypes.FiftyFifty}
623
+ subHeaderText={otherSubHeaderText}
624
+ image={image}
625
+ />
626
+ )
627
+ .toJSON();
628
+
629
+ expect(primary).toMatchSnapshot();
630
+ expect(secondary).toMatchSnapshot();
631
+ expect(secondaryBooksAndMore).toMatchSnapshot();
632
+ expect(secondaryLocations).toMatchSnapshot();
633
+ expect(secondaryResearch).toMatchSnapshot();
634
+ expect(secondaryWhatsOn).toMatchSnapshot();
635
+ expect(tertiary).toMatchSnapshot();
636
+ expect(campaign).toMatchSnapshot();
637
+ expect(fiftyFifty).toMatchSnapshot();
208
638
  });
209
639
  });