@mgdis/core-ui-helpers 1.2.1 → 1.2.2

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +8 -8
  3. package/rollup.config.mjs +3 -3
  4. package/src/angular/mg-angular-logger/mg-angular-logger.spec.ts +1 -1
  5. package/src/angular/mg-angular-logger/mg-angular-logger.ts +2 -1
  6. package/src/locale/index.spec.ts +10 -1
  7. package/src/locale/locale.spec.ts +43 -18
  8. package/src/locale/locale.ts +13 -5
  9. package/src/playwright/utils/utils.spec.ts +16 -9
  10. package/src/playwright/utils/utils.ts +14 -6
  11. package/src/stencil/ide/cem.spec.ts +4 -4
  12. package/src/stencil/ide/cem.ts +9 -9
  13. package/src/stencil/ide/ide.ts +26 -26
  14. package/src/storybook/stencil/stencil.spec.ts +30 -6
  15. package/src/storybook/stencil/stencil.ts +24 -13
  16. package/src/tests/index.spec.ts +7 -1
  17. package/src/tests/unit/unit.conf.ts +9 -2
  18. package/src/tests/unit/unit.spec.ts +103 -61
  19. package/src/tests/unit/unit.ts +38 -11
  20. package/src/utils/attributes/id/id.spec.ts +9 -6
  21. package/src/utils/attributes/id/id.ts +3 -2
  22. package/src/utils/components/components.spec.ts +6 -6
  23. package/src/utils/components/components.ts +19 -5
  24. package/src/utils/elements/elements.ts +4 -2
  25. package/src/utils/number/number.spec.ts +2 -2
  26. package/src/utils/object/object.spec.ts +2 -2
  27. package/src/utils/object/object.ts +2 -1
  28. package/src/utils/string/string.spec.ts +12 -5
  29. package/src/utils/string/string.ts +2 -1
  30. package/src/utils/windows/windows.spec.ts +6 -2
  31. package/src/vue/mg-model/mg-model.ts +7 -2
  32. package/vitest.config.mts +1 -1
  33. package/.turbo/turbo-build.log +0 -49
  34. package/dist/angular/index.cjs +0 -27
  35. package/dist/angular/index.cjs.map +0 -1
  36. package/dist/angular/index.d.ts +0 -21
  37. package/dist/angular/index.js +0 -25
  38. package/dist/angular/index.js.map +0 -1
  39. package/dist/angular/index.umd.js +0 -33
  40. package/dist/angular/index.umd.js.map +0 -1
  41. package/dist/locale/index.cjs +0 -188
  42. package/dist/locale/index.cjs.map +0 -1
  43. package/dist/locale/index.d.ts +0 -110
  44. package/dist/locale/index.js +0 -179
  45. package/dist/locale/index.js.map +0 -1
  46. package/dist/locale/index.umd.js +0 -194
  47. package/dist/locale/index.umd.js.map +0 -1
  48. package/dist/playwright/index.cjs +0 -130
  49. package/dist/playwright/index.cjs.map +0 -1
  50. package/dist/playwright/index.d.ts +0 -39
  51. package/dist/playwright/index.js +0 -126
  52. package/dist/playwright/index.js.map +0 -1
  53. package/dist/playwright/index.umd.js +0 -136
  54. package/dist/playwright/index.umd.js.map +0 -1
  55. package/dist/stencil/index.cjs +0 -363
  56. package/dist/stencil/index.cjs.map +0 -1
  57. package/dist/stencil/index.d.ts +0 -222
  58. package/dist/stencil/index.js +0 -357
  59. package/dist/stencil/index.js.map +0 -1
  60. package/dist/stencil/index.umd.js +0 -369
  61. package/dist/stencil/index.umd.js.map +0 -1
  62. package/dist/storybook/index.cjs +0 -2333
  63. package/dist/storybook/index.cjs.map +0 -1
  64. package/dist/storybook/index.d.ts +0 -85
  65. package/dist/storybook/index.js +0 -2327
  66. package/dist/storybook/index.js.map +0 -1
  67. package/dist/storybook/index.umd.js +0 -2339
  68. package/dist/storybook/index.umd.js.map +0 -1
  69. package/dist/tests/index.cjs +0 -300
  70. package/dist/tests/index.cjs.map +0 -1
  71. package/dist/tests/index.d.ts +0 -100
  72. package/dist/tests/index.js +0 -294
  73. package/dist/tests/index.js.map +0 -1
  74. package/dist/tests/index.umd.js +0 -306
  75. package/dist/tests/index.umd.js.map +0 -1
  76. package/dist/utils/index.cjs +0 -433
  77. package/dist/utils/index.cjs.map +0 -1
  78. package/dist/utils/index.d.ts +0 -265
  79. package/dist/utils/index.js +0 -409
  80. package/dist/utils/index.js.map +0 -1
  81. package/dist/utils/index.umd.js +0 -439
  82. package/dist/utils/index.umd.js.map +0 -1
  83. package/dist/vue/index.cjs +0 -1934
  84. package/dist/vue/index.cjs.map +0 -1
  85. package/dist/vue/index.d.ts +0 -35
  86. package/dist/vue/index.js +0 -1932
  87. package/dist/vue/index.js.map +0 -1
  88. package/dist/vue/index.umd.js +0 -1940
  89. package/dist/vue/index.umd.js.map +0 -1
