MCPcopy
hub / github.com/nilbuild/driver.js / topForOffset

Function topForOffset

tests/popover.test.ts:391–407  ·  view source on GitHub ↗
(popoverOffset: number)

Source from the content-addressed store, hash-verified

389 // tests the feature (offset distances the popover from the element) without
390 // hard-coding the full positioning formula.
391 async function topForOffset(popoverOffset: number): Promise<number> {
392 const el = document.querySelector<HTMLElement>("#intro")!;
393 el.getBoundingClientRect = () => rect({ top: 400, left: 400, right: 600, bottom: 420, width: 200, height: 20 });
394 el.scrollIntoView = () => {};
395
396 const d = createDriver({ animate: false, popoverOffset });
397 d.highlight({ element: "#intro", popover: { title: "Intro", side: "top" } });
398
399 const wrapper = popoverEl() as HTMLElement;
400 wrapper.getBoundingClientRect = () => rect({});
401 d.refresh();
402 await nextFrame();
403
404 const top = parseFloat(wrapper.style.top);
405 d.destroy();
406 return top;
407 }
408
409 it("moves the popover further from the element as the offset grows", async () => {
410 const near = await topForOffset(10);

Callers 1

popover.test.tsFile · 0.85

Calls 4

createDriverFunction · 0.90
popoverElFunction · 0.90
nextFrameFunction · 0.90
rectFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…