Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
import { afterEach, describe, expect, it, vi } from "vitest";
import { scrollToCenter } from "./scroll-within";
afterEach(() => { vi.unstubAllGlobals(); });
function setup(padding: { scrollPaddingTop?: string; scrollPaddingBottom?: string } = {}) {
const scroller = { parentElement: null, scrollTop: 1000, scrollHeight: 4000, clientHeight: 800, getBoundingClientRect: () => ({ top: 100 }), scrollTo: vi.fn() };
const target = { parentElement: scroller, offsetHeight: 40, getBoundingClientRect: () => ({ top: 300 }), scrollIntoView: vi.fn() };
vi.stubGlobal("getComputedStyle", (node: unknown) => (node === scroller ? { overflowY: "auto", ...padding } : { overflowY: "visible" }));
scrollToCenter(target as unknown as HTMLElement, "smooth");
return { scroller, target };
}
describe("scrollToCenter", () => {
it("moves only the nearest scroller, never the page", () => {
const { scroller, target } = setup();
expect(scroller.scrollTo).toHaveBeenCalledWith({ top: 820, behavior: "smooth" });
expect(target.scrollIntoView).not.toHaveBeenCalled();
});
it("centres in the room the scroll-padding leaves above the docked composer", () => {
const { scroller } = setup({ scrollPaddingTop: "auto", scrollPaddingBottom: "160px" });
expect(scroller.scrollTo).toHaveBeenCalledWith({ top: 900, behavior: "smooth" });
});
});