@modernman00/shared-js-lib 1.2.26 โ†’ 1.2.28

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.
@@ -1,7 +1,6 @@
1
1
  import { loginSubmission } from './processAll.js';
2
2
  import { id } from '../UtilityHtml.js';
3
- import { bindEvent } from '../Utility.js';
4
- import { showPassword } from './loginUtility.js';
3
+ import { bindEvent, showPassword } from '../Utility.js';
5
4
  import { matchInput } from '../general.js';
6
5
 
7
6
 
package/AcctMgt/login.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { loginSubmission } from './processAll.js';
2
2
  import { id} from '../UtilityHtml.js';
3
- import { bindEvent } from '../Utility.js';
4
- import { showPassword } from './loginUtility.js';
3
+ import { bindEvent, showPassword } from '../Utility.js';
4
+
5
5
 
6
6
  /**
7
7
  * Creates a reusable admin login handler with password visibility and accessibility support.
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
  import { postFormData } from '../Http.js';
3
3
  import { showLoader, clearLoader } from '../Loader.js';
4
- import { showError, qSel } from '../UtilityHtml.js';
4
+ import {qSel } from '../UtilityHtml.js';
5
+ import { showError } from '../ShowResponse.js';
5
6
  import FormHelper from '../FormHelper.js';
6
7
 
7
8
 
package/Http.js CHANGED
@@ -209,36 +209,3 @@ export const postMultipleApiData = async (url1, url2, formData, token = null) =>
209
209
  * @param {* value} cvalue
210
210
  * @param {* no of days 365} exdays
211
211
  */
212
- export const setCookie = (cname, cvalue, exdays) => {
213
- var d = new Date();
214
- d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
215
- var expires = 'expires=' + d.toUTCString();
216
- document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/';
217
- };
218
-
219
- export const getCookie = (cname) => {
220
- var name = cname + '=';
221
- var ca = document.cookie.split(';');
222
- for (var i = 0; i < ca.length; i++) {
223
- var c = ca[i];
224
- while (c.charAt(0) == ' ') {
225
- c = c.substring(1);
226
- }
227
- if (c.indexOf(name) == 0) {
228
- return c.substring(name.length, c.length);
229
- }
230
- }
231
- return '';
232
- };
233
-
234
- export const checkCookie = () => {
235
- var user = getCookie('username');
236
- if (user != '') {
237
- alert('Welcome again ' + user);
238
- } else {
239
- user = prompt('Please enter your name:', '');
240
- if (user != '' && user != null) {
241
- setCookie('username', user, 365);
242
- }
243
- }
244
- };
@@ -3,16 +3,28 @@ import { forgotSubmitHandler } from '../AcctMgt/forgot.js';
3
3
  import { createAdminLoginHandler } from '../AcctMgt/login.js';
4
4
  import { setupPasswordChange } from '../AcctMgt/changePassword.js';
5
5
  import { loginSubmission } from '../AcctMgt/processAll.js';
6
- import { showPassword } from '../AcctMgt/loginUtility.js';
6
+ import { showPassword, bindEvent } from '../Utility.js';
7
+
7
8
 
8
9
  jest.mock('../AcctMgt/processAll.js');