@@ -1,300 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Utility function that mocks the `MutationObserver` API. Recommended to execute inside `beforeEach`.
5
- * @param mutationObserverMock - Parameter that is sent to the `Object.defineProperty`
6
- * overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
7
- * mock the mutation observer, but its methods.
8
- * You can manually fire an intersection entry:
9
- * @param mutationObserverMock - configuration object
10
- * @returns Mocked MutationObserver
11
- * @example
12
- * ```
13
- * let fireMo;
14
- * setupMutationObserverMock({
15
- * observe: function () {
16
- * fireMo = this.cb;
17
- * },
18
- * });
19
- * ...
20
- * fireMo([{ type: 'childList', addedNodes: [AMockElemenet, AnotherMockElemenet], target: yourMockElemenet }]);;
21
- * ```
22
- */
23
- const setupMutationObserverMock = ({ disconnect, observe, takeRecords }) => {
24
- class MockMutationObserver {
25
- /**
26
- *
27
- */
28
- disconnect = disconnect;
29
- /**
30
- *
31
- */
32
- observe = observe;
33
- /**
34
- *
35
- */
36
- takeRecords = takeRecords;
37
- /**
38
- *
39
- */
40
- cb;
41
- constructor(fn) {
42
- this.cb = fn;
43
- }
44
- }
45
- [window, global].forEach(element => {
46
- Object.defineProperty(element, 'MutationObserver', {
47
- writable: true,
48
- configurable: true,
49
- value: MockMutationObserver,
50
- });
51
- });
52
- return MockMutationObserver;
53
- };
54
- /**
55
- * Utility function that mocks the `ResizeObserver` API. Recommended to execute inside `beforeEach`.
56
- * @param resizeObserverMock - Parameter that is sent to the `Object.defineProperty`
57
- * overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
58
- * mock the resize observer, but its methods.
59
- * You can manually fire an intersection entry:
60
- * @param resizeObserverMock - configuration object
61
- * @returns Mocked ResizeObserver
62
- * @example
63
- * ```
64
- * let fireRo;
65
- * setupResizeObserverMock({
66
- * observe: function () {
67
- * fireRo = this.cb;
68
- * },
69
- * });
70
- * ...
71
- * fireRo([{
72
- * borderBoxSize: ResizeObserverSize[],
73
- * contentBoxSize: ResizeObserverSize[],
74
- * contentRect: DOMRectReadOnly,
75
- * devicePixelContentBoxSize: ResizeObserverSize[],
76
- * target: yourMockElemenet
77
- * }]);;
78
- * ```
79
- */
80
- const setupResizeObserverMock = ({ disconnect, observe }) => {
81
- class MockResizeObserver {
82
- /**
83
- *
84
- */
85
- disconnect = disconnect;
86
- /**
87
- *
88
- */
89
- observe = observe;
90
- /**
91
- *
92
- */
93
- unobserve;
94
- /**
95
- *
96
- */
97
- cb;
98
- constructor(fn) {
99
- this.cb = fn;
100
- }
101
- }
102
- [window, global].forEach(element => {
103
- Object.defineProperty(element, 'ResizeObserver', {
104
- writable: true,
105
- configurable: true,
106
- value: MockResizeObserver,
107
- });
108
- });
109
- return MockResizeObserver;
110
- };
111
- class MockCustomEvent extends Event {
112
- /**
113
- *
114
- */
115
- detail; // eslint-disable-line @typescript-eslint/no-explicit-any
116
- }
117
- /**
118
- * Utility function that mocks the `SubmitEvent` API. Recommended to execute inside `beforeEach`.
119
- * @example
120
- * ```
121
- * setupSubmitEventMock();
122
- * ```
123
- * @returns custom event mock
124
- */
125
- const setupSubmitEventMock = () => {
126
- class SubmitEvent extends MockCustomEvent {
127
- }
128
- [window, global].forEach(element => {
129
- Object.defineProperty(element, 'SubmitEvent', {
130
- writable: true,
131
- configurable: true,
132
- value: SubmitEvent,
133
- });
134
- });
135
- return SubmitEvent;
136
- };
137
- /**
138
- * Utility function that mocks the `requestAnimationFrame` API. Recommended to execute inside `test`.
139
- * @example
140
- * ```
141
- * setUpRequestAnimationFrameMock(jest.runOnlyPendingTimers);
142
- * ```
143
- * @param faketimer - recommended to use jest.runOnlyPendingTimers()
144
- * @returns custom setUpRequestAnimationFrameMock mock
145
- */
146
- const setUpRequestAnimationFrameMock = (faketimer) => {
147
- const requestAnimationFrame = (callback) => {
148
- setTimeout(callback, 1);
149
- faketimer();
150
- return 0;
151
- };
152
- [window, global].forEach(element => {
153
- Object.defineProperty(element, 'requestAnimationFrame', {
154
- writable: true,
155
- configurable: true,
156
- value: requestAnimationFrame,
157
- });
158
- });
159
- return requestAnimationFrame;
160
- };
161
- /**
162
- * Convert string to given type
163
- * @param value - string value to format
164
- * @param type - new value output type
165
- * @returns string value converted to given type
166
- */
167
- const convertString = (value, type) => {
168
- switch (type) {
169
- case 'date':
170
- return new Date(value);
171
- case 'number':
172
- return Number(value);
173
- default:
174
- return value;
175
- }
176
- };
177
- /**
178
- * Get range underflow value from input['min]
179
- * @param input - HTMLInputElement
180
- * @returns truthy iv value is underflow
181
- */
182
- const getRangeUnderflow = (input) => {
183
- const value = convertString(input.value, input.type);
184
- if (['date', 'number'].includes(input.type) && input.hasAttribute('min') && input.value.length > 0) {
185
- const min = convertString(input.min, input.type);
186
- return value < min;
187
- }
188
- else {
189
- return false;
190
- }
191
- };
192
- /**
193
- * Get range overflow value from input['max]
194
- * @param input - HTMLInputElement
195
- * @returns truthy iv value is overflow
196
- */
197
- const getRangeOverflow = (input) => {
198
- const value = convertString(input.value, input.type);
199
- if (['date', 'number'].includes(input.type) && input.hasAttribute('max') && input.value.length > 0) {
200
- const max = convertString(input.max, input.type);
201
- return value > max;
202
- }
203
- else {
204
- return false;
205
- }
206
- };
207
- /**
208
- * HTMLSelectElement type guard
209
- * @param input - HTMLElement to test
210
- * @returns truthy if element is HTMLSelectElement
211
- */
212
- const isHTMLSelectElement = (input) => input.options !== undefined;
213
- /**
214
- * Is value missing from input
215
- * @param input - input to test
216
- * @returns truthy if value is required
217
- */
218
- const isValueMissing = (input) => {
219
- if (input.hasAttribute('required') && input.required === true) {
220
- if (['checkbox', 'radio'].includes(input.type)) {
221
- return input.checked === false;
222
- }
223
- else if (isHTMLSelectElement(input)) {
224
- return input.options.item(input.options.selectedIndex)?.value === '';
225
- }
226
- else {
227
- return input.value.length === 0;
228
- }
229
- }
230
- else {
231
- return false;
232
- }
233
- };
234
- /**
235
- * Get input validity
236
- * @param input - input prototype
237
- * @returns input validity state
238
- */
239
- const getValidity = (input) => {
240
- // required field without a value
241
- const valueMissing = isValueMissing(input);
242
- // value of a number field is not a number | value of a date field is not a date
243
- const badInput = ['number', 'date'].includes(input.type) && isNaN(input.type === 'date' ? Date.parse(input.value) : input.value);
244
- // value does not conform to the pattern
245
- const patternMismatch = input.hasAttribute('pattern') && new RegExp(input.pattern).test(input.value) === false;
246
- // value of a number|date field is higher than the max attribute
247
- const rangeOverflow = getRangeOverflow(input);
248
- // value of a number|date field is lower than the min attribute
249
- const rangeUnderflow = getRangeUnderflow(input);
250
- // value of a number field does not conform to the stepattribute
251
- const stepMismatch = input.type === 'number' && input.hasAttribute('step') && input.step !== 'any' && Number(input.value) % parseFloat(input.step) !== 0;
252
- // the user has edited a too-long value in a field with maxlength
253
- const tooLong = input.hasAttribute('maxLength') && input.value?.length > Number(input.maxLength);
254
- // the user has edited a too-short value in a field with minlength
255
- const tooShort = input.hasAttribute('minLength') && input.value?.length < Number(input.minLength);
256
- // value of a email or URL field is not an email address or URL
257
- const typeMismatch = input.type === 'url' && !URL.canParse(input.value);
258
- // value of validationMessage is not an empty string
259
- const customError = false;
260
- const valid = ![valueMissing, badInput, patternMismatch, rangeOverflow, rangeUnderflow, stepMismatch, tooLong, tooShort, typeMismatch, customError].some(invalid => invalid);
261
- return {
262
- badInput,
263
- customError,
264
- patternMismatch,
265
- rangeOverflow,
266
- rangeUnderflow,
267
- stepMismatch,
268
- tooLong,
269
- tooShort,
270
- typeMismatch,
271
- valid,
272
- valueMissing,
273
- };
274
- };
275
- /**
276
- * Utility function that mocks the HTMLInputElement[`vality`] state API and the HTMLInputElement.checkvalidty() methode.
277
- * Recommended to execute inside `test`.
278
- * @example
279
- * ```
280
- * Array.from(document.querySelectorInputs('input')).forEach(setUpHTMLInputElementValidity);
281
- * ```
282
- */
283
- const setUpHTMLInputElementValidity = (input) => {
284
- input.checkValidity = () => {
285
- const { valid } = getValidity(input);
286
- input.dispatchEvent(new CustomEvent('invalid', { detail: !valid }));
287
- return valid;
288
- };
289
- Object.defineProperty(input, 'validity', {
290
- get: () => getValidity(input),
291
- configurable: true,
292
- });
293
- };
294
-
295
- exports.setUpHTMLInputElementValidity = setUpHTMLInputElementValidity;
296
- exports.setUpRequestAnimationFrameMock = setUpRequestAnimationFrameMock;
297
- exports.setupMutationObserverMock = setupMutationObserverMock;
298
- exports.setupResizeObserverMock = setupResizeObserverMock;
299
- exports.setupSubmitEventMock = setupSubmitEventMock;
300
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/tests/unit/unit.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;AAmBG;AACI,MAAM,yBAAyB,GAAG,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAmC,KAA6B;AAC1I,IAAA,MAAM,oBAAoB,CAAA;AACxB;;AAEG;QACH,UAAU,GAAe,UAAU;AACnC;;AAEG;QACH,OAAO,GAA2D,OAAO;AACzE;;AAEG;QACH,WAAW,GAA2B,WAAW;AACjD;;AAEG;AACH,QAAA,EAAE;AACF,QAAA,WAAA,CAAY,EAAoB,EAAA;AAC9B,YAAA,IAAI,CAAC,EAAE,GAAG,EAAE;QACd;AACD;IAED,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,OAAO,IAAG;AACjC,QAAA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,kBAAkB,EAAE;AACjD,YAAA,QAAQ,EAAE,IAAI;AACd,YAAA,YAAY,EAAE,IAAI;AAClB,YAAA,KAAK,EAAE,oBAAoB;AAC5B,SAAA,CAAC;AACJ,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,oBAAoB;A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AK,CAAC;;IAEvE,MAAM,WAAW,GAAG,KAAK;AAEzB,IAAA,MAAM,KAAK,GAAG,CAAC,CAAC,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC;IAC5K,OAAO;QACL,QAAQ;QACR,WAAW;QACX,eAAe;QACf,aAAa;QACb,cAAc;QACd,YAAY;QACZ,OAAO;QACP,QAAQ;QACR,YAAY;QACZ,KAAK;QACL,YAAY;KACb;AACH,CAAC;AAED;;;;;;;AAOG;AACI,MAAM,6BAA6B,GAAG,CAAC,KAAuB,KAAI;AACvE,IAAA,KAAK,CAAC,aAAa,GAAG,MAAK;QACzB,MAAM,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC,KAAK,CAAC;AACpC,QAAA,KAAK,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;AACnE,QAAA,OAAO,KAAK;AACd,IAAA,CAAC;AACD,IAAA,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE;AACvC,QAAA,GAAG,EAAE,MAAM,WAAW,CAAC,KAAK,CAAC;AAC7B,QAAA,YAAY,EAAE,IAAI;AACnB,KAAA,CAAC;AACJ;;;;;;;;"}
@@ -1,100 +0,0 @@
1
- /**
2
- * Define MutationObserver setup function signature
3
- */
4
- type SetupMutationObserverMockParams = {
5
- disconnect: MutationObserver['disconnect'];
6
- observe: MutationObserver['observe'];
7
- takeRecords: MutationObserver['takeRecords'];
8
- };
9
- /**
10
- * Define ResizeObserver setup function signature
11
- */
12
- type setupResizeObserverMockParams = {
13
- disconnect: ResizeObserver['disconnect'];
14
- observe: ResizeObserver['observe'];
15
- };
16
-
17
- /**
18
- * Utility function that mocks the `MutationObserver` API. Recommended to execute inside `beforeEach`.
19
- * @param mutationObserverMock - Parameter that is sent to the `Object.defineProperty`
20
- * overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
21
- * mock the mutation observer, but its methods.
22
- * You can manually fire an intersection entry:
23
- * @param mutationObserverMock - configuration object
24
- * @returns Mocked MutationObserver
25
- * @example
26
- * ```
27
- * let fireMo;
28
- * setupMutationObserverMock({
29
- * observe: function () {
30
- * fireMo = this.cb;
31
- * },
32
- * });
33
- * ...
34
- * fireMo([{ type: 'childList', addedNodes: [AMockElemenet, AnotherMockElemenet], target: yourMockElemenet }]);;
35
- * ```
36
- */
37
- declare const setupMutationObserverMock: ({ disconnect, observe, takeRecords }: SetupMutationObserverMockParams) => typeof MutationObserver;
38
- /**
39
- * Utility function that mocks the `ResizeObserver` API. Recommended to execute inside `beforeEach`.
40
- * @param resizeObserverMock - Parameter that is sent to the `Object.defineProperty`
41
- * overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
42
- * mock the resize observer, but its methods.
43
- * You can manually fire an intersection entry:
44
- * @param resizeObserverMock - configuration object
45
- * @returns Mocked ResizeObserver
46
- * @example
47
- * ```
48
- * let fireRo;
49
- * setupResizeObserverMock({
50
- * observe: function () {
51
- * fireRo = this.cb;
52
- * },
53
- * });
54
- * ...
55
- * fireRo([{
56
- * borderBoxSize: ResizeObserverSize[],
57
- * contentBoxSize: ResizeObserverSize[],
58
- * contentRect: DOMRectReadOnly,
59
- * devicePixelContentBoxSize: ResizeObserverSize[],
60
- * target: yourMockElemenet
61
- * }]);;
62
- * ```
63
- */
64
- declare const setupResizeObserverMock: ({ disconnect, observe }: setupResizeObserverMockParams) => typeof ResizeObserver;
65
- declare class MockCustomEvent extends Event {
66
- /**
67
- *
68
- */
69
- detail: any;
70
- }
71
- /**
72
- * Utility function that mocks the `SubmitEvent` API. Recommended to execute inside `beforeEach`.
73
- * @example
74
- * ```
75
- * setupSubmitEventMock();
76
- * ```
77
- * @returns custom event mock
78
- */
79
- declare const setupSubmitEventMock: () => typeof MockCustomEvent;
80
- /**
81
- * Utility function that mocks the `requestAnimationFrame` API. Recommended to execute inside `test`.
82
- * @example
83
- * ```
84
- * setUpRequestAnimationFrameMock(jest.runOnlyPendingTimers);
85
- * ```
86
- * @param faketimer - recommended to use jest.runOnlyPendingTimers()
87
- * @returns custom setUpRequestAnimationFrameMock mock
88
- */
89
- declare const setUpRequestAnimationFrameMock: (faketimer: () => void) => (callback: FrameRequestCallback) => number;
90
- /**
91
- * Utility function that mocks the HTMLInputElement[`vality`] state API and the HTMLInputElement.checkvalidty() methode.
92
- * Recommended to execute inside `test`.
93
- * @example
94
- * ```
95
- * Array.from(document.querySelectorInputs('input')).forEach(setUpHTMLInputElementValidity);
96
- * ```
97
- */
98
- declare const setUpHTMLInputElementValidity: (input: HTMLInputElement) => void;
99
-
100
- export { setUpHTMLInputElementValidity, setUpRequestAnimationFrameMock, setupMutationObserverMock, setupResizeObserverMock, setupSubmitEventMock };
@@ -1,294 +0,0 @@
1
- /**
2
- * Utility function that mocks the `MutationObserver` API. Recommended to execute inside `beforeEach`.
3
- * @param mutationObserverMock - Parameter that is sent to the `Object.defineProperty`
4
- * overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
5
- * mock the mutation observer, but its methods.
6
- * You can manually fire an intersection entry:
7
- * @param mutationObserverMock - configuration object
8
- * @returns Mocked MutationObserver
9
- * @example
10
- * ```
11
- * let fireMo;
12
- * setupMutationObserverMock({
13
- * observe: function () {
14
- * fireMo = this.cb;
15
- * },
16
- * });
17
- * ...
18
- * fireMo([{ type: 'childList', addedNodes: [AMockElemenet, AnotherMockElemenet], target: yourMockElemenet }]);;
19
- * ```
20
- */
21
- const setupMutationObserverMock = ({ disconnect, observe, takeRecords }) => {
22
- class MockMutationObserver {
23
- /**
24
- *
25
- */
26
- disconnect = disconnect;
27
- /**
28
- *
29
- */
30
- observe = observe;
31
- /**
32
- *
33
- */
34
- takeRecords = takeRecords;
35
- /**
36
- *
37
- */
38
- cb;
39
- constructor(fn) {
40
- this.cb = fn;
41
- }
42
- }
43
- [window, global].forEach(element => {
44
- Object.defineProperty(element, 'MutationObserver', {
45
- writable: true,
46
- configurable: true,
47
- value: MockMutationObserver,
48
- });
49
- });
50
- return MockMutationObserver;
51
- };
52
- /**
53
- * Utility function that mocks the `ResizeObserver` API. Recommended to execute inside `beforeEach`.
54
- * @param resizeObserverMock - Parameter that is sent to the `Object.defineProperty`
55
- * overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
56
- * mock the resize observer, but its methods.
57
- * You can manually fire an intersection entry:
58
- * @param resizeObserverMock - configuration object
59
- * @returns Mocked ResizeObserver
60
- * @example
61
- * ```
62
- * let fireRo;
63
- * setupResizeObserverMock({
64
- * observe: function () {
65
- * fireRo = this.cb;
66
- * },
67
- * });
68
- * ...
69
- * fireRo([{
70
- * borderBoxSize: ResizeObserverSize[],
71
- * contentBoxSize: ResizeObserverSize[],
72
- * contentRect: DOMRectReadOnly,
73
- * devicePixelContentBoxSize: ResizeObserverSize[],
74
- * target: yourMockElemenet
75
- * }]);;
76
- * ```
77
- */
78
- const setupResizeObserverMock = ({ disconnect, observe }) => {
79
- class MockResizeObserver {
80
- /**
81
- *
82
- */
83
- disconnect = disconnect;
84
- /**
85
- *
86
- */
87
- observe = observe;
88
- /**
89
- *
90
- */
91
- unobserve;
92
- /**
93
- *
94
- */
95
- cb;
96
- constructor(fn) {
97
- this.cb = fn;
98
- }
99
- }
100
- [window, global].forEach(element => {
101
- Object.defineProperty(element, 'ResizeObserver', {
102
- writable: true,
103
- configurable: true,
104
- value: MockResizeObserver,
105
- });
106
- });
107
- return MockResizeObserver;
108
- };
109
- class MockCustomEvent extends Event {
110
- /**
111
- *
112
- */
113
- detail; // eslint-disable-line @typescript-eslint/no-explicit-any
114
- }
115
- /**
116
- * Utility function that mocks the `SubmitEvent` API. Recommended to execute inside `beforeEach`.
117
- * @example
118
- * ```
119
- * setupSubmitEventMock();
120
- * ```
121
- * @returns custom event mock
122
- */
123
- const setupSubmitEventMock = () => {
124
- class SubmitEvent extends MockCustomEvent {
125
- }
126
- [window, global].forEach(element => {
127
- Object.defineProperty(element, 'SubmitEvent', {
128
- writable: true,
129
- configurable: true,
130
- value: SubmitEvent,
131
- });
132
- });
133
- return SubmitEvent;
134
- };
135
- /**
136
- * Utility function that mocks the `requestAnimationFrame` API. Recommended to execute inside `test`.
137
- * @example
138
- * ```
139
- * setUpRequestAnimationFrameMock(jest.runOnlyPendingTimers);
140
- * ```
141
- * @param faketimer - recommended to use jest.runOnlyPendingTimers()
142
- * @returns custom setUpRequestAnimationFrameMock mock
143
- */
144
- const setUpRequestAnimationFrameMock = (faketimer) => {
145
- const requestAnimationFrame = (callback) => {
146
- setTimeout(callback, 1);
147
- faketimer();
148
- return 0;
149
- };
150
- [window, global].forEach(element => {
151
- Object.defineProperty(element, 'requestAnimationFrame', {
152
- writable: true,
153
- configurable: true,
154
- value: requestAnimationFrame,
155
- });
156
- });
157
- return requestAnimationFrame;
158
- };
159
- /**
160
- * Convert string to given type
161
- * @param value - string value to format
162
- * @param type - new value output type
163
- * @returns string value converted to given type
164
- */
165
- const convertString = (value, type) => {
166
- switch (type) {
167
- case 'date':
168
- return new Date(value);
169
- case 'number':
170
- return Number(value);
171
- default:
172
- return value;
173
- }
174
- };
175
- /**
176
- * Get range underflow value from input['min]
177
- * @param input - HTMLInputElement
178
- * @returns truthy iv value is underflow
179
- */
180
- const getRangeUnderflow = (input) => {
181
- const value = convertString(input.value, input.type);
182
- if (['date', 'number'].includes(input.type) && input.hasAttribute('min') && input.value.length > 0) {
183
- const min = convertString(input.min, input.type);
184
- return value < min;
185
- }
186
- else {
187
- return false;
188
- }
189
- };
190
- /**
191
- * Get range overflow value from input['max]
192
- * @param input - HTMLInputElement
193
- * @returns truthy iv value is overflow
194
- */
195
- const getRangeOverflow = (input) => {
196
- const value = convertString(input.value, input.type);
197
- if (['date', 'number'].includes(input.type) && input.hasAttribute('max') && input.value.length > 0) {
198
- const max = convertString(input.max, input.type);
199
- return value > max;
200
- }
201
- else {
202
- return false;
203
- }
204
- };
205
- /**
206
- * HTMLSelectElement type guard
207
- * @param input - HTMLElement to test
208
- * @returns truthy if element is HTMLSelectElement
209
- */
210
- const isHTMLSelectElement = (input) => input.options !== undefined;
211
- /**
212
- * Is value missing from input
213
- * @param input - input to test
214
- * @returns truthy if value is required
215
- */
216
- const isValueMissing = (input) => {
217
- if (input.hasAttribute('required') && input.required === true) {
218
- if (['checkbox', 'radio'].includes(input.type)) {
219
- return input.checked === false;
220
- }
221
- else if (isHTMLSelectElement(input)) {
222
- return input.options.item(input.options.selectedIndex)?.value === '';
223
- }
224
- else {
225
- return input.value.length === 0;
226
- }
227
- }
228
- else {
229
- return false;
230
- }
231
- };
232
- /**
233
- * Get input validity
234
- * @param input - input prototype
235
- * @returns input validity state
236
- */
237
- const getValidity = (input) => {
238
- // required field without a value
239
- const valueMissing = isValueMissing(input);
240
- // value of a number field is not a number | value of a date field is not a date
241
- const badInput = ['number', 'date'].includes(input.type) && isNaN(input.type === 'date' ? Date.parse(input.value) : input.value);
242
- // value does not conform to the pattern
243
- const patternMismatch = input.hasAttribute('pattern') && new RegExp(input.pattern).test(input.value) === false;
244
- // value of a number|date field is higher than the max attribute
245
- const rangeOverflow = getRangeOverflow(input);
246
- // value of a number|date field is lower than the min attribute
247
- const rangeUnderflow = getRangeUnderflow(input);
248
- // value of a number field does not conform to the stepattribute
249
- const stepMismatch = input.type === 'number' && input.hasAttribute('step') && input.step !== 'any' && Number(input.value) % parseFloat(input.step) !== 0;
250
- // the user has edited a too-long value in a field with maxlength
251
- const tooLong = input.hasAttribute('maxLength') && input.value?.length > Number(input.maxLength);
252
- // the user has edited a too-short value in a field with minlength
253
- const tooShort = input.hasAttribute('minLength') && input.value?.length < Number(input.minLength);
254
- // value of a email or URL field is not an email address or URL
255
- const typeMismatch = input.type === 'url' && !URL.canParse(input.value);
256
- // value of validationMessage is not an empty string
257
- const customError = false;
258
- const valid = ![valueMissing, badInput, patternMismatch, rangeOverflow, rangeUnderflow, stepMismatch, tooLong, tooShort, typeMismatch, customError].some(invalid => invalid);
259
- return {
260
- badInput,
261
- customError,
262
- patternMismatch,
263
- rangeOverflow,
264
- rangeUnderflow,
265
- stepMismatch,
266
- tooLong,
267
- tooShort,
268
- typeMismatch,
269
- valid,
270
- valueMissing,
271
- };
272
- };
273
- /**
274
- * Utility function that mocks the HTMLInputElement[`vality`] state API and the HTMLInputElement.checkvalidty() methode.
275
- * Recommended to execute inside `test`.
276
- * @example
277
- * ```
278
- * Array.from(document.querySelectorInputs('input')).forEach(setUpHTMLInputElementValidity);
279
- * ```
280
- */
281
- const setUpHTMLInputElementValidity = (input) => {
282
- input.checkValidity = () => {
283
- const { valid } = getValidity(input);
284
- input.dispatchEvent(new CustomEvent('invalid', { detail: !valid }));
285
- return valid;
286
- };
287
- Object.defineProperty(input, 'validity', {
288
- get: () => getValidity(input),
289
- configurable: true,
290
- });
291
- };
292
-
293
- export { setUpHTMLInputElementValidity, setUpRequestAnimationFrameMock, setupMutationObserverMock, setupResizeObserverMock, setupSubmitEventMock };
294
- //# sourceMappingURL=index.js.map