@applicaster/zapp-react-native-ui-components 16.0.0-rc.6 → 16.0.0-rc.61

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 (129) hide show
  1. package/Components/AudioPlayer/tv/__tests__/audioPlayer.test.js +19 -0
  2. package/Components/AudioPlayer/tv/__tests__/index.test.tsx +120 -0
  3. package/Components/AudioPlayer/tv/index.tsx +5 -1
  4. package/Components/BackgroundImage/BackgroundImage.android.tv.tsx +28 -0
  5. package/Components/BackgroundImage/BackgroundImage.ios.tv.tsx +24 -0
  6. package/Components/BackgroundImage/BackgroundImage.tsx +42 -0
  7. package/Components/BackgroundImage/index.ts +1 -0
  8. package/Components/CellRendererResolver/index.ts +2 -2
  9. package/Components/ComponentResolver/__tests__/componentResolver.test.js +1 -1
  10. package/Components/FocusableGroup/FocusableTvOS.tsx +11 -7
  11. package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +39 -0
  12. package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +64 -0
  13. package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
  14. package/Components/GeneralContentScreen/hookAdapter/__tests__/networkService.test.ts +74 -0
  15. package/Components/GeneralContentScreen/hookAdapter/__tests__/runInBackground.test.ts +139 -0
  16. package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +124 -0
  17. package/Components/GeneralContentScreen/hookAdapter/logger.ts +6 -0
  18. package/Components/GeneralContentScreen/hookAdapter/networkService.ts +53 -0
  19. package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +48 -0
  20. package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +72 -0
  21. package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
  22. package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
  23. package/Components/GeneralContentScreen/index.ts +2 -0
  24. package/Components/Layout/FullWidthRow.tsx +38 -0
  25. package/Components/Layout/TV/ScreenContainer.tsx +5 -0
  26. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +0 -1
  27. package/Components/Layout/TV/index.tsx +3 -4
  28. package/Components/Layout/TV/index.web.tsx +2 -3
  29. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +16 -5
  30. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +47 -21
  31. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +34 -6
  32. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +1 -1
  33. package/Components/MasterCell/DefaultComponents/Image/hoc/utils/__tests__/withDimensions.test.ts +420 -125
  34. package/Components/MasterCell/DefaultComponents/Image/hoc/utils/index.ts +114 -19
  35. package/Components/MasterCell/DefaultComponents/Image/hoc/withDimensions.tsx +19 -8
  36. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -3
  37. package/Components/MasterCell/DefaultComponents/PressableView.tsx +29 -9
  38. package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +4 -0
  39. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +154 -100
  40. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +15 -4
  41. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +56 -22
  42. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +6 -4
  43. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +3 -1
  44. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +32 -21
  45. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +15 -4
  46. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +23 -16
  47. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +8 -3
  48. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +2 -2
  49. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/insertButtonsBetweenLabels.test.ts +45 -13
  50. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +2 -2
  51. package/Components/MasterCell/contexts/PressedStateContext.ts +3 -0
  52. package/Components/MasterCell/dataAdapter.ts +15 -5
  53. package/Components/MasterCell/hooks/index.ts +2 -0
  54. package/Components/MasterCell/hooks/usePressedState.ts +4 -0
  55. package/Components/MasterCell/index.tsx +30 -5
  56. package/Components/MasterCell/utils/__tests__/resolveColor.test.js +169 -132
  57. package/Components/MasterCell/utils/__tests__/resolveColorForProp.test.js +92 -0
  58. package/Components/MasterCell/utils/index.ts +85 -46
  59. package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +314 -0
  60. package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +395 -0
  61. package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +763 -0
  62. package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +653 -0
  63. package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +874 -0
  64. package/Components/ModalComponent/AudioPlayer/Components/NowPlayingHeaderSection.tsx +89 -0
  65. package/Components/ModalComponent/AudioPlayer/Components/index.ts +11 -0
  66. package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +199 -0
  67. package/Components/ModalComponent/BottomSheetDragArea.tsx +33 -0
  68. package/Components/ModalComponent/BottomSheetModalContent.tsx +386 -42
  69. package/Components/ModalComponent/Button/index.tsx +5 -3
  70. package/Components/ModalComponent/Header/index.tsx +20 -7
  71. package/Components/ModalComponent/Header/utils.ts +1 -1
  72. package/Components/ModalComponent/ModalBlocksStyleContext.tsx +10 -0
  73. package/Components/ModalComponent/SortableList.tsx +142 -0
  74. package/Components/ModalComponent/TextInputContent.tsx +100 -0
  75. package/Components/ModalComponent/__tests__/BottomSheetDragArea.test.tsx +74 -0
  76. package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +238 -0
  77. package/Components/ModalComponent/__tests__/TextInputContent.test.tsx +120 -0
  78. package/Components/ModalComponent/__tests__/showTextInput.test.ts +95 -0
  79. package/Components/ModalComponent/index.tsx +11 -0
  80. package/Components/ModalComponent/presets/__tests__/getCell.test.ts +66 -0
  81. package/Components/ModalComponent/presets/dynamicCollectionCell.tsx +78 -0
  82. package/Components/ModalComponent/presets/index.ts +27 -0
  83. package/Components/ModalComponent/presets/selectableCell.tsx +28 -0
  84. package/Components/ModalComponent/presets/standardCell.tsx +41 -0
  85. package/Components/ModalComponent/presets/types.ts +35 -0
  86. package/Components/ModalComponent/showTextInput.ts +43 -0
  87. package/Components/ModalComponent/utils.ts +76 -20
  88. package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +4 -85
  89. package/Components/OfflineHandler/__tests__/index.test.tsx +78 -18
  90. package/Components/OfflineHandler/hooks.ts +123 -0
  91. package/Components/OfflineHandler/index.tsx +51 -73
  92. package/Components/OfflineHandler/utils/index.ts +1 -13
  93. package/Components/PlayerContainer/PlayerContainer.tsx +25 -17
  94. package/Components/PlayerContainer/ProgramInfo/index.tsx +3 -4
  95. package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +337 -0
  96. package/Components/PreloaderWrapper/index.tsx +1 -1
  97. package/Components/River/ComponentsMap/ComponentsMap.tsx +2 -2
  98. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +3 -15
  99. package/Components/Screen/TV/hooks/__tests__/useAfterPaint.test.ts +60 -0
  100. package/Components/Screen/TV/hooks/index.ts +2 -0
  101. package/Components/Screen/TV/hooks/useAfterPaint.ts +23 -0
  102. package/Components/Screen/TV/index.web.tsx +16 -7
  103. package/Components/Screen/index.tsx +8 -4
  104. package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +5 -3
  105. package/Components/ScreenResolverFeedProvider/ScreenResolverFeedProvider.tsx +1 -1
  106. package/Components/ScreenRevealManager/Overlay.tsx +34 -0
  107. package/Components/ScreenRevealManager/__tests__/Overlay.test.tsx +88 -0
  108. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +8 -19
  109. package/Components/TopCutoffOverlay/index.tsx +2 -2
  110. package/Components/Transitioner/Transitioner.tsx +28 -17
  111. package/Components/VideoLive/LiveImageManager.ts +41 -43
  112. package/Components/VideoModal/utils.ts +6 -1
  113. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +12 -5
  114. package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
  115. package/Contexts/CachedDimensionsContext/__tests__/index.test.ts +154 -0
  116. package/Contexts/CachedDimensionsContext/index.ts +17 -2
  117. package/Helpers/ComponentCellSelectionHelper/index.js +0 -6
  118. package/Helpers/index.js +7 -40
  119. package/package.json +6 -5
  120. package/Components/Layout/TV/LayoutBackground.tsx +0 -31
  121. package/Components/OfflineHandler/NotificationView/NotificationView.lg.tsx +0 -112
  122. package/Components/OfflineHandler/NotificationView/NotificationView.samsung.tsx +0 -107
  123. package/Components/OfflineHandler/NotificationView/NotificationView.tsx +0 -153
  124. package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +0 -66
  125. package/Components/OfflineHandler/NotificationView/utils.ts +0 -34
  126. package/Components/Screen/utils.ts +0 -16
  127. package/Helpers/Analytics/index.js +0 -95
  128. /package/Components/MasterCell/DefaultComponents/ButtonContainerView/{index.tv.android.tsx → index.android.tv.tsx} +0 -0
  129. /package/Decorators/ZappPipesDataConnector/__tests__/{Hero.js → Hero.tsx} +0 -0
