@osimatic/helpers-js 1.5.22 → 1.5.24
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/form_helper.js +2 -1
- package/multiple_action_in_table.js +2 -2
- package/package.json +1 -1
- package/tests/form_helper.test.js +29 -0
package/form_helper.js
CHANGED
|
@@ -279,9 +279,10 @@ class FormHelper {
|
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
static hideFormErrors(form) {
|
|
282
|
+
const wasJQuery = form && form.jquery;
|
|
282
283
|
form = toEl(form);
|
|
283
284
|
form.querySelectorAll('div.form_errors').forEach(el => el.remove());
|
|
284
|
-
return form;
|
|
285
|
+
return wasJQuery ? toJquery(form) : form;
|
|
285
286
|
}
|
|
286
287
|
|
|
287
288
|
static getFormErrorText(errors) {
|
|
@@ -7,7 +7,7 @@ class MultipleActionInTable {
|
|
|
7
7
|
// Doit être appelé AVANT l'initialisation DataTable.
|
|
8
8
|
static initCols(table, cellSelector = 'select') {
|
|
9
9
|
table = toEl(table);
|
|
10
|
-
if (!table.classList.contains('table-action_multiple')) {
|
|
10
|
+
if (!table || !table.classList.contains('table-action_multiple')) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
if (MultipleActionInTable.getDivBtn(table) == null) {
|
|
@@ -31,7 +31,7 @@ class MultipleActionInTable {
|
|
|
31
31
|
table = toEl(table);
|
|
32
32
|
const { cellSelector = 'select', imgArrow = '' } = options;
|
|
33
33
|
|
|
34
|
-
if (!table.classList.contains('table-action_multiple')) {
|
|
34
|
+
if (!table || !table.classList.contains('table-action_multiple')) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
|
package/package.json
CHANGED
|
@@ -44,9 +44,15 @@ function addSelect(form, name, options = []) {
|
|
|
44
44
|
return select;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// Simule un objet jQuery wrappant un élément DOM natif
|
|
48
|
+
function mockJQuery(el) {
|
|
49
|
+
return { jquery: '3.0', 0: el, length: 1 };
|
|
50
|
+
}
|
|
51
|
+
|
|
47
52
|
afterEach(() => {
|
|
48
53
|
document.body.innerHTML = '';
|
|
49
54
|
jest.clearAllMocks();
|
|
55
|
+
delete global.$;
|
|
50
56
|
});
|
|
51
57
|
|
|
52
58
|
describe('FormHelper', () => {
|
|
@@ -89,6 +95,18 @@ describe('FormHelper', () => {
|
|
|
89
95
|
expect(onSubmitCallback).toHaveBeenCalledWith(form, customBtn);
|
|
90
96
|
});
|
|
91
97
|
|
|
98
|
+
test('should return jQuery wrapper when passed a jQuery object', () => {
|
|
99
|
+
const form = setupForm();
|
|
100
|
+
addButton(form, 'validate', 'Submit');
|
|
101
|
+
const jqForm = mockJQuery(form);
|
|
102
|
+
global.$ = jest.fn(el => mockJQuery(el));
|
|
103
|
+
|
|
104
|
+
const result = FormHelper.init(jqForm, jest.fn());
|
|
105
|
+
|
|
106
|
+
expect(result).toHaveProperty('jquery');
|
|
107
|
+
expect(result[0]).toBe(form);
|
|
108
|
+
});
|
|
109
|
+
|
|
92
110
|
test('should call buttonLoader with loading on submit', () => {
|
|
93
111
|
const form = setupForm();
|
|
94
112
|
const btn = addButton(form, 'validate', 'Submit');
|
|
@@ -522,6 +540,17 @@ describe('FormHelper', () => {
|
|
|
522
540
|
expect(form.querySelectorAll('div.form_errors').length).toBe(0);
|
|
523
541
|
expect(result).toBe(form);
|
|
524
542
|
});
|
|
543
|
+
|
|
544
|
+
test('should return jQuery wrapper when passed a jQuery object', () => {
|
|
545
|
+
const form = setupForm();
|
|
546
|
+
const jqForm = mockJQuery(form);
|
|
547
|
+
global.$ = jest.fn(el => mockJQuery(el));
|
|
548
|
+
|
|
549
|
+
const result = FormHelper.hideFormErrors(jqForm);
|
|
550
|
+
|
|
551
|
+
expect(result).toHaveProperty('jquery');
|
|
552
|
+
expect(result[0]).toBe(form);
|
|
553
|
+
});
|
|
525
554
|
});
|
|
526
555
|
|
|
527
556
|
describe('displayFormErrorsFromText', () => {
|