Files
adnify/tests/renderer/components/largeFilePageCache.test.ts
adnaan cf3f9354f9 feat: enhance file reading capabilities and improve large file handling
- Added `alignStartToLine` option to `readTextChunk` for better line alignment during reads.
- Introduced `LargeFilePageCache` to optimize large file chunk caching and retrieval.
- Updated `LargeFileViewer` to utilize the new caching mechanism and improve user experience with seek functionality.
- Enhanced workspace state management to ignore non-persisted changes and focus on relevant file metadata.
- Added tests for new features including chunk reading alignment and cache eviction logic.
2026-08-26 15:32:54 +08:00

39 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { LargeFilePageCache } from '@renderer/components/editor/largeFilePageCache'
import type { TextFileChunk } from '@shared/types/fileChunk'
function page(startOffset: number): TextFileChunk {
return {
content: `page-${startOffset}`,
startOffset,
nextOffset: startOffset + 100,
totalSize: 1_000,
eof: false,
}
}
describe('LargeFilePageCache', () => {
it('evicts the least recently used decoded page at the hard capacity', () => {
const cache = new LargeFilePageCache(2)
cache.set(page(0))
cache.set(page(100))
expect(cache.get(0)?.content).toBe('page-0')
cache.set(page(200))
expect(cache.size).toBe(2)
expect(cache.get(100)).toBeUndefined()
expect(cache.get(0)?.content).toBe('page-0')
expect(cache.get(200)?.content).toBe('page-200')
})
it('replaces an existing page without consuming another slot', () => {
const cache = new LargeFilePageCache(2)
cache.set(page(0))
cache.set({ ...page(0), content: 'updated' })
expect(cache.size).toBe(1)
expect(cache.get(0)?.content).toBe('updated')
})
})