Skip to content

armgit / clipy

Public Imported from GitHub
0

The AI-native screen recorder. Record your screen and talk; the people you share it with and your AI agents both get it.

1.9 KB
Raw Blame
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { test } from "node:test";
import { createTranslator } from "use-intl";
import { createServer } from "vite";

const english = JSON.parse(readFileSync(new URL("../src/vendor/i18n/messages/en/desktop.json", import.meta.url), "utf8"));

test("recording sizes come from the window's messages", async (t) => {
  const server = await createServer({
    configFile: false,
    optimizeDeps: { noDiscovery: true },
    server: { middlewareMode: true, hmr: false, watch: null },
  });
  t.after(() => server.close());
  const { formatBytes } = await server.ssrLoadModule("/src/components/LocalModePanel.tsx");

  const en = createTranslator({ locale: "en", messages: { desktop: english }, namespace: "desktop.local" });
  assert.deepEqual([formatBytes(en, 2_340_000_000), formatBytes(en, 12_400_000), formatBytes(en, 20)], ["2.3 GB", "12 MB", "1 KB"]);

  // A locale overlay can rename the units.
  const local = { size: { kb: "{size} Ko", mb: "{size} Mo", gb: "{size} Go" } };
  const fr = createTranslator({ locale: "fr", messages: { desktop: { local } }, namespace: "desktop.local" });
  assert.deepEqual([formatBytes(fr, 2_340_000_000), formatBytes(fr, 12_400_000), formatBytes(fr, 20)], ["2.3 Go", "12 Mo", "1 Ko"]);
});

test("the Local retention sentence keeps its English text", () => {
  const en = createTranslator({ locale: "en", messages: { desktop: english }, namespace: "desktop.local" });
  assert.equal(
    en("retention", { app: "Clipy", device: "Mac", days: 14 }),
    "Local recordings and their AREC context stay in Clipy's folder on this Mac and clear after 14 days unless kept.",
  );
  assert.match(en("retention", { app: "Clipy", device: "PC", days: 1 }), /clear after 1 day unless kept\.$/);
  assert.equal(en("datedExpiry", { date: "Nov 29, 10:15", expiry: "Kept" }), "Nov 29, 10:15 · Kept");
});