import { describe, expect, it } from "vitest"; import { lineForTop, monotonic, topForLine } from "$lib/components/ui/markdownScroll"; const anchors = [ { line: 0, top: 0 }, { line: 4, top: 100 }, { line: 10, top: 400 } ]; describe("topForLine", () => { it("interpolates between the surrounding anchors", () => { expect(topForLine(anchors, 2)).toBe(50); expect(topForLine(anchors, 7)).toBe(250); }); it("clamps past the last anchor", () => { expect(topForLine(anchors, 20)).toBe(400); }); }); describe("lineForTop", () => { it("inverts topForLine", () => { expect(lineForTop(anchors, 250)).toBe(7); expect(lineForTop(anchors, topForLine(anchors, 3.5))).toBe(3.5); }); }); describe("monotonic", () => { it("drops anchors that go back in lines or position", () => { expect( monotonic([ { line: 0, top: 0 }, { line: 2, top: 40 }, { line: 2, top: 60 }, { line: 1, top: 80 }, { line: 5, top: 30 }, { line: 6, top: 90 } ]) ).toEqual([ { line: 0, top: 0 }, { line: 2, top: 40 }, { line: 6, top: 90 } ]); }); });