feat(files): 文件管理四项——侧栏拖拽移动、草稿跨窗口认领、未命名默认存根目录、打开所在位置(docs/25)
This commit is contained in:
36
tests/window-claims.test.ts
Normal file
36
tests/window-claims.test.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
// 跨窗口草稿认领:别的窗口打开着的文档不该在本窗口再弹恢复提示;
|
||||
// 窗口注销或认领过期后,草稿重新可被提示(真正的崩溃恢复不被吞)。
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { createWindowClaims, CLAIM_STALE_MS } from '../src/services/windowClaims'
|
||||
|
||||
describe('跨窗口文档认领', () => {
|
||||
beforeEach(() => { localStorage.clear() })
|
||||
|
||||
it('其他窗口认领的文档键会被列出,本窗口自己的不算', () => {
|
||||
const a = createWindowClaims('win-a')
|
||||
const b = createWindowClaims('win-b')
|
||||
a.update(['path:C:/docs/a.md'])
|
||||
b.update(['path:C:/docs/b.md'])
|
||||
expect([...b.liveClaimedKeys()]).toEqual(['path:C:/docs/a.md'])
|
||||
expect([...a.liveClaimedKeys()]).toEqual(['path:C:/docs/b.md'])
|
||||
})
|
||||
|
||||
it('窗口注销后其认领立即失效', () => {
|
||||
const a = createWindowClaims('win-a')
|
||||
const b = createWindowClaims('win-b')
|
||||
a.update(['path:C:/docs/a.md'])
|
||||
a.dispose()
|
||||
expect(b.liveClaimedKeys().size).toBe(0)
|
||||
})
|
||||
|
||||
it('认领过期(窗口崩溃未注销)后自动失效,不吞崩溃草稿', () => {
|
||||
let t = 1_000_000
|
||||
const now = () => t
|
||||
const a = createWindowClaims('win-a', localStorage, now)
|
||||
const b = createWindowClaims('win-b', localStorage, now)
|
||||
a.update(['path:C:/docs/a.md'])
|
||||
expect(b.liveClaimedKeys().size).toBe(1)
|
||||
t += CLAIM_STALE_MS + 1
|
||||
expect(b.liveClaimedKeys().size).toBe(0)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user