@windstream/react-shared-components 0.2.46 → 0.2.47
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/dist/contentful/index.esm.js +1 -1
- package/dist/contentful/index.esm.js.map +1 -1
- package/dist/contentful/index.js +1 -1
- package/dist/contentful/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/components/brand-button/index.tsx +2 -2
- package/src/contentful/blocks/email-input-block/index.test.tsx +189 -161
|
@@ -1,204 +1,232 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
/// <reference types="@testing-library/jest-dom" />
|
|
3
|
+
|
|
1
4
|
import { EmailInputBlock } from "./index";
|
|
5
|
+
import { EmailInputBlockProps } from "./types";
|
|
2
6
|
|
|
3
7
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
+
const defaultProps: EmailInputBlockProps = {
|
|
10
|
+
onSubmit: jest.fn(),
|
|
11
|
+
};
|
|
9
12
|
|
|
13
|
+
describe("EmailInputBlock", () => {
|
|
10
14
|
beforeEach(() => {
|
|
11
15
|
jest.clearAllMocks();
|
|
12
16
|
});
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
describe("Rendering", () => {
|
|
19
|
+
it("renders with default props", () => {
|
|
20
|
+
const { container } = render(<EmailInputBlock {...defaultProps} />);
|
|
21
|
+
expect(container.querySelector("#email-input")).toBeInTheDocument();
|
|
22
|
+
});
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
it("renders custom anchorId", () => {
|
|
25
|
+
const { container } = render(
|
|
26
|
+
<EmailInputBlock {...defaultProps} anchorId="custom-anchor" />
|
|
27
|
+
);
|
|
28
|
+
expect(container.querySelector("#custom-anchor")).toBeInTheDocument();
|
|
29
|
+
});
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
it("renders title when provided", () => {
|
|
32
|
+
render(<EmailInputBlock {...defaultProps} title="Join us" />);
|
|
33
|
+
const title = screen.getByText("Join us");
|
|
34
|
+
expect(title).toBeInTheDocument();
|
|
35
|
+
expect(title.tagName).toBe("H1");
|
|
36
|
+
});
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
it("does not render title when not provided", () => {
|
|
39
|
+
const { container } = render(<EmailInputBlock {...defaultProps} />);
|
|
40
|
+
expect(container.querySelector("h1")).not.toBeInTheDocument();
|
|
41
|
+
});
|
|
36
42
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
it("renders subTitle when provided", () => {
|
|
44
|
+
render(<EmailInputBlock {...defaultProps} subTitle="Stay updated" />);
|
|
45
|
+
const subtitle = screen.getByText("Stay updated");
|
|
46
|
+
expect(subtitle).toBeInTheDocument();
|
|
47
|
+
expect(subtitle.tagName).toBe("H2");
|
|
48
|
+
});
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
it("does not render subTitle when not provided", () => {
|
|
51
|
+
const { container } = render(<EmailInputBlock {...defaultProps} />);
|
|
52
|
+
expect(container.querySelector("h2")).not.toBeInTheDocument();
|
|
53
|
+
});
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
it("renders emailInputDescription when provided", () => {
|
|
56
|
+
render(
|
|
57
|
+
<EmailInputBlock
|
|
58
|
+
{...defaultProps}
|
|
59
|
+
emailInputDescription="Sign up now"
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
expect(screen.getByText("Sign up now")).toBeInTheDocument();
|
|
63
|
+
});
|
|
54
64
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
it("renders caption when provided", () => {
|
|
66
|
+
render(<EmailInputBlock {...defaultProps} caption="No spam" />);
|
|
67
|
+
expect(screen.getByText("No spam")).toBeInTheDocument();
|
|
68
|
+
});
|
|
59
69
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
it("does not render caption when not provided", () => {
|
|
71
|
+
render(<EmailInputBlock {...defaultProps} />);
|
|
72
|
+
expect(screen.queryByText("No spam")).not.toBeInTheDocument();
|
|
73
|
+
});
|
|
64
74
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
it("uses default placeholder text", () => {
|
|
76
|
+
render(<EmailInputBlock {...defaultProps} />);
|
|
77
|
+
expect(
|
|
78
|
+
screen.getByPlaceholderText("Enter your email here")
|
|
79
|
+
).toBeInTheDocument();
|
|
80
|
+
});
|
|
71
81
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
it("uses custom placeholder text", () => {
|
|
83
|
+
render(
|
|
84
|
+
<EmailInputBlock {...defaultProps} inputPlaceholder="Your email" />
|
|
85
|
+
);
|
|
86
|
+
expect(screen.getByPlaceholderText("Your email")).toBeInTheDocument();
|
|
87
|
+
});
|
|
75
88
|
});
|
|
76
89
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
describe("Form submission", () => {
|
|
91
|
+
it("calls onSubmit with email on valid submission", () => {
|
|
92
|
+
render(<EmailInputBlock {...defaultProps} />);
|
|
93
|
+
const input = screen.getByPlaceholderText("Enter your email here");
|
|
94
|
+
fireEvent.change(input, { target: { value: "test@example.com" } });
|
|
95
|
+
fireEvent.click(screen.getByText("Sign me up"));
|
|
96
|
+
expect(defaultProps.onSubmit).toHaveBeenCalledWith({
|
|
97
|
+
email: "test@example.com",
|
|
98
|
+
});
|
|
84
99
|
});
|
|
85
|
-
});
|
|
86
100
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
it("clears email after successful submission", () => {
|
|
102
|
+
render(<EmailInputBlock {...defaultProps} />);
|
|
103
|
+
const input = screen.getByPlaceholderText(
|
|
104
|
+
"Enter your email here"
|
|
105
|
+
) as HTMLInputElement;
|
|
106
|
+
fireEvent.change(input, { target: { value: "test@example.com" } });
|
|
107
|
+
fireEvent.click(screen.getByText("Sign me up"));
|
|
108
|
+
expect(input.value).toBe("");
|
|
109
|
+
});
|
|
95
110
|
});
|
|
96
111
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
describe("Validation", () => {
|
|
113
|
+
it("shows error for invalid email", () => {
|
|
114
|
+
render(<EmailInputBlock {...defaultProps} />);
|
|
115
|
+
const input = screen.getByPlaceholderText("Enter your email here");
|
|
116
|
+
fireEvent.change(input, { target: { value: "invalid" } });
|
|
117
|
+
fireEvent.click(screen.getByText("Sign me up"));
|
|
118
|
+
expect(screen.getByText("Invalid email address")).toBeInTheDocument();
|
|
119
|
+
expect(defaultProps.onSubmit).not.toHaveBeenCalled();
|
|
120
|
+
});
|
|
105
121
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
122
|
+
it("shows required error for empty email", () => {
|
|
123
|
+
render(<EmailInputBlock {...defaultProps} />);
|
|
124
|
+
fireEvent.click(screen.getByText("Sign me up"));
|
|
125
|
+
expect(screen.getByText("Email is required")).toBeInTheDocument();
|
|
126
|
+
expect(defaultProps.onSubmit).not.toHaveBeenCalled();
|
|
127
|
+
});
|
|
112
128
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
129
|
+
it("clears error when user types a valid email after error", () => {
|
|
130
|
+
render(<EmailInputBlock {...defaultProps} />);
|
|
131
|
+
const input = screen.getByPlaceholderText("Enter your email here");
|
|
132
|
+
fireEvent.change(input, { target: { value: "invalid" } });
|
|
133
|
+
fireEvent.click(screen.getByText("Sign me up"));
|
|
134
|
+
expect(screen.getByText("Invalid email address")).toBeInTheDocument();
|
|
135
|
+
|
|
136
|
+
fireEvent.change(input, { target: { value: "user@test.com" } });
|
|
137
|
+
expect(
|
|
138
|
+
screen.queryByText("Invalid email address")
|
|
139
|
+
).not.toBeInTheDocument();
|
|
140
|
+
});
|
|
124
141
|
});
|
|
125
142
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
143
|
+
describe("Success feedback", () => {
|
|
144
|
+
it("shows success feedback after valid submission", () => {
|
|
145
|
+
render(<EmailInputBlock {...defaultProps} successFeedback="Thanks!" />);
|
|
146
|
+
const input = screen.getByPlaceholderText("Enter your email here");
|
|
147
|
+
fireEvent.change(input, { target: { value: "user@test.com" } });
|
|
148
|
+
fireEvent.click(screen.getByText("Sign me up"));
|
|
149
|
+
expect(screen.getByText("Thanks!")).toBeInTheDocument();
|
|
150
|
+
});
|
|
133
151
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
152
|
+
it("hides success feedback when user types again", () => {
|
|
153
|
+
render(<EmailInputBlock {...defaultProps} successFeedback="Thanks!" />);
|
|
154
|
+
const input = screen.getByPlaceholderText("Enter your email here");
|
|
155
|
+
fireEvent.change(input, { target: { value: "user@test.com" } });
|
|
156
|
+
fireEvent.click(screen.getByText("Sign me up"));
|
|
157
|
+
expect(screen.getByText("Thanks!")).toBeInTheDocument();
|
|
140
158
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
159
|
+
fireEvent.change(input, { target: { value: "x" } });
|
|
160
|
+
expect(screen.queryByText("Thanks!")).not.toBeInTheDocument();
|
|
161
|
+
});
|
|
144
162
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
163
|
+
it("does not show success feedback without successFeedback prop", () => {
|
|
164
|
+
render(<EmailInputBlock {...defaultProps} />);
|
|
165
|
+
const input = screen.getByPlaceholderText("Enter your email here");
|
|
166
|
+
fireEvent.change(input, { target: { value: "user@test.com" } });
|
|
167
|
+
fireEvent.click(screen.getByText("Sign me up"));
|
|
168
|
+
expect(screen.queryByText("Thanks!")).not.toBeInTheDocument();
|
|
169
|
+
});
|
|
152
170
|
});
|
|
153
171
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
172
|
+
describe("Themes", () => {
|
|
173
|
+
it("applies green theme background by default", () => {
|
|
174
|
+
const { container } = render(<EmailInputBlock {...defaultProps} />);
|
|
175
|
+
expect(
|
|
176
|
+
container.querySelector(".bg-bg-fill-brand")
|
|
177
|
+
).toBeInTheDocument();
|
|
178
|
+
});
|
|
158
179
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
180
|
+
it("applies blue theme background class", () => {
|
|
181
|
+
const { container } = render(
|
|
182
|
+
<EmailInputBlock {...defaultProps} themeColor="blue" />
|
|
183
|
+
);
|
|
184
|
+
expect(
|
|
185
|
+
container.querySelector(".bg-bg-fill-brand-supporting")
|
|
186
|
+
).toBeInTheDocument();
|
|
187
|
+
});
|
|
167
188
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
189
|
+
it("applies purple theme background class", () => {
|
|
190
|
+
const { container } = render(
|
|
191
|
+
<EmailInputBlock {...defaultProps} themeColor="purple" />
|
|
192
|
+
);
|
|
193
|
+
expect(
|
|
194
|
+
container.querySelector(".bg-bg-fill-brand-tertiary")
|
|
195
|
+
).toBeInTheDocument();
|
|
196
|
+
});
|
|
176
197
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
198
|
+
it("applies white outer background class by default", () => {
|
|
199
|
+
const { container } = render(<EmailInputBlock {...defaultProps} />);
|
|
200
|
+
expect(container.querySelector("section")).toHaveClass("bg-bg");
|
|
201
|
+
});
|
|
181
202
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
203
|
+
it("uses white text for dark themes", () => {
|
|
204
|
+
render(
|
|
205
|
+
<EmailInputBlock
|
|
206
|
+
{...defaultProps}
|
|
207
|
+
themeColor="blue"
|
|
208
|
+
title="Blue title"
|
|
209
|
+
/>
|
|
210
|
+
);
|
|
211
|
+
expect(screen.getByText("Blue title")).toHaveClass("text-white");
|
|
212
|
+
});
|
|
188
213
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
214
|
+
it("uses dark text for the white theme", () => {
|
|
215
|
+
render(
|
|
216
|
+
<EmailInputBlock
|
|
217
|
+
{...defaultProps}
|
|
218
|
+
themeColor="white"
|
|
219
|
+
title="White title"
|
|
220
|
+
/>
|
|
221
|
+
);
|
|
222
|
+
expect(screen.getByText("White title")).toHaveClass("text-text");
|
|
223
|
+
});
|
|
198
224
|
});
|
|
199
225
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
226
|
+
describe("Call to action", () => {
|
|
227
|
+
it("uses custom ctaText", () => {
|
|
228
|
+
render(<EmailInputBlock {...defaultProps} ctaText="Subscribe" />);
|
|
229
|
+
expect(screen.getByText("Subscribe")).toBeInTheDocument();
|
|
230
|
+
});
|
|
203
231
|
});
|
|
204
232
|
});
|