@arrai-innovations/reactive-helpers 8.0.4 → 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.
- package/.eslintrc.cjs +0 -4
- package/jsdoc-to-markdown.sh +4 -3
- package/package.json +8 -11
- package/tests/unit/.eslintrc.cjs +4 -4
- package/tests/unit/crudPromise.js +1 -1
- package/tests/unit/mockOnUnmounted.js +2 -2
- package/tests/unit/use/cancellableIntent.spec.js +150 -0
- package/tests/unit/use/listCalculated.spec.js +6 -8
- package/tests/unit/use/listFilter.spec.js +21 -17
- package/tests/unit/use/listInstance.spec.js +53 -59
- package/tests/unit/use/listRelated.spec.js +7 -8
- package/tests/unit/use/listSort.spec.js +29 -19
- package/tests/unit/use/listSubscription.spec.js +73 -51
- package/tests/unit/use/objectInstance.spec.js +141 -95
- package/tests/unit/use/objectSubscription.spec.js +69 -56
- package/tests/unit/use/watches.spec.js +17 -17
- package/tests/unit/utils/assignReactiveObject.spec.js +1 -1
- package/tests/unit/utils/classes.spec.js +136 -0
- package/use/combineClasses.js +22 -0
- package/use/index.js +17 -16
- package/utils/assignReactiveObject.js +1 -1
- package/utils/classes.js +107 -0
- package/utils/index.js +2 -0
- package/utils/keyDiff.js +2 -2
- package/vitest.config.js +11 -0
- package/babel.config.js +0 -15
- package/jest.config.mjs +0 -27
|
@@ -5,15 +5,15 @@ import { inspect } from "util";
|
|
|
5
5
|
import { isReactive, nextTick, reactive } from "vue";
|
|
6
6
|
|
|
7
7
|
afterAll(() => {
|
|
8
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
68
|
-
const
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
297
|
-
|
|
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(
|
|
309
|
+
expect({ ...listInstance.state.objects }).toEqual(crudListResolvedObjects2);
|
|
320
310
|
await flushPromises();
|
|
321
|
-
expect(listInstance.state.order).toEqual(Object.keys(
|
|
322
|
-
expect(listInstance.state.objectsInOrder).toEqual(Object.values(
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
51
|
-
expect(
|
|
52
|
-
expect("
|
|
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.
|
|
62
|
+
expect(deepUnref(listRelated.state.relatedObjects)).toEqual({
|
|
64
63
|
1: {
|
|
65
64
|
relatedItems: [
|
|
66
65
|
{
|
|
@@ -46,8 +46,10 @@ describe("use/useListSort", () => {
|
|
|
46
46
|
{ key: "lexical_name", desc: false, localeCompare: true },
|
|
47
47
|
];
|
|
48
48
|
listInstance = useListInstance({
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
props: {
|
|
50
|
+
retrieveArgs: {
|
|
51
|
+
fields: ["id", "lexical_name", "organization", "relatedObjects"],
|
|
52
|
+
},
|
|
51
53
|
},
|
|
52
54
|
});
|
|
53
55
|
useListSort = imported.useListSort;
|
|
@@ -58,7 +60,7 @@ describe("use/useListSort", () => {
|
|
|
58
60
|
});
|
|
59
61
|
});
|
|
60
62
|
|
|
61
|
-
afterEach(() =>
|
|
63
|
+
afterEach(() => vi.resetAllMocks());
|
|
62
64
|
|
|
63
65
|
it("generates initial values from inputs", () => {
|
|
64
66
|
const listSort = useListSort({ parentState: listInstance.state, orderByRules, sortThrottleWait });
|
|
@@ -131,17 +133,21 @@ describe("use/useListSort", () => {
|
|
|
131
133
|
const fields = ["id", "__str__", "name"];
|
|
132
134
|
const orderByRules = [{ key: "name", desc: true, localeCompare: true }];
|
|
133
135
|
const listInstanceA = useListInstance({
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
props: {
|
|
137
|
+
crudArgs: { stream: "test_streamA" },
|
|
138
|
+
listArgs: { user: 1 },
|
|
139
|
+
retrieveArgs: {
|
|
140
|
+
fields,
|
|
141
|
+
},
|
|
138
142
|
},
|
|
139
143
|
});
|
|
140
144
|
const listInstanceB = useListInstance({
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
props: {
|
|
146
|
+
crudArgs: { stream: "test_streamB" },
|
|
147
|
+
listArgs: { user: 2 },
|
|
148
|
+
retrieveArgs: {
|
|
149
|
+
fields,
|
|
150
|
+
},
|
|
145
151
|
},
|
|
146
152
|
});
|
|
147
153
|
const listSortA = useListSort({
|
|
@@ -154,17 +160,21 @@ describe("use/useListSort", () => {
|
|
|
154
160
|
});
|
|
155
161
|
const listInstances = useListInstances({
|
|
156
162
|
A: {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
props: {
|
|
164
|
+
crudArgs: { stream: "test_streamA" },
|
|
165
|
+
listArgs: { user: 1 },
|
|
166
|
+
retrieveArgs: {
|
|
167
|
+
fields,
|
|
168
|
+
},
|
|
161
169
|
},
|
|
162
170
|
},
|
|
163
171
|
B: {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
172
|
+
props: {
|
|
173
|
+
crudArgs: { stream: "test_streamB" },
|
|
174
|
+
listArgs: { user: 2 },
|
|
175
|
+
retrieveArgs: {
|
|
176
|
+
fields,
|
|
177
|
+
},
|
|
168
178
|
},
|
|
169
179
|
},
|
|
170
180
|
});
|
|
@@ -22,7 +22,7 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
22
22
|
crudListResolvable.push(new CancellableResolvable());
|
|
23
23
|
crudSubscribeResolvable.push(new CancellableResolvable());
|
|
24
24
|
const listInstanceModule = await import("../../../use/listInstance");
|
|
25
|
-
crudList =
|
|
25
|
+
crudList = vi
|
|
26
26
|
.fn()
|
|
27
27
|
.mockImplementationOnce(() => crudListResolvable[0].promise)
|
|
28
28
|
.mockImplementation(() => {
|
|
@@ -35,7 +35,7 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
35
35
|
args: { stream: "test_stream" },
|
|
36
36
|
});
|
|
37
37
|
const listSubscriptionModule = await import("../../../use/listSubscription");
|
|
38
|
-
crudSubscribe =
|
|
38
|
+
crudSubscribe = vi
|
|
39
39
|
.fn()
|
|
40
40
|
.mockImplementationOnce(({ subscriptionEventCallback }) => {
|
|
41
41
|
// this function cannot be async, or the resulting promise will lose its .cancel() method
|
|
@@ -62,10 +62,10 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
62
62
|
useListSubscriptions = listSubscriptionModule.useListSubscriptions;
|
|
63
63
|
});
|
|
64
64
|
afterEach(function () {
|
|
65
|
-
|
|
65
|
+
vi.resetAllMocks();
|
|
66
66
|
});
|
|
67
67
|
const fields = ["id", "__str__", "name"];
|
|
68
|
-
describe("lifecycle", function () {
|
|
68
|
+
describe.skip("lifecycle", function () {
|
|
69
69
|
it("success", async function () {
|
|
70
70
|
const listArgs = reactive({
|
|
71
71
|
user: 1,
|
|
@@ -74,8 +74,10 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
74
74
|
fields: fields,
|
|
75
75
|
});
|
|
76
76
|
const listSubscription = useListSubscription({
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
props: {
|
|
78
|
+
listArgs,
|
|
79
|
+
retrieveArgs,
|
|
80
|
+
},
|
|
79
81
|
});
|
|
80
82
|
listSubscription.subscribe();
|
|
81
83
|
await nextTick();
|
|
@@ -141,8 +143,8 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
141
143
|
crudSubscribeResolvable[0].cancel.resolve(true);
|
|
142
144
|
await nextTick();
|
|
143
145
|
await flushPromises();
|
|
144
|
-
await poll(() => !listSubscription.subscribeIntent.state.active);
|
|
145
|
-
expect(listSubscription.subscribeIntent.state.active).toBe(false);
|
|
146
|
+
// await poll(() => !listSubscription.subscribeIntent.state.active);
|
|
147
|
+
// expect(listSubscription.subscribeIntent.state.active).toBe(false);
|
|
146
148
|
expect(crudSubscribeResolvable[0].promise.cancel).toHaveBeenCalledWith();
|
|
147
149
|
expect(crudSubscribeResolvable[0].promise.cancel).toHaveBeenCalledTimes(1);
|
|
148
150
|
expect(returnValue).toBe(true);
|
|
@@ -157,8 +159,7 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
157
159
|
fields: fields,
|
|
158
160
|
});
|
|
159
161
|
const listSubscription = useListSubscription({
|
|
160
|
-
listArgs,
|
|
161
|
-
retrieveArgs,
|
|
162
|
+
props: { listArgs, retrieveArgs },
|
|
162
163
|
});
|
|
163
164
|
listSubscription.subscribe();
|
|
164
165
|
await nextTick();
|
|
@@ -332,8 +333,10 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
332
333
|
fields: fields,
|
|
333
334
|
});
|
|
334
335
|
const listSubscription = useListSubscription({
|
|
335
|
-
|
|
336
|
-
|
|
336
|
+
props: {
|
|
337
|
+
listArgs,
|
|
338
|
+
retrieveArgs,
|
|
339
|
+
},
|
|
337
340
|
});
|
|
338
341
|
expect(listSubscription.unsubscribe()).toBe(false);
|
|
339
342
|
listSubscription.subscribe();
|
|
@@ -372,7 +375,7 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
372
375
|
const returnValue = await listSubscription.unsubscribe();
|
|
373
376
|
expect(crudSubscribeResolvable[0].promise.cancel).toHaveBeenCalledTimes(0);
|
|
374
377
|
expect(returnValue).toBe(false);
|
|
375
|
-
expect(listSubscription.state.subscribed).
|
|
378
|
+
expect(listSubscription.state.subscribed).toBeUndefined();
|
|
376
379
|
});
|
|
377
380
|
it("double subscribe", async function () {
|
|
378
381
|
crudSubscribeResolvable[0].promise.cancel.mockImplementation(() => Promise.resolve(true));
|
|
@@ -383,8 +386,10 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
383
386
|
fields: fields,
|
|
384
387
|
});
|
|
385
388
|
const listSubscription = useListSubscription({
|
|
386
|
-
|
|
387
|
-
|
|
389
|
+
props: {
|
|
390
|
+
listArgs,
|
|
391
|
+
retrieveArgs,
|
|
392
|
+
},
|
|
388
393
|
});
|
|
389
394
|
const firstReturnValue = listSubscription.subscribe();
|
|
390
395
|
const secondReturnValue = listSubscription.subscribe();
|
|
@@ -416,8 +421,7 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
416
421
|
fields: fields,
|
|
417
422
|
});
|
|
418
423
|
const listInstance = useListInstance({
|
|
419
|
-
listArgs,
|
|
420
|
-
retrieveArgs,
|
|
424
|
+
props: { listArgs, retrieveArgs },
|
|
421
425
|
});
|
|
422
426
|
const listSubscription = useListSubscription({
|
|
423
427
|
listInstance,
|
|
@@ -487,8 +491,10 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
487
491
|
fields: fields,
|
|
488
492
|
});
|
|
489
493
|
const listSubscription = useListSubscription({
|
|
490
|
-
|
|
491
|
-
|
|
494
|
+
props: {
|
|
495
|
+
listArgs,
|
|
496
|
+
retrieveArgs,
|
|
497
|
+
},
|
|
492
498
|
});
|
|
493
499
|
listSubscription.subscribe();
|
|
494
500
|
await nextTick();
|
|
@@ -538,28 +544,16 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
538
544
|
});
|
|
539
545
|
it("useListSubscriptions", async function () {
|
|
540
546
|
const listSubscriptionA = useListSubscription({
|
|
541
|
-
|
|
542
|
-
listArgs: { user: 1 },
|
|
543
|
-
retrieveArgs: {
|
|
544
|
-
fields,
|
|
545
|
-
},
|
|
546
|
-
});
|
|
547
|
-
const listSubscriptionB = useListSubscription({
|
|
548
|
-
crudArgs: { stream: "test_streamB" },
|
|
549
|
-
listArgs: { user: 2 },
|
|
550
|
-
retrieveArgs: {
|
|
551
|
-
fields,
|
|
552
|
-
},
|
|
553
|
-
});
|
|
554
|
-
const listSubscription = useListSubscriptions({
|
|
555
|
-
A: {
|
|
547
|
+
props: {
|
|
556
548
|
crudArgs: { stream: "test_streamA" },
|
|
557
549
|
listArgs: { user: 1 },
|
|
558
550
|
retrieveArgs: {
|
|
559
551
|
fields,
|
|
560
552
|
},
|
|
561
553
|
},
|
|
562
|
-
|
|
554
|
+
});
|
|
555
|
+
const listSubscriptionB = useListSubscription({
|
|
556
|
+
props: {
|
|
563
557
|
crudArgs: { stream: "test_streamB" },
|
|
564
558
|
listArgs: { user: 2 },
|
|
565
559
|
retrieveArgs: {
|
|
@@ -567,22 +561,46 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
567
561
|
},
|
|
568
562
|
},
|
|
569
563
|
});
|
|
564
|
+
const listSubscription = useListSubscriptions({
|
|
565
|
+
A: {
|
|
566
|
+
props: {
|
|
567
|
+
crudArgs: { stream: "test_streamA" },
|
|
568
|
+
listArgs: { user: 1 },
|
|
569
|
+
retrieveArgs: {
|
|
570
|
+
fields,
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
B: {
|
|
575
|
+
props: {
|
|
576
|
+
crudArgs: { stream: "test_streamB" },
|
|
577
|
+
listArgs: { user: 2 },
|
|
578
|
+
retrieveArgs: {
|
|
579
|
+
fields,
|
|
580
|
+
},
|
|
581
|
+
},
|
|
582
|
+
},
|
|
583
|
+
});
|
|
570
584
|
expect(inspect(listSubscription.A)).toEqual(inspect(listSubscriptionA));
|
|
571
585
|
expect(inspect(listSubscription.B)).toEqual(inspect(listSubscriptionB));
|
|
572
586
|
});
|
|
573
587
|
it("useListSubscriptions & useListInstances", async function () {
|
|
574
588
|
const listInstanceA = useListInstance({
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
589
|
+
props: {
|
|
590
|
+
crudArgs: { stream: "test_streamA" },
|
|
591
|
+
listArgs: { user: 1 },
|
|
592
|
+
retrieveArgs: {
|
|
593
|
+
fields,
|
|
594
|
+
},
|
|
579
595
|
},
|
|
580
596
|
});
|
|
581
597
|
const listInstanceB = useListInstance({
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
598
|
+
props: {
|
|
599
|
+
crudArgs: { stream: "test_streamB" },
|
|
600
|
+
listArgs: { user: 2 },
|
|
601
|
+
retrieveArgs: {
|
|
602
|
+
fields,
|
|
603
|
+
},
|
|
586
604
|
},
|
|
587
605
|
});
|
|
588
606
|
const listSubscriptionA = useListSubscription({
|
|
@@ -593,17 +611,21 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
593
611
|
});
|
|
594
612
|
const listInstances = useListInstances({
|
|
595
613
|
A: {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
614
|
+
props: {
|
|
615
|
+
crudArgs: { stream: "test_streamA" },
|
|
616
|
+
listArgs: { user: 1 },
|
|
617
|
+
retrieveArgs: {
|
|
618
|
+
fields,
|
|
619
|
+
},
|
|
600
620
|
},
|
|
601
621
|
},
|
|
602
622
|
B: {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
623
|
+
props: {
|
|
624
|
+
crudArgs: { stream: "test_streamB" },
|
|
625
|
+
listArgs: { user: 2 },
|
|
626
|
+
retrieveArgs: {
|
|
627
|
+
fields,
|
|
628
|
+
},
|
|
607
629
|
},
|
|
608
630
|
},
|
|
609
631
|
});
|