@@ -1,205 +1,500 @@
1
- import { withDimensions } from "..";
1
+ import { mergeQueryParams, withDimensions } from "..";
2
+
3
+ const mockWarning = jest.fn();
4
+
5
+ jest.mock("@applicaster/zapp-react-native-utils/logger", () => {
6
+ const mockLogger = {
7
+ addSubsystem: jest.fn(() => mockLogger),
8
+ warning: (...args) => mockWarning(...args),
9
+ };
10
+
11
+ return { coreLogger: mockLogger };
12
+ });
2
13
 
3
14
  describe("withDimensions", () => {
4
15
  const width = 300;
5
16
  const height = 200;
17
+ const defaultTemplate = "width={{width}}&height={{height}}";
6
18
 
7
- it("only width in the beginning", () => {
8
- const url = "https://some_url?width=511&quality=95&sharpen=true";
19
+ beforeEach(() => {
20
+ mockWarning.mockClear();
21
+ });
9
22
 
10
- const result = withDimensions(url, width, height);
23
+ describe("with default template (width={{width}}&height={{height}})", () => {
24
+ it("injects width and height into a URL without existing dimension params", () => {
25
+ const url = "https://some_url?quality=95&sharpen=true";
11
26
 
12
- expect(result).toEqual(
13
- `https://some_url?width=${width}&quality=95&sharpen=true`
14
- );
15
- });
27
+ const result = withDimensions(url, width, height, defaultTemplate);
16
28
 
17
- it("only width in the middle", () => {
18
- const url = "https://some_url?quality=95&width=511&sharpen=true";
29
+ expect(result).toContain("width=300");
30
+ expect(result).toContain("height=200");
31
+ expect(result).toContain("quality=95");
32
+ expect(result).toContain("sharpen=true");
33
+ });
19
34
 
20
- const result = withDimensions(url, width, height);
35
+ it("replaces existing width and height params regardless of original size", () => {
36
+ const url =
37
+ "https://some_url?width=511&quality=95&height=400&sharpen=true";
21
38
 
22
- expect(result).toEqual(
23
- `https://some_url?quality=95&width=${width}&sharpen=true`
24
- );
25
- });
39
+ const result = withDimensions(url, width, height, defaultTemplate);
26
40
 
27
- it("only height in the beginning", () => {
28
- const url = "https://some_url?height=511&quality=95&sharpen=true";
41
+ expect(result).toContain("width=300");
42
+ expect(result).toContain("height=200");
43
+ expect(result).toContain("quality=95");
44
+ });
29
45
 
30
- const result = withDimensions(url, width, height);
46
+ it("replaces width even when new width is larger than original", () => {
47
+ const largeWidth = 1024;
48
+ const url = "https://some_url?width=511&quality=95&sharpen=true";
31
49
 
32
- expect(result).toEqual(
33
- `https://some_url?height=${height}&quality=95&sharpen=true`
34
- );
35
- });
50
+ const result = withDimensions(url, largeWidth, height, defaultTemplate);
36
51
 
37
- it("only height in the middle", () => {
38
- const url = "https://some_url?quality=95&height=511&sharpen=true";
52
+ expect(result).toContain("width=1024");
53
+ });
39
54
 
40
- const result = withDimensions(url, width, height);
55
+ it("replaces height even when new height is larger than original", () => {
56
+ const largeHeight = 1024;
57
+ const url = "https://some_url?height=511&quality=95&sharpen=true";
41
58
 
42
- expect(result).toEqual(
43
- `https://some_url?quality=95&height=${height}&sharpen=true`
44
- );
45
- });
59
+ const result = withDimensions(url, width, largeHeight, defaultTemplate);
46
60
 
47
- it("width and height", () => {
48
- const url = "https://some_url?width=511&quality=95&height=400&sharpen=true";
61
+ expect(result).toContain("height=1024");
62
+ });
49
63
 
50
- const result = withDimensions(url, width, height);
64
+ it("adds width and height to URL with no query params", () => {
65
+ const url = "https://some_url";
51
66
 
52
- expect(result).toEqual(
53
- `https://some_url?width=${width}&quality=95&height=${height}&sharpen=true`
54
- );
55
- });
67
+ const result = withDimensions(url, width, height, defaultTemplate);
56
68
 
57
- it("no width and no height", () => {
58
- const url = "https://some_url?quality=95&sharpen=true";
69
+ expect(result).toContain("width=300");
70
+ expect(result).toContain("height=200");
71
+ });
59
72
 
60
- const result = withDimensions(url, width, height);
73
+ it("truncates decimal width values", () => {
74
+ const decimalWidth = 243.42857142857142;
75
+ const url = "https://some_url?quality=95";
61
76
 
62
- expect(result).toEqual("https://some_url?quality=95&sharpen=true");
63
- });
77
+ const result = withDimensions(url, decimalWidth, height, defaultTemplate);
64
78
 
65
- it("undefined width", () => {
66
- const url = "https://some_url?width=511&quality=95&sharpen=true";
79
+ expect(result).toContain("width=243");
80
+ });
67
81
 
68
- const result = withDimensions(url, undefined, height);
82
+ it("replaces URL with width=0 in the original", () => {
83
+ const url = "https://some_url?width=0&quality=95&sharpen=true";
69
84
 
70
- expect(result).toEqual(
71
- "https://some_url?width=511&quality=95&sharpen=true"
72
- );
73
- });
85
+ const result = withDimensions(url, width, height, defaultTemplate);
74
86
 
75
- it("undefined height", () => {
76
- const url = "https://some_url?height=511&quality=95&sharpen=true";
87
+ expect(result).toContain("width=300");
88
+ });
77
89
 
78
- const result = withDimensions(url, width, undefined);
90
+ it("replaces URL with empty width in the original", () => {
91
+ const url = "https://some_url?width=&quality=95&sharpen=true";
79
92
 
80
- expect(result).toEqual(
81
- "https://some_url?height=511&quality=95&sharpen=true"
82
- );
93
+ const result = withDimensions(url, width, height, defaultTemplate);
94
+
95
+ expect(result).toContain("width=300");
96
+ });
83
97
  });
84
98
 
85
- it("only Width", () => {
86
- const url = "https://some_url?Width=511&quality=95&sharpen=true";
99
+ describe("with custom template", () => {
100
+ it("uses custom short param names (w, h)", () => {
101
+ const template = "w={{width}}&h={{height}}";
102
+ const url = "https://cdn.example.com/image.jpg?quality=95";
87
103
 
88
- const result = withDimensions(url, width, height);
104
+ const result = withDimensions(url, width, height, template);
89
105
 
90
- expect(result).toEqual(
91
- `https://some_url?Width=${width}&quality=95&sharpen=true`
92
- );
93
- });
106
+ expect(result).toContain("w=300");
107
+ expect(result).toContain("h=200");
108
+ expect(result).toContain("quality=95");
109
+ });
94
110
 
95
- it("only heighT", () => {
96
- const url = "https://some_url?heighT=511&quality=95&sharpen=true";
111
+ it("uses template with combined size param (size=WxH)", () => {
112
+ const template = "size={{width}}x{{height}}";
113
+ const url = "https://cdn.example.com/image.jpg?quality=95";
97
114
 
98
- const result = withDimensions(url, width, height);
115
+ const result = withDimensions(url, width, height, template);
99
116
 
100
- expect(result).toEqual(
101
- `https://some_url?heighT=${height}&quality=95&sharpen=true`
102
- );
103
- });
117
+ expect(result).toContain(`size=${width}x${height}`);
118
+ expect(result).toContain("quality=95");
119
+ });
104
120
 
105
- it("no params", () => {
106
- const url = "https://some_url";
121
+ it("replaces existing custom param with same key", () => {
122
+ const template = "w={{width}}&h={{height}}";
123
+ const url = "https://cdn.example.com/image.jpg?w=999&h=888&quality=95";
107
124
 
108
- const result = withDimensions(url, width, height);
125
+ const result = withDimensions(url, width, height, template);
109
126
 
110
- expect(result).toEqual(url);
111
- });
127
+ expect(result).toContain("w=300");
128
+ expect(result).toContain("h=200");
129
+ expect(result).not.toContain("w=999");
130
+ expect(result).not.toContain("h=888");
131
+ });
112
132
 
113
- it("round input width", () => {
114
- const width = 243.42857142857142;
115
- const url = "https://some_url?width=511&quality=95&sharpen=true";
133
+ it("handles template with only width", () => {
134
+ const template = "w={{width}}";
135
+ const url = "https://cdn.example.com/image.jpg";
116
136
 
117
- const result = withDimensions(url, width, height);
137
+ const result = withDimensions(url, width, height, template);
118
138
 
119
- expect(result).toEqual(
120
- "https://some_url?width=243&quality=95&sharpen=true"
121
- );
122
- });
139
+ expect(result).toContain("w=300");
140
+ expect(result).not.toContain("height");
141
+ });
123
142
 
124
- it("takes original width when provided width more than original", () => {
125
- const width = 1024;
126
- const url = "https://some_url?width=511&quality=95&sharpen=true";
143
+ it("handles template with only height", () => {
144
+ const template = "h={{height}}";
145
+ const url = "https://cdn.example.com/image.jpg";
127
146
 
128
- const result = withDimensions(url, width, height);
147
+ const result = withDimensions(url, width, height, template);
129
148
 
130
- expect(result).toEqual(url);
131
- });
149
+ expect(result).toContain("h=200");
150
+ expect(result).not.toContain("width");
151
+ });
132
152
 
133
- it("takes original height when provided height more than original", () => {
134
- const height = 1024;
135
- const url = "https://some_url?height=511&quality=95&sharpen=true";
153
+ it("handles case-insensitive placeholders", () => {
154
+ const template = "w={{Width}}&h={{HEIGHT}}";
155
+ const url = "https://cdn.example.com/image.jpg";
136
156
 
137
- const result = withDimensions(url, width, height);
157
+ const result = withDimensions(url, width, height, template);
138
158
 
139
- expect(result).toEqual(url);
159
+ expect(result).toContain("w=300");
160
+ expect(result).toContain("h=200");
161
+ });
140
162
  });
141
163
 
142
- it("doesnt touch url if no width value is provided", () => {
143
- const url = "https://some_url?width=&quality=95&sharpen=true";
164
+ describe("no template provided", () => {
165
+ it("returns original url when template is undefined", () => {
166
+ const url = "https://some_url?width=511&quality=95&sharpen=true";
144
167
 
145
- const result = withDimensions(url, width, height);
168
+ const result = withDimensions(url, width, height, undefined);
146
169
 
147
- expect(result).toEqual(url);
148
- });
170
+ expect(result).toEqual(url);
171
+ });
172
+
173
+ it("returns original url when template is empty string", () => {
174
+ const url = "https://some_url?width=511&quality=95&sharpen=true";
175
+
176
+ const result = withDimensions(url, width, height, "");
177
+
178
+ expect(result).toEqual(url);
179
+ });
149
180
 
150
- it("doesnt touch url if width=0", () => {
151
- const url = "https://some_url?width=0&quality=95&sharpen=true";
181
+ it("returns original url when template is null", () => {
182
+ const url = "https://some_url?width=511&quality=95&sharpen=true";
152
183
 
153
- const result = withDimensions(url, width, height);
184
+ const result = withDimensions(url, width, height, null);
154
185
 
155
- expect(result).toEqual(url);
186
+ expect(result).toEqual(url);
187
+ });
156
188
  });
157
189
 
158
- it("doesnt touch url if no height value is provided", () => {
159
- const url = "https://some_url?height=&quality=95&sharpen=true";
190
+ describe("invalid / malformed template mappings", () => {
191
+ it("ignores params with unrecognized placeholders like {{heit}}", () => {
192
+ const template = "width={{width}}&height={{heit}}";
193
+ const url = "https://some_url?quality=95";
194
+
195
+ const result = withDimensions(url, width, height, template);
196
+
197
+ expect(result).toContain("width=300");
198
+ expect(result).not.toContain("heit");
199
+ expect(result).not.toContain("height");
200
+ expect(result).toContain("quality=95");
201
+ });
202
+
203
+ it("ignores params with typo placeholder and keeps valid ones", () => {
204
+ const template = "w={{wdth}}&h={{height}}";
205
+ const url = "https://cdn.example.com/image.jpg?quality=95";
206
+
207
+ const result = withDimensions(url, width, height, template);
208
+
209
+ expect(result).toContain("h=200");
210
+ expect(result).not.toContain("wdth");
211
+ expect(result).not.toContain("w=");
212
+ expect(result).toContain("quality=95");
213
+ });
214
+
215
+ it("returns original url when all template params are invalid", () => {
216
+ const template = "w={{wdth}}&h={{hght}}";
217
+ const url = "https://cdn.example.com/image.jpg?quality=95";
218
+
219
+ const result = withDimensions(url, width, height, template);
220
+
221
+ expect(result).toEqual(url);
222
+ });
223
+
224
+ it("ignores completely broken placeholder syntax", () => {
225
+ const template = "width={{width}}&height{{heit}}";
226
+ const url = "https://some_url?quality=95";
227
+
228
+ const result = withDimensions(url, width, height, template);
229
+
230
+ expect(result).toContain("width=300");
231
+ expect(result).not.toContain("heit");
232
+ expect(result).toContain("quality=95");
233
+ });
234
+
235
+ it("ignores param with empty placeholder {{}}", () => {
236
+ const template = "width={{width}}&height={{}}";
237
+ const url = "https://some_url?quality=95";
238
+
239
+ const result = withDimensions(url, width, height, template);
240
+
241
+ expect(result).toContain("width=300");
242
+ expect(result).not.toContain("{{}}");
243
+ });
244
+
245
+ it("ignores malformed placeholder with single closing brace {{heit}", () => {
246
+ const template = "width={{width}}&height={{heit}";
247
+ const url = "https://some_url?quality=95";
248
+
249
+ const result = withDimensions(url, width, height, template);
250
+
251
+ expect(result).toContain("width=300");
252
+ expect(result).not.toContain("heit");
253
+ expect(result).toContain("quality=95");
254
+ });
255
+
256
+ it("ignores malformed placeholder missing closing braces entirely", () => {
257
+ const template = "width={{width}}&height={{height";
258
+ const url = "https://some_url?quality=95";
259
+
260
+ const result = withDimensions(url, width, height, template);
261
+
262
+ expect(result).toContain("width=300");
263
+ expect(result).not.toContain("{{height");
264
+ expect(result).toContain("quality=95");
265
+ });
266
+
267
+ it("logs a warning for each invalid placeholder", () => {
268
+ const template = "width={{width}}&height={{heit}}";
269
+ const url = "https://some_url?quality=95";
270
+
271
+ withDimensions(url, width, height, template);
272
+
273
+ expect(mockWarning).toHaveBeenCalledTimes(1);
160
274
 
161
- const result = withDimensions(url, width, height);
275
+ expect(mockWarning).toHaveBeenCalledWith(
276
+ expect.objectContaining({
277
+ message: expect.stringContaining("{{heit}}"),
278
+ data: expect.objectContaining({
279
+ invalidNames: ["heit"],
280
+ }),
281
+ })
282
+ );
283
+ });
162
284
 
163
- expect(result).toEqual(url);
285
+ it("logs a warning for each dropped param pair independently", () => {
286
+ const template = "w={{wdth}}&h={{hght}}";
287
+ const url = "https://cdn.example.com/image.jpg?quality=95";
288
+
289
+ withDimensions(url, width, height, template);
290
+
291
+ expect(mockWarning).toHaveBeenCalledTimes(2);
292
+ });
293
+
294
+ it("does not log when all placeholders are valid", () => {
295
+ const url = "https://some_url?quality=95";
296
+
297
+ withDimensions(url, width, height, defaultTemplate);
298
+
299
+ expect(mockWarning).not.toHaveBeenCalled();
300
+ });
164
301
  });
165
302
 
166
- it("doesnt touch url if height=0", () => {
167
- const url = "https://some_url?height=0&quality=95&sharpen=true";
303
+ describe("leading question mark in template", () => {
304
+ it("strips leading ? from template", () => {
305
+ const template = "?width={{width}}&height={{height}}";
306
+ const url = "https://some_url?quality=95";
307
+
308
+ const result = withDimensions(url, width, height, template);
309
+
310
+ expect(result).toContain("width=300");
311
+ expect(result).toContain("height=200");
312
+ expect(result).toContain("quality=95");
313
+ });
314
+
315
+ it("strips leading ? with whitespace from template", () => {
316
+ const template = " ?width={{width}}&height={{height}}";
317
+ const url = "https://some_url?quality=95";
318
+
319
+ const result = withDimensions(url, width, height, template);
320
+
321
+ expect(result).toContain("width=300");
322
+ expect(result).toContain("height=200");
323
+ });
324
+
325
+ it("strips leading ? on URL without existing query params", () => {
326
+ const template = "?w={{width}}&h={{height}}";
327
+ const url = "https://cdn.example.com/image.jpg";
328
+
329
+ const result = withDimensions(url, width, height, template);
330
+
331
+ expect(result).toContain("w=300");
332
+ expect(result).toContain("h=200");
333
+ });
334
+
335
+ it("handles template that is just ?", () => {
336
+ const template = "?";
337
+ const url = "https://some_url?quality=95";
168
338
 
169
- const result = withDimensions(url, width, height);
339
+ const result = withDimensions(url, width, height, template);
170
340
 
171
- expect(result).toEqual(url);
341
+ expect(result).toEqual(url);
342
+ });
172
343
  });
173
344
 
174
- it("returns original url ir url is undefined", () => {
175
- const url = undefined;
345
+ describe("URLs without query params", () => {
346
+ it("adds params to a clean URL with no query string", () => {
347
+ const url = "https://cdn.example.com/image.jpg";
176
348
 
177
- const result = withDimensions(url, width, height);
349
+ const result = withDimensions(url, width, height, defaultTemplate);
178
350
 
179
- expect(result).toEqual(url);
351
+ expect(result).toContain("width=300");
352
+ expect(result).toContain("height=200");
353
+ });
354
+
355
+ it("adds custom params to a clean URL with no query string", () => {
356
+ const template = "w={{width}}&h={{height}}";
357
+ const url = "https://cdn.example.com/path/to/image.jpg";
358
+
359
+ const result = withDimensions(url, width, height, template);
360
+
361
+ expect(result).toContain("w=300");
362
+ expect(result).toContain("h=200");
363
+ });
364
+
365
+ it("adds combined size param to URL with no query string", () => {
366
+ const template = "size={{width}}x{{height}}";
367
+ const url = "https://cdn.example.com/image.jpg";
368
+
369
+ const result = withDimensions(url, width, height, template);
370
+
371
+ expect(result).toContain("size=300x200");
372
+ });
373
+
374
+ it("adds only valid params to clean URL when template has invalid mappings", () => {
375
+ const template = "width={{width}}&height={{heit}}";
376
+ const url = "https://cdn.example.com/image.jpg";
377
+
378
+ const result = withDimensions(url, width, height, template);
379
+
380
+ expect(result).toContain("width=300");
381
+ expect(result).not.toContain("heit");
382
+ });
180
383
  });
181
384
 
182
- it("returns original url ir url is empty string", () => {
183
- const url = "";
385
+ describe("edge cases", () => {
386
+ it("returns original url when url is undefined", () => {
387
+ const result = withDimensions(undefined, width, height, defaultTemplate);
388
+
389
+ expect(result).toEqual(undefined);
390
+ });
391
+
392
+ it("returns original url when url is empty string", () => {
393
+ const result = withDimensions("", width, height, defaultTemplate);
394
+
395
+ expect(result).toEqual("");
396
+ });
397
+
398
+ it("returns original url when url is invalid (non-http)", () => {
399
+ const url = "invalid_url";
184
400
 
185
- const result = withDimensions(url, width, height);
401
+ const result = withDimensions(url, width, height, defaultTemplate);
186
402
 
187
- expect(result).toEqual(url);
403
+ expect(result).toEqual(url);
404
+ });
405
+
406
+ it("returns original url when url is a number passed as string", () => {
407
+ const url = 1 as unknown as string;
408
+
409
+ const result = withDimensions(url, width, height, defaultTemplate);
410
+
411
+ expect(result).toEqual(url);
412
+ });
413
+
414
+ it("returns original url when width is undefined and height is undefined", () => {
415
+ const url = "https://some_url?quality=95";
416
+
417
+ const result = withDimensions(url, undefined, undefined, defaultTemplate);
418
+
419
+ expect(result).toEqual(url);
420
+ });
421
+
422
+ it("returns original url when width is 0 and height is 0", () => {
423
+ const url = "https://some_url?quality=95";
424
+
425
+ const result = withDimensions(url, 0, 0, defaultTemplate);
426
+
427
+ expect(result).toEqual(url);
428
+ });
429
+
430
+ it("still works when only width is provided and does not inject height=0", () => {
431
+ const url = "https://some_url?quality=95";
432
+
433
+ const result = withDimensions(url, width, undefined, defaultTemplate);
434
+
435
+ expect(result).toContain("width=300");
436
+ expect(result).not.toContain("height=0");
437
+ expect(result).not.toContain("height=");
438
+ });
439
+
440
+ it("still works when only height is provided and does not inject width=0", () => {
441
+ const url = "https://some_url?quality=95";
442
+
443
+ const result = withDimensions(url, undefined, height, defaultTemplate);
444
+
445
+ expect(result).toContain("height=200");
446
+ expect(result).not.toContain("width=0");
447
+ expect(result).not.toContain("width=");
448
+ });
449
+
450
+ it("preserves URL hash fragment", () => {
451
+ const url = "https://some_url?quality=95#section1";
452
+
453
+ const result = withDimensions(url, width, height, defaultTemplate);
454
+
455
+ expect(result).toContain("width=300");
456
+ expect(result).toContain("height=200");
457
+ });
188
458
  });
459
+ });
189
460
 
190
- it("returns original url ir url is invalid", () => {
191
- const url = "invalid_url";
461
+ describe("mergeQueryParams", () => {
462
+ it("adds new params to URL without existing params", () => {
463
+ const result = mergeQueryParams(
464
+ "https://example.com/img.jpg",
465
+ "w=300&h=200"
466
+ );
192
467
 
193
- const result = withDimensions(url, width, height);
468
+ expect(result).toContain("w=300");
469
+ expect(result).toContain("h=200");
470
+ });
194
471
 
195
- expect(result).toEqual(url);
472
+ it("overwrites existing params with same key", () => {
473
+ const result = mergeQueryParams(
474
+ "https://example.com/img.jpg?w=999&quality=95",
475
+ "w=300"
476
+ );
477
+
478
+ expect(result).toContain("w=300");
479
+ expect(result).not.toContain("w=999");
480
+ expect(result).toContain("quality=95");
196
481
  });
197
482
 
198
- it("returns original url ir url is invalid", () => {
199
- const url = 1 as unknown as string;
483
+ it("returns original URL if parsing fails", () => {
484
+ const badUrl = "not a url at all";
485
+
486
+ const result = mergeQueryParams(badUrl, "w=300");
200
487
 
201
- const result = withDimensions(url, width, height);
488
+ expect(result).toEqual(badUrl);
489
+ });
490
+
491
+ it("handles combined values (e.g. size=300x200)", () => {
492
+ const result = mergeQueryParams(
493
+ "https://example.com/img.jpg?quality=95",
494
+ "size=300x200"
495
+ );
202
496
 
203
- expect(result).toEqual(url);
497
+ expect(result).toContain("size=300x200");
498
+ expect(result).toContain("quality=95");
204
499
  });
205
500
  });