Skip to content

armgit / Piik

Public Imported from GitHub
0

Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

1.7 KB
Raw Blame
import { afterEach, expect, it, vi } from "vitest";
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { getTitleFrames } from "../src/client/ui/copy";
import { composeDocumentTitle, useDocumentTitle } from "../src/client/ui/document-title";

afterEach(() => vi.restoreAllMocks());

function Title({ parts, variations }: { parts: string[]; variations: readonly string[] }) {
  return useDocumentTitle(parts, variations, "preview");
}

it.each(["zh", "en"] as const)("keeps %s room, actual status and warning beside the first decoration", lang => {
  vi.spyOn(Math, "random").mockReturnValue(0);
  const frames = getTitleFrames(lang, false, "hostActive");
  const parts = ["9527", frames.label, "⚠"];
  const title = renderToStaticMarkup(createElement(Title, { parts, variations: frames.variations }));
  expect(title).toBe(renderToStaticMarkup(composeDocumentTitle(...parts, frames.variations[0])));
});

it.each(["paused", "viewerUnavailable", "viewerReady", "hostEnded"] as const)(
  "keeps %s literal", state => {
    const frames = getTitleFrames("en", false, state);
    const title = renderToStaticMarkup(createElement(Title, { parts: ["9527", frames.label], variations: frames.variations }));
    expect(title).toBe(composeDocumentTitle("9527", frames.label));
  },
);

it("keeps the primary visual state separate from its decoration", () => {
  vi.spyOn(Math, "random").mockReturnValue(0);
  const frames = getTitleFrames("en", true, "viewerWaiting");
  const title = renderToStaticMarkup(createElement(Title, { parts: ["9527", frames.label], variations: frames.variations }));
  expect(title).toBe("Piik | 9527 · ⏳ · 👀");
});