@mgdis/core-ui-helpers 1.0.0

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 (146) hide show
  1. package/.turbo/turbo-build.log +52 -0
  2. package/CHANGELOG.md +12 -0
  3. package/LICENSE +29 -0
  4. package/README.md +95 -0
  5. package/dist/angular/index.cjs +27 -0
  6. package/dist/angular/index.cjs.map +1 -0
  7. package/dist/angular/index.d.ts +21 -0
  8. package/dist/angular/index.js +25 -0
  9. package/dist/angular/index.js.map +1 -0
  10. package/dist/angular/index.umd.js +33 -0
  11. package/dist/angular/index.umd.js.map +1 -0
  12. package/dist/locale/index.cjs +164 -0
  13. package/dist/locale/index.cjs.map +1 -0
  14. package/dist/locale/index.d.ts +103 -0
  15. package/dist/locale/index.js +156 -0
  16. package/dist/locale/index.js.map +1 -0
  17. package/dist/locale/index.umd.js +170 -0
  18. package/dist/locale/index.umd.js.map +1 -0
  19. package/dist/playwright/index.cjs +124 -0
  20. package/dist/playwright/index.cjs.map +1 -0
  21. package/dist/playwright/index.d.ts +35 -0
  22. package/dist/playwright/index.js +120 -0
  23. package/dist/playwright/index.js.map +1 -0
  24. package/dist/playwright/index.umd.js +130 -0
  25. package/dist/playwright/index.umd.js.map +1 -0
  26. package/dist/stencil/index.cjs +281 -0
  27. package/dist/stencil/index.cjs.map +1 -0
  28. package/dist/stencil/index.d.ts +111 -0
  29. package/dist/stencil/index.js +277 -0
  30. package/dist/stencil/index.js.map +1 -0
  31. package/dist/stencil/index.umd.js +287 -0
  32. package/dist/stencil/index.umd.js.map +1 -0
  33. package/dist/storybook/index.cjs +2109 -0
  34. package/dist/storybook/index.cjs.map +1 -0
  35. package/dist/storybook/index.d.ts +85 -0
  36. package/dist/storybook/index.js +2103 -0
  37. package/dist/storybook/index.js.map +1 -0
  38. package/dist/storybook/index.umd.js +2115 -0
  39. package/dist/storybook/index.umd.js.map +1 -0
  40. package/dist/tests/index.cjs +166 -0
  41. package/dist/tests/index.cjs.map +1 -0
  42. package/dist/tests/index.d.ts +91 -0
  43. package/dist/tests/index.js +161 -0
  44. package/dist/tests/index.js.map +1 -0
  45. package/dist/tests/index.umd.js +172 -0
  46. package/dist/tests/index.umd.js.map +1 -0
  47. package/dist/utils/index.cjs +433 -0
  48. package/dist/utils/index.cjs.map +1 -0
  49. package/dist/utils/index.d.ts +265 -0
  50. package/dist/utils/index.js +409 -0
  51. package/dist/utils/index.js.map +1 -0
  52. package/dist/utils/index.umd.js +439 -0
  53. package/dist/utils/index.umd.js.map +1 -0
  54. package/dist/vue/index.cjs +1934 -0
  55. package/dist/vue/index.cjs.map +1 -0
  56. package/dist/vue/index.d.ts +35 -0
  57. package/dist/vue/index.js +1932 -0
  58. package/dist/vue/index.js.map +1 -0
  59. package/dist/vue/index.umd.js +1940 -0
  60. package/dist/vue/index.umd.js.map +1 -0
  61. package/json-doc.test.json +253 -0
  62. package/package.json +80 -0
  63. package/rollup.config.mjs +61 -0
  64. package/src/angular/index.spec.ts +8 -0
  65. package/src/angular/index.ts +1 -0
  66. package/src/angular/mg-angular-logger/index.ts +1 -0
  67. package/src/angular/mg-angular-logger/mg-angular-logger.conf.ts +3 -0
  68. package/src/angular/mg-angular-logger/mg-angular-logger.spec.ts +40 -0
  69. package/src/angular/mg-angular-logger/mg-angular-logger.ts +23 -0
  70. package/src/locale/index.spec.ts +14 -0
  71. package/src/locale/index.ts +1 -0
  72. package/src/locale/locale.spec.ts +173 -0
  73. package/src/locale/locale.ts +166 -0
  74. package/src/playwright/config/index.ts +43 -0
  75. package/src/playwright/index.spec.ts +16 -0
  76. package/src/playwright/index.ts +4 -0
  77. package/src/playwright/utils/__snapshots__/utils.spec.ts.snap +48 -0
  78. package/src/playwright/utils/index.ts +1 -0
  79. package/src/playwright/utils/utils.spec.ts +43 -0
  80. package/src/playwright/utils/utils.ts +64 -0
  81. package/src/stencil/ide/__snapshots__/ide.spec.ts.snap +527 -0
  82. package/src/stencil/ide/ide.spec.ts +25 -0
  83. package/src/stencil/ide/ide.ts +214 -0
  84. package/src/stencil/ide/index.ts +1 -0
  85. package/src/stencil/index.spec.ts +12 -0
  86. package/src/stencil/index.ts +1 -0
  87. package/src/storybook/index.spec.ts +15 -0
  88. package/src/storybook/index.ts +1 -0
  89. package/src/storybook/stencil/__snapshots__/stencil.spec.ts.snap +329 -0
  90. package/src/storybook/stencil/index.ts +1 -0
  91. package/src/storybook/stencil/stencil-shim.d.ts +1 -0
  92. package/src/storybook/stencil/stencil.conf.ts +4 -0
  93. package/src/storybook/stencil/stencil.spec.ts +142 -0
  94. package/src/storybook/stencil/stencil.ts +366 -0
  95. package/src/tests/index.spec.ts +13 -0
  96. package/src/tests/index.ts +1 -0
  97. package/src/tests/unit/__snapshots__/unit.spec.ts.snap +52 -0
  98. package/src/tests/unit/index.ts +1 -0
  99. package/src/tests/unit/unit.conf.ts +9 -0
  100. package/src/tests/unit/unit.spec.ts +44 -0
  101. package/src/tests/unit/unit.ts +171 -0
  102. package/src/utils/attributes/class-list/class-list.spec.ts +36 -0
  103. package/src/utils/attributes/class-list/class-list.ts +51 -0
  104. package/src/utils/attributes/class-list/index.ts +1 -0
  105. package/src/utils/attributes/id/id.spec.ts +51 -0
  106. package/src/utils/attributes/id/id.ts +46 -0
  107. package/src/utils/attributes/id/index.ts +1 -0
  108. package/src/utils/attributes/index.ts +3 -0
  109. package/src/utils/attributes/to-kebab-case/index.ts +1 -0
  110. package/src/utils/attributes/to-kebab-case/to-kebab-case.spec.ts +29 -0
  111. package/src/utils/attributes/to-kebab-case/to-kebab-case.ts +23 -0
  112. package/src/utils/components/__snapshots__/components.spec.ts.snap +313 -0
  113. package/src/utils/components/components.conf.ts +11 -0
  114. package/src/utils/components/components.spec.ts +192 -0
  115. package/src/utils/components/components.ts +138 -0
  116. package/src/utils/components/index.ts +2 -0
  117. package/src/utils/date/date.spec.ts +12 -0
  118. package/src/utils/date/date.ts +20 -0
  119. package/src/utils/date/index.ts +1 -0
  120. package/src/utils/elements/elements.spec.ts +17 -0
  121. package/src/utils/elements/elements.ts +16 -0
  122. package/src/utils/elements/index.ts +1 -0
  123. package/src/utils/index.spec.ts +84 -0
  124. package/src/utils/index.ts +8 -0
  125. package/src/utils/number/index.ts +1 -0
  126. package/src/utils/number/number.spec.ts +14 -0
  127. package/src/utils/number/number.ts +6 -0
  128. package/src/utils/object/index.ts +2 -0
  129. package/src/utils/object/object.conf.ts +4 -0
  130. package/src/utils/object/object.spec.ts +98 -0
  131. package/src/utils/object/object.ts +26 -0
  132. package/src/utils/string/index.ts +1 -0
  133. package/src/utils/string/string.spec.ts +47 -0
  134. package/src/utils/string/string.ts +38 -0
  135. package/src/utils/windows/index.ts +1 -0
  136. package/src/utils/windows/windows.spec.ts +65 -0
  137. package/src/utils/windows/windows.ts +50 -0
  138. package/src/vue/index.spec.ts +8 -0
  139. package/src/vue/index.ts +1 -0
  140. package/src/vue/mg-model/index.ts +1 -0
  141. package/src/vue/mg-model/mg-model.conf.ts +6 -0
  142. package/src/vue/mg-model/mg-model.spec.ts +50 -0
  143. package/src/vue/mg-model/mg-model.ts +50 -0
  144. package/tsconfig.json +17 -0
  145. package/typedoc.json +14 -0
  146. package/vitest.config.mts +13 -0
