first commit

This commit is contained in:
baozaotumao2025
2026-07-18 21:10:39 +08:00
commit 1b90e552a5
91 changed files with 9056 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { activity } from '../../../src/auth/activity'
describe('user activity', () => {
beforeEach(() => localStorage.clear())
it('records real input at most once every 30 seconds', () => {
const checkRefresh = vi.fn()
const now = vi.spyOn(Date, 'now').mockReturnValue(1_000_000)
const stop = activity.start(checkRefresh)
window.dispatchEvent(new MouseEvent('click'))
expect(activity.get()).toBe(1_000_000)
now.mockReturnValue(1_010_000)
window.dispatchEvent(new KeyboardEvent('keydown'))
expect(activity.get()).toBe(1_000_000)
now.mockReturnValue(1_031_000)
window.dispatchEvent(new TouchEvent('touchstart'))
expect(activity.get()).toBe(1_031_000)
expect(checkRefresh).toHaveBeenCalledTimes(3)
stop()
})
it('checks on foreground resume without treating visibility as activity', () => {
const checkRefresh = vi.fn()
const stop = activity.start(checkRefresh)
document.dispatchEvent(new Event('visibilitychange'))
expect(checkRefresh).toHaveBeenCalledOnce()
expect(activity.get()).toBe(0)
window.dispatchEvent(new PopStateEvent('popstate'))
expect(activity.get()).toBeGreaterThan(0)
stop()
})
})