@arrai-innovations/reactive-helpers 8.0.3 → 8.1.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 (38) hide show
  1. package/{.eslintrc.js → .eslintrc.cjs} +3 -6
  2. package/.jsdoc2md.json +4 -0
  3. package/README.md +12 -1
  4. package/docs.md +350 -0
  5. package/jsdoc-to-markdown.sh +16 -0
  6. package/lint-staged.config.js +10 -0
  7. package/package.json +15 -13
  8. package/tests/unit/.eslintrc.cjs +10 -0
  9. package/tests/unit/crudPromise.js +1 -1
  10. package/tests/unit/mockOnUnmounted.js +2 -2
  11. package/tests/unit/use/cancellableIntent.spec.js +150 -0
  12. package/tests/unit/use/listCalculated.spec.js +6 -8
  13. package/tests/unit/use/listFilter.spec.js +21 -17
  14. package/tests/unit/use/listInstance.spec.js +53 -59
  15. package/tests/unit/use/listRelated.spec.js +7 -8
  16. package/tests/unit/use/listSort.spec.js +29 -19
  17. package/tests/unit/use/listSubscription.spec.js +73 -51
  18. package/tests/unit/use/objectInstance.spec.js +141 -95
  19. package/tests/unit/use/objectSubscription.spec.js +69 -56
  20. package/tests/unit/use/watches.spec.js +17 -17
  21. package/tests/unit/utils/assignReactiveObject.spec.js +1 -1
  22. package/tests/unit/utils/classes.spec.js +136 -0
  23. package/use/combineClasses.js +22 -0
  24. package/use/index.js +17 -16
  25. package/utils/assignReactiveObject.js +56 -41
  26. package/utils/classes.js +107 -0
  27. package/utils/debugMessage.js +23 -13
  28. package/utils/flattenPaths.js +7 -2
  29. package/utils/index.js +2 -0
  30. package/utils/keyDiff.js +27 -19
  31. package/utils/lifecycleDebug.js +10 -1
  32. package/utils/transformWalk.js +7 -3
  33. package/vitest.config.js +11 -0
  34. package/.lintstagedrc +0 -14
  35. package/babel.config.js +0 -15
  36. package/jest.config.mjs +0 -27
  37. package/tests/unit/.eslintrc.js +0 -10
  38. /package/{.prettierrc.js → .prettierrc.cjs} +0 -0
