mirror of
https://github.com/Heretek-AI/opencode.git
synced 2026-11-22 08:59:26 -10:00
+16
![opencode-agent[bot]](/assets/img/avatar_default.png)



![opencode-agent[bot]](/assets/img/avatar_default.png)



9e0d3976e1
Co-authored-by: Frank <[email protected]> Co-authored-by: Aarav Sareen <[email protected]> Co-authored-by: Brendan Allan <[email protected]> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Jack <[email protected]> Co-authored-by: Brendan Allan <[email protected]> Co-authored-by: Shoubhit Dash <[email protected]> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: James Long <[email protected]> Co-authored-by: Dustin Deus <[email protected]> Co-authored-by: starptech <[email protected]> Co-authored-by: Luke Parker <[email protected]> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <[email protected]> Co-authored-by: Dax <[email protected]> Co-authored-by: usrnk1 <[email protected]> Co-authored-by: Jay <[email protected]> Co-authored-by: runvip <[email protected]> Co-authored-by: opencode <[email protected]> Co-authored-by: Julian Coy <[email protected]> Co-authored-by: Vladimir Glafirov <[email protected]> Co-authored-by: Adam <[email protected]> Co-authored-by: Kit Langton <[email protected]> Co-authored-by: Simon Klee <[email protected]> Co-authored-by: Jay <[email protected]> Co-authored-by: David Hill <[email protected]>
86 lines
2.7 KiB
TypeScript
86 lines
2.7 KiB
TypeScript
import { expect, test } from "bun:test"
|
|
import { createVirtualizer, defaultRangeExtractor } from "@tanstack/solid-virtual"
|
|
import { createRoot, createSignal } from "solid-js"
|
|
import { filterVirtualIndexes } from "@/pages/session/timeline/virtual-items"
|
|
|
|
test("reactive count updates preserve measured row sizes", () => {
|
|
createRoot((dispose) => {
|
|
const [count, setCount] = createSignal(2)
|
|
const virtualizer = createVirtualizer<HTMLDivElement, HTMLDivElement>({
|
|
get count() {
|
|
return count()
|
|
},
|
|
getScrollElement: () => null,
|
|
estimateSize: () => 60,
|
|
initialRect: { width: 800, height: 600 },
|
|
})
|
|
|
|
expect(virtualizer.getTotalSize()).toBe(120)
|
|
virtualizer.resizeItem(0, 100)
|
|
expect(virtualizer.getTotalSize()).toBe(160)
|
|
|
|
setCount(3)
|
|
|
|
expect(virtualizer.itemSizeCache.get(0)).toBe(100)
|
|
expect(virtualizer.getTotalSize()).toBe(220)
|
|
dispose()
|
|
})
|
|
})
|
|
|
|
test("initial rect projects rows before a scroll element connects", () => {
|
|
createRoot((dispose) => {
|
|
const virtualizer = createVirtualizer<HTMLDivElement, HTMLDivElement>({
|
|
count: 100,
|
|
getScrollElement: () => null,
|
|
estimateSize: () => 28,
|
|
initialRect: { width: 0, height: 600 },
|
|
overscan: 10,
|
|
})
|
|
|
|
expect(virtualizer.getVirtualItems().length).toBeGreaterThan(0)
|
|
dispose()
|
|
})
|
|
})
|
|
|
|
test("logical scroll offset includes pending measurement adjustments", () => {
|
|
createRoot((dispose) => {
|
|
const virtualizer = createVirtualizer<HTMLDivElement, HTMLDivElement>({
|
|
count: 2,
|
|
getScrollElement: () => null,
|
|
estimateSize: () => 60,
|
|
initialOffset: 100,
|
|
initialRect: { width: 800, height: 60 },
|
|
})
|
|
|
|
virtualizer.getTotalSize()
|
|
virtualizer.resizeItem(0, 100)
|
|
|
|
expect(virtualizer.scrollOffset).toBe(100)
|
|
expect(virtualizer.getLogicalScrollOffset()).toBe(140)
|
|
dispose()
|
|
})
|
|
})
|
|
|
|
test("stale pinned indexes do not produce missing virtual items after count shrinks", () => {
|
|
createRoot((dispose) => {
|
|
const [count, setCount] = createSignal(2)
|
|
const pinned = [1]
|
|
const virtualizer = createVirtualizer<HTMLDivElement, HTMLDivElement>({
|
|
get count() {
|
|
return count()
|
|
},
|
|
getScrollElement: () => null,
|
|
estimateSize: () => 60,
|
|
initialRect: { width: 800, height: 600 },
|
|
rangeExtractor: (range) =>
|
|
filterVirtualIndexes([...new Set([...defaultRangeExtractor(range), ...pinned])], range.count),
|
|
})
|
|
|
|
expect(virtualizer.getVirtualItems().map((item) => item.index)).toEqual([0, 1])
|
|
setCount(1)
|
|
expect(virtualizer.getVirtualItems().map((item) => item.index)).toEqual([0])
|
|
expect(() => new Map(virtualizer.getVirtualItems().map((item) => [item.key, item]))).not.toThrow()
|
|
dispose()
|
|
})
|
|
})
|