shelflife-react-hooks 1.0.0 → 1.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.
- package/package.json +8 -5
- package/src/context/__tests__/contexts.test.tsx +114 -98
- package/vitest.config.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shelflife-react-hooks",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Preisler25",
|
|
@@ -14,20 +14,23 @@
|
|
|
14
14
|
},
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
17
18
|
"import": "./dist/index.esm.js",
|
|
18
19
|
"require": "./dist/index.cjs.js"
|
|
19
20
|
}
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"@
|
|
24
|
-
"
|
|
23
|
+
"@testing-library/dom": "^10.4.1",
|
|
24
|
+
"@testing-library/react": "^16.3.2",
|
|
25
|
+
"@types/node": "^25.2.3",
|
|
26
|
+
"@types/react": "^19.0.0",
|
|
27
|
+
"jsdom": "^28.1.0",
|
|
25
28
|
"ts-node": "^10.9.2",
|
|
26
29
|
"tsup": "^8.5.1",
|
|
27
30
|
"typescript": "^5.9.3",
|
|
28
31
|
"vitest": "^2.1.9"
|
|
29
32
|
},
|
|
30
33
|
"peerDependencies": {
|
|
31
|
-
"react": "^
|
|
34
|
+
"react": "^19.0.0"
|
|
32
35
|
}
|
|
33
36
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { render, waitFor } from '@testing-library/react';
|
|
3
3
|
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
4
4
|
|
|
5
5
|
import {
|
|
@@ -83,14 +83,16 @@ describe('AuthContext', () => {
|
|
|
83
83
|
|
|
84
84
|
const ctxRef: { current?: ReturnType<typeof useAuth> } = {};
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
<
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
render(
|
|
87
|
+
<AuthProvider baseUrl={baseUrl}>
|
|
88
|
+
<AuthProbe onReady={(value) => {
|
|
89
|
+
ctxRef.current = value;
|
|
90
|
+
}} />
|
|
91
|
+
</AuthProvider>
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
await waitFor(() => {
|
|
95
|
+
expect(ctxRef.current).toBeDefined();
|
|
94
96
|
});
|
|
95
97
|
|
|
96
98
|
const ctx = ctxRef.current;
|
|
@@ -98,12 +100,12 @@ describe('AuthContext', () => {
|
|
|
98
100
|
throw new Error('Auth context not ready');
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
await
|
|
102
|
-
await ctx.login({ email: 'user@example.com', password: 'pass' });
|
|
103
|
-
});
|
|
103
|
+
await ctx.login({ email: 'user@example.com', password: 'pass' });
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
await waitFor(() => {
|
|
106
|
+
expect(ctxRef.current?.token).toBe('token-123');
|
|
107
|
+
expect(ctxRef.current?.user).toEqual({ id: 1, username: 'jane', admin: false });
|
|
108
|
+
});
|
|
107
109
|
});
|
|
108
110
|
});
|
|
109
111
|
|
|
@@ -117,14 +119,16 @@ describe('InviteContext', () => {
|
|
|
117
119
|
|
|
118
120
|
const ctxRef: { current?: ReturnType<typeof useInvites> } = {};
|
|
119
121
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
<
|
|
123
|
-
<
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
render(
|
|
123
|
+
<AuthProvider baseUrl={baseUrl} initialToken="token">
|
|
124
|
+
<InviteProvider baseUrl={baseUrl}>
|
|
125
|
+
<ProviderProbe useHook={useInvites} onReady={(value) => { ctxRef.current = value; }} />
|
|
126
|
+
</InviteProvider>
|
|
127
|
+
</AuthProvider>
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
await waitFor(() => {
|
|
131
|
+
expect(ctxRef.current).toBeDefined();
|
|
128
132
|
});
|
|
129
133
|
|
|
130
134
|
const ctx = ctxRef.current;
|
|
@@ -132,11 +136,11 @@ describe('InviteContext', () => {
|
|
|
132
136
|
throw new Error('Invite context not ready');
|
|
133
137
|
}
|
|
134
138
|
|
|
135
|
-
await
|
|
136
|
-
await ctx.fetchInvites();
|
|
137
|
-
});
|
|
139
|
+
await ctx.fetchInvites();
|
|
138
140
|
|
|
139
|
-
|
|
141
|
+
await waitFor(() => {
|
|
142
|
+
expect(ctxRef.current?.invites).toHaveLength(1);
|
|
143
|
+
});
|
|
140
144
|
});
|
|
141
145
|
});
|
|
142
146
|
|
|
@@ -150,14 +154,16 @@ describe('ProductContext', () => {
|
|
|
150
154
|
|
|
151
155
|
const ctxRef: { current?: ReturnType<typeof useProducts> } = {};
|
|
152
156
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
<
|
|
156
|
-
<
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
render(
|
|
158
|
+
<AuthProvider baseUrl={baseUrl} initialToken="token">
|
|
159
|
+
<ProductProvider baseUrl={baseUrl}>
|
|
160
|
+
<ProviderProbe useHook={useProducts} onReady={(value) => { ctxRef.current = value; }} />
|
|
161
|
+
</ProductProvider>
|
|
162
|
+
</AuthProvider>
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
await waitFor(() => {
|
|
166
|
+
expect(ctxRef.current).toBeDefined();
|
|
161
167
|
});
|
|
162
168
|
|
|
163
169
|
const ctx = ctxRef.current;
|
|
@@ -165,11 +171,11 @@ describe('ProductContext', () => {
|
|
|
165
171
|
throw new Error('Product context not ready');
|
|
166
172
|
}
|
|
167
173
|
|
|
168
|
-
await
|
|
169
|
-
await ctx.fetchProducts();
|
|
170
|
-
});
|
|
174
|
+
await ctx.fetchProducts();
|
|
171
175
|
|
|
172
|
-
|
|
176
|
+
await waitFor(() => {
|
|
177
|
+
expect(ctxRef.current?.products).toHaveLength(1);
|
|
178
|
+
});
|
|
173
179
|
});
|
|
174
180
|
});
|
|
175
181
|
|
|
@@ -188,14 +194,16 @@ describe('RunningLowContext', () => {
|
|
|
188
194
|
|
|
189
195
|
const ctxRef: { current?: ReturnType<typeof useRunningLow> } = {};
|
|
190
196
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
<
|
|
194
|
-
<
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
render(
|
|
198
|
+
<AuthProvider baseUrl={baseUrl} initialToken="token">
|
|
199
|
+
<RunningLowProvider baseUrl={baseUrl}>
|
|
200
|
+
<ProviderProbe useHook={useRunningLow} onReady={(value) => { ctxRef.current = value; }} />
|
|
201
|
+
</RunningLowProvider>
|
|
202
|
+
</AuthProvider>
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
await waitFor(() => {
|
|
206
|
+
expect(ctxRef.current).toBeDefined();
|
|
199
207
|
});
|
|
200
208
|
|
|
201
209
|
const ctx = ctxRef.current;
|
|
@@ -203,11 +211,11 @@ describe('RunningLowContext', () => {
|
|
|
203
211
|
throw new Error('Running low context not ready');
|
|
204
212
|
}
|
|
205
213
|
|
|
206
|
-
await
|
|
207
|
-
await ctx.fetchSettings(1);
|
|
208
|
-
});
|
|
214
|
+
await ctx.fetchSettings(1);
|
|
209
215
|
|
|
210
|
-
|
|
216
|
+
await waitFor(() => {
|
|
217
|
+
expect(ctxRef.current?.settings).toHaveLength(1);
|
|
218
|
+
});
|
|
211
219
|
});
|
|
212
220
|
});
|
|
213
221
|
|
|
@@ -221,14 +229,16 @@ describe('StorageContext', () => {
|
|
|
221
229
|
|
|
222
230
|
const ctxRef: { current?: ReturnType<typeof useStorages> } = {};
|
|
223
231
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
<
|
|
227
|
-
<
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
+
render(
|
|
233
|
+
<AuthProvider baseUrl={baseUrl} initialToken="token">
|
|
234
|
+
<StorageProvider baseUrl={baseUrl}>
|
|
235
|
+
<ProviderProbe useHook={useStorages} onReady={(value) => { ctxRef.current = value; }} />
|
|
236
|
+
</StorageProvider>
|
|
237
|
+
</AuthProvider>
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
await waitFor(() => {
|
|
241
|
+
expect(ctxRef.current).toBeDefined();
|
|
232
242
|
});
|
|
233
243
|
|
|
234
244
|
const ctx = ctxRef.current;
|
|
@@ -236,11 +246,11 @@ describe('StorageContext', () => {
|
|
|
236
246
|
throw new Error('Storage context not ready');
|
|
237
247
|
}
|
|
238
248
|
|
|
239
|
-
await
|
|
240
|
-
await ctx.fetchStorages();
|
|
241
|
-
});
|
|
249
|
+
await ctx.fetchStorages();
|
|
242
250
|
|
|
243
|
-
|
|
251
|
+
await waitFor(() => {
|
|
252
|
+
expect(ctxRef.current?.storages).toHaveLength(1);
|
|
253
|
+
});
|
|
244
254
|
});
|
|
245
255
|
});
|
|
246
256
|
|
|
@@ -259,14 +269,16 @@ describe('StorageItemContext', () => {
|
|
|
259
269
|
|
|
260
270
|
const ctxRef: { current?: ReturnType<typeof useStorageItems> } = {};
|
|
261
271
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
<
|
|
265
|
-
<
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
272
|
+
render(
|
|
273
|
+
<AuthProvider baseUrl={baseUrl} initialToken="token">
|
|
274
|
+
<StorageItemProvider baseUrl={baseUrl}>
|
|
275
|
+
<ProviderProbe useHook={useStorageItems} onReady={(value) => { ctxRef.current = value; }} />
|
|
276
|
+
</StorageItemProvider>
|
|
277
|
+
</AuthProvider>
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
await waitFor(() => {
|
|
281
|
+
expect(ctxRef.current).toBeDefined();
|
|
270
282
|
});
|
|
271
283
|
|
|
272
284
|
const ctx = ctxRef.current;
|
|
@@ -274,11 +286,11 @@ describe('StorageItemContext', () => {
|
|
|
274
286
|
throw new Error('Storage item context not ready');
|
|
275
287
|
}
|
|
276
288
|
|
|
277
|
-
await
|
|
278
|
-
await ctx.fetchItems(1);
|
|
279
|
-
});
|
|
289
|
+
await ctx.fetchItems(1);
|
|
280
290
|
|
|
281
|
-
|
|
291
|
+
await waitFor(() => {
|
|
292
|
+
expect(ctxRef.current?.items).toHaveLength(1);
|
|
293
|
+
});
|
|
282
294
|
});
|
|
283
295
|
});
|
|
284
296
|
|
|
@@ -297,14 +309,16 @@ describe('StorageMemberContext', () => {
|
|
|
297
309
|
|
|
298
310
|
const ctxRef: { current?: ReturnType<typeof useStorageMembers> } = {};
|
|
299
311
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
<
|
|
303
|
-
<
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
312
|
+
render(
|
|
313
|
+
<AuthProvider baseUrl={baseUrl} initialToken="token">
|
|
314
|
+
<StorageMemberProvider baseUrl={baseUrl}>
|
|
315
|
+
<ProviderProbe useHook={useStorageMembers} onReady={(value) => { ctxRef.current = value; }} />
|
|
316
|
+
</StorageMemberProvider>
|
|
317
|
+
</AuthProvider>
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
await waitFor(() => {
|
|
321
|
+
expect(ctxRef.current).toBeDefined();
|
|
308
322
|
});
|
|
309
323
|
|
|
310
324
|
const ctx = ctxRef.current;
|
|
@@ -312,11 +326,11 @@ describe('StorageMemberContext', () => {
|
|
|
312
326
|
throw new Error('Storage member context not ready');
|
|
313
327
|
}
|
|
314
328
|
|
|
315
|
-
await
|
|
316
|
-
await ctx.fetchMembers(1);
|
|
317
|
-
});
|
|
329
|
+
await ctx.fetchMembers(1);
|
|
318
330
|
|
|
319
|
-
|
|
331
|
+
await waitFor(() => {
|
|
332
|
+
expect(ctxRef.current?.members).toHaveLength(1);
|
|
333
|
+
});
|
|
320
334
|
});
|
|
321
335
|
});
|
|
322
336
|
|
|
@@ -330,14 +344,16 @@ describe('UserContext', () => {
|
|
|
330
344
|
|
|
331
345
|
const ctxRef: { current?: ReturnType<typeof useUsers> } = {};
|
|
332
346
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
<
|
|
336
|
-
<
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
347
|
+
render(
|
|
348
|
+
<AuthProvider baseUrl={baseUrl} initialToken="token">
|
|
349
|
+
<UserProvider baseUrl={baseUrl}>
|
|
350
|
+
<ProviderProbe useHook={useUsers} onReady={(value) => { ctxRef.current = value; }} />
|
|
351
|
+
</UserProvider>
|
|
352
|
+
</AuthProvider>
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
await waitFor(() => {
|
|
356
|
+
expect(ctxRef.current).toBeDefined();
|
|
341
357
|
});
|
|
342
358
|
|
|
343
359
|
const ctx = ctxRef.current;
|
|
@@ -345,10 +361,10 @@ describe('UserContext', () => {
|
|
|
345
361
|
throw new Error('User context not ready');
|
|
346
362
|
}
|
|
347
363
|
|
|
348
|
-
await
|
|
349
|
-
await ctx.fetchUsers();
|
|
350
|
-
});
|
|
364
|
+
await ctx.fetchUsers();
|
|
351
365
|
|
|
352
|
-
|
|
366
|
+
await waitFor(() => {
|
|
367
|
+
expect(ctxRef.current?.users).toHaveLength(1);
|
|
368
|
+
});
|
|
353
369
|
});
|
|
354
370
|
});
|