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