Skip to content

The open-source full-stack studio for Opus 5.5 motion video. Reverse engineering for any video. Code video with HTML: recreate, edit and render. BYOA + BYOK · Motion.md · Images, Video, Music & Voice.

811 B
Raw Blame
// @vitest-environment happy-dom
import { afterEach, describe, expect, it, vi } from "vitest";
import { prefetchPreviewForHash } from "./previewPrefetch";

describe("prefetchPreviewForHash", () => {
  afterEach(() => vi.unstubAllGlobals());

  it("requests the opening project's preview once, not on every hash update", () => {
    const fetchStub = vi.fn(() => Promise.resolve(new Response("")));
    vi.stubGlobal("fetch", fetchStub);

    prefetchPreviewForHash("#project/demo");
    prefetchPreviewForHash("#project/demo?t=2&tab=design");
    prefetchPreviewForHash("#project/other");
    prefetchPreviewForHash("#settings");

    expect(fetchStub.mock.calls.map(([url]) => new URL(String(url)).pathname)).toEqual([
      "/api/projects/demo/preview",
      "/api/projects/other/preview",
    ]);
  });
});