Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

test(rail): the rail wears the page's skin once it has asked for the worn theme

milind-sonibd39a7606339
diff --git a/src/components/ChromeRail.test.ts b/src/components/ChromeRail.test.ts
index 0c96cf5a4b..4499070ed2 100644
--- a/src/components/ChromeRail.test.ts
+++ b/src/components/ChromeRail.test.ts
@@ -6,7 +6,7 @@ import { afterEach, expect, it, vi } from "vitest";
vi.mock("@/lib/analytics", () => ({ track: vi.fn() }));
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
let root: Root | null = null;
-afterEach(async () => { await act(async () => root?.unmount()); root = null; document.body.innerHTML = ""; });
+afterEach(async () => { await act(async () => root?.unmount()); root = null; document.body.innerHTML = ""; vi.unstubAllGlobals(); });
it("the window's own rail wears the skin of the page beside it, never keeping it as its own choice", async () => {
let skinOf: (skin: string) => void = () => {};
@@ -22,9 +22,12 @@ it("the window's own rail wears the skin of the page beside it, never keeping it
await act(async () => { await refreshPlaces(); root!.render(createElement(ChromeRail)); });
await act(async () => { await Promise.resolve(); });
expect(host.querySelectorAll("[data-rail-place]")).toHaveLength(2);
- act(() => skinOf("midnight"));
+ // The rail first asks which theme is worn (none here), then wears the page's skin.
+ vi.stubGlobal("fetch", vi.fn(async () => new Response("{}", { status: 404 })));
+ const told = async (skin: string) => act(async () => { skinOf(skin); await new Promise((resolve) => setTimeout(resolve, 0)); });
+ await told("midnight");
expect(document.documentElement.dataset.skin).toBe("midnight");
- act(() => skinOf("<b>"));
+ await told("<b>");
expect(document.documentElement.dataset.skin).toBe("midnight");
expect(applySkin, "the page's choice, never sent back to main as this one's").not.toHaveBeenCalled();
});