Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

1.3 KB
Raw Blame
// @vitest-environment node
import { describe, expect, test } from "vitest";
import { flattenTranslationStrings } from "@editor/data/settingsContentSearch";

describe("flattenTranslationStrings", () => {
  test("keeps plain strings and walks nested subtrees", () => {
    expect(
      flattenTranslationStrings({
        description: "  Static general description:  ",
        nested: { label: "Inner label" },
        list: ["First", "Second"],
      }),
    ).toEqual([
      "Static general description:",
      "Inner label",
      "First",
      "Second",
    ]);
  });

  test("excludes strings that contain unresolved interpolation placeholders", () => {
    expect(
      flattenTranslationStrings({
        defaultLabel: "Default: {{shortcut}}",
        notificationLabel: "Send {{email}} about {{message}}",
        leadingPlaceholder: "{{shortcut}}: Open settings",
        plain: "Keyboard shortcuts",
      }),
    ).toEqual(["Keyboard shortcuts"]);
  });

  test("removes indexed Trans markup", () => {
    expect(flattenTranslationStrings("<0>test</0> setting")).toEqual([
      "test setting",
    ]);
  });

  test("drops placeholder-only content entirely", () => {
    expect(
      flattenTranslationStrings({
        emailOnly: "{{email}}",
        messageOnly: "<0>{{message}}</0>",
        blank: "   ",
      }),
    ).toEqual([]);
  });
});