@@ -18,7 +18,7 @@ describe('useBackgroundJobs', () => {
18
18
const createMockJob = (
19
19
overrides : Partial < BackgroundJob > = { } ,
20
20
) : BackgroundJob => ( {
21
- id : 'test-job-1 ' ,
21
+ id : 'resp_1234567890abcdef1234567890abcdef12345678 ' ,
22
22
status : 'running' ,
23
23
createdAt : '2025-01-01T00:00:00Z' ,
24
24
title : 'Test Job' ,
@@ -28,7 +28,9 @@ describe('useBackgroundJobs', () => {
28
28
describe ( 'initialization and persistence' , ( ) => {
29
29
it ( 'should reset jobs using resetJobs()' , ( ) => {
30
30
const { result } = renderHook ( ( ) => useBackgroundJobs ( ) )
31
- const job = createMockJob ( { id : 'reset-job' } )
31
+ const job = createMockJob ( {
32
+ id : 'resp_abcdef1234567890abcdef1234567890abcdef12' ,
33
+ } )
32
34
act ( ( ) => {
33
35
result . current . addJob ( job )
34
36
} )
@@ -47,8 +49,13 @@ describe('useBackgroundJobs', () => {
47
49
} )
48
50
49
51
it ( 'should load existing jobs from localStorage' , ( ) => {
50
- const job1 = createMockJob ( { id : 'job1' } )
51
- const job2 = createMockJob ( { id : 'job2' , status : 'completed' } )
52
+ const job1 = createMockJob ( {
53
+ id : 'resp_abcdef1234567890abcdef1234567890abcdef11' ,
54
+ } )
55
+ const job2 = createMockJob ( {
56
+ id : 'resp_abcdef1234567890abcdef1234567890abcdef22' ,
57
+ status : 'completed' ,
58
+ } )
52
59
const storedData = { job1, job2 }
53
60
54
61
// Initialize store with existing data using proper API
@@ -96,8 +103,14 @@ describe('useBackgroundJobs', () => {
96
103
97
104
it ( 'should add multiple jobs' , ( ) => {
98
105
const { result } = renderHook ( ( ) => useBackgroundJobs ( ) )
99
- const job1 = createMockJob ( { id : 'job1' , title : 'Job 1' } )
100
- const job2 = createMockJob ( { id : 'job2' , title : 'Job 2' } )
106
+ const job1 = createMockJob ( {
107
+ id : 'resp_abcdef1234567890abcdef1234567890abcdef11' ,
108
+ title : 'Job 1' ,
109
+ } )
110
+ const job2 = createMockJob ( {
111
+ id : 'resp_abcdef1234567890abcdef1234567890abcdef22' ,
112
+ title : 'Job 2' ,
113
+ } )
101
114
102
115
expect ( result . current . jobs ) . toHaveLength ( 0 )
103
116
@@ -134,22 +147,36 @@ describe('useBackgroundJobs', () => {
134
147
135
148
it ( 'should remove a job by id' , ( ) => {
136
149
const { result } = renderHook ( ( ) => useBackgroundJobs ( ) )
137
- const job1 = createMockJob ( { id : 'job1' } )
138
- const job2 = createMockJob ( { id : 'job2' } )
150
+ const job1 = createMockJob ( {
151
+ id : 'resp_abcdef1234567890abcdef1234567890abcdef11' ,
152
+ } )
153
+ const job2 = createMockJob ( {
154
+ id : 'resp_abcdef1234567890abcdef1234567890abcdef22' ,
155
+ } )
139
156
140
157
act ( ( ) => {
141
158
result . current . addJob ( job1 )
142
159
result . current . addJob ( job2 )
143
160
} )
144
161
145
162
act ( ( ) => {
146
- result . current . removeJob ( 'job1' )
163
+ result . current . removeJob (
164
+ 'resp_abcdef1234567890abcdef1234567890abcdef11' ,
165
+ )
147
166
} )
148
167
149
168
expect ( result . current . jobs ) . toHaveLength ( 1 )
150
169
expect ( result . current . jobs ) . toContainEqual ( job2 )
151
- expect ( result . current . getJobById ( 'job1' ) ) . toBeUndefined ( )
152
- expect ( result . current . getJobById ( 'job2' ) ) . toEqual ( job2 )
170
+ expect (
171
+ result . current . getJobById (
172
+ 'resp_abcdef1234567890abcdef1234567890abcdef11' ,
173
+ ) ,
174
+ ) . toBeUndefined ( )
175
+ expect (
176
+ result . current . getJobById (
177
+ 'resp_abcdef1234567890abcdef1234567890abcdef22' ,
178
+ ) ,
179
+ ) . toEqual ( job2 )
153
180
} )
154
181
155
182
it ( 'should handle removing non-existent job gracefully' , ( ) => {
@@ -191,7 +218,9 @@ describe('useBackgroundJobs', () => {
191
218
192
219
it ( 'should handle updating non-existent job gracefully' , ( ) => {
193
220
const { result } = renderHook ( ( ) => useBackgroundJobs ( ) )
194
- const existingJob = createMockJob ( { id : 'existing' } )
221
+ const existingJob = createMockJob ( {
222
+ id : 'resp_abcdef1234567890abcdef1234567890abcdef99' ,
223
+ } )
195
224
196
225
act ( ( ) => {
197
226
result . current . addJob ( existingJob )
@@ -209,8 +238,12 @@ describe('useBackgroundJobs', () => {
209
238
210
239
it ( 'should clear all jobs' , ( ) => {
211
240
const { result } = renderHook ( ( ) => useBackgroundJobs ( ) )
212
- const job1 = createMockJob ( { id : 'job1' } )
213
- const job2 = createMockJob ( { id : 'job2' } )
241
+ const job1 = createMockJob ( {
242
+ id : 'resp_abcdef1234567890abcdef1234567890abcdef11' ,
243
+ } )
244
+ const job2 = createMockJob ( {
245
+ id : 'resp_abcdef1234567890abcdef1234567890abcdef22' ,
246
+ } )
214
247
215
248
act ( ( ) => {
216
249
result . current . addJob ( job1 )
@@ -257,17 +290,17 @@ describe('useBackgroundJobs', () => {
257
290
it ( 'should handle concurrent job operations' , ( ) => {
258
291
const { result } = renderHook ( ( ) => useBackgroundJobs ( ) )
259
292
const runningJob = createMockJob ( {
260
- id : 'concurrent-running-xyz ' ,
293
+ id : 'resp_1111111111111111111111111111111111111111 ' ,
261
294
status : 'running' ,
262
295
title : 'Running Job' ,
263
296
} )
264
297
const completedJob = createMockJob ( {
265
- id : 'concurrent-completed-abc ' ,
298
+ id : 'resp_2222222222222222222222222222222222222222 ' ,
266
299
status : 'completed' ,
267
300
title : 'Completed Job' ,
268
301
} )
269
302
const failedJob = createMockJob ( {
270
- id : 'concurrent-failed-def ' ,
303
+ id : 'resp_3333333333333333333333333333333333333333 ' ,
271
304
status : 'failed' ,
272
305
title : 'Failed Job' ,
273
306
} )
@@ -296,34 +329,45 @@ describe('useBackgroundJobs', () => {
296
329
expect ( result . current . jobs ) . toHaveLength ( 3 )
297
330
298
331
act ( ( ) => {
299
- result . current . removeJob ( 'concurrent-completed-abc' )
332
+ result . current . removeJob (
333
+ 'resp_2222222222222222222222222222222222222222' ,
334
+ )
300
335
} )
301
336
302
337
act ( ( ) => {
303
- result . current . updateJob ( 'concurrent-running-xyz' , {
304
- status : 'completed' ,
305
- } )
338
+ result . current . updateJob (
339
+ 'resp_1111111111111111111111111111111111111111' ,
340
+ {
341
+ status : 'completed' ,
342
+ } ,
343
+ )
306
344
} )
307
345
308
346
expect ( result . current . jobs ) . toHaveLength ( 2 )
309
- expect ( result . current . getJobById ( 'concurrent-running-xyz' ) ?. status ) . toBe (
310
- 'completed' ,
311
- )
312
347
expect (
313
- result . current . getJobById ( 'concurrent-completed-abc' ) ,
348
+ result . current . getJobById (
349
+ 'resp_1111111111111111111111111111111111111111' ,
350
+ ) ?. status ,
351
+ ) . toBe ( 'completed' )
352
+ expect (
353
+ result . current . getJobById (
354
+ 'resp_2222222222222222222222222222222222222222' ,
355
+ ) ,
314
356
) . toBeUndefined ( )
315
- expect ( result . current . getJobById ( 'concurrent-failed-def' ) ) . toEqual (
316
- failedJob ,
317
- )
357
+ expect (
358
+ result . current . getJobById (
359
+ 'resp_3333333333333333333333333333333333333333' ,
360
+ ) ,
361
+ ) . toEqual ( failedJob )
318
362
} )
319
363
320
364
it ( 'should maintain data integrity across browser sessions' , ( ) => {
321
365
const job1 = createMockJob ( {
322
- id : 'browser-session-alpha ' ,
366
+ id : 'resp_6880e725623081a1af3dc14ba0d562620d62da8686c56bdd ' ,
323
367
title : 'Session 1 Job' ,
324
368
} )
325
369
const job2 = createMockJob ( {
326
- id : 'browser-session-beta ' ,
370
+ id : 'resp_7e2b1c8e9f4a3d2b6c1e8f7a9d4c3b2e1f6a8d7c2b3e1f4a6c8d ' ,
327
371
title : 'Session 2 Job' ,
328
372
} )
329
373
@@ -351,30 +395,42 @@ describe('useBackgroundJobs', () => {
351
395
const secondSessionResult = renderHook ( ( ) => useBackgroundJobs ( ) )
352
396
expect ( secondSessionResult . result . current . jobs ) . toHaveLength ( 2 )
353
397
expect (
354
- secondSessionResult . result . current . getJobById ( 'browser-session-alpha' ) ,
398
+ secondSessionResult . result . current . getJobById (
399
+ 'resp_6880e725623081a1af3dc14ba0d562620d62da8686c56bdd' ,
400
+ ) ,
355
401
) . toEqual ( job1 )
356
402
expect (
357
- secondSessionResult . result . current . getJobById ( 'browser-session-beta' ) ,
403
+ secondSessionResult . result . current . getJobById (
404
+ 'resp_7e2b1c8e9f4a3d2b6c1e8f7a9d4c3b2e1f6a8d7c2b3e1f4a6c8d' ,
405
+ ) ,
358
406
) . toEqual ( job2 )
359
407
360
408
act ( ( ) => {
361
- secondSessionResult . result . current . updateJob ( 'browser-session-alpha' , {
362
- status : 'completed' ,
363
- } )
409
+ secondSessionResult . result . current . updateJob (
410
+ 'resp_6880e725623081a1af3dc14ba0d562620d62da8686c56bdd' ,
411
+ {
412
+ status : 'completed' ,
413
+ } ,
414
+ )
364
415
} )
365
416
366
417
expect (
367
- secondSessionResult . result . current . getJobById ( 'browser-session-alpha' )
368
- ?. status ,
418
+ secondSessionResult . result . current . getJobById (
419
+ 'resp_6880e725623081a1af3dc14ba0d562620d62da8686c56bdd' ,
420
+ ) ?. status ,
369
421
) . toBe ( 'completed' )
370
422
371
423
act ( ( ) => {
372
- secondSessionResult . result . current . removeJob ( 'browser-session-beta' )
424
+ secondSessionResult . result . current . removeJob (
425
+ 'resp_7e2b1c8e9f4a3d2b6c1e8f7a9d4c3b2e1f6a8d7c2b3e1f4a6c8d' ,
426
+ )
373
427
} )
374
428
375
429
expect ( secondSessionResult . result . current . jobs ) . toHaveLength ( 1 )
376
430
expect (
377
- secondSessionResult . result . current . getJobById ( 'browser-session-beta' ) ,
431
+ secondSessionResult . result . current . getJobById (
432
+ 'resp_7e2b1c8e9f4a3d2b6c1e8f7a9d4c3b2e1f6a8d7c2b3e1f4a6c8d' ,
433
+ ) ,
378
434
) . toBeUndefined ( )
379
435
380
436
secondSessionResult . unmount ( )
@@ -383,13 +439,15 @@ describe('useBackgroundJobs', () => {
383
439
expect ( thirdSessionResult . result . current . jobs ) . toHaveLength ( 1 )
384
440
385
441
const persistedJob = thirdSessionResult . result . current . getJobById (
386
- 'browser-session-alpha ' ,
442
+ 'resp_6880e725623081a1af3dc14ba0d562620d62da8686c56bdd ' ,
387
443
)
388
444
expect ( persistedJob ) . toBeDefined ( )
389
445
expect ( persistedJob ?. status ) . toBe ( 'completed' )
390
446
expect ( persistedJob ?. title ) . toBe ( 'Session 1 Job' ) // Should preserve other fields
391
447
expect (
392
- thirdSessionResult . result . current . getJobById ( 'browser-session-beta' ) ,
448
+ thirdSessionResult . result . current . getJobById (
449
+ 'resp_7e2b1c8e9f4a3d2b6c1e8f7a9d4c3b2e1f6a8d7c2b3e1f4a6c8d' ,
450
+ ) ,
393
451
) . toBeUndefined ( )
394
452
thirdSessionResult . unmount ( )
395
453
} )
0 commit comments