tsdf 8.0.0-beta.1 → 8.0.0-beta.11
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/dist/main.cjs +1860 -0
- package/dist/main.d.ts +291 -0
- package/dist/main.js +1825 -0
- package/package.json +6 -2
- package/.eslintignore +0 -3
- package/.eslintrc.cjs +0 -119
- package/.gitattributes +0 -22
- package/.prettierrc +0 -6
- package/.vscode/settings.json +0 -3
- package/.vscode/tasks.json +0 -35
- package/fetch-orquestrator-scenarios.excalidraw +0 -10115
- package/scripts/check-if-is-sync.sh +0 -6
- package/src/collectionFetchOrquestrator.ts +0 -23
- package/src/collectionStore.ts +0 -608
- package/src/documentStore.ts +0 -272
- package/src/fetchOrquestrator.ts +0 -335
- package/src/listQueryStore.ts +0 -1190
- package/src/main.ts +0 -22
- package/src/storeShared.ts +0 -5
- package/src/useEnsureIsLoaded.ts +0 -50
- package/src/utils/filterAndMap.ts +0 -20
- package/src/utils/getCacheId.ts +0 -19
- package/src/utils/hooks.ts +0 -110
- package/src/utils/isObject.ts +0 -3
- package/src/utils/math.ts +0 -7
- package/src/utils/serializableClone.ts +0 -3
- package/src/utils/useLatestValue.ts +0 -16
- package/test/__snapshots__/listQueryStore.test.ts.snap +0 -146
- package/test/__snapshots__/listQueryStoreHooks.test.ts.snap +0 -9
- package/test/collectionStore.test.ts +0 -523
- package/test/collectionStoreHooks.test.tsx +0 -651
- package/test/documentStore.test.ts +0 -183
- package/test/documentStoreHooks.test.tsx +0 -857
- package/test/fetchOrquestrator.test.ts +0 -913
- package/test/listQueryStore.test.ts +0 -1158
- package/test/listQueryStoreHooks.test.tsx +0 -662
- package/test/listQueryStoreHooks2.test.tsx +0 -483
- package/test/listQueryStoreHooksMutations.test.tsx +0 -764
- package/test/mocks/fetchMock.ts +0 -296
- package/test/mocks/fetchOrquestratorEnv.ts +0 -370
- package/test/setup/setup.ts +0 -109
- package/test/testHelpers.test.ts +0 -88
- package/test/utils/RenderObjValues.tsx +0 -23
- package/test/utils/arrayUtils.ts +0 -13
- package/test/utils/createDefaultListQueryStore.ts +0 -275
- package/test/utils/createOrVariations.ts +0 -48
- package/test/utils/dedent.ts +0 -50
- package/test/utils/delayCall.ts +0 -25
- package/test/utils/math.ts +0 -3
- package/test/utils/objectUtils.ts +0 -18
- package/test/utils/range.ts +0 -19
- package/test/utils/sleep.ts +0 -3
- package/test/utils/storeUtils.ts +0 -460
- package/tsconfig.json +0 -24
- package/tsconfig.prod.json +0 -9
- package/tsup.config.ts +0 -12
- package/vitest.config.ts +0 -10
|
@@ -1,764 +0,0 @@
|
|
|
1
|
-
import { renderHook } from '@testing-library/react';
|
|
2
|
-
import { expect, test } from 'vitest';
|
|
3
|
-
import {
|
|
4
|
-
createDefaultListQueryStore,
|
|
5
|
-
Tables,
|
|
6
|
-
} from './utils/createDefaultListQueryStore';
|
|
7
|
-
import { randomInt } from './utils/math';
|
|
8
|
-
import { range } from './utils/range';
|
|
9
|
-
import { sleep } from './utils/sleep';
|
|
10
|
-
import { createRenderStore, waitElapsedTime } from './utils/storeUtils';
|
|
11
|
-
|
|
12
|
-
const createTestEnv = createDefaultListQueryStore;
|
|
13
|
-
|
|
14
|
-
const initialServerData: Tables = {
|
|
15
|
-
users: range(1, 5).map((id) => ({ id, name: `User ${id}` })),
|
|
16
|
-
products: range(1, 50).map((id) => ({ id, name: `Product ${id}` })),
|
|
17
|
-
orders: range(1, 50).map((id) => ({ id, name: `Order ${id}` })),
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
async function updateItemName(
|
|
21
|
-
{ store, serverMock }: ReturnType<typeof createTestEnv>,
|
|
22
|
-
tableId: string,
|
|
23
|
-
itemId: number,
|
|
24
|
-
newText: string,
|
|
25
|
-
{
|
|
26
|
-
revalidate,
|
|
27
|
-
optimisticUpdate,
|
|
28
|
-
duration,
|
|
29
|
-
}: {
|
|
30
|
-
revalidate?: boolean;
|
|
31
|
-
optimisticUpdate?: boolean;
|
|
32
|
-
duration?: number;
|
|
33
|
-
} = {},
|
|
34
|
-
) {
|
|
35
|
-
const id = `${tableId}||${itemId}`;
|
|
36
|
-
const endMutation = store.startItemMutation(id);
|
|
37
|
-
|
|
38
|
-
if (optimisticUpdate) {
|
|
39
|
-
store.updateItemState(id, (draftData) => {
|
|
40
|
-
draftData.name = newText;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const result = await serverMock.emulateMutation(
|
|
45
|
-
(data) => {
|
|
46
|
-
data[tableId]![Number(itemId) - 1]!.name = newText;
|
|
47
|
-
},
|
|
48
|
-
{ duration: duration ?? randomInt(500, 1000) },
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
endMutation();
|
|
52
|
-
|
|
53
|
-
if (revalidate) store.invalidateItem(id);
|
|
54
|
-
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function addItemWithIdGeneratedByServer(
|
|
59
|
-
{ store, serverMock }: ReturnType<typeof createTestEnv>,
|
|
60
|
-
tableId: string,
|
|
61
|
-
name: string,
|
|
62
|
-
{
|
|
63
|
-
revalidate: invalidateAfterMutation,
|
|
64
|
-
duration,
|
|
65
|
-
}: {
|
|
66
|
-
revalidate?: boolean;
|
|
67
|
-
duration?: number;
|
|
68
|
-
} = {},
|
|
69
|
-
) {
|
|
70
|
-
const endMutation = store.startItemMutation(`${tableId}||?`);
|
|
71
|
-
|
|
72
|
-
let id: number | undefined;
|
|
73
|
-
|
|
74
|
-
const result = await serverMock.emulateMutation(
|
|
75
|
-
(data) => {
|
|
76
|
-
id = data[tableId]!.length + 1;
|
|
77
|
-
data[tableId]?.push({ id, name });
|
|
78
|
-
},
|
|
79
|
-
{ duration: duration ?? randomInt(500, 1000) },
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
endMutation();
|
|
83
|
-
|
|
84
|
-
store.addItemToState(`${tableId}||${id}`, {
|
|
85
|
-
id: id!,
|
|
86
|
-
name,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
if (invalidateAfterMutation) store.invalidateItem(`${tableId}||${id}`);
|
|
90
|
-
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function addItemWithIdGeneratedByClient(
|
|
95
|
-
{ store, serverMock }: ReturnType<typeof createTestEnv>,
|
|
96
|
-
tableId: string,
|
|
97
|
-
userId: string,
|
|
98
|
-
name: string,
|
|
99
|
-
{
|
|
100
|
-
revalidate,
|
|
101
|
-
duration,
|
|
102
|
-
}: {
|
|
103
|
-
revalidate?: boolean;
|
|
104
|
-
duration?: number;
|
|
105
|
-
} = {},
|
|
106
|
-
) {
|
|
107
|
-
const id = `${tableId}||${userId}`;
|
|
108
|
-
const endMutation = store.startItemMutation(id);
|
|
109
|
-
|
|
110
|
-
store.addItemToState(id, {
|
|
111
|
-
id: Number(userId),
|
|
112
|
-
name,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const result = await serverMock.emulateMutation(
|
|
116
|
-
(data) => {
|
|
117
|
-
data[tableId]?.push({ id: Number(userId), name });
|
|
118
|
-
},
|
|
119
|
-
{ duration: duration ?? randomInt(500, 1000) },
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
endMutation();
|
|
123
|
-
|
|
124
|
-
if (revalidate) store.invalidateItem(id, 'highPriority');
|
|
125
|
-
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async function deleteItem(
|
|
130
|
-
{ store, serverMock }: ReturnType<typeof createTestEnv>,
|
|
131
|
-
tableId: string,
|
|
132
|
-
itemId: number,
|
|
133
|
-
{
|
|
134
|
-
revalidate,
|
|
135
|
-
duration,
|
|
136
|
-
optimisticUpdate,
|
|
137
|
-
}: {
|
|
138
|
-
revalidate?: boolean;
|
|
139
|
-
optimisticUpdate?: boolean;
|
|
140
|
-
duration?: number;
|
|
141
|
-
} = {},
|
|
142
|
-
) {
|
|
143
|
-
const id = `${tableId}||${itemId}`;
|
|
144
|
-
const endMutation = store.startItemMutation(id);
|
|
145
|
-
|
|
146
|
-
if (optimisticUpdate) {
|
|
147
|
-
store.deleteItemState(id);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const result = await serverMock.emulateMutation(
|
|
151
|
-
(data) => {
|
|
152
|
-
data[tableId]!.splice(itemId - 1, 1);
|
|
153
|
-
},
|
|
154
|
-
{ duration: duration ?? randomInt(500, 1000) },
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
endMutation();
|
|
158
|
-
|
|
159
|
-
if (revalidate) store.invalidateItem(id);
|
|
160
|
-
|
|
161
|
-
return result;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
test.concurrent('user updating the name of a record', async () => {
|
|
165
|
-
const env = createTestEnv({
|
|
166
|
-
initialServerData,
|
|
167
|
-
useLoadedSnapshot: { tables: ['users', 'products'] },
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
const renders = createRenderStore();
|
|
171
|
-
|
|
172
|
-
env.serverMock.setFetchDuration(263);
|
|
173
|
-
|
|
174
|
-
renderHook(() => {
|
|
175
|
-
const { data, status } = env.store.useItem('users||1', {
|
|
176
|
-
disableRefetchOnMount: true,
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
renders.add({ status, data });
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
function setName(name: string, duration: number) {
|
|
183
|
-
updateItemName(env, 'users', 1, name, {
|
|
184
|
-
optimisticUpdate: true,
|
|
185
|
-
revalidate: true,
|
|
186
|
-
duration,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// perform mutation
|
|
191
|
-
setName('', 530);
|
|
192
|
-
|
|
193
|
-
expect(env.store.getItemState('users||1')).toMatchObject({ name: '' });
|
|
194
|
-
|
|
195
|
-
await sleep(263);
|
|
196
|
-
|
|
197
|
-
setName('T', 662);
|
|
198
|
-
|
|
199
|
-
await sleep(263);
|
|
200
|
-
|
|
201
|
-
setName('Ty', 560);
|
|
202
|
-
|
|
203
|
-
await sleep(300);
|
|
204
|
-
|
|
205
|
-
setName('Typ', 560);
|
|
206
|
-
|
|
207
|
-
await sleep(226);
|
|
208
|
-
|
|
209
|
-
env.serverMock.setFetchDuration(230);
|
|
210
|
-
|
|
211
|
-
setName('Type', 523);
|
|
212
|
-
|
|
213
|
-
await env.serverMock.waitFetchIdle(500, 1500);
|
|
214
|
-
|
|
215
|
-
expect(env.store.getItemState('users||1')).toMatchObject({ name: 'Type' });
|
|
216
|
-
|
|
217
|
-
expect(renders.snapshot).toMatchSnapshotString(`
|
|
218
|
-
"
|
|
219
|
-
status: success -- data: {id:1, name:User 1}
|
|
220
|
-
status: success -- data: {id:1, name:}
|
|
221
|
-
status: success -- data: {id:1, name:T}
|
|
222
|
-
status: success -- data: {id:1, name:Ty}
|
|
223
|
-
status: success -- data: {id:1, name:Typ}
|
|
224
|
-
status: success -- data: {id:1, name:Type}
|
|
225
|
-
"
|
|
226
|
-
`);
|
|
227
|
-
|
|
228
|
-
expect(env.serverMock.fetchsCount).toBe(1);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test.concurrent(
|
|
232
|
-
'user updating the name of a record, but a RTU is received for a table while the update is in progress',
|
|
233
|
-
async () => {
|
|
234
|
-
const env = createTestEnv({
|
|
235
|
-
initialServerData,
|
|
236
|
-
useLoadedSnapshot: { tables: ['users', 'products'] },
|
|
237
|
-
emulateRTU: true,
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
const renders = createRenderStore();
|
|
241
|
-
|
|
242
|
-
env.serverMock.setFetchDuration([200, 400]);
|
|
243
|
-
|
|
244
|
-
renderHook(() => {
|
|
245
|
-
const { data, status } = env.store.useItem('users||1', {
|
|
246
|
-
returnRefetchingStatus: true,
|
|
247
|
-
disableRefetchOnMount: true,
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
renders.add({ status, data });
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
updateItemName(env, 'users', 1, 'newName', {
|
|
254
|
-
optimisticUpdate: true,
|
|
255
|
-
revalidate: true,
|
|
256
|
-
duration: 400,
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
await sleep(350);
|
|
260
|
-
|
|
261
|
-
env.serverMock.produceData((data) => {
|
|
262
|
-
data.users![0]!.name = 'RTU';
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
await env.serverMock.waitFetchIdle();
|
|
266
|
-
|
|
267
|
-
expect(env.store.getItemState('users||1')).toMatchObject({ name: 'RTU' });
|
|
268
|
-
|
|
269
|
-
expect(env.serverMock.fetchsCount).toBe(1);
|
|
270
|
-
|
|
271
|
-
expect(renders.snapshot).toMatchSnapshotString(`
|
|
272
|
-
"
|
|
273
|
-
status: success -- data: {id:1, name:User 1}
|
|
274
|
-
status: success -- data: {id:1, name:newName}
|
|
275
|
-
status: refetching -- data: {id:1, name:newName}
|
|
276
|
-
status: success -- data: {id:1, name:RTU}
|
|
277
|
-
"
|
|
278
|
-
`);
|
|
279
|
-
},
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
test.concurrent('creation mutation with id generated by server', async () => {
|
|
283
|
-
const env = createTestEnv({
|
|
284
|
-
initialServerData,
|
|
285
|
-
useLoadedSnapshot: { tables: ['users'] },
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
const renders = createRenderStore();
|
|
289
|
-
|
|
290
|
-
env.serverMock.setFetchDuration([200, 400]);
|
|
291
|
-
|
|
292
|
-
renderHook(() => {
|
|
293
|
-
const { items, status } = env.store.useListQuery(
|
|
294
|
-
{ tableId: 'users' },
|
|
295
|
-
{
|
|
296
|
-
returnRefetchingStatus: true,
|
|
297
|
-
disableRefetchOnMount: true,
|
|
298
|
-
itemSelector(data) {
|
|
299
|
-
return data;
|
|
300
|
-
},
|
|
301
|
-
},
|
|
302
|
-
);
|
|
303
|
-
|
|
304
|
-
renders.add({ status, items });
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
addItemWithIdGeneratedByServer(env, 'users', 'newUser', {
|
|
308
|
-
revalidate: true,
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
await env.serverMock.waitFetchIdle(0, 1500);
|
|
312
|
-
|
|
313
|
-
expect(env.serverMock.fetchsCount).toBe(1);
|
|
314
|
-
|
|
315
|
-
expect(renders.getSnapshot({ arrays: 'all' })).toMatchSnapshotString(`
|
|
316
|
-
"
|
|
317
|
-
status: success -- items: [{id:1, name:User 1}, {id:2, name:User 2}, {id:3, name:User 3}, {id:4, name:User 4}, {id:5, name:User 5}]
|
|
318
|
-
status: refetching -- items: [{id:1, name:User 1}, {id:2, name:User 2}, {id:3, name:User 3}, {id:4, name:User 4}, {id:5, name:User 5}]
|
|
319
|
-
status: success -- items: [{id:1, name:User 1}, {id:2, name:User 2}, {id:3, name:User 3}, {id:4, name:User 4}, {id:5, name:User 5}, {id:6, name:newUser}]
|
|
320
|
-
"
|
|
321
|
-
`);
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
test.concurrent('creation mutation with id generated by client', async () => {
|
|
325
|
-
const env = createTestEnv({
|
|
326
|
-
initialServerData,
|
|
327
|
-
useLoadedSnapshot: { tables: ['users'] },
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
const renders = createRenderStore();
|
|
331
|
-
|
|
332
|
-
env.serverMock.setFetchDuration([200, 400]);
|
|
333
|
-
|
|
334
|
-
renderHook(() => {
|
|
335
|
-
const { items, status } = env.store.useListQuery(
|
|
336
|
-
{ tableId: 'users' },
|
|
337
|
-
{
|
|
338
|
-
returnRefetchingStatus: true,
|
|
339
|
-
disableRefetchOnMount: true,
|
|
340
|
-
itemSelector(data) {
|
|
341
|
-
return data;
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
renders.add({ status, items });
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
addItemWithIdGeneratedByClient(env, 'users', '7', 'newUser', {
|
|
350
|
-
revalidate: true,
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
await sleep(10);
|
|
354
|
-
|
|
355
|
-
const mountWihtItemRenders = createRenderStore();
|
|
356
|
-
|
|
357
|
-
// mount comp to check if the mount loading is a problem
|
|
358
|
-
renderHook(() => {
|
|
359
|
-
const { data, status } = env.store.useItem('users||7', {
|
|
360
|
-
returnRefetchingStatus: true,
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
mountWihtItemRenders.add({ status, data });
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
await env.serverMock.waitFetchIdle(0, 1500);
|
|
367
|
-
|
|
368
|
-
expect(env.serverMock.fetchsCount).toBe(2);
|
|
369
|
-
|
|
370
|
-
expect(renders.getSnapshot({ arrays: 'all' })).toMatchSnapshotString(`
|
|
371
|
-
"
|
|
372
|
-
status: success -- items: [{id:1, name:User 1}, {id:2, name:User 2}, {id:3, name:User 3}, {id:4, name:User 4}, {id:5, name:User 5}]
|
|
373
|
-
status: refetching -- items: [{id:1, name:User 1}, {id:2, name:User 2}, {id:3, name:User 3}, {id:4, name:User 4}, {id:5, name:User 5}]
|
|
374
|
-
status: success -- items: [{id:1, name:User 1}, {id:2, name:User 2}, {id:3, name:User 3}, {id:4, name:User 4}, {id:5, name:User 5}, {id:7, name:newUser}]
|
|
375
|
-
"
|
|
376
|
-
`);
|
|
377
|
-
|
|
378
|
-
expect(mountWihtItemRenders.getSnapshot({ arrays: 'all' }))
|
|
379
|
-
.toMatchSnapshotString(`
|
|
380
|
-
"
|
|
381
|
-
status: success -- data: {id:7, name:newUser}
|
|
382
|
-
status: refetching -- data: {id:7, name:newUser}
|
|
383
|
-
status: success -- data: {id:7, name:newUser}
|
|
384
|
-
"
|
|
385
|
-
`);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
test.concurrent(
|
|
389
|
-
'user change multiple records in sequence with RTU enabled',
|
|
390
|
-
async () => {
|
|
391
|
-
const env = createTestEnv({
|
|
392
|
-
initialServerData,
|
|
393
|
-
useLoadedSnapshot: { tables: ['users'] },
|
|
394
|
-
emulateRTU: true,
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
const renders = createRenderStore();
|
|
398
|
-
|
|
399
|
-
env.serverMock.setFetchDuration([200, 400]);
|
|
400
|
-
|
|
401
|
-
renderHook(() => {
|
|
402
|
-
const { items, status } = env.store.useListQuery(
|
|
403
|
-
{ tableId: 'users' },
|
|
404
|
-
{
|
|
405
|
-
returnRefetchingStatus: true,
|
|
406
|
-
disableRefetchOnMount: true,
|
|
407
|
-
itemSelector(data) {
|
|
408
|
-
return `${data.id}:${data.name}`;
|
|
409
|
-
},
|
|
410
|
-
},
|
|
411
|
-
);
|
|
412
|
-
|
|
413
|
-
renders.add({ status, items });
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
function updateName(itemId: number, newName: string) {
|
|
417
|
-
updateItemName(env, 'users', itemId, newName, {
|
|
418
|
-
revalidate: false,
|
|
419
|
-
optimisticUpdate: true,
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
updateName(1, '✅');
|
|
424
|
-
|
|
425
|
-
await sleep(200);
|
|
426
|
-
|
|
427
|
-
updateName(2, '❌');
|
|
428
|
-
|
|
429
|
-
await sleep(250);
|
|
430
|
-
|
|
431
|
-
updateName(3, '✅');
|
|
432
|
-
|
|
433
|
-
await sleep(230);
|
|
434
|
-
|
|
435
|
-
updateName(4, '❌');
|
|
436
|
-
|
|
437
|
-
await sleep(250);
|
|
438
|
-
|
|
439
|
-
updateName(5, '✅');
|
|
440
|
-
|
|
441
|
-
await sleep(250);
|
|
442
|
-
|
|
443
|
-
updateName(3, '❌');
|
|
444
|
-
|
|
445
|
-
await sleep(250);
|
|
446
|
-
|
|
447
|
-
await env.serverMock.waitFetchIdle(400, 1500);
|
|
448
|
-
|
|
449
|
-
expect(renders.getSnapshot({ arrays: 'all' })).toMatchSnapshotString(`
|
|
450
|
-
"
|
|
451
|
-
status: success -- items: [1:User 1, 2:User 2, 3:User 3, 4:User 4, 5:User 5]
|
|
452
|
-
status: success -- items: [1:✅, 2:User 2, 3:User 3, 4:User 4, 5:User 5]
|
|
453
|
-
status: success -- items: [1:✅, 2:❌, 3:User 3, 4:User 4, 5:User 5]
|
|
454
|
-
status: success -- items: [1:✅, 2:❌, 3:✅, 4:User 4, 5:User 5]
|
|
455
|
-
status: success -- items: [1:✅, 2:❌, 3:✅, 4:❌, 5:User 5]
|
|
456
|
-
status: success -- items: [1:✅, 2:❌, 3:✅, 4:❌, 5:✅]
|
|
457
|
-
status: success -- items: [1:✅, 2:❌, 3:❌, 4:❌, 5:✅]
|
|
458
|
-
status: refetching -- items: [1:✅, 2:❌, 3:❌, 4:❌, 5:✅]
|
|
459
|
-
status: success -- items: [1:✅, 2:❌, 3:❌, 4:❌, 5:✅]
|
|
460
|
-
"
|
|
461
|
-
`);
|
|
462
|
-
},
|
|
463
|
-
);
|
|
464
|
-
|
|
465
|
-
test.concurrent(
|
|
466
|
-
'query receives a RTU while the query is loading by the component mount',
|
|
467
|
-
async () => {
|
|
468
|
-
const env = createTestEnv({
|
|
469
|
-
initialServerData,
|
|
470
|
-
emulateRTU: true,
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
const renders = createRenderStore();
|
|
474
|
-
|
|
475
|
-
env.serverMock.setFetchDuration(400);
|
|
476
|
-
|
|
477
|
-
renderHook(() => {
|
|
478
|
-
const { data, status } = env.store.useItem('users||2', {
|
|
479
|
-
returnRefetchingStatus: true,
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
renders.add({ status, data });
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
await sleep(50);
|
|
486
|
-
|
|
487
|
-
env.serverMock.produceData((draft) => {
|
|
488
|
-
draft['users']![1]!.name = '✅';
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
await env.serverMock.waitFetchIdle(400, 1500);
|
|
492
|
-
|
|
493
|
-
expect(renders.snapshot).toMatchSnapshotString(`
|
|
494
|
-
"
|
|
495
|
-
status: loading -- data: null
|
|
496
|
-
status: success -- data: {id:2, name:✅}
|
|
497
|
-
"
|
|
498
|
-
`);
|
|
499
|
-
},
|
|
500
|
-
);
|
|
501
|
-
|
|
502
|
-
test.concurrent('delete mutation with RTU', async () => {
|
|
503
|
-
const env = createTestEnv({
|
|
504
|
-
initialServerData,
|
|
505
|
-
useLoadedSnapshot: { tables: ['users'] },
|
|
506
|
-
emulateRTU: true,
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
const renders = createRenderStore();
|
|
510
|
-
|
|
511
|
-
env.serverMock.setFetchDuration(400);
|
|
512
|
-
|
|
513
|
-
renderHook(() => {
|
|
514
|
-
const { items, status } = env.store.useListQuery(
|
|
515
|
-
{ tableId: 'users' },
|
|
516
|
-
{
|
|
517
|
-
returnRefetchingStatus: true,
|
|
518
|
-
disableRefetchOnMount: true,
|
|
519
|
-
itemSelector(data) {
|
|
520
|
-
return data.name;
|
|
521
|
-
},
|
|
522
|
-
},
|
|
523
|
-
);
|
|
524
|
-
|
|
525
|
-
renders.add({ status, items });
|
|
526
|
-
});
|
|
527
|
-
|
|
528
|
-
deleteItem(env, 'users', 2, { optimisticUpdate: true, duration: 600 });
|
|
529
|
-
|
|
530
|
-
await env.serverMock.waitFetchIdle(0, 1500);
|
|
531
|
-
|
|
532
|
-
expect(renders.getSnapshot({ arrays: 'all' })).toMatchSnapshotString(`
|
|
533
|
-
"
|
|
534
|
-
status: success -- items: [User 1, User 2, User 3, User 4, User 5]
|
|
535
|
-
status: success -- items: [User 1, User 3, User 4, User 5]
|
|
536
|
-
status: refetching -- items: [User 1, User 3, User 4, User 5]
|
|
537
|
-
status: success -- items: [User 1, User 3, User 4, User 5]
|
|
538
|
-
"
|
|
539
|
-
`);
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
test.concurrent('creation mutation with RTU', async () => {
|
|
543
|
-
const env = createTestEnv({
|
|
544
|
-
initialServerData,
|
|
545
|
-
useLoadedSnapshot: { tables: ['users'] },
|
|
546
|
-
emulateRTU: true,
|
|
547
|
-
});
|
|
548
|
-
|
|
549
|
-
const renders = createRenderStore();
|
|
550
|
-
|
|
551
|
-
env.serverMock.setFetchDuration(400);
|
|
552
|
-
|
|
553
|
-
renderHook(() => {
|
|
554
|
-
const { items, status } = env.store.useListQuery(
|
|
555
|
-
{ tableId: 'users' },
|
|
556
|
-
{
|
|
557
|
-
returnRefetchingStatus: true,
|
|
558
|
-
disableRefetchOnMount: true,
|
|
559
|
-
itemSelector(data) {
|
|
560
|
-
return data.name;
|
|
561
|
-
},
|
|
562
|
-
},
|
|
563
|
-
);
|
|
564
|
-
|
|
565
|
-
renders.add({ status, items });
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
addItemWithIdGeneratedByClient(env, 'users', '8', '🆕');
|
|
569
|
-
|
|
570
|
-
await env.serverMock.waitFetchIdle(0, 1500);
|
|
571
|
-
|
|
572
|
-
expect(renders.getSnapshot({ arrays: 'all' })).toMatchSnapshotString(`
|
|
573
|
-
"
|
|
574
|
-
status: success -- items: [User 1, User 2, User 3, User 4, User 5]
|
|
575
|
-
status: refetching -- items: [User 1, User 2, User 3, User 4, User 5]
|
|
576
|
-
status: success -- items: [User 1, User 2, User 3, User 4, User 5, 🆕]
|
|
577
|
-
"
|
|
578
|
-
`);
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
test.concurrent('simple update mutation with RTU', async () => {
|
|
582
|
-
const env = createTestEnv({
|
|
583
|
-
initialServerData,
|
|
584
|
-
useLoadedSnapshot: { tables: ['users'] },
|
|
585
|
-
emulateRTU: true,
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
const renders = createRenderStore();
|
|
589
|
-
|
|
590
|
-
env.serverMock.setFetchDuration(400);
|
|
591
|
-
|
|
592
|
-
renderHook(() => {
|
|
593
|
-
const { items, status } = env.store.useListQuery(
|
|
594
|
-
{ tableId: 'users' },
|
|
595
|
-
{
|
|
596
|
-
returnRefetchingStatus: true,
|
|
597
|
-
disableRefetchOnMount: true,
|
|
598
|
-
itemSelector(data) {
|
|
599
|
-
return data.name;
|
|
600
|
-
},
|
|
601
|
-
},
|
|
602
|
-
);
|
|
603
|
-
|
|
604
|
-
renders.add({ status, items });
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
updateItemName(env, 'users', 5, '🆕');
|
|
608
|
-
|
|
609
|
-
await env.serverMock.waitFetchIdle(0, 1500);
|
|
610
|
-
|
|
611
|
-
expect(renders.getSnapshot({ arrays: 'all' })).toMatchSnapshotString(`
|
|
612
|
-
"
|
|
613
|
-
status: success -- items: [User 1, User 2, User 3, User 4, User 5]
|
|
614
|
-
status: refetching -- items: [User 1, User 2, User 3, User 4, User 5]
|
|
615
|
-
status: success -- items: [User 1, User 2, User 3, User 4, 🆕]
|
|
616
|
-
"
|
|
617
|
-
`);
|
|
618
|
-
});
|
|
619
|
-
|
|
620
|
-
test.concurrent('RTU throttling', async () => {
|
|
621
|
-
const env = createTestEnv({
|
|
622
|
-
initialServerData,
|
|
623
|
-
useLoadedSnapshot: { tables: ['users'] },
|
|
624
|
-
emulateRTU: true,
|
|
625
|
-
dynamicRTUThrottleMs(lastDuration) {
|
|
626
|
-
if (lastDuration < 100) {
|
|
627
|
-
return 200;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
return 300;
|
|
631
|
-
},
|
|
632
|
-
});
|
|
633
|
-
|
|
634
|
-
const renders = createRenderStore();
|
|
635
|
-
|
|
636
|
-
renderHook(() => {
|
|
637
|
-
const { items, status } = env.store.useListQuery(
|
|
638
|
-
{ tableId: 'users' },
|
|
639
|
-
{
|
|
640
|
-
returnRefetchingStatus: true,
|
|
641
|
-
disableRefetchOnMount: true,
|
|
642
|
-
itemSelector(data) {
|
|
643
|
-
return data.name;
|
|
644
|
-
},
|
|
645
|
-
},
|
|
646
|
-
);
|
|
647
|
-
|
|
648
|
-
renders.add({ status, items });
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
const waitUntil = waitElapsedTime();
|
|
652
|
-
|
|
653
|
-
env.serverMock.setFetchDuration(200);
|
|
654
|
-
|
|
655
|
-
updateItemName(env, 'users', 5, '1', { duration: 100 });
|
|
656
|
-
|
|
657
|
-
await waitUntil(350);
|
|
658
|
-
|
|
659
|
-
env.serverMock.setFetchDuration(30);
|
|
660
|
-
|
|
661
|
-
updateItemName(env, 'users', 5, '2', { duration: 100 });
|
|
662
|
-
|
|
663
|
-
await waitUntil(670);
|
|
664
|
-
|
|
665
|
-
updateItemName(env, 'users', 5, '3', { duration: 100 });
|
|
666
|
-
|
|
667
|
-
await waitUntil(900);
|
|
668
|
-
|
|
669
|
-
expect(
|
|
670
|
-
env.serverMock.fetchs[1]!.time.start - env.serverMock.fetchs[0]!.time.end,
|
|
671
|
-
).toBeGreaterThanOrEqual(300);
|
|
672
|
-
|
|
673
|
-
const diffLastFetch =
|
|
674
|
-
env.serverMock.fetchs[2]!.time.start - env.serverMock.fetchs[1]!.time.end;
|
|
675
|
-
|
|
676
|
-
expect(diffLastFetch).toBeGreaterThanOrEqual(200);
|
|
677
|
-
expect(diffLastFetch).toBeLessThan(300);
|
|
678
|
-
|
|
679
|
-
expect(renders.getSnapshot({ arrays: 'firstAndLast' }))
|
|
680
|
-
.toMatchSnapshotString(`
|
|
681
|
-
"
|
|
682
|
-
status: success -- items: [User 1, ...(3 between), User 5]
|
|
683
|
-
status: refetching -- items: [User 1, ...(3 between), User 5]
|
|
684
|
-
status: success -- items: [User 1, ...(3 between), 1]
|
|
685
|
-
status: refetching -- items: [User 1, ...(3 between), 1]
|
|
686
|
-
status: success -- items: [User 1, ...(3 between), 2]
|
|
687
|
-
status: refetching -- items: [User 1, ...(3 between), 2]
|
|
688
|
-
status: success -- items: [User 1, ...(3 between), 3]
|
|
689
|
-
"
|
|
690
|
-
`);
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
test.concurrent('mount component after a RTU', async () => {
|
|
694
|
-
const env = createTestEnv({
|
|
695
|
-
initialServerData,
|
|
696
|
-
useLoadedSnapshot: { tables: ['users'] },
|
|
697
|
-
emulateRTU: true,
|
|
698
|
-
dynamicRTUThrottleMs(lastDuration) {
|
|
699
|
-
if (lastDuration < 100) {
|
|
700
|
-
return 200;
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
return 300;
|
|
704
|
-
},
|
|
705
|
-
});
|
|
706
|
-
|
|
707
|
-
const renders = createRenderStore();
|
|
708
|
-
|
|
709
|
-
env.serverMock.produceData((draft) => {
|
|
710
|
-
draft['users']?.push({
|
|
711
|
-
id: 6,
|
|
712
|
-
name: 'User 6',
|
|
713
|
-
});
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
await sleep(100);
|
|
717
|
-
|
|
718
|
-
expect(env.store.store.state.queries).toMatchSnapshotString(`
|
|
719
|
-
{
|
|
720
|
-
"[{\\"tableId\\":\\"users\\"}]": {
|
|
721
|
-
"error": null,
|
|
722
|
-
"hasMore": false,
|
|
723
|
-
"items": [
|
|
724
|
-
"users||1",
|
|
725
|
-
"users||2",
|
|
726
|
-
"users||3",
|
|
727
|
-
"users||4",
|
|
728
|
-
"users||5",
|
|
729
|
-
],
|
|
730
|
-
"payload": {
|
|
731
|
-
"tableId": "users",
|
|
732
|
-
},
|
|
733
|
-
"refetchOnMount": "realtimeUpdate",
|
|
734
|
-
"status": "success",
|
|
735
|
-
"wasLoaded": true,
|
|
736
|
-
},
|
|
737
|
-
}
|
|
738
|
-
`);
|
|
739
|
-
|
|
740
|
-
renderHook(() => {
|
|
741
|
-
const { items, status } = env.store.useListQuery(
|
|
742
|
-
{ tableId: 'users' },
|
|
743
|
-
{
|
|
744
|
-
returnRefetchingStatus: true,
|
|
745
|
-
disableRefetchOnMount: true,
|
|
746
|
-
itemSelector(data) {
|
|
747
|
-
return data.name;
|
|
748
|
-
},
|
|
749
|
-
},
|
|
750
|
-
);
|
|
751
|
-
|
|
752
|
-
renders.add({ status, items });
|
|
753
|
-
});
|
|
754
|
-
|
|
755
|
-
await env.serverMock.waitFetchIdle(0, 1500);
|
|
756
|
-
|
|
757
|
-
expect(renders.getSnapshot({ arrays: 'all' })).toMatchSnapshotString(`
|
|
758
|
-
"
|
|
759
|
-
status: success -- items: [User 1, User 2, User 3, User 4, User 5]
|
|
760
|
-
status: refetching -- items: [User 1, User 2, User 3, User 4, User 5]
|
|
761
|
-
status: success -- items: [User 1, User 2, User 3, User 4, User 5, User 6]
|
|
762
|
-
"
|
|
763
|
-
`);
|
|
764
|
-
});
|