9
- jest.mock('../AcctMgt/loginUtility.js');
10
+ jest.mock('../Utility.js');
11
+
12
+ // Then patch the specific function after DOM is available
13
+ beforeEach(() => {
14
+ bindEvent.mockImplementation(({ id, event = 'click', handler }) => {
15
+ const el = document.getElementById(id);
16
+ if (el) el.addEventListener(event, handler);
17
+ });
10
18
 
11
- // Utility to mock DOM elements
12
- const mockDOM = (ids) => {
13
- ids.forEach(id => {
14
- const el = document.createElement('button');
19
+ showPassword.mockImplementation(() => {});
20
+ });
21
+
22
+ // ๐Ÿงช Utility to scaffold DOM elements
23
+ const injectDOM = (elements) => {
24
+ elements.forEach(({ tag = 'button', id, value = '' }) => {
25
+ const el = document.createElement(tag);
15
26
  el.setAttribute('id', id);
27
+ if (value) el.value = value;
16
28
  document.body.appendChild(el);
17
29
  });
18
30
  };
@@ -23,8 +35,9 @@ afterEach(() => {
23
35
  });
24
36
 
25
37
  describe('AcctMgt Handlers', () => {
26
- test('createCodeSubmitHandler submits code form correctly', () => {
27
- mockDOM(['button']);
38
+ test('๐Ÿงพ createCodeSubmitHandler submits code form correctly', () => {
39
+ injectDOM([{ id: 'button' }]);
40
+
28
41
  createCodeSubmitHandler({
29
42
  formId: 'codeForm',
30
43
  inputId: 'code_id',
@@ -46,11 +59,11 @@ describe('AcctMgt Handlers', () => {
46
59
  );
47
60
  });
48
61
 
49
- test('forgotSubmitHandler submits email form correctly', () => {
50
- mockDOM(['button']);
51
- const emailInput = document.createElement('input');
52
- emailInput.setAttribute('id', 'email_id');
53
- document.body.appendChild(emailInput);
62
+ test('๐Ÿ“ง forgotSubmitHandler submits email form correctly', () => {
63
+ injectDOM([
64
+ { id: 'button' },
65
+ { tag: 'input', id: 'email_id', value: 'user@example.com' }
66
+ ]);
54
67
 
55
68
  forgotSubmitHandler({
56
69
  formId: 'forgotPassword',
@@ -73,11 +86,12 @@ describe('AcctMgt Handlers', () => {
73
86
  );
74
87
  });
75
88
 
76
- test('createAdminLoginHandler sets attributes and submits login', () => {
77
- mockDOM(['button', 'showPassword_id']);
78
- const passwordInput = document.createElement('input');
79
- passwordInput.setAttribute('id', 'password_id');
80
- document.body.appendChild(passwordInput);
89
+ test('๐Ÿ” createAdminLoginHandler sets attributes and submits login', () => {
90
+ injectDOM([
91
+ { id: 'button' },
92
+ { id: 'showPassword_id' },
93
+ { tag: 'input', id: 'password_id' }
94
+ ]);
81
95
 
82
96
  createAdminLoginHandler({
83
97
  formId: 'managed',
@@ -102,29 +116,19 @@ describe('AcctMgt Handlers', () => {
102
116
  { maxLength: { id: ['password_id', 'email_id'], max: [30, 50] } }
103
117
  );
104
118
 
105
- expect(passwordInput.getAttribute('autocomplete')).toBe('current-password');
119
+ expect(document.getElementById('password_id').getAttribute('autocomplete')).toBe('current-password');
106
120
  expect(showPassword).toHaveBeenCalledWith('password_id');
107
121
  });
108
122
 
109
- test('setupPasswordChange submits when passwords match', () => {
110
- mockDOM(['button', 'showPassword_id']);
111
- const passwordInput = document.createElement('input');
112
- passwordInput.setAttribute('id', 'password_id');
113
- passwordInput.value = 'Secure123!';
114
- document.body.appendChild(passwordInput);
115
-
116
- const confirmInput = document.createElement('input');
117
- confirmInput.setAttribute('id', 'confirm_password_id');
118
- confirmInput.value = 'Secure123!';
119
- document.body.appendChild(confirmInput);
120
-
121
- const errorEl = document.createElement('div');
122
- errorEl.setAttribute('id', 'confirm_password_error');
123
- document.body.appendChild(errorEl);
124
-
125
- const helpEl = document.createElement('div');
126
- helpEl.setAttribute('id', 'password_help');
127
- document.body.appendChild(helpEl);
123
+ test('๐Ÿ” setupPasswordChange submits when passwords match', () => {
124
+ injectDOM([
125
+ { id: 'button' },
126
+ { id: 'showPassword_id' },
127
+ { tag: 'input', id: 'password_id', value: 'Secure123!' },
128
+ { tag: 'input', id: 'confirm_password_id', value: 'Secure123!' },
129
+ { tag: 'div', id: 'confirm_password_error' },
130
+ { tag: 'div', id: 'password_help' }
131
+ ]);
128
132
 
129
133
  setupPasswordChange({
130
134
  buttonId: 'button',
@@ -1,3 +1,3 @@
1
1
  <?php
2
- define('APP_VERSION', 'v1.2.27');
2
+ define('APP_VERSION', 'v1.2.29');
3
3
 
package/index.js CHANGED
@@ -1,10 +1,7 @@
1
1
  export * from './Http.js';
2
2
  export * from './UtilityHtml.js';
3
- export * from './FormProcessing.js';
4
3
  export * from './Utility.js';
5
4
  export * from './Loader.js';
6
- export * from './ForgotPassword.js';
7
- export * from './Login.js';
8
5
  export * from './Cookie.js';
9
6
  export * from './FormHelper.js';
10
7
  export * from './Loader.js';
@@ -15,6 +12,5 @@ export * from './AcctMgt/changePassword.js';
15
12
  export * from './AcctMgt/code.js';
16
13
  export * from './AcctMgt/forgot.js';
17
14
  export * from './AcctMgt/login.js';
18
- export * from './AcctMgt/loginUtility.js';
19
15
  export * from './AcctMgt/processAll.js';
20
16
  export * from './general.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modernman00/shared-js-lib",
3
- "version": "1.2.26",
3
+ "version": "1.2.28",
4
4
  "description": "Reusable JS utilities for numerous js problems",
5
5
  "homepage": "https://github.com/modernman00/shared-js-lib#readme",
6
6
  "keywords": [
@@ -1,11 +0,0 @@
1
- import { id } from '../UtilityHtml.js';
2
-
3
- export const showPassword = (inputId) => {
4
- const y = id(inputId);
5
- if (y.type === 'password') {
6
-
7
- y.type = 'text';
8
- } else {
9
- y.type = 'password';
10
- }
11
- };