Skip to content

Commit e12f35d

Browse files
mozziusclaude
andcommitted
add a triggers helper to the new posts check tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 069dade commit e12f35d

2 files changed

Lines changed: 16 additions & 29 deletions

File tree

‎src/features/followingV2/home/useNewPostsCheck.test.ts‎

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ async function setup(initial: Partial<Props> = {}) {
111111
}
112112
}
113113

114+
/** The triggers `check` was called with, in order. */
115+
function triggers(check: {mock: {calls: [NewPostsCheckTrigger, unknown][]}}) {
116+
return check.mock.calls.map(([trigger]) => trigger)
117+
}
118+
114119
/** Lets the promises that settle checks run their course. */
115120
async function flush() {
116121
await act(async () => {
@@ -242,12 +247,7 @@ describe('check', () => {
242247
await returnToApp(5 * MINUTE)
243248
await hopToApp()
244249
await advance(10 * MINUTE)
245-
expect(view.check.mock.calls.map(([trigger]) => trigger)).toEqual([
246-
'focus',
247-
'return',
248-
'hop',
249-
'interval',
250-
])
250+
expect(triggers(view.check)).toEqual(['focus', 'return', 'hop', 'interval'])
251251
})
252252

253253
it('is told when the clock was set: the top page, then a successful check', async () => {
@@ -294,7 +294,7 @@ describe('in a memo() component', () => {
294294
await flush()
295295
await returnToApp(5 * MINUTE)
296296

297-
expect(check.mock.calls.map(([trigger]) => trigger)).toEqual(['return'])
297+
expect(triggers(check)).toEqual(['return'])
298298
})
299299
})
300300

@@ -337,9 +337,7 @@ describe('return', () => {
337337
const view = await setup({isBusy: true})
338338
await returnToApp(5 * MINUTE)
339339
await view.update({isBusy: false, topFetchedAt: Date.now()})
340-
expect(view.check.mock.calls.map(([trigger]) => trigger)).toEqual([
341-
'return',
342-
])
340+
expect(triggers(view.check)).toEqual(['return'])
343341
})
344342

345343
it('checks once for held-up returns, as a `return` if any was significant', async () => {
@@ -348,16 +346,11 @@ describe('return', () => {
348346
await returnToApp(5 * MINUTE)
349347
await hopToApp()
350348
await view.update({isBusy: false})
351-
expect(view.check.mock.calls.map(([trigger]) => trigger)).toEqual([
352-
'return',
353-
])
349+
expect(triggers(view.check)).toEqual(['return'])
354350

355351
// The next one starts afresh.
356352
await hopToApp()
357-
expect(view.check.mock.calls.map(([trigger]) => trigger)).toEqual([
358-
'return',
359-
'hop',
360-
])
353+
expect(triggers(view.check)).toEqual(['return', 'hop'])
361354
})
362355

363356
it('is ignored while the view is inactive', async () => {
@@ -389,10 +382,7 @@ describe('return', () => {
389382
// Nor does it make a later hop significant.
390383
await view.update({isActive: true})
391384
await hopToApp()
392-
expect(view.check.mock.calls.map(([trigger]) => trigger)).toEqual([
393-
'focus',
394-
'hop',
395-
])
385+
expect(triggers(view.check)).toEqual(['focus', 'hop'])
396386
})
397387

398388
it('is dropped if the view is left and come back to before it is judged', async () => {
@@ -404,7 +394,7 @@ describe('return', () => {
404394

405395
// Nor does it make a later hop significant.
406396
await hopToApp()
407-
expect(view.check.mock.calls.map(([trigger]) => trigger)).toEqual(['hop'])
397+
expect(triggers(view.check)).toEqual(['hop'])
408398
})
409399
})
410400

@@ -535,10 +525,7 @@ describe('limits', () => {
535525
view.check.mockResolvedValueOnce(true)
536526
response.reject(new Error('Network request failed'))
537527
await flush()
538-
expect(view.check.mock.calls.map(([trigger]) => trigger)).toEqual([
539-
'focus',
540-
'return',
541-
])
528+
expect(triggers(view.check)).toEqual(['focus', 'return'])
542529
expect(view.found()).toEqual(['return'])
543530
})
544531

‎src/features/followingV2/home/useNewPostsCheck.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export function useNewPostsCheck<T>({
6464
interval?: number
6565
/**
6666
* Resolves to what is newer than the top page, or a falsy value if nothing
67-
* is. Rejects if it can't tell, which leaves the clock alone. It's told what
68-
* prompted it, for a surface that shows what it finds differently on a
69-
* significant return, and when the clock was set (`freshAt`), for metrics.
67+
* is. Rejects if it can't tell, which leaves the clock alone. It gets the
68+
* trigger, for surfaces that treat a significant return differently, and
69+
* `freshAt`, when the clock was last set, for metrics.
7070
*/
7171
check: (
7272
trigger: NewPostsCheckTrigger,

0 commit comments

Comments
 (0)