@arrai-innovations/reactive-helpers 18.0.0 → 18.0.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 (216) hide show
  1. package/package.json +20 -6
  2. package/types/config/listCrud.d.ts +153 -0
  3. package/types/config/listCrud.d.ts.map +1 -0
  4. package/types/config/objectCrud.d.ts +171 -0
  5. package/types/config/objectCrud.d.ts.map +1 -0
  6. package/types/index.d.ts +37 -0
  7. package/types/index.d.ts.map +1 -0
  8. package/types/tests/unit/config/listCrud.spec.d.ts +2 -0
  9. package/types/tests/unit/config/listCrud.spec.d.ts.map +1 -0
  10. package/types/tests/unit/config/objectCrud.spec.d.ts +2 -0
  11. package/types/tests/unit/config/objectCrud.spec.d.ts.map +1 -0
  12. package/types/tests/unit/crudPromise.d.ts +25 -0
  13. package/types/tests/unit/crudPromise.d.ts.map +1 -0
  14. package/types/tests/unit/expectHelpers.d.ts +2 -0
  15. package/types/tests/unit/expectHelpers.d.ts.map +1 -0
  16. package/types/tests/unit/mockOnUnmounted.d.ts +2 -0
  17. package/types/tests/unit/mockOnUnmounted.d.ts.map +1 -0
  18. package/types/tests/unit/poll.d.ts +2 -0
  19. package/types/tests/unit/poll.d.ts.map +1 -0
  20. package/types/tests/unit/use/cancellableIntent.spec.d.ts +2 -0
  21. package/types/tests/unit/use/cancellableIntent.spec.d.ts.map +1 -0
  22. package/types/tests/unit/use/listCalculated.spec.d.ts +2 -0
  23. package/types/tests/unit/use/listCalculated.spec.d.ts.map +1 -0
  24. package/types/tests/unit/use/listFilter.spec.d.ts +2 -0
  25. package/types/tests/unit/use/listFilter.spec.d.ts.map +1 -0
  26. package/types/tests/unit/use/listInstance.spec.d.ts +2 -0
  27. package/types/tests/unit/use/listInstance.spec.d.ts.map +1 -0
  28. package/types/tests/unit/use/listRelated.spec.d.ts +2 -0
  29. package/types/tests/unit/use/listRelated.spec.d.ts.map +1 -0
  30. package/types/tests/unit/use/listSearch.spec.d.ts +2 -0
  31. package/types/tests/unit/use/listSearch.spec.d.ts.map +1 -0
  32. package/types/tests/unit/use/listSort.spec.d.ts +2 -0
  33. package/types/tests/unit/use/listSort.spec.d.ts.map +1 -0
  34. package/types/tests/unit/use/listSubscription.spec.d.ts +2 -0
  35. package/types/tests/unit/use/listSubscription.spec.d.ts.map +1 -0
  36. package/types/tests/unit/use/loadingError.spec.d.ts +2 -0
  37. package/types/tests/unit/use/loadingError.spec.d.ts.map +1 -0
  38. package/types/tests/unit/use/objectInstance.spec.d.ts +2 -0
  39. package/types/tests/unit/use/objectInstance.spec.d.ts.map +1 -0
  40. package/types/tests/unit/use/objectSubscription.spec.d.ts +2 -0
  41. package/types/tests/unit/use/objectSubscription.spec.d.ts.map +1 -0
  42. package/types/tests/unit/use/proxyLoadingError.spec.d.ts +2 -0
  43. package/types/tests/unit/use/proxyLoadingError.spec.d.ts.map +1 -0
  44. package/types/tests/unit/use/search.spec.d.ts +2 -0
  45. package/types/tests/unit/use/search.spec.d.ts.map +1 -0
  46. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts +2 -0
  47. package/types/tests/unit/utils/assignReactiveObject.spec.d.ts.map +1 -0
  48. package/types/tests/unit/utils/classes.spec.d.ts +2 -0
  49. package/types/tests/unit/utils/classes.spec.d.ts.map +1 -0
  50. package/types/tests/unit/utils/deleteKey.spec.d.ts +2 -0
  51. package/types/tests/unit/utils/deleteKey.spec.d.ts.map +1 -0
  52. package/types/tests/unit/utils/flattenPaths.spec.d.ts +2 -0
  53. package/types/tests/unit/utils/flattenPaths.spec.d.ts.map +1 -0
  54. package/types/tests/unit/utils/keyDiff.spec.d.ts +2 -0
  55. package/types/tests/unit/utils/keyDiff.spec.d.ts.map +1 -0
  56. package/types/tests/unit/utils/set.spec.d.ts +2 -0
  57. package/types/tests/unit/utils/set.spec.d.ts.map +1 -0
  58. package/types/tests/unit/utils/watches.spec.d.ts +2 -0
  59. package/types/tests/unit/utils/watches.spec.d.ts.map +1 -0
  60. package/types/use/cancellableIntent.d.ts +129 -0
  61. package/types/use/cancellableIntent.d.ts.map +1 -0
  62. package/types/use/combineClasses.d.ts +43 -0
  63. package/types/use/combineClasses.d.ts.map +1 -0
  64. package/types/use/list.d.ts +176 -0
  65. package/types/use/list.d.ts.map +1 -0
  66. package/types/use/listCalculated.d.ts +192 -0
  67. package/types/use/listCalculated.d.ts.map +1 -0
  68. package/types/use/listFilter.d.ts +203 -0
  69. package/types/use/listFilter.d.ts.map +1 -0
  70. package/types/use/listInstance.d.ts +357 -0
  71. package/types/use/listInstance.d.ts.map +1 -0
  72. package/types/use/listKeys.d.ts +15 -0
  73. package/types/use/listKeys.d.ts.map +1 -0
  74. package/types/use/listRelated.d.ts +239 -0
  75. package/types/use/listRelated.d.ts.map +1 -0
  76. package/types/use/listSearch.d.ts +298 -0
  77. package/types/use/listSearch.d.ts.map +1 -0
  78. package/types/use/listSort.d.ts +235 -0
  79. package/types/use/listSort.d.ts.map +1 -0
  80. package/types/use/listSubscription.d.ts +218 -0
  81. package/types/use/listSubscription.d.ts.map +1 -0
  82. package/types/use/loadingError.d.ts +81 -0
  83. package/types/use/loadingError.d.ts.map +1 -0
  84. package/types/use/object.d.ts +67 -0
  85. package/types/use/object.d.ts.map +1 -0
  86. package/types/use/objectCalculated.d.ts +215 -0
  87. package/types/use/objectCalculated.d.ts.map +1 -0
  88. package/types/use/objectInstance.d.ts +289 -0
  89. package/types/use/objectInstance.d.ts.map +1 -0
  90. package/types/use/objectRelated.d.ts +264 -0
  91. package/types/use/objectRelated.d.ts.map +1 -0
  92. package/types/use/objectSubscription.d.ts +249 -0
  93. package/types/use/objectSubscription.d.ts.map +1 -0
  94. package/types/use/paginatedListInstance.d.ts +51 -0
  95. package/types/use/paginatedListInstance.d.ts.map +1 -0
  96. package/types/use/proxyLoadingError.d.ts +36 -0
  97. package/types/use/proxyLoadingError.d.ts.map +1 -0
  98. package/types/use/search.d.ts +144 -0
  99. package/types/use/search.d.ts.map +1 -0
  100. package/types/use/watchesRunning.d.ts +63 -0
  101. package/types/use/watchesRunning.d.ts.map +1 -0
  102. package/types/utils/assignReactiveObject.d.ts +115 -0
  103. package/types/utils/assignReactiveObject.d.ts.map +1 -0
  104. package/types/utils/classes.d.ts +22 -0
  105. package/types/utils/classes.d.ts.map +1 -0
  106. package/types/utils/compact.d.ts +4 -0
  107. package/types/utils/compact.d.ts.map +1 -0
  108. package/types/utils/deleteKey.d.ts +16 -0
  109. package/types/utils/deleteKey.d.ts.map +1 -0
  110. package/types/utils/flattenPaths.d.ts +23 -0
  111. package/types/utils/flattenPaths.d.ts.map +1 -0
  112. package/types/utils/getFakePk.d.ts +13 -0
  113. package/types/utils/getFakePk.d.ts.map +1 -0
  114. package/types/utils/keepAliveTry.d.ts +15 -0
  115. package/types/utils/keepAliveTry.d.ts.map +1 -0
  116. package/types/utils/keyDiff.d.ts +63 -0
  117. package/types/utils/keyDiff.d.ts.map +1 -0
  118. package/types/utils/loadingCombine.d.ts +9 -0
  119. package/types/utils/loadingCombine.d.ts.map +1 -0
  120. package/types/utils/proxyRunning.d.ts +9 -0
  121. package/types/utils/proxyRunning.d.ts.map +1 -0
  122. package/types/utils/relatedCalculatedHelpers.d.ts +5 -0
  123. package/types/utils/relatedCalculatedHelpers.d.ts.map +1 -0
  124. package/types/utils/set.d.ts +7 -0
  125. package/types/utils/set.d.ts.map +1 -0
  126. package/types/utils/transformWalk.d.ts +2 -0
  127. package/types/utils/transformWalk.d.ts.map +1 -0
  128. package/types/utils/watches.d.ts +155 -0
  129. package/types/utils/watches.d.ts.map +1 -0
  130. package/use/loadingError.js +1 -1
  131. package/.circleci/config.yml +0 -88
  132. package/.commitlintrc.json +0 -25
  133. package/.editorconfig +0 -5
  134. package/.husky/commit-msg +0 -3
  135. package/.husky/pre-commit +0 -3
  136. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  137. package/.idea/encodings.xml +0 -6
  138. package/.idea/inspectionProfiles/Project_Default.xml +0 -7
  139. package/.idea/modules.xml +0 -8
  140. package/.idea/prettier.xml +0 -8
  141. package/.idea/reactive-helpers.iml +0 -15
  142. package/.prettierignore +0 -5
  143. package/.prettierrc.cjs +0 -5
  144. package/.vscode/extensions.json +0 -3
  145. package/docs/README.md +0 -45
  146. package/docs/config/listCrud.md +0 -422
  147. package/docs/config/objectCrud.md +0 -427
  148. package/docs/use/cancellableIntent.md +0 -165
  149. package/docs/use/combineClasses.md +0 -62
  150. package/docs/use/list.md +0 -361
  151. package/docs/use/listCalculated.md +0 -794
  152. package/docs/use/listFilter.md +0 -897
  153. package/docs/use/listInstance.md +0 -559
  154. package/docs/use/listKeys.md +0 -91
  155. package/docs/use/listRelated.md +0 -706
  156. package/docs/use/listSearch.md +0 -903
  157. package/docs/use/listSort.md +0 -1171
  158. package/docs/use/listSubscription.md +0 -393
  159. package/docs/use/loadingError.md +0 -115
  160. package/docs/use/object.md +0 -668
  161. package/docs/use/objectCalculated.md +0 -741
  162. package/docs/use/objectInstance.md +0 -685
  163. package/docs/use/objectRelated.md +0 -723
  164. package/docs/use/objectSubscription.md +0 -538
  165. package/docs/use/paginatedListInstance.md +0 -155
  166. package/docs/use/proxyLoadingError.md +0 -51
  167. package/docs/use/search.md +0 -321
  168. package/docs/use/watchesRunning.md +0 -84
  169. package/docs/utils/assignReactiveObject.md +0 -413
  170. package/docs/utils/classes.md +0 -139
  171. package/docs/utils/compact.md +0 -67
  172. package/docs/utils/deleteKey.md +0 -61
  173. package/docs/utils/flattenPaths.md +0 -53
  174. package/docs/utils/getFakePk.md +0 -39
  175. package/docs/utils/keepAliveTry.md +0 -59
  176. package/docs/utils/keyDiff.md +0 -117
  177. package/docs/utils/loadingCombine.md +0 -30
  178. package/docs/utils/proxyRunning.md +0 -39
  179. package/docs/utils/relatedCalculatedHelpers.md +0 -93
  180. package/docs/utils/set.md +0 -223
  181. package/docs/utils/transformWalk.md +0 -68
  182. package/docs/utils/watches.md +0 -489
  183. package/eslint.config.js +0 -125
  184. package/lint-staged.config.js +0 -10
  185. package/makeTypeDoc.sh +0 -25
  186. package/make_type_doc.js +0 -59
  187. package/tests/unit/config/listCrud.spec.js +0 -114
  188. package/tests/unit/config/objectCrud.spec.js +0 -160
  189. package/tests/unit/crudPromise.js +0 -40
  190. package/tests/unit/expectHelpers.js +0 -6
  191. package/tests/unit/mockOnUnmounted.js +0 -9
  192. package/tests/unit/poll.js +0 -50
  193. package/tests/unit/use/cancellableIntent.spec.js +0 -152
  194. package/tests/unit/use/listCalculated.spec.js +0 -135
  195. package/tests/unit/use/listFilter.spec.js +0 -484
  196. package/tests/unit/use/listInstance.spec.js +0 -1166
  197. package/tests/unit/use/listRelated.spec.js +0 -260
  198. package/tests/unit/use/listSearch.spec.js +0 -586
  199. package/tests/unit/use/listSort.spec.js +0 -418
  200. package/tests/unit/use/listSubscription.spec.js +0 -845
  201. package/tests/unit/use/loadingError.spec.js +0 -43
  202. package/tests/unit/use/objectInstance.spec.js +0 -1525
  203. package/tests/unit/use/objectSubscription.spec.js +0 -849
  204. package/tests/unit/use/proxyLoadingError.spec.js +0 -64
  205. package/tests/unit/use/search.spec.js +0 -248
  206. package/tests/unit/utils/assignReactiveObject.spec.js +0 -593
  207. package/tests/unit/utils/classes.spec.js +0 -427
  208. package/tests/unit/utils/deleteKey.spec.js +0 -265
  209. package/tests/unit/utils/flattenPaths.spec.js +0 -126
  210. package/tests/unit/utils/keyDiff.spec.js +0 -110
  211. package/tests/unit/utils/set.spec.js +0 -81
  212. package/tests/unit/utils/watches.spec.js +0 -276
  213. package/tsconfig.json +0 -19
  214. package/typedoc-local-plugins/customize-output.js +0 -13
  215. package/typedoc.json +0 -11
  216. package/vitest.config.js +0 -11
