@osimatic/helpers-js 1.4.24 → 1.4.25
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/.claude/settings.local.json +2 -1
- package/chartjs.js +1 -1
- package/date_time.js +25 -16
- package/draw.js +3 -2
- package/duration.js +12 -15
- package/event_bus.js +2 -2
- package/file.js +1 -1
- package/form_helper.js +1 -1
- package/http_client.js +2 -0
- package/jwt.js +18 -6
- package/media.js +1 -1
- package/number.js +2 -3
- package/package.json +3 -2
- package/social_network.js +5 -0
- package/string.js +11 -2
- package/tests/chartjs.test.js +273 -0
- package/tests/date_time/DatePeriod.test.js +179 -0
- package/tests/date_time/DateTime.test.js +492 -0
- package/tests/date_time/SqlDate.test.js +205 -0
- package/tests/date_time/SqlDateTime.test.js +326 -0
- package/tests/date_time/SqlTime.test.js +162 -0
- package/tests/date_time/TimestampUnix.test.js +262 -0
- package/tests/draw.test.js +271 -0
- package/tests/duration.test.js +365 -0
- package/tests/event_bus.test.js +268 -0
- package/tests/file.test.js +358 -0
- package/tests/form_date.test.js +417 -0
- package/tests/form_helper.test.js +415 -0
- package/tests/http_client.test.js +570 -0
- package/tests/jwt.test.js +804 -0
- package/tests/media.test.js +458 -0
- package/tests/network.test.js +489 -0
- package/tests/number.test.js +448 -0
- package/tests/open_street_map.test.js +388 -0
- package/tests/shopping_cart.test.js +355 -0
- package/tests/social_network.test.js +333 -0
- package/tests/string.test.js +473 -0
- package/tests/user.test.js +204 -0
- package/tests/util.test.js +99 -0
- package/tests/visitor.test.js +508 -0
- package/tmpclaude-00a6-cwd +1 -0
- package/tmpclaude-0526-cwd +1 -0
- package/tmpclaude-0973-cwd +1 -0
- package/tmpclaude-0b61-cwd +1 -0
- package/tmpclaude-146f-cwd +1 -0
- package/tmpclaude-223d-cwd +1 -0
- package/tmpclaude-2330-cwd +1 -0
- package/tmpclaude-282a-cwd +1 -0
- package/tmpclaude-2846-cwd +1 -0
- package/tmpclaude-28a6-cwd +1 -0
- package/tmpclaude-2b5a-cwd +1 -0
- package/tmpclaude-2def-cwd +1 -0
- package/tmpclaude-3906-cwd +1 -0
- package/tmpclaude-3b32-cwd +1 -0
- package/tmpclaude-3da9-cwd +1 -0
- package/tmpclaude-3dc3-cwd +1 -0
- package/tmpclaude-3e3b-cwd +1 -0
- package/tmpclaude-43b6-cwd +1 -0
- package/tmpclaude-4495-cwd +1 -0
- package/tmpclaude-462f-cwd +1 -0
- package/tmpclaude-4b29-cwd +1 -0
- package/tmpclaude-4db5-cwd +1 -0
- package/tmpclaude-4e01-cwd +1 -0
- package/tmpclaude-5101-cwd +1 -0
- package/tmpclaude-524f-cwd +1 -0
- package/tmpclaude-5636-cwd +1 -0
- package/tmpclaude-5cdd-cwd +1 -0
- package/tmpclaude-5f1f-cwd +1 -0
- package/tmpclaude-6078-cwd +1 -0
- package/tmpclaude-622e-cwd +1 -0
- package/tmpclaude-6802-cwd +1 -0
- package/tmpclaude-6e36-cwd +1 -0
- package/tmpclaude-7793-cwd +1 -0
- package/tmpclaude-7f96-cwd +1 -0
- package/tmpclaude-8566-cwd +1 -0
- package/tmpclaude-8874-cwd +1 -0
- package/tmpclaude-8915-cwd +1 -0
- package/tmpclaude-8c8b-cwd +1 -0
- package/tmpclaude-94df-cwd +1 -0
- package/tmpclaude-9859-cwd +1 -0
- package/tmpclaude-9ac5-cwd +1 -0
- package/tmpclaude-9f18-cwd +1 -0
- package/tmpclaude-a202-cwd +1 -0
- package/tmpclaude-a741-cwd +1 -0
- package/tmpclaude-ab5f-cwd +1 -0
- package/tmpclaude-b008-cwd +1 -0
- package/tmpclaude-b0a1-cwd +1 -0
- package/tmpclaude-b63d-cwd +1 -0
- package/tmpclaude-b681-cwd +1 -0
- package/tmpclaude-b72d-cwd +1 -0
- package/tmpclaude-b92f-cwd +1 -0
- package/tmpclaude-bc49-cwd +1 -0
- package/tmpclaude-bc50-cwd +1 -0
- package/tmpclaude-bccf-cwd +1 -0
- package/tmpclaude-be55-cwd +1 -0
- package/tmpclaude-c228-cwd +1 -0
- package/tmpclaude-c717-cwd +1 -0
- package/tmpclaude-c7ce-cwd +1 -0
- package/tmpclaude-cf3e-cwd +1 -0
- package/tmpclaude-d142-cwd +1 -0
- package/tmpclaude-d5bc-cwd +1 -0
- package/tmpclaude-d6ae-cwd +1 -0
- package/tmpclaude-d77a-cwd +1 -0
- package/tmpclaude-d8da-cwd +1 -0
- package/tmpclaude-dbdb-cwd +1 -0
- package/tmpclaude-de61-cwd +1 -0
- package/tmpclaude-de81-cwd +1 -0
- package/tmpclaude-df9d-cwd +1 -0
- package/tmpclaude-e786-cwd +1 -0
- package/tmpclaude-f01d-cwd +1 -0
- package/tmpclaude-f2a9-cwd +1 -0
- package/tmpclaude-fc36-cwd +1 -0
- package/tmpclaude-ffef-cwd +1 -0
- package/visitor.js +2 -2
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
require('../array'); // For removeEmptyValues method
|
|
2
|
+
const { FormHelper, ArrayField, EditValue } = require('../form_helper');
|
|
3
|
+
|
|
4
|
+
describe('FormHelper', () => {
|
|
5
|
+
describe('extractErrorKeyOfJson', () => {
|
|
6
|
+
test('should return null for undefined', () => {
|
|
7
|
+
expect(FormHelper.extractErrorKeyOfJson(undefined)).toBeNull();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('should return null for null', () => {
|
|
11
|
+
expect(FormHelper.extractErrorKeyOfJson(null)).toBeNull();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('should extract error from json.error', () => {
|
|
15
|
+
expect(FormHelper.extractErrorKeyOfJson({ error: 'invalid_data' })).toBe('invalid_data');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('should extract error from json[0].error', () => {
|
|
19
|
+
expect(FormHelper.extractErrorKeyOfJson([{ error: 'field_error' }])).toBe('field_error');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('should extract error from json[0][0] when array format', () => {
|
|
23
|
+
expect(FormHelper.extractErrorKeyOfJson([['error_key', 'error message']])).toBe('error_key');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('should return null when onlyIfUniqueError=true and multiple errors', () => {
|
|
27
|
+
expect(FormHelper.extractErrorKeyOfJson([{ error: 'err1' }, { error: 'err2' }], true)).toBeNull();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('should return error when onlyIfUniqueError=true and single error', () => {
|
|
31
|
+
expect(FormHelper.extractErrorKeyOfJson([{ error: 'err1' }], true)).toBe('err1');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('should handle empty array', () => {
|
|
35
|
+
expect(FormHelper.extractErrorKeyOfJson([])).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('extractErrorMessageOfJson', () => {
|
|
40
|
+
test('should return null for undefined', () => {
|
|
41
|
+
expect(FormHelper.extractErrorMessageOfJson(undefined)).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should return null for null', () => {
|
|
45
|
+
expect(FormHelper.extractErrorMessageOfJson(null)).toBeNull();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('should extract error message from json.error', () => {
|
|
49
|
+
expect(FormHelper.extractErrorMessageOfJson({ error: 'Invalid data' })).toBe('Invalid data');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('should extract error message from json[0].error', () => {
|
|
53
|
+
expect(FormHelper.extractErrorMessageOfJson([{ error: 'Field error' }])).toBe('Field error');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('should extract error message from json[0][1] when array format', () => {
|
|
57
|
+
expect(FormHelper.extractErrorMessageOfJson([['error_key', 'Error message']])).toBe('Error message');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('should return null when onlyIfUniqueError=true and multiple errors', () => {
|
|
61
|
+
expect(FormHelper.extractErrorMessageOfJson([{ error: 'err1' }, { error: 'err2' }], true)).toBeNull();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('should return error when onlyIfUniqueError=true and single error', () => {
|
|
65
|
+
expect(FormHelper.extractErrorMessageOfJson([{ error: 'err1' }], true)).toBe('err1');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('getDataFromFormData', () => {
|
|
70
|
+
test('should convert FormData to object', () => {
|
|
71
|
+
const formData = new FormData();
|
|
72
|
+
formData.append('name', 'John');
|
|
73
|
+
formData.append('email', 'john@example.com');
|
|
74
|
+
|
|
75
|
+
const result = FormHelper.getDataFromFormData(formData);
|
|
76
|
+
|
|
77
|
+
expect(result).toEqual({
|
|
78
|
+
name: 'John',
|
|
79
|
+
email: 'john@example.com'
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('should handle empty FormData', () => {
|
|
84
|
+
const formData = new FormData();
|
|
85
|
+
const result = FormHelper.getDataFromFormData(formData);
|
|
86
|
+
|
|
87
|
+
expect(result).toEqual({});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('should handle multiple values for same key (last value wins)', () => {
|
|
91
|
+
const formData = new FormData();
|
|
92
|
+
formData.append('tag', 'tag1');
|
|
93
|
+
formData.append('tag', 'tag2');
|
|
94
|
+
|
|
95
|
+
const result = FormHelper.getDataFromFormData(formData);
|
|
96
|
+
|
|
97
|
+
// FormData entries() with same key will have last value
|
|
98
|
+
expect(result.tag).toBe('tag2');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('should handle special characters', () => {
|
|
102
|
+
const formData = new FormData();
|
|
103
|
+
formData.append('field', 'value with spaces & special!');
|
|
104
|
+
|
|
105
|
+
const result = FormHelper.getDataFromFormData(formData);
|
|
106
|
+
|
|
107
|
+
expect(result.field).toBe('value with spaces & special!');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('getFormErrorText', () => {
|
|
112
|
+
test('should convert errors object to HTML text', () => {
|
|
113
|
+
const errors = {
|
|
114
|
+
field1: 'Error message 1',
|
|
115
|
+
field2: 'Error message 2'
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const result = FormHelper.getFormErrorText(errors);
|
|
119
|
+
|
|
120
|
+
expect(result).toContain('<span>Error message 1</span>');
|
|
121
|
+
expect(result).toContain('<span>Error message 2</span>');
|
|
122
|
+
expect(result).toContain('<br/>');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('should handle error_description format', () => {
|
|
126
|
+
const errors = {
|
|
127
|
+
field1: { error_description: 'Detailed error' }
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const result = FormHelper.getFormErrorText(errors);
|
|
131
|
+
|
|
132
|
+
expect(result).toBe('<span>Detailed error</span>');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('should handle array format [key, message]', () => {
|
|
136
|
+
const errors = {
|
|
137
|
+
field1: ['error_key', 'Error message']
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const result = FormHelper.getFormErrorText(errors);
|
|
141
|
+
|
|
142
|
+
expect(result).toBe('<span>Error message</span>');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('should skip function properties', () => {
|
|
146
|
+
const errors = {
|
|
147
|
+
field1: 'Error 1',
|
|
148
|
+
someFunction: function() {}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const result = FormHelper.getFormErrorText(errors);
|
|
152
|
+
|
|
153
|
+
expect(result).toBe('<span>Error 1</span>');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('should remove empty values', () => {
|
|
157
|
+
const errors = {
|
|
158
|
+
field1: 'Error 1',
|
|
159
|
+
field2: '',
|
|
160
|
+
field3: null,
|
|
161
|
+
field4: 'Error 4'
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const result = FormHelper.getFormErrorText(errors);
|
|
165
|
+
|
|
166
|
+
expect(result).toContain('<span>Error 1</span>');
|
|
167
|
+
expect(result).toContain('<span>Error 4</span>');
|
|
168
|
+
expect(result).not.toContain('<span></span>');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('should handle empty errors object', () => {
|
|
172
|
+
const result = FormHelper.getFormErrorText({});
|
|
173
|
+
|
|
174
|
+
expect(result).toBe('');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('should handle mixed error formats', () => {
|
|
178
|
+
const errors = {
|
|
179
|
+
field1: 'Simple error',
|
|
180
|
+
field2: { error_description: 'Described error' },
|
|
181
|
+
field3: ['key', 'Array error']
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const result = FormHelper.getFormErrorText(errors);
|
|
185
|
+
|
|
186
|
+
expect(result).toContain('<span>Simple error</span>');
|
|
187
|
+
expect(result).toContain('<span>Described error</span>');
|
|
188
|
+
expect(result).toContain('<span>Array error</span>');
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('buttonLoader with jQuery mock', () => {
|
|
193
|
+
let mockButton;
|
|
194
|
+
|
|
195
|
+
beforeEach(() => {
|
|
196
|
+
// Mock jQuery button
|
|
197
|
+
mockButton = {
|
|
198
|
+
attr: jest.fn().mockReturnThis(),
|
|
199
|
+
data: jest.fn().mockReturnThis(),
|
|
200
|
+
html: jest.fn().mockReturnThis(),
|
|
201
|
+
addClass: jest.fn().mockReturnThis(),
|
|
202
|
+
removeClass: jest.fn().mockReturnThis(),
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// Mock $ to return mockButton
|
|
206
|
+
global.$ = jest.fn(() => mockButton);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
afterEach(() => {
|
|
210
|
+
delete global.$;
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('should disable button on loading', () => {
|
|
214
|
+
mockButton.attr.mockImplementation((key, value) => {
|
|
215
|
+
if (key === 'disabled' && value === undefined) {
|
|
216
|
+
return false; // button not disabled initially
|
|
217
|
+
}
|
|
218
|
+
return mockButton;
|
|
219
|
+
});
|
|
220
|
+
mockButton.data.mockImplementation((key, value) => {
|
|
221
|
+
if (key === 'btn-text') return 'Original Text';
|
|
222
|
+
return mockButton;
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
FormHelper.buttonLoader(mockButton, 'loading');
|
|
226
|
+
|
|
227
|
+
expect(mockButton.attr).toHaveBeenCalledWith('disabled', true);
|
|
228
|
+
expect(mockButton.addClass).toHaveBeenCalledWith('disabled');
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('should enable button on reset', () => {
|
|
232
|
+
mockButton.data.mockReturnValue('Original Text');
|
|
233
|
+
|
|
234
|
+
FormHelper.buttonLoader(mockButton, 'reset');
|
|
235
|
+
|
|
236
|
+
expect(mockButton.html).toHaveBeenCalledWith('Original Text');
|
|
237
|
+
expect(mockButton.removeClass).toHaveBeenCalledWith('disabled');
|
|
238
|
+
expect(mockButton.attr).toHaveBeenCalledWith('disabled', false);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test('should use custom loading text if provided', () => {
|
|
242
|
+
mockButton.attr.mockImplementation((key) => {
|
|
243
|
+
if (key === 'disabled') return false;
|
|
244
|
+
return mockButton;
|
|
245
|
+
});
|
|
246
|
+
mockButton.data.mockImplementation((key) => {
|
|
247
|
+
if (key === 'loading-text') return 'Custom Loading...';
|
|
248
|
+
return mockButton;
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
FormHelper.buttonLoader(mockButton, 'start');
|
|
252
|
+
|
|
253
|
+
expect(mockButton.html).toHaveBeenCalledWith('Custom Loading...');
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test('should handle "start" action same as "loading"', () => {
|
|
257
|
+
mockButton.attr.mockImplementation((key) => {
|
|
258
|
+
if (key === 'disabled') return false;
|
|
259
|
+
return mockButton;
|
|
260
|
+
});
|
|
261
|
+
mockButton.data.mockReturnValue(null);
|
|
262
|
+
|
|
263
|
+
FormHelper.buttonLoader(mockButton, 'start');
|
|
264
|
+
|
|
265
|
+
expect(mockButton.attr).toHaveBeenCalledWith('disabled', true);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test('should handle "stop" action same as "reset"', () => {
|
|
269
|
+
mockButton.data.mockReturnValue('Original');
|
|
270
|
+
|
|
271
|
+
FormHelper.buttonLoader(mockButton, 'stop');
|
|
272
|
+
|
|
273
|
+
expect(mockButton.attr).toHaveBeenCalledWith('disabled', false);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test('should return button object', () => {
|
|
277
|
+
mockButton.data.mockReturnValue('Text');
|
|
278
|
+
const result = FormHelper.buttonLoader(mockButton, 'reset');
|
|
279
|
+
|
|
280
|
+
expect(result).toBe(mockButton);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe('getInputValue', () => {
|
|
285
|
+
test('should return null for undefined input', () => {
|
|
286
|
+
expect(FormHelper.getInputValue(undefined)).toBeNull();
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test('should return null for empty string value', () => {
|
|
290
|
+
const mockInput = { val: jest.fn(() => '') };
|
|
291
|
+
global.$ = jest.fn(() => mockInput);
|
|
292
|
+
|
|
293
|
+
expect(FormHelper.getInputValue(mockInput)).toBeNull();
|
|
294
|
+
|
|
295
|
+
delete global.$;
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test('should return null for null value', () => {
|
|
299
|
+
const mockInput = { val: jest.fn(() => null) };
|
|
300
|
+
global.$ = jest.fn(() => mockInput);
|
|
301
|
+
|
|
302
|
+
expect(FormHelper.getInputValue(mockInput)).toBeNull();
|
|
303
|
+
|
|
304
|
+
delete global.$;
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test('should return value when present', () => {
|
|
308
|
+
const mockInput = { val: jest.fn(() => 'test value') };
|
|
309
|
+
global.$ = jest.fn(() => mockInput);
|
|
310
|
+
|
|
311
|
+
expect(FormHelper.getInputValue(mockInput)).toBe('test value');
|
|
312
|
+
|
|
313
|
+
delete global.$;
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
describe('getLinesOfTextarea', () => {
|
|
318
|
+
test('should split textarea by newlines and filter empty', () => {
|
|
319
|
+
const mockTextarea = {
|
|
320
|
+
val: jest.fn(() => 'line1\nline2\nline3')
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const result = FormHelper.getLinesOfTextarea(mockTextarea);
|
|
324
|
+
|
|
325
|
+
expect(result).toEqual(['line1', 'line2', 'line3']);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test('should handle Windows line endings', () => {
|
|
329
|
+
const mockTextarea = {
|
|
330
|
+
val: jest.fn(() => 'line1\r\nline2\r\nline3')
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const result = FormHelper.getLinesOfTextarea(mockTextarea);
|
|
334
|
+
|
|
335
|
+
expect(result).toEqual(['line1', 'line2', 'line3']);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test('should filter empty lines', () => {
|
|
339
|
+
const mockTextarea = {
|
|
340
|
+
val: jest.fn(() => 'line1\n\nline2\n\n\nline3')
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const result = FormHelper.getLinesOfTextarea(mockTextarea);
|
|
344
|
+
|
|
345
|
+
expect(result).toEqual(['line1', 'line2', 'line3']);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test('should handle Mac line endings', () => {
|
|
349
|
+
const mockTextarea = {
|
|
350
|
+
val: jest.fn(() => 'line1\rline2\rline3')
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const result = FormHelper.getLinesOfTextarea(mockTextarea);
|
|
354
|
+
|
|
355
|
+
expect(result).toEqual(['line1', 'line2', 'line3']);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test('should handle empty textarea', () => {
|
|
359
|
+
const mockTextarea = {
|
|
360
|
+
val: jest.fn(() => '')
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const result = FormHelper.getLinesOfTextarea(mockTextarea);
|
|
364
|
+
|
|
365
|
+
expect(result).toEqual([]);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
test('should handle single line', () => {
|
|
369
|
+
const mockTextarea = {
|
|
370
|
+
val: jest.fn(() => 'single line')
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
const result = FormHelper.getLinesOfTextarea(mockTextarea);
|
|
374
|
+
|
|
375
|
+
expect(result).toEqual(['single line']);
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
describe('hideFormErrors', () => {
|
|
380
|
+
test('should remove form_errors div', () => {
|
|
381
|
+
const mockForm = {
|
|
382
|
+
find: jest.fn().mockReturnThis(),
|
|
383
|
+
remove: jest.fn().mockReturnThis()
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const result = FormHelper.hideFormErrors(mockForm);
|
|
387
|
+
|
|
388
|
+
expect(mockForm.find).toHaveBeenCalledWith('div.form_errors');
|
|
389
|
+
expect(mockForm.remove).toHaveBeenCalled();
|
|
390
|
+
expect(result).toBe(mockForm);
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
describe('ArrayField', () => {
|
|
396
|
+
test('should be a class', () => {
|
|
397
|
+
expect(typeof ArrayField).toBe('function');
|
|
398
|
+
expect(typeof ArrayField.init).toBe('function');
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
test('init should be a static method', () => {
|
|
402
|
+
expect(typeof ArrayField.init).toBe('function');
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
describe('EditValue', () => {
|
|
407
|
+
test('should be a class', () => {
|
|
408
|
+
expect(typeof EditValue).toBe('function');
|
|
409
|
+
expect(typeof EditValue.init).toBe('function');
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
test('init should be a static method', () => {
|
|
413
|
+
expect(typeof EditValue.init).toBe('function');
|
|
414
|
+
});
|
|
415
|
+
});
|