1import { describe, expect, it } from "vite-plus/test";
2
3import { sectionCollapseAnchorScrollTop } from "./pullRequestSummaryScroll.logic";
4
5describe("section collapse scroll anchoring", () => {
6 it("returns the section's natural offset when its heading is pinned", () => {
7 expect(
8 sectionCollapseAnchorScrollTop({
9 scrollTop: 600,
10 viewportTop: 264,
11 sectionTop: -200,
12 headingTop: 264,
13 }),
14 ).toBe(136);
15 });
16
17 it("allows a fractional sticky-edge difference", () => {
18 expect(
19 sectionCollapseAnchorScrollTop({
20 scrollTop: 500,
21 viewportTop: 264,
22 sectionTop: 100,
23 headingTop: 264.5,
24 }),
25 ).toBe(336);
26 });
27
28 it("leaves the scroll position alone before the heading becomes sticky", () => {
29 expect(
30 sectionCollapseAnchorScrollTop({
31 scrollTop: 120,
32 viewportTop: 264,
33 sectionTop: 320,
34 headingTop: 320,
35 }),
36 ).toBeNull();
37 });
38
39 it("does not produce a negative scroll offset", () => {
40 expect(
41 sectionCollapseAnchorScrollTop({
42 scrollTop: 20,
43 viewportTop: 264,
44 sectionTop: 200,
45 headingTop: 264,
46 }),
47 ).toBe(0);
48 });
49});