promptTemplateTelemetry.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. buildPromptTemplateClickTelemetryPayload,
  4. PROMPT_TEMPLATE_CLICK_EVENT_NAME,
  5. } from "@/lib/promptTemplateTelemetry.js";
  6. describe("prompt template click telemetry", () => {
  7. it("builds the shared click payload with a stable template id and full localized prompt", () => {
  8. expect(
  9. buildPromptTemplateClickTelemetryPayload({
  10. templateId: "weekly-summary",
  11. templateName: "周报总结",
  12. templatePrompt: "请总结最近一周的工作进展。",
  13. }),
  14. ).toEqual({
  15. elementName: PROMPT_TEMPLATE_CLICK_EVENT_NAME,
  16. eventRegion: "app.session",
  17. eventType: "ck",
  18. eventText: "周报总结",
  19. eventExtraDetail: {
  20. template_id: "weekly-summary",
  21. template_prompt: "请总结最近一周的工作进展。",
  22. },
  23. });
  24. });
  25. it("keeps the English label and prompt when the current locale resolves English text", () => {
  26. expect(
  27. buildPromptTemplateClickTelemetryPayload({
  28. templateId: "create-pdf",
  29. templateName: "Create PDF",
  30. templatePrompt: "Create a PDF from the workspace.",
  31. }).eventExtraDetail,
  32. ).toEqual({
  33. template_id: "create-pdf",
  34. template_prompt: "Create a PDF from the workspace.",
  35. });
  36. });
  37. });