@capillarytech/creatives-library 8.0.276-alpha.0 → 8.0.276

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.
@@ -107,9 +107,4 @@ describe('Creatives SmsTraiEdit test/>', () => {
107
107
  renderedComponent.update();
108
108
  expect(renderedComponent).toMatchSnapshot();
109
109
  });
110
- it('should cancel', () => {
111
- renderedComponent.find('button.cancel-dlt-msg').props().onClick();
112
- renderedComponent.update();
113
- expect(renderedComponent).toMatchSnapshot();
114
- });
115
110
  });
@@ -868,13 +868,6 @@ export const Viber = (props) => {
868
868
  >
869
869
  <FormattedMessage {...creativesMessages.testAndPreview} />
870
870
  </CapButton>
871
- <CapButton
872
- onClick={handleClose}
873
- className="cancel-msg"
874
- type="secondary"
875
- >
876
- <FormattedMessage {...messages.cancelButtonLabel} />
877
- </CapButton>
878
871
  </ViberFooter>
879
872
  </CapSpin>
880
873
  {/* Test and Preview Slidebox */}
@@ -121,8 +121,5 @@
121
121
  margin-top: $CAP_SPACE_08;
122
122
  }
123
123
  .test-and-preview-button {
124
- top: 18px;
125
- }
126
- .viber-create-msg {
127
- margin-left: 178px;
124
+ margin-left: 120px;
128
125
  }
@@ -16,5 +16,7 @@ export const ViberFooter = styled.div`
16
16
  .ant-btn {
17
17
  margin-right: ${CAP_SPACE_16};
18
18
  }
19
+ .viber-create-msg{
20
+ bottom:unset;
19
21
  }
20
22
  `;