@@ -0,0 +1,150 @@
1
+ import { useCancellableIntent } from "../../../use/index.js";
2
+ import { CancellableResolvable } from "../crudPromise.js";
3
+ import flushPromises from "flush-promises";
4
+ import { nextTick, reactive, ref } from "vue";
5
+
6
+ describe("use/cancellableIntent", () => {
7
+ let mockAwaitableWithCancel, cancellableResolvable;
8
+ beforeEach(async () => {
9
+ cancellableResolvable = new CancellableResolvable();
10
+ mockAwaitableWithCancel = vi.fn().mockReturnValue(cancellableResolvable.promise);
11
+ });
12
+ afterEach(() => {
13
+ cancellableResolvable = null;
14
+ vi.resetAllMocks();
15
+ });
16
+ it("should throw an error if awaitableWithCancel is not provided", () => {
17
+ expect(() => {
18
+ useCancellableIntent({});
19
+ }).toThrow("awaitableWithCancel is required");
20
+ });
21
+
22
+ it("should throw an error if awaitableWithCancel is not a function", () => {
23
+ expect(() => {
24
+ useCancellableIntent({
25
+ awaitableWithCancel: "not a function",
26
+ });
27
+ }).toThrow("awaitableWithCancel must be a function");
28
+ });
29
+ describe("Resolution", () => {
30
+ it("should initiate the intent and resolve the promise when the awaitableWithCancel resolves", async () => {
31
+ const subscribeIntent = useCancellableIntent({
32
+ awaitableWithCancel: mockAwaitableWithCancel,
33
+ watchArguments: {
34
+ testArg: 1,
35
+ },
36
+ });
37
+ await nextTick();
38
+ await flushPromises();
39
+ expect(mockAwaitableWithCancel).toHaveBeenCalledTimes(1);
40
+ expect(subscribeIntent.state.active).toBe(true);
41
+ expect(subscribeIntent.state.resolving).toBe(true);
42
+
43
+ cancellableResolvable.resolve(true);
44
+
45
+ await nextTick();
46
+ await flushPromises();
47
+
48
+ expect(subscribeIntent.state.active).toBe(false);
49
+ expect(subscribeIntent.state.resolving).toBe(false);
50
+ });
51
+ });
52
+
53
+ describe("Cancellation", () => {
54
+ it("should cancel the previous promise when watched arguments changed", async () => {
55
+ let testArgRef = ref(1);
56
+ const subscribeIntent = useCancellableIntent({
57
+ awaitableWithCancel: mockAwaitableWithCancel,
58
+ watchArguments: reactive({
59
+ testArg: testArgRef,
60
+ }),
61
+ clearActiveOnResolved: true,
62
+ });
63
+ await nextTick();
64
+ await flushPromises();
65
+ expect(mockAwaitableWithCancel).toHaveBeenCalledTimes(1);
66
+ expect(subscribeIntent.state.active).toBe(true);
67
+ expect(subscribeIntent.state.resolving).toBe(true);
68
+ testArgRef.value = 2;
69
+
70
+ await nextTick();
71
+ await flushPromises();
72
+ expect(cancellableResolvable.promise.cancel).toHaveBeenCalledTimes(1);
73
+ expect(subscribeIntent.state.active).toBe(true);
74
+ expect(subscribeIntent.state.resolving).toBe(true);
75
+
76
+ cancellableResolvable.resolve(true);
77
+ await nextTick();
78
+ await flushPromises();
79
+ expect(subscribeIntent.state.active).toBe(false);
80
+ expect(subscribeIntent.state.resolving).toBe(false);
81
+ });
82
+ });
83
+
84
+ describe("Delay", () => {
85
+ it("should handle the delayed watch properly", async () => {
86
+ let testGuardRef = ref(true);
87
+ const subscribeIntent = useCancellableIntent({
88
+ awaitableWithCancel: mockAwaitableWithCancel,
89
+ watchArguments: {
90
+ testArg: 1,
91
+ },
92
+ guardArguments: reactive({
93
+ testGuard: testGuardRef,
94
+ }),
95
+ });
96
+
97
+ expect(mockAwaitableWithCancel).not.toHaveBeenCalled();
98
+ expect(subscribeIntent.state.activeCount).toBeUndefined();
99
+ expect(subscribeIntent.state.resolvingCount).toBeUndefined();
100
+
101
+ testGuardRef.value = false;
102
+ await nextTick();
103
+ await flushPromises();
104
+ expect(mockAwaitableWithCancel).toHaveBeenCalled();
105
+ expect(subscribeIntent.state.active).toBe(true);
106
+ expect(subscribeIntent.state.resolving).toBe(true);
107
+
108
+ cancellableResolvable.resolve(true);
109
+ await nextTick();
110
+ await flushPromises();
111
+ expect(subscribeIntent.state.active).toBe(false);
112
+ expect(subscribeIntent.state.resolving).toBe(false);
113
+ });
114
+ });
115
+ describe("Rejection", () => {
116
+ //error is not being caught
117
+ it.skip("errored", async () => {
118
+ const consoleErrorMock = vi.spyOn(console, "error").mockImplementation(() => {});
119
+ const subscribeIntent = useCancellableIntent({
120
+ awaitableWithCancel: mockAwaitableWithCancel,
121
+ watchArguments: {
122
+ testArg: 1,
123
+ },
124
+ });
125
+ await nextTick();
126
+ await flushPromises();
127
+
128
+ const mockError = new Error("rejected");
129
+ cancellableResolvable.reject(mockError);
130
+
131
+ await nextTick();
132
+ await flushPromises();
133
+
134
+ expect(cancellableResolvable.promise.cancel).toHaveBeenCalledTimes(1);
135
+ expect(subscribeIntent.state.active).toBe(true);
136
+ expect(subscribeIntent.state.resolving).toBe(true);
137
+
138
+ await cancellableResolvable.cancel.resolve(true);
139
+ await nextTick();
140
+ await flushPromises();
141
+
142
+ await expect(cancellableResolvable.promise).rejects.toThrow(mockError);
143
+ expect(consoleErrorMock).toHaveBeenCalledWith(mockError);
144
+ expect(subscribeIntent.state.active).toBe(false);
145
+ expect(subscribeIntent.state.resolving).toBe(false);
146
+ expect(subscribeIntent.state.errored).toBe(true);
147
+ expect(subscribeIntent.state.error).toBe(mockError);
148
+ });
149
+ });
150
+ });
@@ -10,8 +10,8 @@ describe("use/listCalculated", () => {
10
10
  useListCalculated = listCalculatedModule.useListCalculated;
11
11
  });
