import { describe, expect, it } from 'vitest' import { scrollElementIntoContainer } from '@/lib/scrollElementIntoContainer' describe('scrollElementIntoContainer', () => { it('scrolls down when the target overflows the container bottom', () => { const container = { getBoundingClientRect: () => ({ top: 100, bottom: 300, left: 0, right: 100, width: 100, height: 200 }), scrollTop: 0, } as HTMLElement const target = { getBoundingClientRect: () => ({ top: 280, bottom: 340, left: 0, right: 100, width: 100, height: 60 }), } as HTMLElement scrollElementIntoContainer(container, target) expect(container.scrollTop).toBe(40) }) it('scrolls up when the target overflows the container top', () => { const container = { getBoundingClientRect: () => ({ top: 100, bottom: 300, left: 0, right: 100, width: 100, height: 200 }), scrollTop: 80, } as HTMLElement const target = { getBoundingClientRect: () => ({ top: 60, bottom: 120, left: 0, right: 100, width: 100, height: 60 }), } as HTMLElement scrollElementIntoContainer(container, target) expect(container.scrollTop).toBe(40) }) it('does nothing when the target is already fully visible', () => { const container = { getBoundingClientRect: () => ({ top: 100, bottom: 300, left: 0, right: 100, width: 100, height: 200 }), scrollTop: 12, } as HTMLElement const target = { getBoundingClientRect: () => ({ top: 140, bottom: 200, left: 0, right: 100, width: 100, height: 60 }), } as HTMLElement scrollElementIntoContainer(container, target) expect(container.scrollTop).toBe(12) }) })