index-client.spec.ts 976 B

1234567891011121314151617181920
  1. import { describe, expect, it } from 'vitest'
  2. import { createIndexSelection, isNewerIndexView } from '../src/client/index-state'
  3. describe('索引界面的会话与请求隔离', () => {
  4. it('不同会话选择不同书,不建立全局当前书状态', () => {
  5. const selection = createIndexSelection()
  6. selection.choose('session-a', 'book:a')
  7. selection.choose('session-b', 'book:b')
  8. expect(selection.get('session-a')).toBe('book:a')
  9. expect(selection.get('session-b')).toBe('book:b')
  10. selection.dispose()
  11. expect(selection.get('session-a')).toBeUndefined()
  12. })
  13. it('控制操作后的新代次不能被迟到轮询回退', () => {
  14. const newest = { generation: 5, updatedAt: 2000 }
  15. expect(isNewerIndexView(newest, { generation: 4, updatedAt: 3000 })).toBe(false)
  16. expect(isNewerIndexView(newest, { generation: 5, updatedAt: 1999 })).toBe(false)
  17. expect(isNewerIndexView(newest, { generation: 6, updatedAt: 2000 })).toBe(true)
  18. })
  19. })