i18n.test.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { describe, expect, it } from "vitest";
  2. import { describeAt, strings } from "#ui/i18n.ts";
  3. import { nextZoom } from "#ui/viewers/types.ts";
  4. describe("describeAt", () => {
  5. const t = strings("en-US");
  6. it("says locators the way people do", () => {
  7. expect(describeAt("page:3", t)).toBe("Page 3");
  8. expect(describeAt("page:2-4", t)).toBe("Pages 2–4");
  9. expect(describeAt("page:4", t, true)).toBe("page 4");
  10. expect(describeAt("slide:2/shape:7", t)).toBe("Slide 2 · Shape");
  11. expect(describeAt("p:12", t)).toBe("Paragraph 12");
  12. expect(describeAt("t:1/r3c1", t)).toBe("Table 1 · R3C1");
  13. expect(describeAt("Plan!C2:D2", t)).toBe("Plan · C2:D2");
  14. expect(describeAt("'Q3 data'!A1", t)).toBe("Q3 data · A1");
  15. expect(describeAt("'Q3 data'", t)).toBe("Q3 data");
  16. });
  17. it("has Chinese labels", () => {
  18. expect(describeAt("page:3", strings("zh-CN"))).toBe("第 3 页");
  19. });
  20. });
  21. describe("strings", () => {
  22. // The default profile opens every format.
  23. it("names every format the plugin opens", () => {
  24. expect(strings("en").emptyCaption).toContain(".docx, .xlsx, .pptx or .pdf");
  25. expect(strings("en").openFile).toBe("Open file");
  26. expect(strings("en").errors.unsupported_type[1]).toBe(
  27. "Office opens .docx, .xlsx, .pptx and .pdf files.",
  28. );
  29. expect(strings("zh-CN").emptyCaption).toContain(".docx、.xlsx、.pptx 或 .pdf");
  30. expect(strings("zh-CN").openFile).toBe("打开文件");
  31. });
  32. });
  33. describe("nextZoom", () => {
  34. it("steps through the zoom ladder within 25–400%", () => {
  35. expect(nextZoom(100, 1)).toBe(110);
  36. expect(nextZoom(100, -1)).toBe(90);
  37. expect(nextZoom(117, 1)).toBe(125);
  38. expect(nextZoom(400, 1)).toBe(400);
  39. expect(nextZoom(25, -1)).toBe(25);
  40. });
  41. });
  42. describe("tool wording", () => {
  43. it("names every format for the default profile", async () => {
  44. const wording = await import("#office/wording.ts");
  45. expect(wording.FILE_NOUN).toBe("an Office or PDF file");
  46. expect(wording.FILES_NOUN).toBe("Office and PDF files");
  47. expect(wording.EXAMPLE_ANCHORS).toBe(
  48. "report.docx#p:12, model.xlsx#Revenue!B2:F9, deck.pptx#slide:3, paper.pdf#page:5",
  49. );
  50. expect(wording.TARGET_NOUNS).toBe("paragraph, cell range, slide, shape or page");
  51. expect(wording.QUOTE_BEST_FOR).toBe("PDF pages and long paragraphs");
  52. expect(wording.CAPTURE_EXAMPLES).toBe(
  53. "deck.pptx#slide:3, paper.pdf#page:2, report.docx#p:12 or model.xlsx#Revenue!A1:H30",
  54. );
  55. });
  56. });