@windstream/react-shared-components 0.2.39 → 0.2.42
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.d.ts +1 -1
- package/dist/contentful/index.esm.js +2 -2
- package/dist/contentful/index.esm.js.map +1 -1
- package/dist/contentful/index.js +2 -2
- package/dist/contentful/index.js.map +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/next/index.esm.js +1 -1
- package/dist/next/index.esm.js.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/next/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utils/index.esm.js +1 -1
- package/dist/utils/index.esm.js.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/brand-button/index.tsx +4 -4
- package/src/components/link/index.test.tsx +2 -2
- package/src/components/link/index.tsx +1 -1
- package/src/contentful/blocks/button/Button.stories.tsx +0 -1
- package/src/contentful/blocks/button/index.test.tsx +109 -8
- package/src/contentful/blocks/button/index.tsx +64 -18
- package/src/contentful/blocks/button/types.ts +1 -1
- package/src/contentful/blocks/cards/blog-card/index.tsx +3 -5
- package/src/contentful/blocks/cards/floating-image-card/index.test.tsx +69 -2
- package/src/contentful/blocks/cards/floating-image-card/index.tsx +7 -4
- package/src/contentful/blocks/carousel/helper.test.tsx +33 -10
- package/src/contentful/blocks/carousel/index.test.tsx +6 -8
- package/src/contentful/blocks/carousel/types.test.ts +10 -0
- package/src/contentful/blocks/cta-callout/CtaCallout.stories.tsx +0 -1
- package/src/contentful/blocks/dynamic-tabs/ordered-tab-views.tsx +1 -1
- package/src/contentful/blocks/ordered-list/index.tsx +2 -2
- package/src/contentful/blocks/primary-hero/index.tsx +1 -1
- package/src/hooks/contentful/use-contentful-rich-text.tsx +69 -9
- package/src/hooks/use-carousel-swipe.test.ts +26 -6
- package/src/types/micro-components.ts +2 -2
package/package.json
CHANGED
|
@@ -48,17 +48,17 @@ export const BrandButton = forwardRef<
|
|
|
48
48
|
const getVariantClasses = () => {
|
|
49
49
|
const baseClasses = cx(
|
|
50
50
|
sizeToClassNames(size),
|
|
51
|
-
"rounded-button pl-15 pr-15 inline-flex gap-2 items-center justify-center outline-none focus:
|
|
51
|
+
"rounded-button pl-15 pr-15 inline-flex gap-2 items-center justify-center outline-none focus:outline focus:outline-2 focus:outline-offset-2 cursor-pointer transition-colors duration-200 align-top sm:whitespace-nowrap",
|
|
52
52
|
fullWidth ? "w-full" : "w-auto"
|
|
53
53
|
);
|
|
54
54
|
|
|
55
55
|
const variantClasses: Record<ButtonVariantsT, string> = {
|
|
56
56
|
primary_brand:
|
|
57
|
-
"bg-bg-fill-brand text-text-brand-on-bg-fill [&:not(:disabled)]:hover:bg-bg-fill-brand-hover focus:
|
|
57
|
+
"bg-bg-fill-brand text-text-brand-on-bg-fill [&:not(:disabled)]:hover:bg-bg-fill-brand-hover focus:outline-bg-fill-brand disabled:bg-bg-fill-brand-disabled",
|
|
58
58
|
primary_inverse:
|
|
59
|
-
"bg-bg-fill-inverse text-text-inverse [&:not(:disabled)]:hover:bg-bg-fill-inverse-hover focus:
|
|
59
|
+
"bg-bg-fill-inverse text-text-inverse [&:not(:disabled)]:hover:bg-bg-fill-inverse-hover focus:outline-bg-fill-inverse disabled:bg-bg-fill-inverse-disabled",
|
|
60
60
|
secondary:
|
|
61
|
-
"border border-border-secondary-on-bg-fill bg-bg-fill-secondary text-text [&:not(:disabled)]:hover:bg-bg-fill-secondary-hover focus:bg-bg-fill-secondary focus:
|
|
61
|
+
"border border-border-secondary-on-bg-fill bg-bg-fill-secondary text-text [&:not(:disabled)]:hover:bg-bg-fill-secondary-hover focus:bg-bg-fill-secondary focus:outline-input-border-hover disabled:bg-bg-fill-secondary",
|
|
62
62
|
};
|
|
63
63
|
const stateClasses = cx(
|
|
64
64
|
(disabled || isLoading) && "cursor-not-allowed",
|
|
@@ -155,14 +155,14 @@ describe("Link", () => {
|
|
|
155
155
|
expect(el).toHaveAttribute("target", "_blank");
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
-
it("adds rel=noopener
|
|
158
|
+
it("adds rel=noopener for external links", () => {
|
|
159
159
|
render(
|
|
160
160
|
<Link href="https://example.com" external={true}>
|
|
161
161
|
External
|
|
162
162
|
</Link>
|
|
163
163
|
);
|
|
164
164
|
const el = screen.getByText("External").closest("a");
|
|
165
|
-
expect(el).toHaveAttribute("rel", "noopener
|
|
165
|
+
expect(el).toHaveAttribute("rel", "noopener");
|
|
166
166
|
});
|
|
167
167
|
|
|
168
168
|
it("does not add target for disabled external links", () => {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Button } from "./index";
|
|
3
3
|
|
|
4
|
+
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
|
5
|
+
import "@testing-library/jest-dom/jest-globals";
|
|
4
6
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
5
7
|
|
|
6
8
|
jest.mock("@shared/components/brand-button", () => ({
|
|
@@ -9,6 +11,9 @@ jest.mock("@shared/components/brand-button", () => ({
|
|
|
9
11
|
href,
|
|
10
12
|
text,
|
|
11
13
|
label,
|
|
14
|
+
iconName,
|
|
15
|
+
iconSize,
|
|
16
|
+
iconFill,
|
|
12
17
|
onClick,
|
|
13
18
|
id,
|
|
14
19
|
variant,
|
|
@@ -27,6 +32,9 @@ jest.mock("@shared/components/brand-button", () => ({
|
|
|
27
32
|
data-variant={variant}
|
|
28
33
|
data-full-width={fullWidth}
|
|
29
34
|
data-size={size}
|
|
35
|
+
data-icon-name={iconName}
|
|
36
|
+
data-icon-size={iconSize}
|
|
37
|
+
data-icon-fill={iconFill}
|
|
30
38
|
className={buttonClassName}
|
|
31
39
|
onClick={onClick}
|
|
32
40
|
>
|
|
@@ -85,7 +93,9 @@ jest.mock("@shared/utils/utm", () => ({
|
|
|
85
93
|
}));
|
|
86
94
|
|
|
87
95
|
describe("Button", () => {
|
|
88
|
-
beforeEach(() =>
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
jest.clearAllMocks();
|
|
98
|
+
});
|
|
89
99
|
|
|
90
100
|
describe("showButtonAs='solid' (default)", () => {
|
|
91
101
|
it("renders BrandButton as anchor when href is provided", () => {
|
|
@@ -158,12 +168,12 @@ describe("Button", () => {
|
|
|
158
168
|
expect(link.className).toContain("extra");
|
|
159
169
|
});
|
|
160
170
|
|
|
161
|
-
it("renders MaterialIcon when
|
|
171
|
+
it("renders MaterialIcon when buttonIconName is provided", () => {
|
|
162
172
|
render(
|
|
163
173
|
<Button
|
|
164
174
|
showButtonAs="text"
|
|
165
175
|
buttonLabel="Go"
|
|
166
|
-
|
|
176
|
+
buttonIconName="arrow_forward"
|
|
167
177
|
iconSize={20}
|
|
168
178
|
iconFill={1}
|
|
169
179
|
/>
|
|
@@ -174,10 +184,103 @@ describe("Button", () => {
|
|
|
174
184
|
expect(icon).toHaveAttribute("data-fill", "1");
|
|
175
185
|
});
|
|
176
186
|
|
|
187
|
+
it("does not render MaterialIcon when buttonIconName is absent", () => {
|
|
188
|
+
render(
|
|
189
|
+
<Button
|
|
190
|
+
showButtonAs="text"
|
|
191
|
+
buttonLabel="Go"
|
|
192
|
+
iconName="arrow_forward"
|
|
193
|
+
iconSize={20}
|
|
194
|
+
iconFill={1}
|
|
195
|
+
/>
|
|
196
|
+
);
|
|
197
|
+
expect(screen.queryByTestId("material-icon")).not.toBeInTheDocument();
|
|
198
|
+
});
|
|
199
|
+
|
|
177
200
|
it("does not render MaterialIcon when iconName is not provided", () => {
|
|
178
201
|
render(<Button showButtonAs="text" buttonLabel="Go" />);
|
|
179
202
|
expect(screen.queryByTestId("material-icon")).not.toBeInTheDocument();
|
|
180
203
|
});
|
|
204
|
+
|
|
205
|
+
it("renders buttonIconName icon before label when buttonIconPosition is left", () => {
|
|
206
|
+
render(
|
|
207
|
+
<Button
|
|
208
|
+
showButtonAs="text"
|
|
209
|
+
buttonLabel="See Jobs"
|
|
210
|
+
href="/jobs"
|
|
211
|
+
buttonIconName="expand_circle_right"
|
|
212
|
+
buttonIconPosition="left"
|
|
213
|
+
/>
|
|
214
|
+
);
|
|
215
|
+
const link = screen.getByTestId("link");
|
|
216
|
+
const icon = screen.getByTestId("material-icon");
|
|
217
|
+
expect(icon).toBeInTheDocument();
|
|
218
|
+
expect(link.firstElementChild).toBe(icon);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("renders buttonIconName icon after label by default", () => {
|
|
222
|
+
render(
|
|
223
|
+
<Button
|
|
224
|
+
showButtonAs="text"
|
|
225
|
+
buttonLabel="See Jobs"
|
|
226
|
+
href="/jobs"
|
|
227
|
+
buttonIconName="expand_circle_right"
|
|
228
|
+
/>
|
|
229
|
+
);
|
|
230
|
+
const link = screen.getByTestId("link");
|
|
231
|
+
const icon = screen.getByTestId("material-icon");
|
|
232
|
+
expect(icon).toBeInTheDocument();
|
|
233
|
+
expect(link.lastElementChild).toBe(icon);
|
|
234
|
+
expect(link.className).toContain("no-underline");
|
|
235
|
+
expect(link.className).toContain("inline-flex");
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe("buttonIconName behavior", () => {
|
|
240
|
+
it("renders solid CTA icon before label when buttonIconPosition is left", () => {
|
|
241
|
+
render(
|
|
242
|
+
<Button
|
|
243
|
+
buttonLabel="See Jobs"
|
|
244
|
+
href="/jobs"
|
|
245
|
+
buttonIconName="expand_circle_right"
|
|
246
|
+
buttonIconPosition="left"
|
|
247
|
+
iconSize={20}
|
|
248
|
+
iconFill={1}
|
|
249
|
+
/>
|
|
250
|
+
);
|
|
251
|
+
const link = screen.getByRole("link", { name: /see jobs/i });
|
|
252
|
+
expect(link).toHaveAttribute("data-icon-name", "expand_circle_right");
|
|
253
|
+
expect(link).toHaveAttribute("data-icon-size", "20");
|
|
254
|
+
expect(link).toHaveAttribute("data-icon-fill", "1");
|
|
255
|
+
expect(link).toHaveClass("flex-row-reverse");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("renders solid CTA icon after label when buttonIconPosition is right", () => {
|
|
259
|
+
render(
|
|
260
|
+
<Button
|
|
261
|
+
buttonLabel="See Jobs"
|
|
262
|
+
href="/jobs"
|
|
263
|
+
buttonIconName="expand_circle_right"
|
|
264
|
+
buttonIconPosition="right"
|
|
265
|
+
/>
|
|
266
|
+
);
|
|
267
|
+
const link = screen.getByRole("link", { name: /see jobs/i });
|
|
268
|
+
expect(link).toHaveAttribute("data-icon-name", "expand_circle_right");
|
|
269
|
+
expect(link).not.toHaveClass("flex-row-reverse");
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("passes through non-standard variant values", () => {
|
|
273
|
+
render(
|
|
274
|
+
<Button
|
|
275
|
+
buttonLabel="See Jobs"
|
|
276
|
+
href="/jobs"
|
|
277
|
+
buttonVariant={"primary_navy" as any}
|
|
278
|
+
/>
|
|
279
|
+
);
|
|
280
|
+
const button = screen.getByTestId("brand-button");
|
|
281
|
+
expect(button).toHaveAttribute("data-variant", "primary_navy");
|
|
282
|
+
});
|
|
283
|
+
|
|
181
284
|
});
|
|
182
285
|
|
|
183
286
|
describe("showButtonAs='unstyled'", () => {
|
|
@@ -212,11 +315,9 @@ describe("Button", () => {
|
|
|
212
315
|
);
|
|
213
316
|
});
|
|
214
317
|
|
|
215
|
-
it("
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
);
|
|
219
|
-
expect(container.innerHTML).toBe("");
|
|
318
|
+
it("falls back to normal CTA when renderCheckPlans is not provided", () => {
|
|
319
|
+
render(<Button preDefinedFunctionExecution="check availability" />);
|
|
320
|
+
expect(screen.getByTestId("brand-button")).toBeInTheDocument();
|
|
220
321
|
});
|
|
221
322
|
});
|
|
222
323
|
|
|
@@ -9,10 +9,17 @@ import { BrandButton, ButtonVariantsT } from "@shared/components/brand-button";
|
|
|
9
9
|
import { Button as CoreButton } from "@shared/components/button";
|
|
10
10
|
import { Link } from "@shared/components/link";
|
|
11
11
|
import { MaterialIcon } from "@shared/components/material-icon";
|
|
12
|
+
import type { IconName } from "@shared/components/material-icon/types";
|
|
12
13
|
import { Text } from "@shared/components/text";
|
|
13
14
|
import { cx } from "@shared/utils";
|
|
14
15
|
import { buildPreservedQueryHref } from "@shared/utils/utm";
|
|
15
16
|
|
|
17
|
+
const textVariantClasses: Record<string, string> = {
|
|
18
|
+
primary_brand: "text-text-brand",
|
|
19
|
+
primary_inverse: "text-text",
|
|
20
|
+
secondary: "text-text",
|
|
21
|
+
};
|
|
22
|
+
|
|
16
23
|
export const Button: React.FC<ButtonProps> = props => {
|
|
17
24
|
const {
|
|
18
25
|
showButtonAs = "solid",
|
|
@@ -33,8 +40,9 @@ export const Button: React.FC<ButtonProps> = props => {
|
|
|
33
40
|
idNameToOpen,
|
|
34
41
|
onModalButtonClick,
|
|
35
42
|
onClick,
|
|
36
|
-
iconName,
|
|
37
43
|
iconFill = 0,
|
|
44
|
+
buttonIconName,
|
|
45
|
+
buttonIconPosition,
|
|
38
46
|
size,
|
|
39
47
|
iconSize = 24,
|
|
40
48
|
preserveQueryParameters,
|
|
@@ -42,6 +50,13 @@ export const Button: React.FC<ButtonProps> = props => {
|
|
|
42
50
|
animationType = DEFAULT_BUTTON_ANIMATION_TYPE,
|
|
43
51
|
...rest
|
|
44
52
|
} = props;
|
|
53
|
+
|
|
54
|
+
const isLeftIcon = buttonIconPosition === "left";
|
|
55
|
+
const matIconName = buttonIconName as IconName | undefined;
|
|
56
|
+
const brandButtonClassName = cx(
|
|
57
|
+
buttonClassName,
|
|
58
|
+
isLeftIcon && matIconName ? "flex-row-reverse" : ""
|
|
59
|
+
);
|
|
45
60
|
|
|
46
61
|
if (
|
|
47
62
|
preDefinedFunctionExecution === "check availability" &&
|
|
@@ -116,7 +131,6 @@ export const Button: React.FC<ButtonProps> = props => {
|
|
|
116
131
|
: href && preserveQueryParameters && currentSearch
|
|
117
132
|
? buildPreservedQueryHref(href, currentSearch)
|
|
118
133
|
: href;
|
|
119
|
-
|
|
120
134
|
let CTA = (
|
|
121
135
|
<CoreButton onClick={buttonClick} className={buttonClassName} {...rest} />
|
|
122
136
|
);
|
|
@@ -132,9 +146,12 @@ export const Button: React.FC<ButtonProps> = props => {
|
|
|
132
146
|
text={buttonLabel}
|
|
133
147
|
label={buttonPrefix}
|
|
134
148
|
fullWidth={fullWidth}
|
|
135
|
-
buttonClassName={
|
|
149
|
+
buttonClassName={brandButtonClassName}
|
|
136
150
|
size={size}
|
|
137
151
|
onClick={linkClick}
|
|
152
|
+
iconName={matIconName}
|
|
153
|
+
iconSize={iconSize}
|
|
154
|
+
iconFill={iconFill}
|
|
138
155
|
disableAnimation={disableAnimation}
|
|
139
156
|
animationType={animationType}
|
|
140
157
|
/>
|
|
@@ -147,7 +164,10 @@ export const Button: React.FC<ButtonProps> = props => {
|
|
|
147
164
|
fullWidth={fullWidth}
|
|
148
165
|
size={size}
|
|
149
166
|
onClick={buttonClick}
|
|
150
|
-
|
|
167
|
+
iconName={matIconName}
|
|
168
|
+
iconSize={iconSize}
|
|
169
|
+
iconFill={iconFill}
|
|
170
|
+
buttonClassName={brandButtonClassName}
|
|
151
171
|
disableAnimation={disableAnimation}
|
|
152
172
|
animationType={animationType}
|
|
153
173
|
/>
|
|
@@ -160,16 +180,34 @@ export const Button: React.FC<ButtonProps> = props => {
|
|
|
160
180
|
href={resolvedHref}
|
|
161
181
|
target={target}
|
|
162
182
|
variant={linkVariant || "default"}
|
|
163
|
-
className={
|
|
183
|
+
className={cx(
|
|
184
|
+
matIconName &&
|
|
185
|
+
"label1 inline-flex items-center gap-2 no-underline",
|
|
186
|
+
textVariantClasses[buttonVariant],
|
|
187
|
+
linkClassName
|
|
188
|
+
)}
|
|
164
189
|
onClick={linkClick}
|
|
165
190
|
>
|
|
166
|
-
{
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
191
|
+
{matIconName ? (
|
|
192
|
+
<>
|
|
193
|
+
{isLeftIcon ? (
|
|
194
|
+
<MaterialIcon
|
|
195
|
+
name={matIconName as IconName}
|
|
196
|
+
size={iconSize}
|
|
197
|
+
fill={iconFill}
|
|
198
|
+
/>
|
|
199
|
+
) : null}
|
|
200
|
+
{buttonLabel}
|
|
201
|
+
{!isLeftIcon ? (
|
|
202
|
+
<MaterialIcon
|
|
203
|
+
name={matIconName as IconName}
|
|
204
|
+
size={iconSize}
|
|
205
|
+
fill={iconFill}
|
|
206
|
+
/>
|
|
207
|
+
) : null}
|
|
208
|
+
</>
|
|
209
|
+
) : (
|
|
210
|
+
<>{buttonLabel}</>
|
|
173
211
|
)}
|
|
174
212
|
</Link>
|
|
175
213
|
);
|
|
@@ -184,10 +222,10 @@ export const Button: React.FC<ButtonProps> = props => {
|
|
|
184
222
|
text={buttonLabel}
|
|
185
223
|
label={buttonPrefix}
|
|
186
224
|
fullWidth={fullWidth}
|
|
187
|
-
buttonClassName={
|
|
225
|
+
buttonClassName={brandButtonClassName}
|
|
188
226
|
size={size}
|
|
189
227
|
onClick={linkClick}
|
|
190
|
-
iconName={
|
|
228
|
+
iconName={matIconName}
|
|
191
229
|
iconSize={iconSize}
|
|
192
230
|
iconFill={iconFill}
|
|
193
231
|
disableAnimation={disableAnimation}
|
|
@@ -200,10 +238,10 @@ export const Button: React.FC<ButtonProps> = props => {
|
|
|
200
238
|
text={buttonLabel}
|
|
201
239
|
label={buttonPrefix}
|
|
202
240
|
fullWidth={fullWidth}
|
|
203
|
-
buttonClassName={
|
|
241
|
+
buttonClassName={brandButtonClassName}
|
|
204
242
|
size={size}
|
|
205
243
|
onClick={buttonClick}
|
|
206
|
-
iconName={
|
|
244
|
+
iconName={matIconName}
|
|
207
245
|
iconSize={iconSize}
|
|
208
246
|
iconFill={iconFill}
|
|
209
247
|
disableAnimation={disableAnimation}
|
|
@@ -237,12 +275,20 @@ export const Button: React.FC<ButtonProps> = props => {
|
|
|
237
275
|
)}
|
|
238
276
|
aria-label={buttonLabel}
|
|
239
277
|
>
|
|
278
|
+
{isLeftIcon && matIconName ? (
|
|
279
|
+
<MaterialIcon
|
|
280
|
+
name={matIconName as IconName}
|
|
281
|
+
fill={iconFill}
|
|
282
|
+
size={iconSize}
|
|
283
|
+
weight="200"
|
|
284
|
+
/>
|
|
285
|
+
) : null}
|
|
240
286
|
<Text aria-label={buttonLabel} className="label1 text-nowrap">
|
|
241
287
|
{buttonLabel}
|
|
242
288
|
</Text>
|
|
243
|
-
{
|
|
289
|
+
{matIconName && !isLeftIcon && (
|
|
244
290
|
<MaterialIcon
|
|
245
|
-
name={
|
|
291
|
+
name={matIconName as IconName}
|
|
246
292
|
fill={iconFill}
|
|
247
293
|
size={iconSize}
|
|
248
294
|
weight="200"
|
|
@@ -109,11 +109,9 @@ export const BlogCard: React.FC<BlogCardProps> = ({
|
|
|
109
109
|
|
|
110
110
|
{/* Fallback stretched link keeps the card navigable when no title link is rendered */}
|
|
111
111
|
{!title && (
|
|
112
|
-
<Link
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
className="absolute inset-0 z-10"
|
|
116
|
-
/>
|
|
112
|
+
<Link href={href} className="absolute inset-0 z-10">
|
|
113
|
+
<span className="sr-only">{category ?? "Read more"}</span>
|
|
114
|
+
</Link>
|
|
117
115
|
)}
|
|
118
116
|
</article>
|
|
119
117
|
);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { FloatingImageCard } from "./index";
|
|
3
3
|
|
|
4
|
+
import { describe, expect, it, jest } from "@jest/globals";
|
|
5
|
+
import "@testing-library/jest-dom/jest-globals";
|
|
4
6
|
import { render, screen } from "@testing-library/react";
|
|
5
7
|
|
|
6
8
|
jest.mock("@shared/components/next-image", () => ({
|
|
7
|
-
NextImage: ({ src, alt, width, height, className, onClick }: any) => (
|
|
9
|
+
NextImage: ({ src, alt, width, height, className, onClick, ...rest }: any) => (
|
|
8
10
|
<img
|
|
9
11
|
data-testid="next-image"
|
|
10
12
|
src={src}
|
|
@@ -13,6 +15,7 @@ jest.mock("@shared/components/next-image", () => ({
|
|
|
13
15
|
height={height}
|
|
14
16
|
className={className}
|
|
15
17
|
onClick={onClick}
|
|
18
|
+
{...rest}
|
|
16
19
|
/>
|
|
17
20
|
),
|
|
18
21
|
}));
|
|
@@ -98,6 +101,68 @@ describe("FloatingImageCard", () => {
|
|
|
98
101
|
render(<FloatingImageCard card={defaultCard} />);
|
|
99
102
|
expect(screen.queryByTestId("cta-button")).not.toBeInTheDocument();
|
|
100
103
|
});
|
|
104
|
+
|
|
105
|
+
it("renders Button when buttonIconName is provided", () => {
|
|
106
|
+
const card = {
|
|
107
|
+
...defaultCard,
|
|
108
|
+
cta: {
|
|
109
|
+
buttonLabel: "See Jobs",
|
|
110
|
+
href: "/jobs",
|
|
111
|
+
showButtonAs: "text" as const,
|
|
112
|
+
buttonIconName: "expand_circle_right",
|
|
113
|
+
buttonIconPosition: "left" as const,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
render(<FloatingImageCard card={card} />);
|
|
118
|
+
expect(screen.getByTestId("cta-button")).toBeInTheDocument();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("renders Button for primary_inverse text CTA variant", () => {
|
|
122
|
+
const card = {
|
|
123
|
+
...defaultCard,
|
|
124
|
+
cta: {
|
|
125
|
+
buttonLabel: "See Jobs",
|
|
126
|
+
href: "/jobs",
|
|
127
|
+
showButtonAs: "text" as const,
|
|
128
|
+
buttonVariant: "primary_inverse" as const,
|
|
129
|
+
buttonIconName: "expand_circle_right",
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
render(<FloatingImageCard card={card} />);
|
|
134
|
+
expect(screen.getByTestId("cta-button")).toBeInTheDocument();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("renders Button for primary_navy alias", () => {
|
|
138
|
+
const card = {
|
|
139
|
+
...defaultCard,
|
|
140
|
+
cta: {
|
|
141
|
+
buttonLabel: "See Jobs",
|
|
142
|
+
href: "/jobs",
|
|
143
|
+
showButtonAs: "text" as const,
|
|
144
|
+
buttonVariant: "primary_navy" as any,
|
|
145
|
+
buttonIconName: "expand_circle_right",
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
render(<FloatingImageCard card={card} />);
|
|
150
|
+
expect(screen.getByTestId("cta-button")).toBeInTheDocument();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("renders authored icon CTA when buttonIconName is set even if href is missing", () => {
|
|
154
|
+
const card = {
|
|
155
|
+
...defaultCard,
|
|
156
|
+
cta: {
|
|
157
|
+
buttonLabel: "See Jobs",
|
|
158
|
+
showButtonAs: "text" as const,
|
|
159
|
+
buttonIconName: "expand_circle_right",
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
render(<FloatingImageCard card={card} />);
|
|
164
|
+
expect(screen.getByTestId("cta-button")).toBeInTheDocument();
|
|
165
|
+
});
|
|
101
166
|
});
|
|
102
167
|
|
|
103
168
|
describe("CTA alignment", () => {
|
|
@@ -158,7 +223,9 @@ describe("FloatingImageCard", () => {
|
|
|
158
223
|
|
|
159
224
|
describe("Image link", () => {
|
|
160
225
|
it("makes image clickable when imageLink is provided", () => {
|
|
161
|
-
const windowOpen = jest
|
|
226
|
+
const windowOpen = jest
|
|
227
|
+
.spyOn(window, "open")
|
|
228
|
+
.mockImplementation(() => null);
|
|
162
229
|
const card = {
|
|
163
230
|
...defaultCard,
|
|
164
231
|
imageLink: "https://example.com",
|
|
@@ -106,11 +106,14 @@ export const FloatingImageCard: React.FC<FloatingImageCardProps> = ({
|
|
|
106
106
|
<div className={cx(ctaAlignmentClass, "mt-auto")}>
|
|
107
107
|
{cta ? (
|
|
108
108
|
<Button
|
|
109
|
-
linkVariant="unstyled"
|
|
110
|
-
linkClassName="label1 flex items-center gap-2 text-text"
|
|
111
109
|
{...cta}
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
showButtonAs={
|
|
111
|
+
cta.showButtonAs || (cta.buttonIconName ? undefined : "text-with-icon")
|
|
112
|
+
}
|
|
113
|
+
iconName={
|
|
114
|
+
cta.iconName || (cta.buttonIconName ? undefined : "expand_circle_right")
|
|
115
|
+
}
|
|
116
|
+
iconFill={cta.iconFill ?? 1}
|
|
114
117
|
// Button animates ONLY when BOTH are explicitly enabled:
|
|
115
118
|
// - the parent Callout animation is enabled (disableAnimation === false)
|
|
116
119
|
// - the button's own disableAnimation is enabled (=== false)
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
CarouselWithTestimonialCards,
|
|
8
8
|
} from "./types";
|
|
9
9
|
|
|
10
|
-
import { fireEvent, render, screen } from "@testing-library/react";
|
|
10
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
11
11
|
|
|
12
12
|
// Mock sub-components
|
|
13
13
|
jest.mock("@shared/components/button", () => ({
|
|
@@ -84,6 +84,12 @@ jest.mock("@shared/utils", () => ({
|
|
|
84
84
|
}));
|
|
85
85
|
|
|
86
86
|
describe("ProductCardCarousel", () => {
|
|
87
|
+
beforeEach(() => {
|
|
88
|
+
Object.defineProperty(HTMLElement.prototype, "offsetWidth", {
|
|
89
|
+
configurable: true,
|
|
90
|
+
get: () => 900,
|
|
91
|
+
});
|
|
92
|
+
});
|
|
87
93
|
const createProductFields = (
|
|
88
94
|
items: any[] = []
|
|
89
95
|
): CarouselWithProductCards => ({
|
|
@@ -208,39 +214,56 @@ describe("ProductCardCarousel", () => {
|
|
|
208
214
|
expect(card).toHaveAttribute("data-plan", "500 Mbps");
|
|
209
215
|
});
|
|
210
216
|
|
|
211
|
-
it("renders
|
|
217
|
+
it("renders Next arrow and hides Previous on first slide in carousel mode", async () => {
|
|
212
218
|
const items = Array.from({ length: 4 }, (_, i) => ({
|
|
213
219
|
...sampleProduct,
|
|
214
220
|
sys: { id: `prod-${i}` },
|
|
215
221
|
}));
|
|
216
222
|
const fields = createProductFields(items);
|
|
217
223
|
render(<ProductCardCarousel fields={fields} />);
|
|
218
|
-
|
|
219
|
-
|
|
224
|
+
|
|
225
|
+
fireEvent(window, new Event("resize"));
|
|
226
|
+
|
|
227
|
+
await waitFor(() =>
|
|
228
|
+
expect(screen.getByLabelText("Next")).toBeInTheDocument()
|
|
229
|
+
);
|
|
230
|
+
expect(screen.queryByLabelText("Previous")).not.toBeInTheDocument();
|
|
220
231
|
});
|
|
221
232
|
|
|
222
|
-
it("
|
|
233
|
+
it("shows Previous after moving forward, then hides it after returning to first slide", async () => {
|
|
223
234
|
const items = Array.from({ length: 4 }, (_, i) => ({
|
|
224
235
|
...sampleProduct,
|
|
225
236
|
sys: { id: `prod-${i}` },
|
|
226
237
|
}));
|
|
227
238
|
const fields = createProductFields(items);
|
|
228
239
|
render(<ProductCardCarousel fields={fields} />);
|
|
229
|
-
|
|
230
|
-
fireEvent
|
|
231
|
-
|
|
240
|
+
|
|
241
|
+
fireEvent(window, new Event("resize"));
|
|
242
|
+
|
|
243
|
+
const nextBtn = await screen.findByLabelText("Next");
|
|
244
|
+
fireEvent.click(nextBtn);
|
|
245
|
+
|
|
246
|
+
const prevBtn = await screen.findByLabelText("Previous");
|
|
232
247
|
expect(prevBtn).toBeInTheDocument();
|
|
248
|
+
|
|
249
|
+
fireEvent.click(prevBtn);
|
|
250
|
+
|
|
251
|
+
expect(screen.queryByLabelText("Previous")).not.toBeInTheDocument();
|
|
233
252
|
});
|
|
234
253
|
|
|
235
|
-
it("calls nextSlide on Next button click", () => {
|
|
254
|
+
it("calls nextSlide on Next button click", async () => {
|
|
236
255
|
const items = Array.from({ length: 4 }, (_, i) => ({
|
|
237
256
|
...sampleProduct,
|
|
238
257
|
sys: { id: `prod-${i}` },
|
|
239
258
|
}));
|
|
240
259
|
const fields = createProductFields(items);
|
|
241
260
|
render(<ProductCardCarousel fields={fields} />);
|
|
242
|
-
|
|
261
|
+
|
|
262
|
+
fireEvent(window, new Event("resize"));
|
|
263
|
+
|
|
264
|
+
const nextBtn = await screen.findByLabelText("Next");
|
|
243
265
|
fireEvent.click(nextBtn);
|
|
266
|
+
|
|
244
267
|
expect(nextBtn).toBeInTheDocument();
|
|
245
268
|
});
|
|
246
269
|
|