@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,586 +0,0 @@
1
- import { doAwaitNot, doAwaitTimeout } from "../../../utils/watches.js";
2
- import { nextTick, reactive, ref, unref } from "vue";
3
- import { deepUnref } from "vue-deepunref";
4
-
5
- describe("use/listSearch", () => {
6
- let useListInstance, useListSearch, useListSearches, useListSort, useListRelated, useListCalculated, useListFilter;
7
- beforeEach(async () => {
8
- const listInstanceModule = await import("../../../use/listInstance.js");
9
- useListInstance = listInstanceModule.useListInstance;
10
- const listSearchModule = await import("../../../use/listSearch.js");
11
- useListSearch = listSearchModule.useListSearch;
12
- useListSearches = listSearchModule.useListSearches;
13
- const listSortModule = await import("../../../use/listSort.js");
14
- useListSort = listSortModule.useListSort;
15
- const listRelatedModule = await import("../../../use/listRelated.js");
16
- useListRelated = listRelatedModule.useListRelated;
17
- const listCalculatedModule = await import("../../../use/listCalculated.js");
18
- useListCalculated = listCalculatedModule.useListCalculated;
19
- const listFilterModule = await import("../../../use/listFilter.js");
20
- useListFilter = listFilterModule.useListFilter;
21
- });
22
- it("should match by search term", async () => {
23
- const textSearchValue = ref("one");
24
- // const textSearchValue = ref("");
25
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
26
- const search = useListSearch({
27
- parentState: list.state,
28
- props: reactive({
29
- textSearchRules: ["name"],
30
- textSearchValue,
31
- }),
32
- throttle: 20,
33
- });
34
- await doAwaitNot({
35
- obj: search.state,
36
- prop: "running",
37
- });
38
- expect(search.state.objects).toEqual({});
39
- list.addListObject({ id: 1, name: "one", has_things: true });
40
- await doAwaitNot({
41
- obj: search.state,
42
- prop: "running",
43
- });
44
- await doAwaitTimeout(100);
45
- expect(search.state.objects).toEqual({
46
- 1: { id: 1, name: "one", has_things: true },
47
- });
48
- list.addListObject({ id: 2, name: "two", has_things: true });
49
- await doAwaitNot({
50
- obj: search.state,
51
- prop: "running",
52
- });
53
- expect(search.state.objects).toEqual({
54
- 1: { id: 1, name: "one", has_things: true },
55
- });
56
- list.addListObject({ id: 3, name: "three", has_things: true });
57
- await doAwaitNot({
58
- obj: search.state,
59
- prop: "running",
60
- });
61
- expect(search.state.objects).toEqual({
62
- 1: { id: 1, name: "one", has_things: true },
63
- });
64
- textSearchValue.value = "three";
65
- await doAwaitNot({
66
- obj: search.state,
67
- prop: "running",
68
- });
69
- expect(search.state.objects).toEqual({
70
- 3: { id: 3, name: "three", has_things: true },
71
- });
72
- list.addListObject({ id: 4, name: "four", has_things: true });
73
- await doAwaitNot({
74
- obj: search.state,
75
- prop: "running",
76
- });
77
- expect(search.state.objects).toEqual({
78
- 3: { id: 3, name: "three", has_things: true },
79
- });
80
- });
81
- it("no args: returns objects unsearched", async () => {
82
- const listInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
83
- const listItems = [
84
- { id: 4, name: "four", has_things: true },
85
- { id: 2, name: "two", has_things: true },
86
- { id: 3, name: "three", has_things: true },
87
- { id: 1, name: "one", has_things: true },
88
- ];
89
- for (const item of listItems) {
90
- listInstance.addListObject(item);
91
- }
92
- const search = useListSearch({
93
- parentState: listInstance.state,
94
- throttle: 20,
95
- });
96
- await nextTick();
97
- await nextTick();
98
- await nextTick();
99
- expect(search.state.objects).toEqual(listInstance.state.objects);
100
- });
101
- describe("useListSearch operates on parentState modified by useListSort", () => {
102
- it("computes state.order and state.objects in order", async () => {
103
- vi.resetAllMocks();
104
- const orderByRules = [{ key: "name", desc: true, localeCompare: false }];
105
- const sortThrottleWait = 0;
106
- const listInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
107
- const listItems = [
108
- { id: 4, name: "four", has_things: true },
109
- { id: 2, name: "two", has_things: true },
110
- { id: 3, name: "three", has_things: true },
111
- { id: 1, name: "one", has_things: true },
112
- ];
113
- const expectedOrder = ["2", "3", "1", "4"];
114
- const orderedObjects = [
115
- { id: 2, name: "two", has_things: true },
116
- { id: 3, name: "three", has_things: true },
117
- { id: 1, name: "one", has_things: true },
118
- { id: 4, name: "four", has_things: true },
119
- ];
120
- const listSort = useListSort({ parentState: listInstance.state, orderByRules, sortThrottleWait });
121
- for (const item of listItems) {
122
- listInstance.addListObject(item);
123
- }
124
- const search = useListSearch({
125
- parentState: listSort.state,
126
- throttle: 20,
127
- });
128
- await doAwaitNot({
129
- obj: search.state,
130
- prop: "running",
131
- });
132
- expect(search.state.order).toEqual(expectedOrder);
133
- expect(deepUnref(search.state.objectsInOrder)).toEqual(orderedObjects);
134
- });
135
- });
136
- describe("useListSearches accepts args and parentStates", () => {
137
- it("looks the same as individual useListSearch instances", async () => {
138
- vi.resetAllMocks();
139
- const fields = ["id", "__str__", "name"];
140
- const listInstanceA = useListInstance({
141
- props: {
142
- crudArgs: { stream: "test_streamA" },
143
- pkKey: "id",
144
- listArgs: { user: 1 },
145
- retrieveArgs: {
146
- fields,
147
- },
148
- },
149
- keepOldPages: false,
150
- });
151
- const listInstanceB = useListInstance({
152
- props: {
153
- crudArgs: { stream: "test_streamB" },
154
- pkKey: "id",
155
- listArgs: { user: 2 },
156
- retrieveArgs: {
157
- fields,
158
- },
159
- },
160
- keepOldPages: false,
161
- });
162
-
163
- const textSearchValueMarkerA = { marker: "A" };
164
- const textSearchValueA = ref(textSearchValueMarkerA);
165
- const textSearchValueMarkerB = { marker: "B" };
166
- const textSearchValueB = ref(textSearchValueMarkerB);
167
-
168
- const listSearchA = useListSearch({
169
- parentState: listInstanceA.state,
170
- props: reactive({
171
- textSearchRules: ["name"],
172
- textSearchValue: textSearchValueA,
173
- customSearchOptions: {
174
- limit: 10,
175
- },
176
- customIndexOptions: {
177
- tokenize: "full",
178
- },
179
- }),
180
- throttle: 20,
181
- });
182
- const listSearchB = useListSearch({
183
- parentState: listInstanceB.state,
184
- props: reactive({
185
- textSearchRules: ["code"],
186
- textSearchValue: textSearchValueB,
187
- customSearchOptions: {
188
- limit: 30,
189
- },
190
- customIndexOptions: {
191
- tokenize: "strict",
192
- },
193
- }),
194
- throttle: 40,
195
- });
196
- const listSearchArgs = {
197
- A: {
198
- parentState: listInstanceA.state,
199
- props: reactive({
200
- textSearchRules: ["name"],
201
- textSearchValue: textSearchValueA,
202
- customSearchOptions: {
203
- limit: 10,
204
- },
205
- customIndexOptions: {
206
- tokenize: "full",
207
- },
208
- }),
209
- throttle: 20,
210
- },
211
- B: {
212
- parentState: listInstanceB.state,
213
- props: reactive({
214
- textSearchRules: ["code"],
215
- textSearchValue: textSearchValueB,
216
- customSearchOptions: {
217
- limit: 30,
218
- },
219
- customIndexOptions: {
220
- tokenize: "strict",
221
- },
222
- }),
223
- throttle: 40,
224
- },
225
- };
226
- const listInstances = {
227
- A: listInstanceA,
228
- B: listInstanceB,
229
- };
230
- const listSearches = useListSearches(listSearchArgs);
231
-
232
- expect(unref(listSearches.A.state.textSearchRules)).toEqual(unref(listSearchA.state.textSearchRules));
233
- expect(unref(listSearches.B.state.textSearchRules)).toEqual(unref(listSearchB.state.textSearchRules));
234
- expect(unref(listSearches.A.parentState)).toEqual(unref(listSearchA.parentState));
235
- expect(unref(listSearches.B.parentState)).toEqual(unref(listSearchB.parentState));
236
- expect(deepUnref(listSearches.A.state)).toEqual(deepUnref(listSearchA.state));
237
- expect(deepUnref(listSearches.B.state)).toEqual(deepUnref(listSearchB.state));
238
- expect(deepUnref(listSearches.A.textSearchIndex.state)).toEqual(
239
- deepUnref(listSearchA.textSearchIndex.state)
240
- );
241
- expect(deepUnref(listSearches.B.textSearchIndex.state)).toEqual(
242
- deepUnref(listSearchB.textSearchIndex.state)
243
- );
244
- });
245
- });
246
- describe("useListSearch accepts relatedItem. and calculatedItem. rules", () => {
247
- it("in textSearchRules", async () => {
248
- const textSearchValue = ref("four");
249
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
250
- const relatedList = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
251
- const related = useListRelated({
252
- parentState: list.state,
253
- relatedObjectsRules: {
254
- relatedRuleName: {
255
- objects: relatedList.state.objects,
256
- pkKey: "related_id",
257
- },
258
- },
259
- });
260
- const calculated = useListCalculated({
261
- parentState: related.state,
262
- calculatedObjectsRules: {
263
- calculatedRuleName: (object) => object.id + "calculated",
264
- },
265
- });
266
- const search = useListSearch({
267
- parentState: calculated.state,
268
- props: reactive({
269
- textSearchRules: ["relatedItem.relatedRuleName.name", "calculatedItem.calculatedRuleName"],
270
- textSearchValue,
271
- }),
272
- throttle: 20,
273
- });
274
- await doAwaitNot({
275
- obj: search.state,
276
- prop: "running",
277
- });
278
- expect(search.state.objects).toEqual({});
279
- relatedList.addListObject({ id: 2, name: "two", has_things: false });
280
- list.addListObject({ id: 1, name: "one", has_things: true, related_id: 2 });
281
- relatedList.addListObject({ id: 4, name: "four", has_things: false });
282
- list.addListObject({ id: 3, name: "three", has_things: true, related_id: 4 });
283
- await doAwaitNot({
284
- obj: search.state,
285
- prop: "running",
286
- });
287
-
288
- expect(search.state.objects).toEqual({
289
- 3: { id: 3, name: "three", has_things: true, related_id: 4 },
290
- });
291
- textSearchValue.value = "1calculated";
292
- await doAwaitNot({
293
- obj: search.state,
294
- prop: "running",
295
- });
296
- expect(search.state.objects).toEqual({
297
- 1: { id: 1, name: "one", has_things: true, related_id: 2 },
298
- });
299
- });
300
- });
301
- describe("useListSearch updates index when", () => {
302
- it("parentState.objects is updated", async () => {
303
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
304
- const textSearchValue = ref("");
305
- const search = useListSearch({
306
- parentState: list.state,
307
- props: reactive({
308
- textSearchRules: ["name"],
309
- textSearchValue,
310
- }),
311
- throttle: 20,
312
- });
313
- expect(search.state.objects).toEqual({});
314
- list.addListObject({ id: 1, name: "one" });
315
- list.addListObject({ id: 2, name: "two" });
316
-
317
- await doAwaitNot({
318
- obj: search.state,
319
- prop: "running",
320
- });
321
- expect(search.state.objects).toEqual({
322
- 1: { id: 1, name: "one" },
323
- 2: { id: 2, name: "two" },
324
- });
325
- textSearchValue.value = "one";
326
- await doAwaitNot({
327
- obj: search.state,
328
- prop: "running",
329
- });
330
- await doAwaitTimeout(500);
331
- expect(search.state.objects).toEqual({
332
- 1: { id: 1, name: "one" },
333
- });
334
- list.state.objects[2].name = "one";
335
- await doAwaitNot({
336
- obj: search.state,
337
- prop: "running",
338
- });
339
- expect(search.state.objects).toEqual({
340
- 1: { id: 1, name: "one" },
341
- 2: { id: 2, name: "one" },
342
- });
343
- });
344
- it("parentState.relatedObjects is updated", async () => {
345
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
346
- const relatedList = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
347
- const related = useListRelated({
348
- parentState: list.state,
349
- relatedObjectsRules: reactive({
350
- relatedRuleName: {
351
- objects: relatedList.state.objects,
352
- pkKey: "related_id",
353
- },
354
- }),
355
- });
356
- const textSearchValue = ref("");
357
- const search = useListSearch({
358
- parentState: related.state,
359
- props: reactive({
360
- textSearchRules: ["relatedItem.relatedRuleName.name"],
361
- textSearchValue,
362
- }),
363
- throttle: 20,
364
- });
365
- await nextTick();
366
- expect(search.state.objects).toEqual({});
367
- relatedList.addListObject({ id: 2, name: "two", has_things: false });
368
- list.addListObject({ id: 1, name: "one", has_things: true, related_id: 2 });
369
- relatedList.addListObject({ id: 4, name: "four", has_things: false });
370
- list.addListObject({ id: 3, name: "three", has_things: true, related_id: 4 });
371
- await doAwaitNot({
372
- obj: search.state,
373
- prop: "running",
374
- });
375
- expect(search.state.objects).toEqual({
376
- 1: { id: 1, name: "one", has_things: true, related_id: 2 },
377
- 3: { id: 3, name: "three", has_things: true, related_id: 4 },
378
- });
379
- textSearchValue.value = "four";
380
- await doAwaitNot({
381
- obj: search.state,
382
- prop: "running",
383
- });
384
- expect(search.state.objects).toEqual({
385
- 3: { id: 3, name: "three", has_things: true, related_id: 4 },
386
- });
387
- });
388
- it("parentState.calculatedObjects is updated", async () => {
389
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
390
- const calculated = useListCalculated({
391
- parentState: list.state,
392
- calculatedObjectsRules: reactive({
393
- calculatedRuleName: (object) => object.basis.split("").join("z"),
394
- }),
395
- });
396
- const textSearchValue = ref("");
397
- const search = useListSearch({
398
- parentState: calculated.state,
399
- props: reactive({
400
- textSearchRules: ["calculatedItem.calculatedRuleName"],
401
- textSearchValue,
402
- }),
403
- throttle: 20,
404
- });
405
- await nextTick();
406
- expect(search.state.objects).toEqual({});
407
- list.addListObject({ id: 1, name: "one", basis: "one" });
408
- list.addListObject({ id: 2, name: "two", basis: "two" });
409
- await doAwaitNot({
410
- obj: search.state,
411
- prop: "running",
412
- });
413
- expect(search.state.objects).toEqual({
414
- 1: { id: 1, name: "one", basis: "one" },
415
- 2: { id: 2, name: "two", basis: "two" },
416
- });
417
- textSearchValue.value = "oznze";
418
- await doAwaitNot({
419
- obj: search.state,
420
- prop: "running",
421
- });
422
- expect(search.state.objects).toEqual({
423
- 1: { id: 1, name: "one", basis: "one" },
424
- });
425
- list.state.objects[2].basis = "one";
426
- await doAwaitNot({
427
- obj: search.state,
428
- prop: "running",
429
- });
430
- expect(search.state.objects).toEqual({
431
- 1: { id: 1, name: "one", basis: "one" },
432
- 2: { id: 2, name: "two", basis: "one" },
433
- });
434
- });
435
- it("textSearchRules is updated", async () => {
436
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
437
- const textSearchValue = ref("");
438
- const searchProps = reactive({
439
- textSearchValue,
440
- textSearchRules: ["name"],
441
- });
442
- const search = useListSearch({
443
- parentState: list.state,
444
- props: searchProps,
445
- throttle: 20,
446
- });
447
- await nextTick();
448
- expect(search.state.objects).toEqual({});
449
- list.addListObject({ id: 1, name: "one", code: "eno" });
450
- list.addListObject({ id: 2, name: "two", code: "owt" });
451
- await doAwaitNot({
452
- obj: search.state,
453
- prop: "running",
454
- });
455
- expect(search.state.objects).toEqual({
456
- 1: { id: 1, name: "one", code: "eno" },
457
- 2: { id: 2, name: "two", code: "owt" },
458
- });
459
- textSearchValue.value = "one";
460
- await doAwaitNot({
461
- obj: search.state,
462
- prop: "running",
463
- });
464
- expect(search.state.objects).toEqual({
465
- 1: { id: 1, name: "one", code: "eno" },
466
- });
467
- searchProps.textSearchRules = ["code"];
468
- await doAwaitNot({
469
- obj: search.state,
470
- prop: "running",
471
- });
472
- expect(search.state.objects).toEqual({});
473
- textSearchValue.value = "eno";
474
- await doAwaitNot({
475
- obj: search.state,
476
- prop: "running",
477
- });
478
- expect(search.state.objects).toEqual({
479
- 1: { id: 1, name: "one", code: "eno" },
480
- });
481
- });
482
- });
483
- it("does not pass through when showAllWhenEmpty is false", async () => {
484
- const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
485
- const textSearchValue = ref("");
486
- const search = useListSearch({
487
- parentState: list.state,
488
- props: reactive({
489
- textSearchRules: ["name"],
490
- textSearchValue,
491
- }),
492
- throttle: 20,
493
- showAllWhenEmpty: false,
494
- });
495
- await doAwaitNot({
496
- obj: search.state,
497
- prop: "running",
498
- });
499
- expect(search.state.objects).toEqual({});
500
- list.addListObject({ id: 1, name: "one" });
501
- list.addListObject({ id: 2, name: "two" });
502
- await doAwaitNot({
503
- obj: search.state,
504
- prop: "running",
505
- });
506
- expect(search.state.objects).toEqual({});
507
- textSearchValue.value = "one";
508
- await doAwaitNot({
509
- obj: search.state,
510
- prop: "running",
511
- });
512
- });
513
- it("should update when parentState is filtered in pass through mode.", async () => {
514
- const listInstance = useListInstance({
515
- props: { pkKey: "id" },
516
- keepOldPages: false,
517
- });
518
- const allowedFilter = ref((obj) => !obj.filtered);
519
- const listFilter = useListFilter({
520
- parentState: listInstance.state,
521
- allowedFilter,
522
- });
523
- const textSearchValue = ref("");
524
- const listSearch = useListSearch({
525
- parentState: listFilter.state,
526
- props: reactive({
527
- textSearchRules: ["name"],
528
- textSearchValue,
529
- }),
530
- throttle: 20,
531
- });
532
- await doAwaitNot({
533
- obj: listSearch.state,
534
- prop: "running",
535
- });
536
- expect(listSearch.state.objects).toEqual({});
537
- expect(listSearch.state.order).toEqual([]);
538
- expect(listSearch.state.objectsInOrder).toEqual([]);
539
- listInstance.addListObject({
540
- id: 1,
541
- filtered: false,
542
- });
543
- listInstance.addListObject({
544
- id: 2,
545
- filtered: true,
546
- });
547
- listInstance.addListObject({
548
- id: 3,
549
- filtered: false,
550
- });
551
- await doAwaitNot({
552
- obj: listSearch.state,
553
- prop: "running",
554
- });
555
- expect(listSearch.state.objects).toEqual({
556
- 1: {
557
- id: 1,
558
- filtered: false,
559
- },
560
- 3: {
561
- id: 3,
562
- filtered: false,
563
- },
564
- });
565
- expect(listSearch.state.order).toEqual(["1", "3"]);
566
- expect(listSearch.state.objectsInOrder.map((e) => e.id)).toEqual([1, 3]);
567
- listInstance.state.objects[2].filtered = false;
568
- listInstance.state.objects[1].filtered = true;
569
- await doAwaitNot({
570
- obj: listSearch.state,
571
- prop: "running",
572
- });
573
- expect(listSearch.state.objects).toEqual({
574
- 2: {
575
- id: 2,
576
- filtered: false,
577
- },
578
- 3: {
579
- id: 3,
580
- filtered: false,
581
- },
582
- });
583
- expect(listSearch.state.order).toEqual(["2", "3"]);
584
- expect(listSearch.state.objectsInOrder.map((e) => e.id)).toEqual([2, 3]);
585
- });
586
- });