align.test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { describe, expect, it } from "vitest";
  2. import { alignBlocks } from "#ui/viewers/align.ts";
  3. const blocks = [
  4. { at: "p:1", text: "Title" },
  5. { at: "p:2", text: "First paragraph that spans two pages." },
  6. { at: "t:1", text: "a b c d" },
  7. { at: "p:3", text: "" },
  8. { at: "p:4", text: "Last" },
  9. ];
  10. describe("alignBlocks", () => {
  11. it("maps elements in order, including split paragraphs and empty ones", () => {
  12. const elements = [
  13. { text: "Title", table: false },
  14. { text: "First paragraph that", table: false },
  15. { text: " spans two pages.", table: false },
  16. { text: "a b c d", table: true },
  17. { text: "", table: false },
  18. { text: "Last", table: false },
  19. ];
  20. expect(alignBlocks(elements, blocks)).toEqual(["p:1", "p:2", "p:2", "t:1", "p:3", "p:4"]);
  21. });
  22. it("skips unknown elements and resynchronises", () => {
  23. const elements = [
  24. { text: "Title", table: false },
  25. { text: "Rendered only by the viewer", table: false },
  26. { text: "First paragraph that spans two pages.", table: false },
  27. { text: "Last", table: false },
  28. ];
  29. expect(alignBlocks(elements, blocks)).toEqual(["p:1", null, "p:2", "p:4"]);
  30. });
  31. });