weekendPlanDialogFixture.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import weekendPlanHeroUrl from "@/assets/cloud-content/weekend-plan-hero.html?url";
  2. import weekendPlanResultDialogFixture from "@/components/cloud-content-dialog/mocks/weekendPlanResultDialog.zh-CN.json" with { type: "json" };
  3. import type { CloudContentDialogPayload } from "@/components/cloud-content-dialog/cloudContentDialogTypes.js";
  4. // 这是受控内容模板;HTTP mock 注入真实 ZIP 元数据后才是 wire payload。
  5. const weekendPlanResultDialogMockResponse = weekendPlanResultDialogFixture;
  6. export interface WeekendPlanResultDialogMockInput {
  7. locale: "zh-CN" | "en-US";
  8. planName: string;
  9. amountLabel: string;
  10. benefits: string[];
  11. endsAtLabel: string;
  12. title: string;
  13. description: string;
  14. descriptionFormat?: CloudContentDialogPayload["dialog"]["description"]["format"];
  15. replayLabel: string;
  16. confirmLabel: string;
  17. shareLabel: string;
  18. shareText: string;
  19. endsAtPrefix?: string;
  20. }
  21. export function createWeekendPlanResultDialogMock(
  22. input: WeekendPlanResultDialogMockInput,
  23. ): CloudContentDialogPayload {
  24. const amountSeparatorIndex = input.amountLabel.lastIndexOf(" ");
  25. const amountValue =
  26. amountSeparatorIndex > 0 ? input.amountLabel.slice(0, amountSeparatorIndex) : input.amountLabel;
  27. const amountUnit =
  28. amountSeparatorIndex > 0 ? input.amountLabel.slice(amountSeparatorIndex + 1) : "";
  29. return {
  30. schemaVersion: 1,
  31. id: weekendPlanResultDialogMockResponse.id,
  32. revision: weekendPlanResultDialogMockResponse.revision,
  33. kind: "campaign",
  34. locale: input.locale,
  35. dialog: {
  36. hero: {
  37. type: "interactive_bundle",
  38. runtime: "zcode-hero-sandbox-v1",
  39. resolvedUrl: weekendPlanHeroUrl,
  40. viewport: { aspectRatio: "4:3" },
  41. data: {
  42. planName: input.planName,
  43. amountLabel: input.amountLabel,
  44. amountValue,
  45. amountUnit,
  46. benefits: input.benefits,
  47. endsAtLabel: input.endsAtLabel,
  48. endsAtPrefix:
  49. input.endsAtPrefix ?? (input.locale === "zh-CN" ? "有效期至" : "Valid until"),
  50. replayLabel: input.replayLabel,
  51. },
  52. events:
  53. weekendPlanResultDialogMockResponse.dialog.hero.type === "interactive_bundle"
  54. ? weekendPlanResultDialogMockResponse.dialog.hero.events
  55. : { replay: "replay" },
  56. },
  57. title: input.title,
  58. description: { format: input.descriptionFormat ?? "plain_text", text: input.description },
  59. buttons: [
  60. {
  61. id: weekendPlanResultDialogMockResponse.dialog.buttons[0]!.id,
  62. label: input.confirmLabel,
  63. variant: "primary",
  64. actionId: weekendPlanResultDialogMockResponse.dialog.buttons[0]!.actionId,
  65. },
  66. {
  67. id: weekendPlanResultDialogMockResponse.dialog.buttons[1]!.id,
  68. label: input.shareLabel,
  69. variant: "secondary",
  70. actionId: weekendPlanResultDialogMockResponse.dialog.buttons[1]!.actionId,
  71. },
  72. ],
  73. },
  74. actions: {
  75. "open-model-settings": { type: "navigate", destination: "model_settings" },
  76. "copy-share": {
  77. type: "copy_text",
  78. text: input.shareText,
  79. },
  80. },
  81. };
  82. }