@@ -1,427 +0,0 @@
1
- import { combineClasses, objectifyClasses, stringifyClass, stringifyClasses } from "../../../utils/classes.js";
2
- import { describe, expect, it } from "vitest";
3
- import { computed, reactive, ref, shallowRef } from "vue";
4
-
5
- describe("utils/classes.js", () => {
6
- describe("objectifyClasses", () => {
7
- it("should objectify a mix of undefined, strings, arrays and objects", () => {
8
- const actual = objectifyClasses("test test5", undefined, ["test2", "test3"], { test4: true, test5: false });
9
- const expected = {
10
- test: true,
11
- test2: true,
12
- test3: true,
13
- test4: true,
14
- test5: false,
15
- };
16
- expect(actual).toStrictEqual(expected);
17
- });
18
- it("should stringify classes reactively when inputs change", () => {
19
- const classRef = ref("initial-class");
20
- const classObj = reactive({ classA: true, classB: false });
21
- const classArray = ref(["array-class1", "array-class2"]);
22
-
23
- const computedResult = computed(() => stringifyClasses(classRef, classObj, classArray));
24
-
25
- expect(computedResult.value).toBe("initial-class classA array-class1 array-class2");
26
-
27
- classRef.value = "updated-class";
28
- classObj.classB = true;
29
- classArray.value.push("array-class3");
30
-
31
- expect(computedResult.value).toBe("updated-class classA classB array-class1 array-class2 array-class3");
32
- });
33
- it("should preserve refs in the output when necessary", () => {
34
- const trueRef = ref(true);
35
- const falseRef = ref(false);
36
- const result = objectifyClasses({ classA: trueRef, classB: falseRef });
37
-
38
- expect(result.classA).toBe(true);
39
- expect(result.classB).toBe(false);
40
- });
41
- it("should flatten objects and arrays into a single object", () => {
42
- const actual = objectifyClasses("test", ["test2", "test3"], { test4: true, test5: false }, [
43
- ["test6", "test7"],
44
- { test8: true, test9: false },
45
- undefined,
46
- "test10",
47
- ]);
48
- const expected = {
49
- test: true,
50
- test2: true,
51
- test3: true,
52
- test4: true,
53
- test5: false,
54
- test6: true,
55
- test7: true,
56
- test8: true,
57
- test9: false,
58
- test10: true,
59
- };
60
- expect(actual).toStrictEqual(expected);
61
- });
62
- it("should flatten objects and arrays into a single object reactively", () => {
63
- const reactiveStructure = reactive({
64
- classA: ref(true),
65
- nested: {
66
- classB: ref(false),
67
- nestedAgain: {
68
- classC: ref(true),
69
- },
70
- },
71
- });
72
- const result = computed(() => objectifyClasses(reactiveStructure));
73
- const expected = {
74
- classA: true,
75
- classB: false,
76
- classC: true,
77
- };
78
- expect(result.value).toStrictEqual(expected);
79
-
80
- reactiveStructure.nested.classB = true;
81
- reactiveStructure.nested.nestedAgain.classC = false;
82
- expect(result.value).toStrictEqual({
83
- classA: true,
84
- classB: true,
85
- classC: false,
86
- });
87
- });
88
- it("should handle negation of individual classes in a compound key", () => {
89
- const actual = objectifyClasses({
90
- "classA classB": true,
91
- classC: false,
92
- });
93
- const expected = {
94
- classA: true,
95
- classB: true,
96
- classC: false,
97
- };
98
- expect(actual).toStrictEqual(expected);
99
- });
100
- });
101
- describe("combineClasses", () => {
102
- it("should combine all strings", () => {
103
- const actual = combineClasses("test", "test2");
104
- const expected = "test test2";
105
- expect(actual).toBe(expected);
106
- });
107
- it("should combine all arrays of strings", () => {
108
- const actual = combineClasses(["test", "test2"], [["test3", "test4"]]);
109
- const expected = "test test2 test3 test4";
110
- expect(actual).toBe(expected);
111
- });
112
- it("should combine all objects", () => {
113
- const actual = combineClasses({ test: true, test2: true }, { test2: false, test3: true, test4: false });
114
- const expected = {
115
- test: true,
116
- test2: false,
117
- test3: true,
118
- test4: false,
119
- };
120
- expect(actual).toStrictEqual(expected);
121
- });
122
- it("should combine all objects, with a value adding a class and a following value negating that class using a false value", () => {
123
- const actual = combineClasses({ test: true, test2: true }, { test2: false, test3: true, test4: false });
124
- const expected = {
125
- test: true,
126
- test2: false,
127
- test3: true,
128
- test4: false,
129
- };
130
- expect(actual).toStrictEqual(expected);
131
- });
132
-
133
- it("should combine all objects reactively, with a value adding a class and a following value negating that class using a false value", () => {
134
- const classObj = reactive({ test: true, test2: true });
135
- const negatingObj = reactive({ test2: false, test3: true, test4: false });
136
-
137
- const computedResult = computed(() => {
138
- console.log("running computed, with changes:", classObj, negatingObj);
139
- return combineClasses(classObj, negatingObj);
140
- });
141
-
142
- expect(computedResult.value).toStrictEqual({
143
- test: true,
144
- test2: false,
145
- test3: true,
146
- test4: false,
147
- });
148
-
149
- classObj.test2 = false;
150
- negatingObj.test3 = false;
151
- expect(computedResult.value).toStrictEqual({
152
- test: true,
153
- test2: false,
154
- test3: false,
155
- test4: false,
156
- });
157
- });
158
- it("should combine deep mixes of undefined, strings, arrays and objects", () => {
159
- const actual = combineClasses("test test5", undefined, ["test2", "test3"], { test4: true, test5: false }, [
160
- ["test6", "test7"],
161
- { test8: true, test9: false },
162
- undefined,
163
- "test10",
164
- ]);
165
- const expected = {
166
- test: true,
167
- test2: true,
168
- test3: true,
169
- test4: true,
170
- test5: false,
171
- test6: true,
172
- test7: true,
173
- test8: true,
174
- test9: false,
175
- test10: true,
176
- };
177
- expect(actual).toStrictEqual(expected);
178
- });
179
- it("should combine deep mixes of undefined, strings, arrays, objects with refs and refs to strings, arrays & objects", () => {
180
- const falseRef = ref(false);
181
- const trueRef = ref(true);
182
- const stringRef = ref("test");
183
- const arrayRef = ref(["test2", "test3"]);
184
- // refs to objects are turned reactive by Vue before becoming the value of the ref
185
- // so nested refs are unref'd as if passed to reactive()
186
- const objectRef = ref({ test4: trueRef, test5: falseRef });
187
- const actual = combineClasses("test test4 test5", undefined, arrayRef, objectRef, [
188
- ["test6", "test7"],
189
- { test8: trueRef, test9: falseRef },
190
- undefined,
191
- stringRef,
192
- ]);
193
- const expected = {
194
- test: true,
195
- test2: true,
196
- test3: true,
197
- test4: true,
198
- test5: false,
199
- test6: true,
200
- test7: true,
201
- test8: true,
202
- test9: false,
203
- };
204
- expect(actual).toStrictEqual(expected);
205
- });
206
- it("should reactively update when ref inputs change", () => {
207
- const classRef = ref("initial-class");
208
-
209
- const computedResult = computed(() => combineClasses(classRef));
210
-
211
- expect(computedResult.value).toBe("initial-class");
212
-
213
- classRef.value = "updated-class";
214
- expect(computedResult.value).toBe("updated-class");
215
- });
216
- it("should reactively update when reactive object inputs change", () => {
217
- const classObj = reactive({ classA: true, classB: false });
218
-
219
- const computedResult = computed(() => combineClasses(classObj));
220
-
221
- expect(computedResult.value).toStrictEqual({
222
- classA: true,
223
- classB: false,
224
- });
225
-
226
- classObj.classB = true;
227
- classObj.classA = false;
228
-
229
- expect(computedResult.value).toStrictEqual({
230
- classA: false,
231
- classB: true,
232
- });
233
- });
234
- it("should handle nested reactive structures", () => {
235
- const nestedReactive = reactive({
236
- classA: ref(true),
237
- nested: {
238
- classB: ref(false),
239
- nestedAgain: {
240
- classC: ref(true),
241
- },
242
- },
243
- });
244
-
245
- const computedResult = computed(() => combineClasses(nestedReactive));
246
-
247
- expect(computedResult.value).toStrictEqual({
248
- classA: true,
249
- classB: false,
250
- classC: true,
251
- });
252
-
253
- nestedReactive.nested.classB = true;
254
- nestedReactive.nested.nestedAgain.classC = false;
255
-
256
- expect(computedResult.value).toStrictEqual({
257
- classA: true,
258
- classB: true,
259
- classC: false,
260
- });
261
- });
262
- it("should handle computed properties as inputs", () => {
263
- const baseClass = ref("base");
264
- const isActive = ref(true);
265
- const dynamicClass = computed(() => (isActive.value ? "active" : "inactive"));
266
-
267
- const computedResult = computed(() => combineClasses(baseClass, dynamicClass));
268
-
269
- expect(computedResult.value).toBe("base active");
270
-
271
- isActive.value = false;
272
-
273
- expect(computedResult.value).toBe("base inactive");
274
- });
275
- it("should handle shallowRef inputs correctly", () => {
276
- const shallowClassRef = shallowRef({ classA: true, classB: false });
277
-
278
- const computedResult = computed(() => combineClasses(shallowClassRef));
279
-
280
- expect(computedResult.value).toStrictEqual({
281
- classA: true,
282
- classB: false,
283
- });
284
-
285
- shallowClassRef.value.classB = true;
286
- expect(computedResult.value).toStrictEqual({
287
- classA: true,
288
- classB: false, // shallowRef does not react to nested changes
289
- });
290
-
291
- shallowClassRef.value = {
292
- classA: false,
293
- classB: true,
294
- };
295
- expect(computedResult.value).toStrictEqual({
296
- classA: false,
297
- classB: true,
298
- });
299
- });
300
- it("should unwrap nested refs correctly", () => {
301
- const nestedRefs = {
302
- classA: ref(true),
303
- nested: {
304
- classB: ref(false),
305
- nestedAgain: {
306
- classC: ref(true),
307
- },
308
- },
309
- };
310
-
311
- const result = combineClasses(nestedRefs);
312
-
313
- expect(result).toStrictEqual({
314
- classA: true,
315
- classB: false,
316
- classC: true,
317
- });
318
- });
319
- });
320
- describe("stringifyClass", () => {
321
- it("should stringify a string", () => {
322
- const actual = stringifyClass("test");
323
- const expected = "test";
324
- expect(actual).toBe(expected);
325
- });
326
- it("should stringify an array", () => {
327
- const actual = stringifyClass(["test", "test2"]);
328
- const expected = "test test2";
329
- expect(actual).toBe(expected);
330
- });
331
- it("should stringify an object", () => {
332
- const actual = stringifyClass({ test: true, test2: false });
333
- const expected = "test";
334
- expect(actual).toBe(expected);
335
- });
336
- it("should let undefined pass through", () => {
337
- const actual = stringifyClass(undefined);
338
- const expected = undefined;
339
- expect(actual).toBe(expected);
340
- });
341
- it("should handle reactive inputs becoming undefined or null", () => {
342
- const classRef = ref("initial-class");
343
- const result = ref();
344
-
345
- const computedResult = computed(() => {
346
- result.value = stringifyClass(classRef);
347
- });
348
-
349
- computedResult.value;
350
- expect(result.value).toBe("initial-class");
351
-
352
- classRef.value = undefined;
353
- computedResult.value;
354
- expect(result.value).toBe(undefined);
355
-
356
- classRef.value = null;
357
- computedResult.value;
358
- expect(result.value).toBe(null);
359
-
360
- classRef.value = "new-class";
361
- computedResult.value;
362
- expect(result.value).toBe("new-class");
363
- });
364
- });
365
- describe("stringifyClasses", () => {
366
- it("should stringify a mix of undefined, strings, arrays and objects", () => {
367
- const actual = stringifyClasses("test test5", undefined, ["test2", "test3"], { test4: true, test5: false });
368
- const expected = "test test5 test2 test3 test4";
369
- expect(actual).toBe(expected);
370
- });
371
- it("should stringify classes reactively when inputs change", () => {
372
- const classRef = ref("initial-class");
373
- const classObj = reactive({ classA: true, classB: false });
374
- const classArray = ref(["array-class1", "array-class2"]);
375
-
376
- const result = ref();
377
-
378
- const computedResult = computed(() => {
379
- result.value = stringifyClasses(classRef, classObj, classArray);
380
- });
381
-
382
- computedResult.value;
383
- expect(result.value).toBe("initial-class classA array-class1 array-class2");
384
-
385
- classRef.value = "updated-class";
386
- classObj.classB = true;
387
- classArray.value.push("array-class3");
388
-
389
- computedResult.value;
390
- expect(result.value).toBe("updated-class classA classB array-class1 array-class2 array-class3");
391
- });
392
- it("should handle reactive arrays containing refs", () => {
393
- const classArray = reactive([ref("class1"), ref("class2")]);
394
- const result = ref();
395
-
396
- const computedResult = computed(() => {
397
- result.value = stringifyClasses(classArray);
398
- });
399
-
400
- computedResult.value;
401
- expect(result.value).toBe("class1 class2");
402
-
403
- classArray[0].value = "updated-class1";
404
- classArray.push(ref("class3"));
405
- computedResult.value;
406
- expect(result.value).toBe("updated-class1 class2 class3");
407
- });
408
- it("should work correctly within a component-like setup", () => {
409
- const props = reactive({
410
- baseClass: "button",
411
- isActive: ref(true),
412
- });
413
-
414
- const className = computed(() => {
415
- return stringifyClasses(props.baseClass, { active: props.isActive });
416
- });
417
-
418
- expect(className.value).toBe("button active");
419
-
420
- props.isActive = false;
421
- expect(className.value).toBe("button");
422
-
423
- props.baseClass = "link";
424
- expect(className.value).toBe("link");
425
- });
426
- });
427
- });
@@ -1,265 +0,0 @@
1
- import { del, lodashLikePathSplit } from "../../../utils/deleteKey.js";
2
-
3
- describe("utils/deleteKey.js", () => {
4
- describe("pathSplitRegex", () => {
5
- const tests = [
6
- {
7
- path: "",
8
- expected: [""],
9
- obj: {},
10
- },
11
- {
12
- path: "a",
13
- expected: ["a"],
14
- obj: { a: 1 },
15
- },
16
- {
17
- path: "a.",
18
- expected: ["a", ""],
19
- obj: { a: 1 },
20
- },
21
- {
22
- path: "a.b.c",
23
- expected: ["a", "b", "c"],
24
- obj: { a: { b: { c: 1 } } },
25
- },
26
- {
27
- path: "a[b[c]]",
28
- expected: ["a", "b", "c"],
29
- obj: { a: { b: { c: 1 } } },
30
- },
31
- {
32
- path: "a.b.",
33
- expected: ["a", "b", ""],
34
- obj: { a: { b: { c: 1 } } },
35
- },
36
- {
37
- path: "a[b[1]]",
38
- expected: ["a", "b", "1"],
39
- obj: { a: { b: [1, 2, 3] } },
40
- },
41
- {
42
- path: "a[b[1].c]",
43
- expected: ["a", "b", "1", "c"],
44
- obj: { a: { b: [{ c: 1 }, { c: 2 }, { c: 3 }] } },
45
- },
46
- {
47
- path: "a[1]",
48
- expected: ["a", "1"],
49
- obj: { a: [1, 2, 3] },
50
- },
51
- {
52
- path: "a[1].b",
53
- expected: ["a", "1", "b"],
54
- obj: { a: [{ b: 1 }, { b: 2 }, { b: 3 }] },
55
- },
56
- {
57
- path: "a[1].b[1]",
58
- expected: ["a", "1", "b", "1"],
59
- obj: { a: [{ b: [1, 2, 3] }, { b: [4, 5, 6] }, { b: [7, 8, 9] }] },
60
- },
61
- {
62
- path: "a[1].",
63
- expected: ["a", "1", ""],
64
- obj: { a: [{}, {}, {}] },
65
- },
66
- {
67
- path: "a[1].b[1].",
68
- expected: ["a", "1", "b", "1", ""],
69
- obj: { a: [{ b: [1, {}, 3] }, { b: [4, {}, 6] }, { b: [7, {}, 9] }] },
70
- },
71
- {
72
- path: "a[1].c",
73
- expected: ["a", "1", "c"],
74
- obj: { a: [{ b: [1, 2, 3] }, { b: [4, 5, 6] }, { c: [7, 8, 9] }] },
75
- },
76
- {
77
- path: "c[",
78
- expected: ["c["],
79
- obj: { "c[": 1 },
80
- },
81
- {
82
- path: "c[1",
83
- expected: ["c[1"],
84
- obj: { "c[1": 1 },
85
- },
86
- {
87
- path: "c]",
88
- expected: ["c]"],
89
- obj: { "c]": 1 },
90
- },
91
- {
92
- path: "c1]",
93
- expected: ["c1]"],
94
- obj: { "c1]": 1 },
95
- },
96
- {
97
- path: "$property",
98
- expected: ["$property"],
99
- obj: { $property: 1 },
100
- },
101
- {
102
- path: "~path",
103
- expected: ["~path"],
104
- obj: { "~path": 1 },
105
- },
106
- {
107
- path: "name_with_special$characters",
108
- expected: ["name_with_special$characters"],
109
- obj: { name_with_special$characters: 1 },
110
- },
111
- {
112
- path: "a[1][1]",
113
- expected: ["a", "1", "1"],
114
- obj: [{ a: [1, 2, 3] }, { a: [4, 5, 6] }, { a: [7, 8, 9] }],
115
- },
116
- {
117
- path: "b[[1]]",
118
- expected: ["b", "1"],
119
- obj: [{ b: [1, 2, 3] }, { b: [4, 5, 6] }, { b: [7, 8, 9] }],
120
- },
121
- {
122
- path: "c[1][",
123
- expected: ["c", "1"],
124
- obj: {
125
- c: [{}, { "[": 1 }, {}],
126
- },
127
- },
128
- {
129
- path: "c[1][",
130
- expected: ["c[1]["],
131
- obj: {
132
- "c[1][": 1,
133
- },
134
- },
135
- {
136
- path: "c[[2]",
137
- expected: ["c", "2"],
138
- obj: {
139
- c: [1, 2, 3],
140
- },
141
- },
142
- {
143
- path: "c[1][.f[3]",
144
- expected: ["c", "1", "f", "3"],
145
- obj: {
146
- c: [{}, { f: [1, 2, 3, 4] }],
147
- },
148
- },
149
- {
150
- path: "c[1][.f[3]",
151
- expected: ["c[1][.f[3]"],
152
- obj: {
153
- "c[1][.f[3]": 1,
154
- },
155
- },
156
- {
157
- path: "[1][1]",
158
- expected: ["1", "1"],
159
- obj: [
160
- [1, 2, 3],
161
- [4, 5, 6],
162
- [7, 8, 9],
163
- ],
164
- },
165
- ];
166
- for (let i = 0; i < tests.length; i++) {
167
- it(`should split ${tests[i].path}`, () => {
168
- const path = tests[i].path;
169
- const expected = tests[i].expected;
170
- const obj = tests[i].obj;
171
- const actual = lodashLikePathSplit(path, obj);
172
- expect(actual, `Failed on path ${path} for obj ${JSON.stringify(obj)}`).toEqual(expected);
173
- });
174
- }
175
- });
176
- describe("del", () => {
177
- describe("Basic Cases", () => {
178
- it("should delete a key from an object", () => {
179
- const obj = { a: 1, b: 2 };
180
- del(obj, "a");
181
- expect(obj).toEqual({ b: 2 });
182
- });
183
- it("should delete a deep key from an object", () => {
184
- const obj = { a: { b: { c: 1 } } };
185
- del(obj, "a.b.c");
186
- expect(obj).toEqual({ a: { b: {} } });
187
- });
188
- it("should delete an index from an array", () => {
189
- const obj = { a: [1, 2, 3] };
190
- del(obj, "a[1]");
191
- expect(obj).toEqual({ a: [1, undefined, 3] });
192
- });
193
- it("should delete a deep index from an array", () => {
194
- const obj = { a: [{ b: 1 }, { b: 2 }, { b: 3 }] };
195
- del(obj, "a[1].b");
196
- expect(obj).toEqual({ a: [{ b: 1 }, {}, { b: 3 }] });
197
- });
198
- it("should delete a deep index from a key with multiple indexes", () => {
199
- const obj = { a: [{ b: [1, 2, 3] }, { b: [4, 5, 6] }, { b: [7, 8, 9] }] };
200
- del(obj, "a[1].b[1]");
201
- expect(obj).toEqual({ a: [{ b: [1, 2, 3] }, { b: [4, undefined, 6] }, { b: [7, 8, 9] }] });
202
- });
203
- });
204
- describe("Edge Cases", () => {
205
- it("should handle deleting a non-existent key", () => {
206
- const obj = { a: 1, b: 2 };
207
- del(obj, "c");
208
- expect(obj).toEqual({ a: 1, b: 2 });
209
- });
210
- it("should handled deleting a key in a non-existent object", () => {
211
- const obj = { a: 1, b: 2 };
212
- del(obj, "c.d");
213
- expect(obj).toEqual({ a: 1, b: 2 });
214
- });
215
- it("should handle deleting an index in a non-existent array", () => {
216
- const obj = { a: 1, b: 2 };
217
- del(obj, "c[0]");
218
- expect(obj).toEqual({ a: 1, b: 2 });
219
- });
220
- it("should handle deleting a non-existent index in an array", () => {
221
- const obj = { a: [1, 2, 3] };
222
- del(obj, "a[3]");
223
- expect(obj).toEqual({ a: [1, 2, 3] });
224
- });
225
- it("should handle deleting a non-existent index in a deep array", () => {
226
- const obj = { a: [{ b: [1, 2, 3] }, { b: [4, 5, 6] }, { b: [7, 8, 9] }] };
227
- del(obj, "a[1].b[3]");
228
- expect(obj).toEqual({ a: [{ b: [1, 2, 3] }, { b: [4, 5, 6] }, { b: [7, 8, 9] }] });
229
- });
230
- it("should handled unpaired brackets as a key", () => {
231
- const obj = { a: 1, b: 2, "c[": 3 };
232
- del(obj, "c[");
233
- expect(obj).toEqual({ a: 1, b: 2 });
234
- });
235
- it("should handle deleting a key with a trailing dot", () => {
236
- const obj = { a: 1, b: 2 };
237
- del(obj, "a.");
238
- expect(obj).toEqual({ a: 1, b: 2 });
239
- });
240
- it("should handle deleting a key with a trailing dot in a deep object", () => {
241
- const obj = { a: { b: { c: 1 } } };
242
- del(obj, "a.b.");
243
- expect(obj).toEqual({ a: { b: { c: 1 } } });
244
- });
245
- it("should handle an array as the root object", () => {
246
- const obj = [1, 2, 3];
247
- del(obj, "[1]");
248
- expect(obj).toEqual([1, undefined, 3]);
249
- });
250
- it("should handle nested arrays as the root object", () => {
251
- const obj = [
252
- [1, 2, 3],
253
- [4, 5, 6],
254
- [7, 8, 9],
255
- ];
256
- del(obj, "[1][1]");
257
- expect(obj).toEqual([
258
- [1, 2, 3],
259
- [4, undefined, 6],
260
- [7, 8, 9],
261
- ]);
262
- });
263
- });
264
- });
265
- });