12
12
  it("should return a list of calculated items", async () => {
13
- const mainListInstance = useListInstance({});
14
- const calculatedListInstance = useListInstance({});
13
+ const mainListInstance = useListInstance({ props: {} });
14
+ const calculatedListInstance = useListInstance({ props: {} });
15
15
  mainListInstance.addListObject({
16
16
  id: "1",
17
17
  name: "main",
@@ -36,15 +36,13 @@ describe("use/listCalculated", () => {
36
36
  calculatedItems: (obj) => obj.calculated_items.map((x) => calculatedListInstance.state.objects[x]),
37
37
  calculatedItem: (obj) => calculatedListInstance.state.objects[obj.calculated_id],
38
38
  },
39
- calculatedObjectsPropertyName: "myCalculatedObjects",
40
39
  });
41
40
  await nextTick();
42
41
  // listCalculated.state.objects is doing proxy shenanigans
43
42
  // in uses handler.has
44
- expect("myCalculatedObjects" in listCalculated.state).toBe(true);
45
- expect(!!listCalculated.state.myCalculatedObjects?.[1]).toBe(true);
46
- expect("calculatedItems" in listCalculated.state.myCalculatedObjects[1]).toBe(true);
47
- expect("calculatedItem" in listCalculated.state.myCalculatedObjects[1]).toBe(true);
43
+ expect(!!listCalculated.state.calculatedObjects?.[1]).toBe(true);
44
+ expect("calculatedItems" in listCalculated.state.calculatedObjects[1]).toBe(true);
45
+ expect("calculatedItem" in listCalculated.state.calculatedObjects[1]).toBe(true);
48
46
  // expect uses enumeration, which uses handler.ownKeys and handler.getOwnPropertyDescriptor
49
47
  expect(deepUnref(listCalculated.state.objects)).toEqual({
50
48
  1: {
@@ -54,7 +52,7 @@ describe("use/listCalculated", () => {
54
52
  calculated_items: ["2", "3"],
55
53
  },
56
54
  });
57
- expect(deepUnref(listCalculated.state.myCalculatedObjects)).toEqual({
55
+ expect(deepUnref(listCalculated.state.calculatedObjects)).toEqual({
58
56
  1: {
59
57
  calculatedItems: [
60
58
  {
@@ -18,7 +18,7 @@ describe("use/listFilter", () => {
18
18
  });
19
19
 
20
20
  it("should match an allowed values list", async () => {
21
- const list = useListInstance({});
21
+ const list = useListInstance({ props: {} });
22
22
  const filter = useListFilter({
23
23
  parentState: list.state,
24
24
  allowedValues: reactive({
@@ -52,7 +52,7 @@ describe("use/listFilter", () => {
52
52
  });
53
53
  });
54
54
  it("should match an allowed filter function", async () => {
55
- const list = useListInstance({});
55
+ const list = useListInstance({ props: {} });
56
56
  const filter = useListFilter({
57
57
  parentState: list.state,
58
58
  allowedFilter: (object) => object.id == 1 || object.id == 3,
@@ -84,7 +84,7 @@ describe("use/listFilter", () => {
84
84
  });
85
85
  it("should match by search term", async () => {
86
86
  const textSearchValue = ref("one");
87
- const list = useListInstance({});
87
+ const list = useListInstance({ props: {} });
88
88
  const filter = useListFilter({
89
89
  parentState: list.state,
90
90
  useTextSearch: true,
@@ -151,7 +151,7 @@ describe("use/listFilter", () => {
151
151
  });
152
152
  });
153
153
  it("should match an excluded filter function", async () => {
154
- const list = useListInstance({});
154
+ const list = useListInstance({ props: {} });
155
155
  const filter = useListFilter({
156
156
  parentState: list.state,
157
157
  excludedFilter: (object) => object.id == 2 || object.id == 4,
@@ -182,7 +182,7 @@ describe("use/listFilter", () => {
182
182
  });
183
183
  });
184
184
  it("should exclude an excludedValues parameter", async () => {
185
- const list = useListInstance({});
185
+ const list = useListInstance({ props: {} });
186
186
  const filter = useListFilter({
187
187
  parentState: list.state,
188
188
  excludedValues: reactive({
@@ -216,7 +216,7 @@ describe("use/listFilter", () => {
216
216
  });
217
217
  });
218
218
  it("no args: returns objects unfiltered", async () => {
219
- const listInstance = useListInstance({});
219
+ const listInstance = useListInstance({ props: {} });
220
220
  const listItems = [
221
221
  { id: 4, name: "four", has_things: true },
222
222
  { id: 2, name: "two", has_things: true },
@@ -235,10 +235,10 @@ describe("use/listFilter", () => {
235
235
  });
236
236
  describe("useListFilter operates on parentState modified by useListSort", () => {
237
237
  it("computes state.order and state.objects in order", async () => {
238
- jest.resetAllMocks();
238
+ vi.resetAllMocks();
239
239
  const orderByRules = [{ key: "name", desc: true, localeCompare: false }];
240
240
  const sortThrottleWait = 0;
241
- const listInstance = useListInstance({});
241
+ const listInstance = useListInstance({ props: {} });
242
242
  const listItems = [
243
243
  { id: 4, name: "four", has_things: true },
244
244
  { id: 2, name: "two", has_things: true },
@@ -266,20 +266,24 @@ describe("use/listFilter", () => {
266
266
  });
267
267
  describe("useListFilters accepts args and parentInstances", () => {
268
268
  it("returns filtered objects", async () => {
269
- jest.resetAllMocks();
269
+ vi.resetAllMocks();
270
270
  const fields = ["id", "__str__", "name"];
271
271
  const listInstanceA = useListInstance({
272
- crudArgs: { stream: "test_streamA" },
273
- listArgs: { user: 1 },
274
- retrieveArgs: {
275
- fields,
272
+ props: {
273
+ crudArgs: { stream: "test_streamA" },
274
+ listArgs: { user: 1 },
275
+ retrieveArgs: {
276
+ fields,
277
+ },
276
278
  },
277
279
  });
278
280
  const listInstanceB = useListInstance({
279
- crudArgs: { stream: "test_streamB" },
280
- listArgs: { user: 2 },
281
- retrieveArgs: {
282
- fields,
281
+ props: {
282
+ crudArgs: { stream: "test_streamB" },
283
+ listArgs: { user: 2 },
284
+ retrieveArgs: {
285
+ fields,
286
+ },
283
287
  },
284
288
  });
285
289
  const listFilterA = useListFilter({
@@ -5,15 +5,15 @@ import { inspect } from "util";
5
5
  import { isReactive, nextTick, reactive } from "vue";
6
6
 
7
7
  afterAll(() => {
8
- jest.restoreAllMocks();
8
+ vi.restoreAllMocks();
9
9
  });
10
10
 
11
11
  const fields = ["id", "__str__", "name"];
12
- describe("use/listInstance.spec.js", function () {
12
+ describe.skip("use/listInstance.spec.js", function () {
13
13
  let useListInstance, ListError, useListInstances, globalList;
14
14
  beforeEach(async () => {
15
15
  const imported = await import("../../../use/listInstance");
16
- globalList = jest.fn();
16
+ globalList = vi.fn();
17
17
  imported.setListInstanceCrud({
18
18
  list: globalList,
19
19
  args: { stream: "test_stream" },
@@ -23,7 +23,7 @@ describe("use/listInstance.spec.js", function () {
23
23
  useListInstances = imported.useListInstances;
24
24
  });
25
25
  afterEach(function () {
26
- jest.resetAllMocks();
26
+ vi.resetAllMocks();
27
27
  });
28
28
  const crudListResolvedPage1 = [
29
29
  {
@@ -64,8 +64,8 @@ describe("use/listInstance.spec.js", function () {
64
64
  __str__: "nvm",
65
65
  name: "nvm",
66
66
  };
67
- const crudListResolvedObjectsMid = keyBy(crudListResolvedPage1, "id");
68
- const crudListResolvedObjects = keyBy([...crudListResolvedPage1, ...crudListResolvedPage2], "id");
67
+ const crudListResolvedObjects1 = keyBy(crudListResolvedPage1, "id");
68
+ const crudListResolvedObjects2 = keyBy(crudListResolvedPage2, "id");
69
69
  describe("list", function () {
70
70
  it("success", async function () {
71
71
  const listArgs = reactive({
@@ -74,10 +74,7 @@ describe("use/listInstance.spec.js", function () {
74
74
  const retrieveArgs = reactive({
75
75
  fields,
76
76
  });
77
- const listInstance = useListInstance({
78
- listArgs,
79
- retrieveArgs,
80
- });
77
+ const listInstance = useListInstance({ props: { listArgs, retrieveArgs } });
81
78
  let crudListResolve;
82
79
  const crudListPromise = new Promise((resolve) => {
83
80
  crudListResolve = resolve;
@@ -107,14 +104,13 @@ describe("use/listInstance.spec.js", function () {
107
104
  expectErrorToBeNull(listInstance.state.error);
108
105
  expect(listInstance.state.errored).toBe(false);
109
106
  expect(listInstance.state.loading).toBe(true);
110
- expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjectsMid);
107
+ expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects1);
111
108
 
112
109
  passedPageCallback(crudListResolvedPage2);
113
-
114
110
  expectErrorToBeNull(listInstance.state.error);
115
111
  expect(listInstance.state.errored).toBe(false);
116
112
  expect(listInstance.state.loading).toBe(true);
117
- expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects);
113
+ expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects2);
118
114
 
119
115
  crudListResolve();
120
116
  await flushPromises();
@@ -124,7 +120,7 @@ describe("use/listInstance.spec.js", function () {
124
120
  expectErrorToBeNull(listInstance.state.error);
125
121
  expect(listInstance.state.errored).toBe(false);
126
122
  expect(listInstance.state.loading).toBe(false);
127
- expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects);
123
+ expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects2);
128
124
  expect(globalList).toHaveBeenCalledWith({
129
125
  crudArgs: { stream: "test_stream" },
130
126
  listArgs: { user: 1 },
@@ -140,10 +136,7 @@ describe("use/listInstance.spec.js", function () {
140
136
  const retrieveArgs = reactive({
141
137
  fields,
142
138
  });
143
- const listInstance = useListInstance({
144
- listArgs,
145
- retrieveArgs,
146
- });
139
+ const listInstance = useListInstance({ props: { listArgs, retrieveArgs } });
147
140
  expectErrorToBeNull(listInstance.state.error);
148
141
  expect(listInstance.state.errored).toBe(false);
149
142
  expect(listInstance.state.loading).toBeUndefined();
@@ -172,10 +165,7 @@ describe("use/listInstance.spec.js", function () {
172
165
  const retrieveArgs = reactive({
173
166
  fields,
174
167
  });
175
- const listInstance = useListInstance({
176
- listArgs,
177
- retrieveArgs,
178
- });
168
+ const listInstance = useListInstance({ props: { listArgs, retrieveArgs } });
179
169
  let crudListReject;
180
170
  const crudListPromise = new Promise((resolve, reject) => {
181
171
  crudListReject = reject;
@@ -226,9 +216,7 @@ describe("use/listInstance.spec.js", function () {
226
216
  fields,
227
217
  });
228
218
  const listInstance = useListInstance({
229
- listArgs,
230
- retrieveArgs,
231
- crudArgs: { stream: "custom_stream" },
219
+ props: { listArgs, retrieveArgs, crudArgs: { stream: "custom_stream" } },
232
220
  });
233
221
  let crudListResolve;
234
222
  const crudListPromise = new Promise((resolve) => {
@@ -259,14 +247,14 @@ describe("use/listInstance.spec.js", function () {
259
247
  expectErrorToBeNull(listInstance.state.error);
260
248
  expect(listInstance.state.errored).toBe(false);
261
249
  expect(listInstance.state.loading).toBe(true);
262
- expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjectsMid);
250
+ expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects1);
263
251
 
264
252
  passedPageCallback(crudListResolvedPage2);
265
253
 
266
254
  expectErrorToBeNull(listInstance.state.error);
267
255
  expect(listInstance.state.errored).toBe(false);
268
256
  expect(listInstance.state.loading).toBe(true);
269
- expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects);
257
+ expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects2);
270
258
 
271
259
  crudListResolve();
272
260
  await flushPromises();
@@ -276,7 +264,7 @@ describe("use/listInstance.spec.js", function () {
276
264
  expectErrorToBeNull(listInstance.state.error);
277
265
  expect(listInstance.state.errored).toBe(false);
278
266
  expect(listInstance.state.loading).toBe(false);
279
- expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects);
267
+ expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects2);
280
268
  expect(globalList).toHaveBeenCalledWith({
281
269
  crudArgs: { stream: "custom_stream" },
282
270
  listArgs: { user: 1 },
@@ -293,8 +281,10 @@ describe("use/listInstance.spec.js", function () {
293
281
  fields,
294
282
  });
295
283
  const listInstance = useListInstance({
296
- listArgs,
297
- retrieveArgs,
284
+ props: {
285
+ listArgs,
286
+ retrieveArgs,
287
+ },
298
288
  });
299
289
  let crudListResolve;
300
290
  const crudListPromise = new Promise((resolve) => {
@@ -316,10 +306,10 @@ describe("use/listInstance.spec.js", function () {
316
306
  expectErrorToBeNull(listInstance.state.error);
317
307
  expect(listInstance.state.errored).toBe(false);
318
308
  expect(listInstance.state.loading).toBe(false);
319
- expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects);
309
+ expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects2);
320
310
  await flushPromises();
321
- expect(listInstance.state.order).toEqual(Object.keys(crudListResolvedObjects));
322
- expect(listInstance.state.objectsInOrder).toEqual(Object.values(crudListResolvedObjects));
311
+ expect(listInstance.state.order).toEqual(Object.keys(crudListResolvedObjects2));
312
+ expect(listInstance.state.objectsInOrder).toEqual(Object.values(crudListResolvedObjects2));
323
313
  expect(globalList).toHaveBeenCalledWith({
324
314
  crudArgs: { stream: "test_stream" },
325
315
  listArgs: { user: 1 },
@@ -340,28 +330,16 @@ describe("use/listInstance.spec.js", function () {
340
330
  });
341
331
  it("useListInstances", async function () {
342
332
  const listInstanceA = useListInstance({
343
- crudArgs: { stream: "test_streamA" },
344
- id: 1,
345
- retrieveArgs: {
346
- fields,
347
- },
348
- });
349
- const listInstanceB = useListInstance({
350
- crudArgs: { stream: "test_streamB" },
351
- id: 2,
352
- retrieveArgs: {
353
- fields,
354
- },
355
- });
356
- const listInstances = useListInstances({
357
- A: {
333
+ props: {
358
334
  crudArgs: { stream: "test_streamA" },
359
335
  id: 1,
360
336
  retrieveArgs: {
361
337
  fields,
362
338
  },
363
339
  },
364
- B: {
340
+ });
341
+ const listInstanceB = useListInstance({
342
+ props: {
365
343
  crudArgs: { stream: "test_streamB" },
366
344
  id: 2,
367
345
  retrieveArgs: {
@@ -369,19 +347,39 @@ describe("use/listInstance.spec.js", function () {
369
347
  },
370
348
  },
371
349
  });
350
+ const listInstances = useListInstances({
351
+ A: {
352
+ props: {
353
+ crudArgs: { stream: "test_streamA" },
354
+ id: 1,
355
+ retrieveArgs: {
356
+ fields,
357
+ },
358
+ },
359
+ },
360
+ B: {
361
+ props: {
362
+ crudArgs: { stream: "test_streamB" },
363
+ id: 2,
364
+ retrieveArgs: {
365
+ fields,
366
+ },
367
+ },
368
+ },
369
+ });
372
370
  expect(inspect(listInstances.A)).toEqual(inspect(listInstanceA));
373
371
  expect(inspect(listInstances.B)).toEqual(inspect(listInstanceB));
374
372
  });
375
373
  describe("addListObject", function () {
376
374
  it("errored", function () {
377
- const listInstance = useListInstance({});
375
+ const listInstance = useListInstance({ props: {} });
378
376
  expect(() => listInstance.addListObject({ listObject })).toThrowError(ListError);
379
377
  listObject.id = listInstance.getFakeId();
380
378
  listInstance.addListObject(listObject);
381
379
  expect(() => listInstance.addListObject({ listObject })).toThrowError(ListError);
382
380
  });
383
381
  it("succeeded", function () {
384
- const listInstance = useListInstance({});
382
+ const listInstance = useListInstance({ props: {} });
385
383
  const newId = listInstance.getFakeId();
386
384
  listObject.id = newId;
387
385
  listInstance.addListObject(listObject);
@@ -392,7 +390,7 @@ describe("use/listInstance.spec.js", function () {
392
390
  });
393
391
  describe("updateListObject", function () {
394
392
  it("errors", function () {
395
- const listInstance = useListInstance({});
393
+ const listInstance = useListInstance({ props: {} });
396
394
  expect(() => listInstance.updateListObject({ listObject })).toThrowError(ListError);
397
395
  listObject.id = -50002000;
398
396
  listInstance.addListObject(listObject);
@@ -400,8 +398,7 @@ describe("use/listInstance.spec.js", function () {
400
398
  });
401
399
  it("succeeds", async function () {
402
400
  const listInstance = useListInstance({
403
- listArgs: { user: 1 },
404
- retrieveArgs: { fields: fields },
401
+ props: { listArgs: { user: 1 }, retrieveArgs: { fields: fields } },
405
402
  });
406
403
  let crudListResolve;
407
404
  const crudListPromise = new Promise((resolve) => {
@@ -426,7 +423,7 @@ describe("use/listInstance.spec.js", function () {
426
423
  });
427
424
  describe("getFakeId", function () {
428
425
  it("returns fakeId", function () {
429
- const listInstance = useListInstance({});
426
+ const listInstance = useListInstance({ props: {} });
430
427
  const fakeId = listInstance.getFakeId();
431
428
  expect(fakeId).toBeTruthy();
432
429
  });
@@ -454,10 +451,7 @@ describe("use/listInstance.spec.js", function () {
454
451
  __str__: "yuio",
455
452
  name: "yiuo",
456
453
  };
457
- const listInstance = useListInstance({
458
- listArgs: { user: 1 },
459
- retrieveArgs: { fields: fields },
460
- });
454
+ const listInstance = useListInstance({ props: { listArgs: { user: 1 }, retrieveArgs: { fields: fields } } });
461
455
  let crudListResolve;
462
456
  const crudListPromise = new Promise((resolve) => {
463
457
  crudListResolve = resolve;
@@ -1,3 +1,4 @@
1
+ // import { useListInstance, useListRelated } from "../../../use/listRelated";
1
2
  import { nextTick } from "vue";
2
3
  import { deepUnref } from "vue-deepunref";
3
4
 
@@ -10,8 +11,8 @@ describe("use/listRelated", () => {
10
11
  useListRelated = listRelatedModule.useListRelated;
11
12
  });
12
13
  it("should return a list of related items", async () => {
13
- const mainListInstance = useListInstance({});
14
- const relatedListInstance = useListInstance({});
14
+ const mainListInstance = useListInstance({ props: {} });
15
+ const relatedListInstance = useListInstance({ props: {} });
15
16
  mainListInstance.addListObject({
16
17
  id: "1",
17
18
  name: "main",
@@ -42,15 +43,13 @@ describe("use/listRelated", () => {
42
43
  pkKey: "related_id",
43
44
  },
44
45
  },
45
- relatedObjectsPropertyName: "myRelatedObjects",
46
46
  });
47
47
  await nextTick();
48
48
  // listRelated.state.objects is doing proxy shenanigans
49
49
  // in uses handler.has
50
- expect("myRelatedObjects" in listRelated.state).toBe(true);
51
- expect(!!listRelated.state.myRelatedObjects?.[1]).toBe(true);
52
- expect("relatedItems" in listRelated.state.myRelatedObjects[1]).toBe(true);
53
- expect("relatedItem" in listRelated.state.myRelatedObjects[1]).toBe(true);
50
+ expect(!!listRelated.state.relatedObjects?.[1]).toBe(true);
51
+ expect("relatedItems" in listRelated.state.relatedObjects[1]).toBe(true);
52
+ expect("relatedItem" in listRelated.state.relatedObjects[1]).toBe(true);
54
53
  // expect uses enumeration, which uses handler.ownKeys and handler.getOwnPropertyDescriptor
55
54
  expect(deepUnref(listRelated.state.objects)).toEqual({
56
55
  1: {
@@ -60,7 +59,7 @@ describe("use/listRelated", () => {
60
59
  related_items: ["2", "3"],
61
60
  },
62
61
  });
63
- expect(deepUnref(listRelated.state.myRelatedObjects)).toEqual({
62
+ expect(deepUnref(listRelated.state.relatedObjects)).toEqual({
64
63
  1: {
65
64
  relatedItems: [
66
65
  {