@windstream/react-shared-components 0.1.93 → 0.1.95

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 (112) hide show
  1. package/dist/contentful/index.esm.js +2 -2
  2. package/dist/contentful/index.esm.js.map +1 -1
  3. package/dist/contentful/index.js +3 -3
  4. package/dist/contentful/index.js.map +1 -1
  5. package/dist/core.d.ts +2 -2
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.esm.js +1 -1
  8. package/dist/index.esm.js.map +1 -1
  9. package/dist/index.js +3 -3
  10. package/dist/index.js.map +1 -1
  11. package/dist/styles.css +1 -1
  12. package/dist/utils/index.esm.js +1 -1
  13. package/dist/utils/index.js +1 -1
  14. package/package.json +14 -8
  15. package/src/components/accordion/index.test.tsx +270 -0
  16. package/src/components/alert-card/index.test.tsx +152 -0
  17. package/src/components/animation-wrapper/index.test.tsx +424 -0
  18. package/src/components/brand-button/index.test.tsx +292 -0
  19. package/src/components/button/index.test.tsx +91 -0
  20. package/src/components/call-button/index.test.tsx +260 -0
  21. package/src/components/checkbox/index.test.tsx +252 -0
  22. package/src/components/checklist/index.test.tsx +231 -0
  23. package/src/components/checklist/index.tsx +64 -29
  24. package/src/components/checklist/types.ts +7 -1
  25. package/src/components/collapse/index.test.tsx +277 -0
  26. package/src/components/collapse/index.tsx +1 -0
  27. package/src/components/divider/index.test.tsx +53 -0
  28. package/src/components/image/index.test.tsx +174 -0
  29. package/src/components/input/index.test.tsx +348 -0
  30. package/src/components/link/index.test.tsx +199 -0
  31. package/src/components/list/index.test.tsx +166 -0
  32. package/src/components/material-icon/index.test.tsx +130 -0
  33. package/src/components/modal/index.test.tsx +310 -0
  34. package/src/components/next-image/index.test.tsx +406 -0
  35. package/src/components/pagination/index.test.tsx +521 -0
  36. package/src/components/radio-button/index.test.tsx +151 -0
  37. package/src/components/see-more/index.test.tsx +96 -0
  38. package/src/components/select/index.test.tsx +256 -0
  39. package/src/components/select-plan-button/index.test.tsx +173 -0
  40. package/src/components/skeleton/index.test.tsx +74 -0
  41. package/src/components/spinner/index.test.tsx +76 -0
  42. package/src/components/text/index.test.tsx +65 -0
  43. package/src/components/tooltip/index.test.tsx +50 -0
  44. package/src/components/view-cart-button/index.test.tsx +57 -0
  45. package/src/contentful/blocks/accordion/index.test.tsx +218 -0
  46. package/src/contentful/blocks/accordion/index.tsx +3 -1
  47. package/src/contentful/blocks/address-input-banner/index.test.tsx +132 -0
  48. package/src/contentful/blocks/anchored-bottom-banner/index.test.tsx +287 -0
  49. package/src/contentful/blocks/blogs-grid/BlogGrid.stories.tsx +5 -4
  50. package/src/contentful/blocks/blogs-grid/index.test.tsx +355 -0
  51. package/src/contentful/blocks/blogs-grid-base/index.test.tsx +274 -0
  52. package/src/contentful/blocks/breadcrumbs/index.test.tsx +281 -0
  53. package/src/contentful/blocks/button/index.test.tsx +339 -0
  54. package/src/contentful/blocks/callout/index.test.tsx +539 -0
  55. package/src/contentful/blocks/cards/blog-card/index.test.tsx +218 -0
  56. package/src/contentful/blocks/cards/floating-image-card/index.test.tsx +201 -0
  57. package/src/contentful/blocks/cards/full-image-card/index.test.tsx +216 -0
  58. package/src/contentful/blocks/cards/index.test.tsx +39 -0
  59. package/src/contentful/blocks/cards/product-card/index.test.tsx +263 -0
  60. package/src/contentful/blocks/cards/simple-card/index.test.tsx +364 -0
  61. package/src/contentful/blocks/cards/simple-card/index.tsx +1 -1
  62. package/src/contentful/blocks/cards/testimonial-card/index.test.tsx +180 -0
  63. package/src/contentful/blocks/carousel/helper.test.tsx +539 -0
  64. package/src/contentful/blocks/carousel/index.test.tsx +308 -0
  65. package/src/contentful/blocks/carousel/types.test.ts +16 -0
  66. package/src/contentful/blocks/cart-retention-banner/index.test.tsx +409 -0
  67. package/src/contentful/blocks/cart-retention-banner/index.tsx +4 -4
  68. package/src/contentful/blocks/comparison-table/index.test.tsx +114 -0
  69. package/src/contentful/blocks/cookiebanner/index.test.tsx +277 -0
  70. package/src/contentful/blocks/cta-callout/index.test.tsx +244 -0
  71. package/src/contentful/blocks/dynamic-tabs/index.test.tsx +240 -0
  72. package/src/contentful/blocks/email-input-block/index.test.tsx +213 -0
  73. package/src/contentful/blocks/email-input-block/index.tsx +40 -35
  74. package/src/contentful/blocks/find-kinetic/index.test.tsx +269 -0
  75. package/src/contentful/blocks/floating-banner/index.test.tsx +246 -0
  76. package/src/contentful/blocks/footer/index.test.tsx +302 -0
  77. package/src/contentful/blocks/image-promo-bar/helper.test.tsx +61 -0
  78. package/src/contentful/blocks/image-promo-bar/index.test.tsx +467 -0
  79. package/src/contentful/blocks/image-promo-bar/index.tsx +248 -246
  80. package/src/contentful/blocks/image-promo-bar/vimeo-embed.test.tsx +142 -0
  81. package/src/contentful/blocks/image-promo-bar/youtube-embed.test.tsx +104 -0
  82. package/src/contentful/blocks/modal/index.test.tsx +209 -0
  83. package/src/contentful/blocks/navigation/desktop-link-groups.tsx/index.test.tsx +208 -0
  84. package/src/contentful/blocks/navigation/index.test.tsx +924 -0
  85. package/src/contentful/blocks/navigation/mobile-link-groups.tsx/index.test.tsx +131 -0
  86. package/src/contentful/blocks/primary-hero/index.test.tsx +286 -0
  87. package/src/contentful/blocks/primary-hero/index.tsx +7 -4
  88. package/src/contentful/blocks/search-block/index.test.tsx +268 -0
  89. package/src/contentful/blocks/shape-background-wrapper/index.test.tsx +284 -0
  90. package/src/contentful/blocks/text/index.test.tsx +36 -0
  91. package/src/contentful/index.test.ts +45 -0
  92. package/src/global-mocks/contentful/to-document.ts +25 -0
  93. package/src/global-mocks/cookie.ts +48 -0
  94. package/src/global-mocks/cx.ts +37 -0
  95. package/src/global-mocks/index.ts +89 -0
  96. package/src/global-mocks/speed-card-bg.ts +27 -0
  97. package/src/global-mocks/utm.ts +49 -0
  98. package/src/hooks/contentful/use-contentful-rich-text.test.tsx +1758 -0
  99. package/src/hooks/contentful/use-contentful-rich-text.tsx +1 -1
  100. package/src/hooks/contentful/use-processed-check-list.test.tsx +277 -0
  101. package/src/hooks/use-body-scroll-lock.test.ts +134 -0
  102. package/src/hooks/use-carousel-swipe.test.ts +393 -0
  103. package/src/hooks/use-outside-click.test.ts +142 -0
  104. package/src/index.ts +1 -1
  105. package/src/next/index.test.ts +7 -0
  106. package/src/setupTests.ts +17 -11
  107. package/src/utils/contentful/to-document.test.ts +85 -0
  108. package/src/utils/cookie.test.ts +180 -0
  109. package/src/utils/cx.test.ts +90 -0
  110. package/src/utils/index.test.ts +115 -0
  111. package/src/utils/speed-card-bg.test.ts +46 -0
  112. package/src/utils/utm.test.ts +359 -0
