@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,274 @@
1
+ import React from "react";
2
+ import { BlogGridBase } from "./index";
3
+ import { BlogCategoryOption, BlogGridBaseProps } from "./types";
4
+
5
+ import { fireEvent, render, screen } from "@testing-library/react";
6
+
7
+ jest.mock("@shared/components/pagination", () => ({
8
+ Pagination: ({ currentPage, totalPages, onPageChange, ariaLabel }: any) => (
9
+ <nav aria-label={ariaLabel} data-testid="pagination">
10
+ <span>
11
+ Page {currentPage} of {totalPages}
12
+ </span>
13
+ <button data-testid="page-next" onClick={() => onPageChange(2)}>
14
+ Next
15
+ </button>
16
+ <button data-testid="page-first" onClick={() => onPageChange(1)}>
17
+ First
18
+ </button>
19
+ </nav>
20
+ ),
21
+ }));
22
+
23
+ jest.mock("@shared/components/select", () => ({
24
+ Select: ({ options, value, onChange, className }: any) => (
25
+ <select
26
+ data-testid="category-select"
27
+ className={className}
28
+ value={value?.value}
29
+ onChange={e => {
30
+ const opt = options.find((o: any) => o.value === e.target.value);
31
+ onChange(opt);
32
+ }}
33
+ >
34
+ {options.map((o: any) => (
35
+ <option key={o.value} value={o.value}>
36
+ {o.label}
37
+ </option>
38
+ ))}
39
+ </select>
40
+ ),
41
+ }));
42
+
43
+ jest.mock("@shared/components/text", () => ({
44
+ Text: ({ as: Tag = "span", children, className }: any) => (
45
+ <Tag className={className}>{children}</Tag>
46
+ ),
47
+ }));
48
+
49
+ jest.mock("@shared/contentful/blocks/cards/blog-card", () => ({
50
+ BlogCard: ({ href, title, category, image, imageComponent, index }: any) => (
51
+ <a
52
+ href={href}
53
+ data-testid={`blog-card-${index}`}
54
+ data-has-image={!!image}
55
+ data-has-image-component={!!imageComponent}
56
+ >
57
+ {title} - {category}
58
+ </a>
59
+ ),
60
+ }));
61
+
62
+ const categoryOptions: BlogCategoryOption[] = [
63
+ { value: "all", label: "All Categories" },
64
+ { value: "tech", label: "Technology" },
65
+ { value: "news", label: "News" },
66
+ ];
67
+
68
+ const mockArticles = [
69
+ {
70
+ slug: "/article-1",
71
+ title: "Article One",
72
+ shortDescription: "Desc 1",
73
+ blogCreationDate: "2024-01-01",
74
+ category: "tech",
75
+ cover: {
76
+ url: "https://img.test/1.jpg",
77
+ width: 600,
78
+ height: 338,
79
+ title: "Cover 1",
80
+ },
81
+ },
82
+ {
83
+ slug: "article-2",
84
+ title: "Article Two",
85
+ shortDescription: "Desc 2",
86
+ blogCreationDate: "2024-02-01",
87
+ category: "news",
88
+ cover: { url: "https://img.test/2.jpg" },
89
+ },
90
+ {
91
+ slug: "article-3",
92
+ title: "Article Three",
93
+ shortDescription: "Desc 3",
94
+ blogCreationDate: "2024-03-01",
95
+ category: "tech",
96
+ },
97
+ ];
98
+
99
+ const defaultProps: BlogGridBaseProps = {
100
+ paginatedArticles: mockArticles,
101
+ totalArticles: 10,
102
+ currentPage: 1,
103
+ totalPages: 3,
104
+ selectedCategory: categoryOptions[0],
105
+ categoryOptions,
106
+ onCategoryChange: jest.fn(),
107
+ onPageChange: jest.fn(),
108
+ };
109
+
110
+ describe("BlogGridBase", () => {
111
+ beforeEach(() => jest.clearAllMocks());
112
+
113
+ describe("Rendering", () => {
114
+ it("renders section with correct attributes", () => {
115
+ const { container } = render(<BlogGridBase {...defaultProps} />);
116
+ const section = container.querySelector("section");
117
+ expect(section).toHaveAttribute("aria-label", "Blog articles");
118
+ expect(section).toHaveAttribute("data-section-type", "blogs-grid");
119
+ expect(section).toHaveAttribute("data-section-index", "0");
120
+ });
121
+
122
+ it("renders default title", () => {
123
+ render(<BlogGridBase {...defaultProps} />);
124
+ expect(screen.getByText("recent articles")).toBeInTheDocument();
125
+ });
126
+
127
+ it("renders custom title", () => {
128
+ render(<BlogGridBase {...defaultProps} title="custom title" />);
129
+ expect(screen.getByText("custom title")).toBeInTheDocument();
130
+ });
131
+
132
+ it("renders article count", () => {
133
+ render(<BlogGridBase {...defaultProps} />);
134
+ expect(screen.getByText("3 of 10 articles")).toBeInTheDocument();
135
+ });
136
+
137
+ it("renders all blog cards", () => {
138
+ render(<BlogGridBase {...defaultProps} />);
139
+ expect(screen.getByTestId("blog-card-0")).toBeInTheDocument();
140
+ expect(screen.getByTestId("blog-card-1")).toBeInTheDocument();
141
+ expect(screen.getByTestId("blog-card-2")).toBeInTheDocument();
142
+ });
143
+
144
+ it("renders empty state when no articles", () => {
145
+ render(<BlogGridBase {...defaultProps} paginatedArticles={[]} />);
146
+ expect(screen.getByText("No articles found.")).toBeInTheDocument();
147
+ });
148
+
149
+ it("hides category controls when categoryOptions is empty", () => {
150
+ render(<BlogGridBase {...defaultProps} categoryOptions={[]} />);
151
+ expect(screen.queryByTestId("category-select")).not.toBeInTheDocument();
152
+ });
153
+ });
154
+
155
+ describe("Slug handling", () => {
156
+ it("keeps href unchanged when slug starts with /", () => {
157
+ render(<BlogGridBase {...defaultProps} />);
158
+ expect(screen.getByTestId("blog-card-0")).toHaveAttribute(
159
+ "href",
160
+ "/article-1"
161
+ );
162
+ });
163
+
164
+ it("prepends / to slug when it does not start with /", () => {
165
+ render(<BlogGridBase {...defaultProps} />);
166
+ expect(screen.getByTestId("blog-card-1")).toHaveAttribute(
167
+ "href",
168
+ "/article-2"
169
+ );
170
+ });
171
+ });
172
+
173
+ describe("Category filter", () => {
174
+ it("calls onCategoryChange with selected category", () => {
175
+ render(<BlogGridBase {...defaultProps} />);
176
+ fireEvent.change(screen.getByTestId("category-select"), {
177
+ target: { value: "tech" },
178
+ });
179
+ expect(defaultProps.onCategoryChange).toHaveBeenCalledWith({
180
+ value: "tech",
181
+ label: "Technology",
182
+ });
183
+ });
184
+
185
+ it("does nothing when value is falsy", () => {
186
+ render(<BlogGridBase {...defaultProps} />);
187
+ fireEvent.change(screen.getByTestId("category-select"), {
188
+ target: { value: "nonexistent" },
189
+ });
190
+ expect(defaultProps.onCategoryChange).not.toHaveBeenCalled();
191
+ });
192
+
193
+ it("works without onCategoryChange callback", () => {
194
+ render(<BlogGridBase {...defaultProps} onCategoryChange={undefined} />);
195
+ expect(() => {
196
+ fireEvent.change(screen.getByTestId("category-select"), {
197
+ target: { value: "tech" },
198
+ });
199
+ }).not.toThrow();
200
+ });
201
+ });
202
+
203
+ describe("Pagination", () => {
204
+ it("renders pagination when totalPages > 1", () => {
205
+ render(<BlogGridBase {...defaultProps} />);
206
+ expect(screen.getByTestId("pagination")).toBeInTheDocument();
207
+ });
208
+
209
+ it("does not render pagination when totalPages is 1", () => {
210
+ render(<BlogGridBase {...defaultProps} totalPages={1} />);
211
+ expect(screen.queryByTestId("pagination")).not.toBeInTheDocument();
212
+ });
213
+
214
+ it("calls onPageChange with page number", () => {
215
+ render(<BlogGridBase {...defaultProps} />);
216
+ fireEvent.click(screen.getByTestId("page-next"));
217
+ expect(defaultProps.onPageChange).toHaveBeenCalledWith(2);
218
+ });
219
+
220
+ it("works without onPageChange callback", () => {
221
+ render(<BlogGridBase {...defaultProps} onPageChange={undefined} />);
222
+ expect(() => {
223
+ fireEvent.click(screen.getByTestId("page-next"));
224
+ }).not.toThrow();
225
+ });
226
+ });
227
+
228
+ describe("Cover image handling", () => {
229
+ it("passes image data when cover has url", () => {
230
+ render(<BlogGridBase {...defaultProps} />);
231
+ expect(screen.getByTestId("blog-card-0")).toHaveAttribute(
232
+ "data-has-image",
233
+ "true"
234
+ );
235
+ });
236
+
237
+ it("passes undefined image when no cover", () => {
238
+ render(<BlogGridBase {...defaultProps} />);
239
+ expect(screen.getByTestId("blog-card-2")).toHaveAttribute(
240
+ "data-has-image",
241
+ "false"
242
+ );
243
+ });
244
+
245
+ it("uses default width/height when not provided", () => {
246
+ // article-2 has cover with url but no width/height
247
+ render(<BlogGridBase {...defaultProps} />);
248
+ expect(screen.getByTestId("blog-card-1")).toHaveAttribute(
249
+ "data-has-image",
250
+ "true"
251
+ );
252
+ });
253
+
254
+ it("uses fallback alt when cover title and article title are missing", () => {
255
+ const articles = [
256
+ { slug: "no-title", cover: { url: "https://img.test/x.jpg" } },
257
+ ];
258
+ render(<BlogGridBase {...defaultProps} paginatedArticles={articles} />);
259
+ expect(screen.getByTestId("blog-card-0")).toHaveAttribute(
260
+ "data-has-image",
261
+ "true"
262
+ );
263
+ });
264
+
265
+ it("passes imageComponent to BlogCard", () => {
266
+ const MockImage = (props: any) => <img {...props} />;
267
+ render(<BlogGridBase {...defaultProps} imageComponent={MockImage} />);
268
+ expect(screen.getByTestId("blog-card-0")).toHaveAttribute(
269
+ "data-has-image-component",
270
+ "true"
271
+ );
272
+ });
273
+ });
274
+ });
@@ -0,0 +1,281 @@
1
+ import "@testing-library/jest-dom";
2
+
3
+ import React from "react";
4
+ import { BreadcrumbNavigation } from "./index";
5
+
6
+ import { render, screen } from "@testing-library/react";
7
+
8
+ jest.mock("@shared/components/material-icon", () => ({
9
+ MaterialIcon: ({ name, className }: any) => (
10
+ <span data-testid="material-icon" className={className}>
11
+ {name}
12
+ </span>
13
+ ),
14
+ }));
15
+
16
+ jest.mock("@shared/components/text", () => ({
17
+ Text: ({ as: Tag = "span", children, className }: any) => (
18
+ <Tag className={className}>{children}</Tag>
19
+ ),
20
+ }));
21
+
22
+ const baseLinks = [
23
+ { buttonLabel: "Home", href: "/" },
24
+ { buttonLabel: "Blog", href: "/blog" },
25
+ { buttonLabel: "Current Page" },
26
+ ];
27
+
28
+ describe("BreadcrumbNavigation", () => {
29
+ it("renders nothing when links is empty", () => {
30
+ const { container } = render(<BreadcrumbNavigation links={[]} />);
31
+ expect(container.querySelector("nav")).not.toBeInTheDocument();
32
+ });
33
+
34
+ it("renders nothing when links is undefined", () => {
35
+ const { container } = render(<BreadcrumbNavigation />);
36
+ expect(container.querySelector("nav")).not.toBeInTheDocument();
37
+ });
38
+
39
+ it("renders nav with aria-label", () => {
40
+ render(<BreadcrumbNavigation links={baseLinks} />);
41
+ expect(screen.getByLabelText("Breadcrumb")).toBeInTheDocument();
42
+ });
43
+
44
+ it("renders non-last links as anchor elements with chevron", () => {
45
+ const { container } = render(<BreadcrumbNavigation links={baseLinks} />);
46
+ const anchors = container.querySelectorAll("a");
47
+ expect(anchors).toHaveLength(2);
48
+ expect(anchors[0]).toHaveAttribute("href", "/");
49
+ expect(anchors[0]).toHaveTextContent("Home");
50
+ expect(anchors[1]).toHaveAttribute("href", "/blog");
51
+ const icons = screen.getAllByTestId("material-icon");
52
+ expect(icons).toHaveLength(2);
53
+ icons.forEach(icon => {
54
+ expect(icon).toHaveTextContent("chevron_right");
55
+ });
56
+ });
57
+
58
+ it("renders last link as Text span", () => {
59
+ render(<BreadcrumbNavigation links={baseLinks} />);
60
+ expect(screen.getByText("Current Page")).toBeInTheDocument();
61
+ });
62
+
63
+ describe("textColor", () => {
64
+ it("applies dark text color by default", () => {
65
+ const { container } = render(
66
+ <BreadcrumbNavigation links={baseLinks} textColor="dark" />
67
+ );
68
+ const anchor = container.querySelector("a");
69
+ expect(anchor?.className).toContain("text-text");
70
+ });
71
+
72
+ it("applies light text color", () => {
73
+ const { container } = render(
74
+ <BreadcrumbNavigation links={baseLinks} textColor="light" />
75
+ );
76
+ const anchor = container.querySelector("a");
77
+ expect(anchor?.className).toContain("text-white");
78
+ });
79
+
80
+ it("applies mobileTextColor override", () => {
81
+ const { container } = render(
82
+ <BreadcrumbNavigation
83
+ links={baseLinks}
84
+ textColor="dark"
85
+ mobileTextColor="light"
86
+ />
87
+ );
88
+ const anchor = container.querySelector("a");
89
+ expect(anchor?.className).toContain("text-white");
90
+ });
91
+
92
+ it("applies desktopTextColor override", () => {
93
+ const { container } = render(
94
+ <BreadcrumbNavigation
95
+ links={baseLinks}
96
+ textColor="dark"
97
+ desktopTextColor="light"
98
+ />
99
+ );
100
+ const anchor = container.querySelector("a");
101
+ expect(anchor?.className).toContain("xl:text-white");
102
+ });
103
+ });
104
+
105
+ describe("float prop", () => {
106
+ it("applies absolute class when float is always", () => {
107
+ const { container } = render(
108
+ <BreadcrumbNavigation links={baseLinks} float="always" />
109
+ );
110
+ const ol = container.querySelector("ol");
111
+ expect(ol?.className).toContain("absolute");
112
+ });
113
+
114
+ it("applies relative xl:absolute class when float is desktop (default)", () => {
115
+ const { container } = render(
116
+ <BreadcrumbNavigation links={baseLinks} float="desktop" />
117
+ );
118
+ const ol = container.querySelector("ol");
119
+ expect(ol?.className).toContain("relative xl:absolute");
120
+ });
121
+
122
+ it("applies absolute xl:relative class when float is mobile", () => {
123
+ const { container } = render(
124
+ <BreadcrumbNavigation links={baseLinks} float="mobile" />
125
+ );
126
+ const ol = container.querySelector("ol");
127
+ expect(ol?.className).toContain("absolute xl:relative");
128
+ });
129
+
130
+ it("applies relative class when float is none", () => {
131
+ const { container } = render(
132
+ <BreadcrumbNavigation links={baseLinks} float="none" />
133
+ );
134
+ const ol = container.querySelector("ol");
135
+ expect(ol?.className).toContain("relative");
136
+ expect(ol?.className).not.toContain("absolute");
137
+ });
138
+
139
+ it("applies px-7 when float is always", () => {
140
+ const { container } = render(
141
+ <BreadcrumbNavigation links={baseLinks} float="always" />
142
+ );
143
+ const ol = container.querySelector("ol");
144
+ expect(ol?.className).toContain("px-7");
145
+ });
146
+ });
147
+
148
+ describe("maxWidth", () => {
149
+ it("applies max-w-120 class when maxWidth is true", () => {
150
+ const { container } = render(
151
+ <BreadcrumbNavigation links={baseLinks} maxWidth={true} />
152
+ );
153
+ expect(container.querySelector("nav")?.className).toContain("max-w-120");
154
+ });
155
+
156
+ it("applies mx-auto without max-w-120 when maxWidth is false", () => {
157
+ const { container } = render(
158
+ <BreadcrumbNavigation links={baseLinks} maxWidth={false} />
159
+ );
160
+ const nav = container.querySelector("nav");
161
+ expect(nav?.className).toContain("mx-auto");
162
+ expect(nav?.className).not.toContain("max-w-120");
163
+ });
164
+
165
+ it("applies mx-5 when maxWidth is true and float is none", () => {
166
+ const { container } = render(
167
+ <BreadcrumbNavigation links={baseLinks} maxWidth={true} float="none" />
168
+ );
169
+ const nav = container.querySelector("nav");
170
+ expect(nav?.className).toContain("mx-5");
171
+ });
172
+
173
+ it("does not apply mx-5 when float is not none", () => {
174
+ const { container } = render(
175
+ <BreadcrumbNavigation
176
+ links={baseLinks}
177
+ maxWidth={true}
178
+ float="always"
179
+ />
180
+ );
181
+ const nav = container.querySelector("nav");
182
+ expect(nav?.className).not.toContain("mx-5");
183
+ });
184
+ });
185
+
186
+ describe("Image handling", () => {
187
+ it("renders image with https prefix for protocol-relative URLs", () => {
188
+ const links = [
189
+ {
190
+ buttonLabel: "Home",
191
+ href: "/",
192
+ image: { url: "//cdn.test/img.png", alt: "Logo" },
193
+ },
194
+ { buttonLabel: "Current" },
195
+ ];
196
+ render(<BreadcrumbNavigation links={links} />);
197
+ const img = screen.getAllByRole("img")[0];
198
+ expect(img).toHaveAttribute("src", "https://cdn.test/img.png");
199
+ expect(img).toHaveAttribute("alt", "Logo");
200
+ });
201
+
202
+ it("renders image with original URL when it does not start with //", () => {
203
+ const links = [
204
+ {
205
+ buttonLabel: "Home",
206
+ href: "/",
207
+ image: { url: "https://cdn.test/img.png", alt: "Logo" },
208
+ },
209
+ { buttonLabel: "Current" },
210
+ ];
211
+ render(<BreadcrumbNavigation links={links} />);
212
+ expect(screen.getAllByRole("img")[0]).toHaveAttribute(
213
+ "src",
214
+ "https://cdn.test/img.png"
215
+ );
216
+ });
217
+
218
+ it("does not render image when url is missing", () => {
219
+ const links = [
220
+ { buttonLabel: "Home", href: "/", image: {} },
221
+ { buttonLabel: "Current" },
222
+ ];
223
+ render(<BreadcrumbNavigation links={links} />);
224
+ expect(screen.queryByRole("img")).not.toBeInTheDocument();
225
+ });
226
+
227
+ it("renders image on last breadcrumb item", () => {
228
+ const links = [
229
+ { buttonLabel: "Home", href: "/" },
230
+ {
231
+ buttonLabel: "Current",
232
+ image: { url: "https://cdn.test/last.png", alt: "Last" },
233
+ },
234
+ ];
235
+ render(<BreadcrumbNavigation links={links} />);
236
+ expect(screen.getByRole("img")).toHaveAttribute(
237
+ "src",
238
+ "https://cdn.test/last.png"
239
+ );
240
+ });
241
+
242
+ it("uses empty alt when image alt is not provided", () => {
243
+ const links = [
244
+ {
245
+ buttonLabel: "Home",
246
+ href: "/",
247
+ image: { url: "https://cdn.test/img.png" },
248
+ },
249
+ { buttonLabel: "Current" },
250
+ ];
251
+ const { container } = render(<BreadcrumbNavigation links={links} />);
252
+ const img = container.querySelector("img");
253
+ expect(img).toHaveAttribute("alt", "");
254
+ });
255
+ });
256
+
257
+ describe("default float behavior", () => {
258
+ it("defaults float to desktop", () => {
259
+ const { container } = render(<BreadcrumbNavigation links={baseLinks} />);
260
+ const ol = container.querySelector("ol");
261
+ expect(ol?.className).toContain("relative xl:absolute");
262
+ });
263
+
264
+ it("default textColor derives mobileTextColor as dark when float is desktop", () => {
265
+ const { container } = render(
266
+ <BreadcrumbNavigation links={baseLinks} textColor="light" />
267
+ );
268
+ // When float=desktop, resolvedMobile = "dark" (always)
269
+ const anchor = container.querySelector("a");
270
+ expect(anchor?.className).toContain("text-text");
271
+ });
272
+
273
+ it("default textColor derives desktopTextColor from textColor when float is desktop", () => {
274
+ const { container } = render(
275
+ <BreadcrumbNavigation links={baseLinks} textColor="light" />
276
+ );
277
+ const anchor = container.querySelector("a");
278
+ expect(anchor?.className).toContain("xl:text-white");
279
+ });
280
+ });
281
+ });