@@ -1,298 +0,0 @@
1
- /**
2
- * Tests for imageUrlUpload utils: fetchImageFromUrl and uploadImageFromUrlHelper
3
- */
4
-
5
- import { fetchImageFromUrl, uploadImageFromUrlHelper } from '../imageUrlUpload';
6
-
7
- describe('imageUrlUpload', () => {
8
- const formatMessage = jest.fn((msg) => msg?.id ?? msg?.defaultMessage ?? 'formatted');
9
- const messages = {
10
- imageTypeInvalid: { id: 'imageTypeInvalid' },
11
- imageSizeInvalid: { id: 'imageSizeInvalid' },
12
- imageLoadError: { id: 'imageLoadError' },
13
- };
14
-
15
- beforeEach(() => {
16
- jest.clearAllMocks();
17
- formatMessage.mockImplementation((msg) => (msg && typeof msg === 'object' && msg.id) ? msg.id : 'formatted');
18
- });
19
-
20
- describe('fetchImageFromUrl', () => {
21
- const validUrl = 'https://example.com/image.jpg';
22
-
23
- it('throws when url is missing', async () => {
24
- await expect(fetchImageFromUrl()).rejects.toThrow('URL is required');
25
- await expect(fetchImageFromUrl(null)).rejects.toThrow('URL is required');
26
- });
27
-
28
- it('throws when url is empty string', async () => {
29
- await expect(fetchImageFromUrl('')).rejects.toThrow('URL is required');
30
- });
31
-
32
- it('throws when url is only whitespace', async () => {
33
- await expect(fetchImageFromUrl(' ')).rejects.toThrow('URL is required');
34
- });
35
-
36
- it('trims url before fetching', async () => {
37
- const mockResponse = { ok: true, headers: new Headers() };
38
- global.fetch = jest.fn().mockResolvedValue(mockResponse);
39
-
40
- await fetchImageFromUrl(' https://example.com/img.png ');
41
- expect(global.fetch).toHaveBeenCalledWith(
42
- 'https://example.com/img.png',
43
- expect.objectContaining({ method: 'GET', redirect: 'follow', mode: 'cors' })
44
- );
45
- });
46
-
47
- it('returns response when fetch is ok', async () => {
48
- const mockResponse = { ok: true, status: 200, headers: new Headers() };
49
- global.fetch = jest.fn().mockResolvedValue(mockResponse);
50
-
51
- const result = await fetchImageFromUrl(validUrl);
52
- expect(result).toBe(mockResponse);
53
- expect(global.fetch).toHaveBeenCalledWith(
54
- validUrl,
55
- expect.objectContaining({ method: 'GET', redirect: 'follow', mode: 'cors' })
56
- );
57
- });
58
-
59
- it('throws when response is not ok', async () => {
60
- const mockResponse = { ok: false, status: 404, statusText: 'Not Found' };
61
- global.fetch = jest.fn().mockResolvedValue(mockResponse);
62
-
63
- await expect(fetchImageFromUrl(validUrl)).rejects.toThrow(
64
- 'Failed to fetch image: 404 Not Found'
65
- );
66
- });
67
-
68
- it('throws on network or CORS error', async () => {
69
- global.fetch = jest.fn().mockRejectedValue(new Error('Network error'));
70
-
71
- await expect(fetchImageFromUrl(validUrl)).rejects.toThrow('Network error');
72
- });
73
- });
74
-
75
- describe('uploadImageFromUrlHelper', () => {
76
- const uploadAssetFn = jest.fn();
77
- const fileNamePrefix = 'test-image';
78
- const maxSize = 5000000;
79
-
80
- it('returns error when content type is not allowed', async () => {
81
- const response = {
82
- ok: true,
83
- headers: new Headers({ 'Content-Type': 'text/html' }),
84
- blob: jest.fn().mockResolvedValue(new Blob()),
85
- };
86
- global.fetch = jest.fn().mockResolvedValue(response);
87
-
88
- const result = await uploadImageFromUrlHelper(
89
- 'https://example.com/page',
90
- formatMessage,
91
- messages,
92
- uploadAssetFn,
93
- fileNamePrefix,
94
- maxSize,
95
- ['image/jpeg', 'image/png']
96
- );
97
-
98
- expect(result).toEqual({ success: false, error: 'imageTypeInvalid' });
99
- expect(formatMessage).toHaveBeenCalledWith(messages.imageTypeInvalid);
100
- expect(uploadAssetFn).not.toHaveBeenCalled();
101
- });
102
-
103
- it('normalizes content type by stripping charset and trimming', async () => {
104
- const response = {
105
- ok: true,
106
- headers: new Headers({ 'Content-Type': ' image/PNG; charset=utf-8 ' }),
107
- blob: jest.fn().mockResolvedValue(new Blob(['x'], { type: 'image/png' })),
108
- };
109
- global.fetch = jest.fn().mockResolvedValue(response);
110
-
111
- const OriginalImage = global.Image;
112
- global.Image = class MockImage {
113
- constructor() {
114
- this.width = 10;
115
- this.height = 10;
116
- setTimeout(() => { if (this.onload) this.onload(); }, 0);
117
- }
118
-
119
- get src() { return this._src; }
120
-
121
- set src(v) { this._src = v; }
122
- };
123
-
124
- const result = await uploadImageFromUrlHelper(
125
- 'https://example.com/img.png',
126
- formatMessage,
127
- messages,
128
- uploadAssetFn,
129
- fileNamePrefix,
130
- maxSize,
131
- ['image/png']
132
- );
133
-
134
- global.Image = OriginalImage;
135
-
136
- expect(result.success).toBe(true);
137
- expect(uploadAssetFn).toHaveBeenCalledWith(
138
- expect.any(File),
139
- 'image',
140
- expect.objectContaining({ width: 10, height: 10, error: false })
141
- );
142
- const file = uploadAssetFn.mock.calls[0][0];
143
- expect(file.name).toMatch(/\.png$/);
144
- });
145
-
146
- it('returns error when blob size exceeds maxSize', async () => {
147
- const largeBlob = new Blob([new ArrayBuffer(maxSize + 1)]);
148
- const response = {
149
- ok: true,
150
- headers: new Headers({ 'Content-Type': 'image/jpeg' }),
151
- blob: jest.fn().mockResolvedValue(largeBlob),
152
- };
153
- global.fetch = jest.fn().mockResolvedValue(response);
154
-
155
- const result = await uploadImageFromUrlHelper(
156
- 'https://example.com/large.jpg',
157
- formatMessage,
158
- messages,
159
- uploadAssetFn,
160
- fileNamePrefix,
161
- maxSize
162
- );
163
-
164
- expect(result).toEqual({ success: false, error: 'imageSizeInvalid' });
165
- expect(formatMessage).toHaveBeenCalledWith(messages.imageSizeInvalid);
166
- expect(uploadAssetFn).not.toHaveBeenCalled();
167
- });
168
-
169
- it('returns error when image fails to load (invalid image data)', async () => {
170
- const blob = new Blob(['not-an-image'], { type: 'image/jpeg' });
171
- const response = {
172
- ok: true,
173
- headers: new Headers({ 'Content-Type': 'image/jpeg' }),
174
- blob: jest.fn().mockResolvedValue(blob),
175
- };
176
- global.fetch = jest.fn().mockResolvedValue(response);
177
-
178
- const OriginalImage = global.Image;
179
- global.Image = class MockImage {
180
- constructor() {
181
- setTimeout(() => {
182
- if (this.onerror) this.onerror(new Event('error'));
183
- }, 0);
184
- }
185
-
186
- get src() { return this._src; }
187
-
188
- set src(v) { this._src = v; }
189
- };
190
-
191
- const result = await uploadImageFromUrlHelper(
192
- 'https://example.com/bad.jpg',
193
- formatMessage,
194
- messages,
195
- uploadAssetFn,
196
- fileNamePrefix,
197
- maxSize
198
- );
199
-
200
- global.Image = OriginalImage;
201
-
202
- expect(result.success).toBe(false);
203
- expect(result.error).toBe('imageLoadError');
204
- expect(formatMessage).toHaveBeenCalledWith(messages.imageLoadError);
205
- expect(uploadAssetFn).not.toHaveBeenCalled();
206
- });
207
-
208
- it('returns error on fetch failure and uses imageLoadError message', async () => {
209
- global.fetch = jest.fn().mockRejectedValue(new Error('CORS'));
210
-
211
- const result = await uploadImageFromUrlHelper(
212
- 'https://example.com/image.jpg',
213
- formatMessage,
214
- messages,
215
- uploadAssetFn,
216
- fileNamePrefix,
217
- maxSize
218
- );
219
-
220
- expect(result).toEqual({ success: false, error: 'imageLoadError' });
221
- expect(formatMessage).toHaveBeenCalledWith(messages.imageLoadError);
222
- expect(uploadAssetFn).not.toHaveBeenCalled();
223
- });
224
-
225
- it('trims url before processing', async () => {
226
- const response = {
227
- ok: true,
228
- headers: new Headers({ 'Content-Type': 'image/jpeg' }),
229
- blob: jest.fn().mockResolvedValue(new Blob()),
230
- };
231
- global.fetch = jest.fn().mockResolvedValue(response);
232
-
233
- await uploadImageFromUrlHelper(
234
- ' https://example.com/img.jpg ',
235
- formatMessage,
236
- messages,
237
- uploadAssetFn,
238
- fileNamePrefix,
239
- maxSize
240
- );
241
-
242
- expect(global.fetch).toHaveBeenCalledWith(
243
- 'https://example.com/img.jpg',
244
- expect.any(Object)
245
- );
246
- });
247
-
248
- it('calls uploadAssetFn with file, type and fileParams on success', async () => {
249
- const blob = new Blob([new ArrayBuffer(100)], { type: 'image/png' });
250
- const response = {
251
- ok: true,
252
- headers: new Headers({ 'Content-Type': 'image/png' }),
253
- blob: jest.fn().mockResolvedValue(blob),
254
- };
255
- global.fetch = jest.fn().mockResolvedValue(response);
256
-
257
- const OriginalImage = global.Image;
258
- global.Image = class MockImage {
259
- constructor() {
260
- this.width = 100;
261
- this.height = 80;
262
- setTimeout(() => {
263
- if (this.onload) this.onload();
264
- }, 0);
265
- }
266
-
267
- get src() { return this._src; }
268
-
269
- set src(v) { this._src = v; }
270
- };
271
-
272
- const result = await uploadImageFromUrlHelper(
273
- 'https://example.com/valid.png',
274
- formatMessage,
275
- messages,
276
- uploadAssetFn,
277
- fileNamePrefix,
278
- maxSize
279
- );
280
-
281
- global.Image = OriginalImage;
282
-
283
- expect(result).toEqual({ success: true, error: '' });
284
- expect(uploadAssetFn).toHaveBeenCalledTimes(1);
285
- const [file, type, fileParams] = uploadAssetFn.mock.calls[0];
286
- expect(file).toBeInstanceOf(File);
287
- expect(file.name).toMatch(new RegExp(`^${fileNamePrefix}\\.png$`));
288
- expect(type).toBe('image');
289
- expect(fileParams).toEqual(
290
- expect.objectContaining({
291
- width: 100,
292
- height: 80,
293
- error: false,
294
- })
295
- );
296
- });
297
- });
298
- });