@@ -0,0 +1,348 @@
1
+ import "@testing-library/jest-dom";
2
+
3
+ import { createRef } from "react";
4
+ import { Input, InputField } from "./index";
5
+
6
+ import { fireEvent, render, screen } from "@testing-library/react";
7
+
8
+ // Mock dependencies
9
+ jest.mock("@shared/components/material-icon", () => ({
10
+ MaterialIcon: ({ name, size, className }: any) => (
11
+ <span data-testid={`icon-${name}`} data-size={size} className={className}>
12
+ {name}
13
+ </span>
14
+ ),
15
+ }));
16
+
17
+ jest.mock("@shared/components/text", () => ({
18
+ Text: ({ children, className, as }: any) => {
19
+ const Tag = as || "span";
20
+ return (
21
+ <Tag data-testid="text" className={className}>
22
+ {children}
23
+ </Tag>
24
+ );
25
+ },
26
+ }));
27
+
28
+ jest.mock("@shared/utils", () => ({
29
+ cx: (...args: any[]) => args.filter(Boolean).join(" "),
30
+ }));
31
+
32
+ describe("Input", () => {
33
+ it("has displayName set to Input", () => {
34
+ expect(Input.displayName).toBe("Input");
35
+ });
36
+
37
+ describe("basic rendering", () => {
38
+ it("renders an input element", () => {
39
+ render(<Input />);
40
+ expect(screen.getByRole("textbox")).toBeInTheDocument();
41
+ });
42
+
43
+ it("renders with placeholder", () => {
44
+ render(<Input placeholder="Enter text" />);
45
+ expect(screen.getByPlaceholderText("Enter text")).toBeInTheDocument();
46
+ });
47
+
48
+ it("renders with default type text", () => {
49
+ render(<Input data-testid="input" />);
50
+ const input = screen.getByTestId("input");
51
+ expect(input).toHaveAttribute("type", "text");
52
+ });
53
+
54
+ it("renders with custom type", () => {
55
+ render(<Input type="email" data-testid="input" />);
56
+ const input = screen.getByTestId("input");
57
+ expect(input).toHaveAttribute("type", "email");
58
+ });
59
+ });
60
+
61
+ describe("ref forwarding", () => {
62
+ it("forwards ref to input element", () => {
63
+ const ref = createRef<HTMLInputElement>();
64
+ render(<Input ref={ref} />);
65
+ expect(ref.current).toBeInstanceOf(HTMLInputElement);
66
+ });
67
+
68
+ it("can imperatively focus the input via ref", () => {
69
+ const ref = createRef<HTMLInputElement>();
70
+ render(<Input ref={ref} />);
71
+ ref.current?.focus();
72
+ expect(ref.current).toBe(document.activeElement);
73
+ });
74
+ });
75
+
76
+ describe("label", () => {
77
+ it("renders label when provided", () => {
78
+ render(<Input label="Email" />);
79
+ expect(screen.getByText("Email")).toBeInTheDocument();
80
+ });
81
+
82
+ it("does not render label when not provided", () => {
83
+ const { container } = render(<Input />);
84
+ expect(container.querySelector("label")).not.toBeInTheDocument();
85
+ });
86
+
87
+ it("associates label with input via htmlFor/id", () => {
88
+ render(<Input label="Username" />);
89
+ const input = screen.getByRole("textbox");
90
+ expect(input).toHaveAttribute("id", "Username");
91
+ });
92
+
93
+ it("shows required asterisk when required is true", () => {
94
+ render(<Input label="Email" required={true} />);
95
+ expect(screen.getByText("*")).toBeInTheDocument();
96
+ });
97
+
98
+ it("does not show asterisk when required is false", () => {
99
+ render(<Input label="Email" />);
100
+ expect(screen.queryByText("*")).not.toBeInTheDocument();
101
+ });
102
+ });
103
+
104
+ describe("size variants", () => {
105
+ it("applies medium size class by default", () => {
106
+ const { container } = render(<Input />);
107
+ const wrapper = container.querySelector(".relative.flex");
108
+ expect(wrapper?.className).toContain("h-14");
109
+ });
110
+
111
+ it("applies slim size class", () => {
112
+ const { container } = render(<Input size="slim" />);
113
+ const wrapper = container.querySelector(".relative.flex");
114
+ expect(wrapper?.className).toContain("h-12");
115
+ });
116
+
117
+ it("applies large size class", () => {
118
+ const { container } = render(<Input size="large" />);
119
+ const wrapper = container.querySelector(".relative.flex");
120
+ expect(wrapper?.className).toContain("h-[60px]");
121
+ });
122
+ });
123
+
124
+ describe("state management", () => {
125
+ it("applies hover state on mouseOver", () => {
126
+ render(<Input data-testid="input" />);
127
+ const input = screen.getByTestId("input");
128
+ fireEvent.mouseOver(input);
129
+ const wrapper = input.closest(".relative.flex");
130
+ expect(wrapper?.className).toContain("border-input-border-hover");
131
+ });
132
+
133
+ it("removes hover state on mouseOut", () => {
134
+ render(<Input data-testid="input" />);
135
+ const input = screen.getByTestId("input");
136
+ fireEvent.mouseOver(input);
137
+ fireEvent.mouseOut(input);
138
+ const wrapper = input.closest(".relative.flex");
139
+ expect(wrapper?.className).not.toContain("border-input-border-hover");
140
+ });
141
+
142
+ it("applies focus state on focus", () => {
143
+ render(<Input data-testid="input" />);
144
+ const input = screen.getByTestId("input");
145
+ fireEvent.focus(input);
146
+ const wrapper = input.closest(".relative.flex");
147
+ expect(wrapper?.className).toContain("border-input-border-selected");
148
+ });
149
+
150
+ it("removes focus state on blur", () => {
151
+ render(<Input data-testid="input" />);
152
+ const input = screen.getByTestId("input");
153
+ fireEvent.focus(input);
154
+ fireEvent.blur(input);
155
+ const wrapper = input.closest(".relative.flex");
156
+ expect(wrapper?.className).not.toContain("border-input-border-selected");
157
+ });
158
+
159
+ it("calls onFocus callback", () => {
160
+ const onFocus = jest.fn();
161
+ render(<Input data-testid="input" onFocus={onFocus} />);
162
+ fireEvent.focus(screen.getByTestId("input"));
163
+ expect(onFocus).toHaveBeenCalled();
164
+ });
165
+
166
+ it("calls onBlur callback", () => {
167
+ const onBlur = jest.fn();
168
+ render(<Input data-testid="input" onBlur={onBlur} />);
169
+ fireEvent.blur(screen.getByTestId("input"));
170
+ expect(onBlur).toHaveBeenCalled();
171
+ });
172
+ });
173
+
174
+ describe("error state", () => {
175
+ it("applies error state styling when state is error", () => {
176
+ const { container } = render(<Input state="error" />);
177
+ const wrapper = container.querySelector(".relative.flex");
178
+ expect(wrapper?.className).toContain("border-input-border-critical");
179
+ });
180
+
181
+ it("displays error text when state is error and errorText provided", () => {
182
+ render(<Input state="error" errorText="Invalid input" />);
183
+ expect(screen.getByText("Invalid input")).toBeInTheDocument();
184
+ });
185
+
186
+ it("does not display error text when state is not error", () => {
187
+ render(<Input state="default" errorText="Invalid input" />);
188
+ expect(screen.queryByText("Invalid input")).not.toBeInTheDocument();
189
+ });
190
+
191
+ it("does not display error section when errorText is empty", () => {
192
+ render(<Input state="error" errorText="" />);
193
+ expect(screen.queryByTestId("icon-info")).not.toBeInTheDocument();
194
+ });
195
+
196
+ it("applies error state when hasError is true", () => {
197
+ const { container } = render(<Input hasError={true} />);
198
+ const wrapper = container.querySelector(".relative.flex");
199
+ expect(wrapper?.className).toContain("border-input-border-critical");
200
+ });
201
+
202
+ it("hasError overrides state prop", () => {
203
+ const { container } = render(<Input hasError={true} state="default" />);
204
+ const wrapper = container.querySelector(".relative.flex");
205
+ expect(wrapper?.className).toContain("border-input-border-critical");
206
+ });
207
+
208
+ it("renders info icon with error text", () => {
209
+ render(<Input state="error" errorText="Error msg" />);
210
+ expect(screen.getByTestId("icon-info")).toBeInTheDocument();
211
+ });
212
+ });
213
+
214
+ describe("prefix icon", () => {
215
+ it("renders prefix icon when prefixIconName is provided", () => {
216
+ render(<Input prefixIconName="search" />);
217
+ expect(screen.getByTestId("icon-search")).toBeInTheDocument();
218
+ });
219
+
220
+ it("does not render prefix icon when not provided", () => {
221
+ render(<Input />);
222
+ expect(screen.queryByTestId("icon-search")).not.toBeInTheDocument();
223
+ expect(screen.queryByTestId("icon-location_on")).not.toBeInTheDocument();
224
+ });
225
+
226
+ it("applies custom prefix icon size", () => {
227
+ render(<Input prefixIconName="search" prefixIconSize={40} />);
228
+ const icon = screen.getByTestId("icon-search");
229
+ expect(icon).toHaveAttribute("data-size", "40");
230
+ });
231
+
232
+ it("applies prefixIconClassName", () => {
233
+ render(
234
+ <Input prefixIconName="search" prefixIconClassName="text-gray-500" />
235
+ );
236
+ const icon = screen.getByTestId("icon-search");
237
+ expect(icon).toHaveClass("text-gray-500");
238
+ });
239
+ });
240
+
241
+ describe("suffix icon and password toggle", () => {
242
+ it("renders suffix icon when suffixIconName is provided", () => {
243
+ render(<Input suffixIconName="visibility" />);
244
+ // Default inputType is "text", so icon shows "visibility"
245
+ expect(screen.getByTestId("icon-visibility")).toBeInTheDocument();
246
+ });
247
+
248
+ it("toggles password visibility on suffix icon click", () => {
249
+ render(
250
+ <Input
251
+ type="password"
252
+ suffixIconName="visibility"
253
+ data-testid="input"
254
+ />
255
+ );
256
+ const input = screen.getByTestId("input");
257
+ expect(input).toHaveAttribute("type", "password");
258
+
259
+ // When type is password, icon shows visibility_off
260
+ const iconWrapper = screen.getByTestId(
261
+ "icon-visibility_off"
262
+ ).parentElement;
263
+ fireEvent.click(iconWrapper!);
264
+ expect(input).toHaveAttribute("type", "text");
265
+
266
+ // After toggle to text, icon shows visibility
267
+ const visibleIcon = screen.getByTestId("icon-visibility").parentElement;
268
+ fireEvent.click(visibleIcon!);
269
+ expect(input).toHaveAttribute("type", "password");
270
+ });
271
+
272
+ it("shows visibility icon when type is text after toggle", () => {
273
+ render(<Input type="password" suffixIconName="visibility" />);
274
+ const iconWrapper = screen.getByTestId(
275
+ "icon-visibility_off"
276
+ ).parentElement;
277
+ fireEvent.click(iconWrapper!);
278
+ expect(screen.getByTestId("icon-visibility")).toBeInTheDocument();
279
+ });
280
+ });
281
+
282
+ describe("disabled and loading", () => {
283
+ it("disables input when disabled prop is true", () => {
284
+ render(<Input disabled={true} data-testid="input" />);
285
+ expect(screen.getByTestId("input")).toBeDisabled();
286
+ });
287
+
288
+ it("disables input when loading is true", () => {
289
+ render(<Input loading={true} data-testid="input" />);
290
+ expect(screen.getByTestId("input")).toBeDisabled();
291
+ });
292
+
293
+ it("is not disabled by default", () => {
294
+ render(<Input data-testid="input" />);
295
+ expect(screen.getByTestId("input")).not.toBeDisabled();
296
+ });
297
+ });
298
+
299
+ describe("containerClassName", () => {
300
+ it("applies containerClassName to the input wrapper", () => {
301
+ const { container } = render(<Input containerClassName="custom-cnt" />);
302
+ const wrapper = container.querySelector(".relative.flex");
303
+ expect(wrapper?.className).toContain("custom-cnt");
304
+ });
305
+ });
306
+
307
+ describe("className", () => {
308
+ it("applies className to the input element", () => {
309
+ render(<Input className="custom-input" data-testid="input" />);
310
+ const input = screen.getByTestId("input");
311
+ expect(input).toHaveClass("custom-input");
312
+ });
313
+ });
314
+
315
+ describe("state prop variants", () => {
316
+ it("applies focus styling when state is focus", () => {
317
+ const { container } = render(<Input state="focus" />);
318
+ const wrapper = container.querySelector(".relative.flex");
319
+ expect(wrapper?.className).toContain("border-input-border-selected");
320
+ });
321
+
322
+ it("applies active styling when state is active", () => {
323
+ const { container } = render(<Input state="active" />);
324
+ const wrapper = container.querySelector(".relative.flex");
325
+ expect(wrapper?.className).toContain("border-input-border-selected");
326
+ });
327
+
328
+ it("applies hover styling when state is hover and not focused", () => {
329
+ const { container } = render(<Input state="hover" />);
330
+ const wrapper = container.querySelector(".relative.flex");
331
+ expect(wrapper?.className).toContain("border-input-border-hover");
332
+ });
333
+
334
+ it("does not apply hover styling when state is hover but focused", () => {
335
+ render(<Input state="hover" data-testid="input" />);
336
+ const input = screen.getByTestId("input");
337
+ fireEvent.focus(input);
338
+ const wrapper = input.closest(".relative.flex");
339
+ expect(wrapper?.className).not.toContain("border-input-border-hover");
340
+ });
341
+ });
342
+
343
+ describe("InputField export", () => {
344
+ it("exports InputField as a render function", () => {
345
+ expect(typeof InputField).toBe("function");
346
+ });
347
+ });
348
+ });
@@ -0,0 +1,199 @@
1
+ import React from "react";
2
+ import { Link } from "./index";
3
+
4
+ import { fireEvent, render, screen } from "@testing-library/react";
5
+
6
+ import "@testing-library/jest-dom";
7
+
8
+ // Mock next/link
9
+ jest.mock("next/link", () => {
10
+ const MockLink = ({ children, href, className, onClick, ...rest }: any) => (
11
+ <a href={href} className={className} onClick={onClick} {...rest}>
12
+ {children}
13
+ </a>
14
+ );
15
+ MockLink.displayName = "MockNextLink";
16
+ return MockLink;
17
+ });
18
+
19
+ describe("Link", () => {
20
+ describe("Rendering", () => {
21
+ it("renders children content", () => {
22
+ render(<Link href="/test">Click me</Link>);
23
+ expect(screen.getByText("Click me")).toBeInTheDocument();
24
+ });
25
+
26
+ it("has correct displayName", () => {
27
+ expect(Link.displayName).toBe("Link");
28
+ });
29
+
30
+ it("renders as a Next.js Link for internal links", () => {
31
+ render(<Link href="/internal">Internal</Link>);
32
+ const el = screen.getByText("Internal");
33
+ expect(el.closest("a")).toHaveAttribute("href", "/internal");
34
+ });
35
+
36
+ it("renders as <a> for external links", () => {
37
+ render(
38
+ <Link href="https://example.com" external={true}>
39
+ External
40
+ </Link>
41
+ );
42
+ const el = screen.getByText("External");
43
+ expect(el.closest("a")).toHaveAttribute("href", "https://example.com");
44
+ });
45
+
46
+ it("renders as <a> for http links even without external prop", () => {
47
+ render(<Link href="https://example.com">Auto External</Link>);
48
+ const el = screen.getByText("Auto External");
49
+ expect(el.closest("a")).toHaveAttribute("href", "https://example.com");
50
+ });
51
+ });
52
+
53
+ describe("Variants", () => {
54
+ it("applies unstyled variant with no extra classes", () => {
55
+ render(
56
+ <Link href="/test" variant="unstyled">
57
+ Unstyled
58
+ </Link>
59
+ );
60
+ const el = screen.getByText("Unstyled").closest("a");
61
+ expect(el?.className).toContain("link--unstyled");
62
+ });
63
+
64
+ it("applies default variant classes", () => {
65
+ render(
66
+ <Link href="/test" variant="default">
67
+ Default
68
+ </Link>
69
+ );
70
+ const el = screen.getByText("Default").closest("a");
71
+ expect(el?.className).toContain("link--default");
72
+ expect(el?.className).toContain("underline");
73
+ });
74
+ });
75
+
76
+ describe("Disabled state", () => {
77
+ it("adds disabled class when disabled", () => {
78
+ render(
79
+ <Link href="/test" disabled={true}>
80
+ Disabled
81
+ </Link>
82
+ );
83
+ const el = screen.getByText("Disabled").closest("a");
84
+ expect(el?.className).toContain("link--disabled");
85
+ });
86
+
87
+ it("sets aria-disabled when disabled", () => {
88
+ render(
89
+ <Link href="/test" disabled={true} external={true}>
90
+ Disabled
91
+ </Link>
92
+ );
93
+ const el = screen.getByText("Disabled").closest("a");
94
+ expect(el).toHaveAttribute("aria-disabled", "true");
95
+ });
96
+
97
+ it("sets tabIndex -1 when disabled", () => {
98
+ render(
99
+ <Link href="/test" disabled={true} external={true}>
100
+ Disabled
101
+ </Link>
102
+ );
103
+ const el = screen.getByText("Disabled").closest("a");
104
+ expect(el).toHaveAttribute("tabindex", "-1");
105
+ });
106
+
107
+ it("prevents click when disabled", () => {
108
+ const onClick = jest.fn();
109
+ render(
110
+ <Link href="/test" disabled={true} external={true} onClick={onClick}>
111
+ Disabled
112
+ </Link>
113
+ );
114
+ const el = screen.getByText("Disabled").closest("a")!;
115
+ fireEvent.click(el);
116
+ expect(onClick).not.toHaveBeenCalled();
117
+ });
118
+ });
119
+
120
+ describe("External links", () => {
121
+ it("adds target=_blank for external links", () => {
122
+ render(
123
+ <Link href="https://example.com" external={true}>
124
+ External
125
+ </Link>
126
+ );
127
+ const el = screen.getByText("External").closest("a");
128
+ expect(el).toHaveAttribute("target", "_blank");
129
+ });
130
+
131
+ it("adds rel=noopener noreferrer for external links", () => {
132
+ render(
133
+ <Link href="https://example.com" external={true}>
134
+ External
135
+ </Link>
136
+ );
137
+ const el = screen.getByText("External").closest("a");
138
+ expect(el).toHaveAttribute("rel", "noopener noreferrer");
139
+ });
140
+
141
+ it("does not add target for disabled external links", () => {
142
+ render(
143
+ <Link href="https://example.com" external={true} disabled={true}>
144
+ External
145
+ </Link>
146
+ );
147
+ const el = screen.getByText("External").closest("a");
148
+ expect(el).not.toHaveAttribute("target", "_blank");
149
+ });
150
+ });
151
+
152
+ describe("Event handling", () => {
153
+ it("calls onClick handler when clicked", () => {
154
+ const onClick = jest.fn();
155
+ render(
156
+ <Link href="https://example.com" external={true} onClick={onClick}>
157
+ Click
158
+ </Link>
159
+ );
160
+ const el = screen.getByText("Click").closest("a")!;
161
+ fireEvent.click(el);
162
+ expect(onClick).toHaveBeenCalledTimes(1);
163
+ });
164
+ });
165
+
166
+ describe("Ref forwarding", () => {
167
+ it("forwards ref to the anchor element", () => {
168
+ const ref = React.createRef<HTMLAnchorElement>();
169
+ render(
170
+ <Link ref={ref} href="https://test.com" external={true}>
171
+ Ref
172
+ </Link>
173
+ );
174
+ expect(ref.current).toBeInstanceOf(HTMLAnchorElement);
175
+ });
176
+ });
177
+
178
+ describe("Custom className and style", () => {
179
+ it("applies custom className", () => {
180
+ render(
181
+ <Link href="/test" className="custom-class">
182
+ Custom
183
+ </Link>
184
+ );
185
+ const el = screen.getByText("Custom").closest("a");
186
+ expect(el?.className).toContain("custom-class");
187
+ });
188
+
189
+ it("applies inline style", () => {
190
+ render(
191
+ <Link href="https://test.com" external={true} style={{ color: "red" }}>
192
+ Styled
193
+ </Link>
194
+ );
195
+ const el = screen.getByText("Styled").closest("a")!;
196
+ expect(el.style.color).toBe("red");
197
+ });
198
+ });
199
+ });