@@ -0,0 +1,166 @@
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
+ exports.setUpRequestAnimationFrameMock = setUpRequestAnimationFrameMock;
163
+ exports.setupMutationObserverMock = setupMutationObserverMock;
164
+ exports.setupResizeObserverMock = setupResizeObserverMock;
165
+ exports.setupSubmitEventMock = setupSubmitEventMock;
166
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/tests/unit/unit.ts"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YAAY,EAAE,IAAI;AAClB,YAAA,KAAK,EAAE,kBAAkB;AAC1B,SAAA,CAAC;AACJ,KAAC,CAAC;AAEF,IAAA,OAAO,kBAAkB;AAC3B;AAEA,MAAM,eAAgB,SAAQ,KAAK,CAAA;AACjC;;AAEG;IACH,MAAM,CAAM;AACb;AAED;;;;;;;AAOG;AACI,MAAM,oBAAoB,GAAG,MAA6B;IAC/D,MAAM,WAAY,SAAQ,eAAe,CAAA;AAAG;IAE5C,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,OAAO,IAAG;AACjC,QAAA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE;AAC5C,YAAA,QAAQ,EAAE,IAAI;AACd,YAAA,YAAY,EAAE,IAAI;AAClB,YAAA,KAAK,EAAE,WAAW;AACnB,SAAA,CAAC;AACJ,KAAC,CAAC;AAEF,IAAA,OAAO,WAAW;AACpB;AAEA;;;;;;;;AAQG;AACU,MAAA,8BAA8B,GAAG,CAAC,SAAqB,KAAkC;AACpG,IAAA,MAAM,qBAAqB,GAAG,CAAC,QAA8B,KAAI;AAC/D,QAAA,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;AACvB,QAAA,SAAS,EAAE;AACX,QAAA,OAAO,CAAC;AACV,KAAC;IAED,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,OAAO,IAAG;AACjC,QAAA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,uBAAuB,EAAE;AACtD,YAAA,QAAQ,EAAE,IAAI;AACd,YAAA,YAAY,EAAE,IAAI;AAClB,YAAA,KAAK,EAAE,qBAAqB;AAC7B,SAAA,CAAC;AACJ,KAAC,CAAC;AAEF,IAAA,OAAO,qBAAqB;AAC9B;;;;;;;"}
@@ -0,0 +1,91 @@
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
+ export { setUpRequestAnimationFrameMock, setupMutationObserverMock, setupResizeObserverMock, setupSubmitEventMock };
@@ -0,0 +1,161 @@
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
+ export { setUpRequestAnimationFrameMock, setupMutationObserverMock, setupResizeObserverMock, setupSubmitEventMock };
161
+ //# 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,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAmC,KAA6B;AAC1I,IAAA,MAAM,oBAAoB,CAAA;AACxB;;AAEG;QACH,UAAU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;;;;AAOG;AACI,MAAM,oBAAoB,GAAG,MAA6B;IAC/D,MAAM,WAAY,SAAQ,eAAe,CAAA;AAAG;IAE5C,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,OAAO,IAAG;AACjC,QAAA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,aAAa,EAAE;AAC5C,YAAA,QAAQ,EAAE,IAAI;AACd,YAAA,YAAY,EAAE,IAAI;AAClB,YAAA,KAAK,EAAE,WAAW;AACnB,SAAA,CAAC;AACJ,KAAC,CAAC;AAEF,IAAA,OAAO,WAAW;AACpB;AAEA;;;;;;;;AAQG;AACU,MAAA,8BAA8B,GAAG,CAAC,SAAqB,KAAkC;AACpG,IAAA,MAAM,qBAAqB,GAAG,CAAC,QAA8B,KAAI;AAC/D,QAAA,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;AACvB,QAAA,SAAS,EAAE;AACX,QAAA,OAAO,CAAC;AACV,KAAC;IAED,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,OAAO,IAAG;AACjC,QAAA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,uBAAuB,EAAE;AACtD,YAAA,QAAQ,EAAE,IAAI;AACd,YAAA,YAAY,EAAE,IAAI;AAClB,YAAA,KAAK,EAAE,qBAAqB;AAC7B,SAAA,CAAC;AACJ,KAAC,CAAC;AAEF,IAAA,OAAO,qBAAqB;AAC9B;;;;"}
@@ -0,0 +1,172 @@
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
+ exports.setUpRequestAnimationFrameMock = setUpRequestAnimationFrameMock;
167
+ exports.setupMutationObserverMock = setupMutationObserverMock;
168
+ exports.setupResizeObserverMock = setupResizeObserverMock;
169
+ exports.setupSubmitEventMock = setupSubmitEventMock;
170
+
171
+ }));
172
+ //# 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,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAmC,KAA6B;IAC1I,IAAA,MAAM,oBAAoB,CAAA;IACxB;;IAEG;YACH,UAAU,GAAe,UAAU;IACnC;;IAEG;YACH,OAAO,GAA2D,OAAO;IACzE;;IAEG;YACH,WAAW,GAA2B,WAAW;IACjD;;IAEG;IACH,QAAA,EAAE;IACF,QAAA,WAAA,CAAY,EAAoB,EAAA;IAC9B,YAAA,IAAI,CAAC,EAAE,GAAG,EAAE;;IAEf;QAED,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,OAAO,IAAG;IACjC,QAAA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,kBAAkB,EAAE;IACjD,YAAA,QAAQ,EAAE,IAAI;IACd,YAAA,YAAY,EAAE,IAAI;IAClB,YAAA,KAAK,EAAE,oBAAoB;IAC5B,SAAA,CAAC;IACJ,KAAC,CAAC;IAEF,IAAA,OAAO,oBAAoB;IAC7B;IAEA;;;;;;;;;;;;;;;;;;;;;;;;;IAyBG;AACU,UAAA,uBAAuB,GAAG,CAAC,EAAE,UAAU,EAAE,OAAO,EAAiC,KAA2B;IACvH,IAAA,MAAM,kBAAkB,CAAA;IACtB;;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