@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.
- package/Components/AudioPlayer/tv/__tests__/audioPlayer.test.js +19 -0
- package/Components/AudioPlayer/tv/__tests__/index.test.tsx +120 -0
- package/Components/AudioPlayer/tv/index.tsx +5 -1
- package/Components/BackgroundImage/BackgroundImage.android.tv.tsx +28 -0
- package/Components/BackgroundImage/BackgroundImage.ios.tv.tsx +24 -0
- package/Components/BackgroundImage/BackgroundImage.tsx +42 -0
- package/Components/BackgroundImage/index.ts +1 -0
- package/Components/CellRendererResolver/index.ts +2 -2
- package/Components/ComponentResolver/__tests__/componentResolver.test.js +1 -1
- package/Components/FocusableGroup/FocusableTvOS.tsx +11 -7
- package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +39 -0
- package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +64 -0
- package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/networkService.test.ts +74 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/runInBackground.test.ts +139 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +124 -0
- package/Components/GeneralContentScreen/hookAdapter/logger.ts +6 -0
- package/Components/GeneralContentScreen/hookAdapter/networkService.ts +53 -0
- package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +48 -0
- package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +72 -0
- package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
- package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
- package/Components/GeneralContentScreen/index.ts +2 -0
- package/Components/Layout/FullWidthRow.tsx +38 -0
- package/Components/Layout/TV/ScreenContainer.tsx +5 -0
- package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +0 -1
- package/Components/Layout/TV/index.tsx +3 -4
- package/Components/Layout/TV/index.web.tsx +2 -3
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +16 -5
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +47 -21
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +34 -6
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +1 -1
- package/Components/MasterCell/DefaultComponents/Image/hoc/utils/__tests__/withDimensions.test.ts +420 -125
- package/Components/MasterCell/DefaultComponents/Image/hoc/utils/index.ts +114 -19
- package/Components/MasterCell/DefaultComponents/Image/hoc/withDimensions.tsx +19 -8
- package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -3
- package/Components/MasterCell/DefaultComponents/PressableView.tsx +29 -9
- package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +4 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +154 -100
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +15 -4
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +56 -22
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +6 -4
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +3 -1
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +32 -21
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +15 -4
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +23 -16
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +8 -3
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +2 -2
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/insertButtonsBetweenLabels.test.ts +45 -13
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +2 -2
- package/Components/MasterCell/contexts/PressedStateContext.ts +3 -0
- package/Components/MasterCell/dataAdapter.ts +15 -5
- package/Components/MasterCell/hooks/index.ts +2 -0
- package/Components/MasterCell/hooks/usePressedState.ts +4 -0
- package/Components/MasterCell/index.tsx +30 -5
- package/Components/MasterCell/utils/__tests__/resolveColor.test.js +169 -132
- package/Components/MasterCell/utils/__tests__/resolveColorForProp.test.js +92 -0
- package/Components/MasterCell/utils/index.ts +85 -46
- package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +314 -0
- package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +395 -0
- package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +763 -0
- package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +653 -0
- package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +874 -0
- package/Components/ModalComponent/AudioPlayer/Components/NowPlayingHeaderSection.tsx +89 -0
- package/Components/ModalComponent/AudioPlayer/Components/index.ts +11 -0
- package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +199 -0
- package/Components/ModalComponent/BottomSheetDragArea.tsx +33 -0
- package/Components/ModalComponent/BottomSheetModalContent.tsx +386 -42
- package/Components/ModalComponent/Button/index.tsx +5 -3
- package/Components/ModalComponent/Header/index.tsx +20 -7
- package/Components/ModalComponent/Header/utils.ts +1 -1
- package/Components/ModalComponent/ModalBlocksStyleContext.tsx +10 -0
- package/Components/ModalComponent/SortableList.tsx +142 -0
- package/Components/ModalComponent/TextInputContent.tsx +100 -0
- package/Components/ModalComponent/__tests__/BottomSheetDragArea.test.tsx +74 -0
- package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +238 -0
- package/Components/ModalComponent/__tests__/TextInputContent.test.tsx +120 -0
- package/Components/ModalComponent/__tests__/showTextInput.test.ts +95 -0
- package/Components/ModalComponent/index.tsx +11 -0
- package/Components/ModalComponent/presets/__tests__/getCell.test.ts +66 -0
- package/Components/ModalComponent/presets/dynamicCollectionCell.tsx +78 -0
- package/Components/ModalComponent/presets/index.ts +27 -0
- package/Components/ModalComponent/presets/selectableCell.tsx +28 -0
- package/Components/ModalComponent/presets/standardCell.tsx +41 -0
- package/Components/ModalComponent/presets/types.ts +35 -0
- package/Components/ModalComponent/showTextInput.ts +43 -0
- package/Components/ModalComponent/utils.ts +76 -20
- package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +4 -85
- package/Components/OfflineHandler/__tests__/index.test.tsx +78 -18
- package/Components/OfflineHandler/hooks.ts +123 -0
- package/Components/OfflineHandler/index.tsx +51 -73
- package/Components/OfflineHandler/utils/index.ts +1 -13
- package/Components/PlayerContainer/PlayerContainer.tsx +25 -17
- package/Components/PlayerContainer/ProgramInfo/index.tsx +3 -4
- package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +337 -0
- package/Components/PreloaderWrapper/index.tsx +1 -1
- package/Components/River/ComponentsMap/ComponentsMap.tsx +2 -2
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +3 -15
- package/Components/Screen/TV/hooks/__tests__/useAfterPaint.test.ts +60 -0
- package/Components/Screen/TV/hooks/index.ts +2 -0
- package/Components/Screen/TV/hooks/useAfterPaint.ts +23 -0
- package/Components/Screen/TV/index.web.tsx +16 -7
- package/Components/Screen/index.tsx +8 -4
- package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +5 -3
- package/Components/ScreenResolverFeedProvider/ScreenResolverFeedProvider.tsx +1 -1
- package/Components/ScreenRevealManager/Overlay.tsx +34 -0
- package/Components/ScreenRevealManager/__tests__/Overlay.test.tsx +88 -0
- package/Components/ScreenRevealManager/withScreenRevealManager.tsx +8 -19
- package/Components/TopCutoffOverlay/index.tsx +2 -2
- package/Components/Transitioner/Transitioner.tsx +28 -17
- package/Components/VideoLive/LiveImageManager.ts +41 -43
- package/Components/VideoModal/utils.ts +6 -1
- package/Components/ZappFrameworkComponents/BarView/BarView.tsx +12 -5
- package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
- package/Contexts/CachedDimensionsContext/__tests__/index.test.ts +154 -0
- package/Contexts/CachedDimensionsContext/index.ts +17 -2
- package/Helpers/ComponentCellSelectionHelper/index.js +0 -6
- package/Helpers/index.js +7 -40
- package/package.json +6 -5
- package/Components/Layout/TV/LayoutBackground.tsx +0 -31
- package/Components/OfflineHandler/NotificationView/NotificationView.lg.tsx +0 -112
- package/Components/OfflineHandler/NotificationView/NotificationView.samsung.tsx +0 -107
- package/Components/OfflineHandler/NotificationView/NotificationView.tsx +0 -153
- package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +0 -66
- package/Components/OfflineHandler/NotificationView/utils.ts +0 -34
- package/Components/Screen/utils.ts +0 -16
- package/Helpers/Analytics/index.js +0 -95
- /package/Components/MasterCell/DefaultComponents/ButtonContainerView/{index.tv.android.tsx → index.android.tv.tsx} +0 -0
- /package/Decorators/ZappPipesDataConnector/__tests__/{Hero.js → Hero.tsx} +0 -0
package/Components/MasterCell/DefaultComponents/Image/hoc/utils/__tests__/withDimensions.test.ts
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
mockWarning.mockClear();
|
|
21
|
+
});
|
|
9
22
|
|
|
10
|
-
|
|
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
|
-
|
|
13
|
-
`https://some_url?width=${width}&quality=95&sharpen=true`
|
|
14
|
-
);
|
|
15
|
-
});
|
|
27
|
+
const result = withDimensions(url, width, height, defaultTemplate);
|
|
16
28
|
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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
|
-
|
|
23
|
-
`https://some_url?quality=95&width=${width}&sharpen=true`
|
|
24
|
-
);
|
|
25
|
-
});
|
|
39
|
+
const result = withDimensions(url, width, height, defaultTemplate);
|
|
26
40
|
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
expect(result).toContain("width=300");
|
|
42
|
+
expect(result).toContain("height=200");
|
|
43
|
+
expect(result).toContain("quality=95");
|
|
44
|
+
});
|
|
29
45
|
|
|
30
|
-
|
|
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
|
-
|
|
33
|
-
`https://some_url?height=${height}&quality=95&sharpen=true`
|
|
34
|
-
);
|
|
35
|
-
});
|
|
50
|
+
const result = withDimensions(url, largeWidth, height, defaultTemplate);
|
|
36
51
|
|
|
37
|
-
|
|
38
|
-
|
|
52
|
+
expect(result).toContain("width=1024");
|
|
53
|
+
});
|
|
39
54
|
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
`https://some_url?quality=95&height=${height}&sharpen=true`
|
|
44
|
-
);
|
|
45
|
-
});
|
|
59
|
+
const result = withDimensions(url, width, largeHeight, defaultTemplate);
|
|
46
60
|
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
expect(result).toContain("height=1024");
|
|
62
|
+
});
|
|
49
63
|
|
|
50
|
-
|
|
64
|
+
it("adds width and height to URL with no query params", () => {
|
|
65
|
+
const url = "https://some_url";
|
|
51
66
|
|
|
52
|
-
|
|
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
|
-
|
|
58
|
-
|
|
69
|
+
expect(result).toContain("width=300");
|
|
70
|
+
expect(result).toContain("height=200");
|
|
71
|
+
});
|
|
59
72
|
|
|
60
|
-
|
|
73
|
+
it("truncates decimal width values", () => {
|
|
74
|
+
const decimalWidth = 243.42857142857142;
|
|
75
|
+
const url = "https://some_url?quality=95";
|
|
61
76
|
|
|
62
|
-
|
|
63
|
-
});
|
|
77
|
+
const result = withDimensions(url, decimalWidth, height, defaultTemplate);
|
|
64
78
|
|
|
65
|
-
|
|
66
|
-
|
|
79
|
+
expect(result).toContain("width=243");
|
|
80
|
+
});
|
|
67
81
|
|
|
68
|
-
|
|
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
|
-
|
|
71
|
-
"https://some_url?width=511&quality=95&sharpen=true"
|
|
72
|
-
);
|
|
73
|
-
});
|
|
85
|
+
const result = withDimensions(url, width, height, defaultTemplate);
|
|
74
86
|
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
expect(result).toContain("width=300");
|
|
88
|
+
});
|
|
77
89
|
|
|
78
|
-
|
|
90
|
+
it("replaces URL with empty width in the original", () => {
|
|
91
|
+
const url = "https://some_url?width=&quality=95&sharpen=true";
|
|
79
92
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
93
|
+
const result = withDimensions(url, width, height, defaultTemplate);
|
|
94
|
+
|
|
95
|
+
expect(result).toContain("width=300");
|
|
96
|
+
});
|
|
83
97
|
});
|
|
84
98
|
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
104
|
+
const result = withDimensions(url, width, height, template);
|
|
89
105
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
106
|
+
expect(result).toContain("w=300");
|
|
107
|
+
expect(result).toContain("h=200");
|
|
108
|
+
expect(result).toContain("quality=95");
|
|
109
|
+
});
|
|
94
110
|
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
115
|
+
const result = withDimensions(url, width, height, template);
|
|
99
116
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
);
|
|
103
|
-
});
|
|
117
|
+
expect(result).toContain(`size=${width}x${height}`);
|
|
118
|
+
expect(result).toContain("quality=95");
|
|
119
|
+
});
|
|
104
120
|
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
125
|
+
const result = withDimensions(url, width, height, template);
|
|
109
126
|
|
|
110
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
133
|
+
it("handles template with only width", () => {
|
|
134
|
+
const template = "w={{width}}";
|
|
135
|
+
const url = "https://cdn.example.com/image.jpg";
|
|
116
136
|
|
|
117
|
-
|
|
137
|
+
const result = withDimensions(url, width, height, template);
|
|
118
138
|
|
|
119
|
-
|
|
120
|
-
"
|
|
121
|
-
);
|
|
122
|
-
});
|
|
139
|
+
expect(result).toContain("w=300");
|
|
140
|
+
expect(result).not.toContain("height");
|
|
141
|
+
});
|
|
123
142
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
143
|
+
it("handles template with only height", () => {
|
|
144
|
+
const template = "h={{height}}";
|
|
145
|
+
const url = "https://cdn.example.com/image.jpg";
|
|
127
146
|
|
|
128
|
-
|
|
147
|
+
const result = withDimensions(url, width, height, template);
|
|
129
148
|
|
|
130
|
-
|
|
131
|
-
|
|
149
|
+
expect(result).toContain("h=200");
|
|
150
|
+
expect(result).not.toContain("width");
|
|
151
|
+
});
|
|
132
152
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
157
|
+
const result = withDimensions(url, width, height, template);
|
|
138
158
|
|
|
139
|
-
|
|
159
|
+
expect(result).toContain("w=300");
|
|
160
|
+
expect(result).toContain("h=200");
|
|
161
|
+
});
|
|
140
162
|
});
|
|
141
163
|
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
168
|
+
const result = withDimensions(url, width, height, undefined);
|
|
146
169
|
|
|
147
|
-
|
|
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
|
-
|
|
151
|
-
|
|
181
|
+
it("returns original url when template is null", () => {
|
|
182
|
+
const url = "https://some_url?width=511&quality=95&sharpen=true";
|
|
152
183
|
|
|
153
|
-
|
|
184
|
+
const result = withDimensions(url, width, height, null);
|
|
154
185
|
|
|
155
|
-
|
|
186
|
+
expect(result).toEqual(url);
|
|
187
|
+
});
|
|
156
188
|
});
|
|
157
189
|
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
167
|
-
|
|
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
|
-
|
|
339
|
+
const result = withDimensions(url, width, height, template);
|
|
170
340
|
|
|
171
|
-
|
|
341
|
+
expect(result).toEqual(url);
|
|
342
|
+
});
|
|
172
343
|
});
|
|
173
344
|
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
349
|
+
const result = withDimensions(url, width, height, defaultTemplate);
|
|
178
350
|
|
|
179
|
-
|
|
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
|
-
|
|
183
|
-
|
|
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
|
-
|
|
401
|
+
const result = withDimensions(url, width, height, defaultTemplate);
|
|
186
402
|
|
|
187
|
-
|
|
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
|
-
|
|
191
|
-
|
|
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
|
-
|
|
468
|
+
expect(result).toContain("w=300");
|
|
469
|
+
expect(result).toContain("h=200");
|
|
470
|
+
});
|
|
194
471
|
|
|
195
|
-
|
|
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
|
|
199
|
-
const
|
|
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
|
-
|
|
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).
|
|
497
|
+
expect(result).toContain("size=300x200");
|
|
498
|
+
expect(result).toContain("quality=95");
|
|
204
499
|
});
|
|
205
500
|
});
|