|
1 | 1 | // Interactive outbound tests cover channel outbound interactive payload construction. |
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | | -import { renderMessagePresentationChartFallbackText } from "../../../interactive/payload.js"; |
| 3 | +import { |
| 4 | + renderMessagePresentationChartFallbackText, |
| 5 | + renderMessagePresentationFallbackText, |
| 6 | +} from "../../../interactive/payload.js"; |
4 | 7 | import { |
5 | 8 | adaptMessagePresentationForChannel, |
6 | 9 | applyPresentationActionLimits, |
@@ -355,7 +358,7 @@ describe("presentation capability limits", () => { |
355 | 358 | placeholder: "Enviro", |
356 | 359 | options: [{ label: "Canary", value: "canary" }], |
357 | 360 | }, |
358 | | - { type: "context", text: "Environment target:\n- Produc" }, |
| 361 | + { type: "context", text: "Environment target:\n- Production cluster" }, |
359 | 362 | ], |
360 | 363 | }); |
361 | 364 | }); |
@@ -396,8 +399,8 @@ describe("presentation capability limits", () => { |
396 | 399 | }); |
397 | 400 |
|
398 | 401 | expect(presentation.blocks).toEqual([ |
399 | | - { type: "context", text: "Actions:\n- Approve\n- Rollback" }, |
400 | | - { type: "context", text: "Environment:\n- Canary\n- Product" }, |
| 402 | + { type: "context", text: "Actions:\n- Approve deployment\n- Rollback deployment" }, |
| 403 | + { type: "context", text: "Environment:\n- Canary cluster\n- Production cluster" }, |
401 | 404 | ]); |
402 | 405 | }); |
403 | 406 |
|
@@ -536,7 +539,7 @@ describe("presentation capability limits", () => { |
536 | 539 | }); |
537 | 540 |
|
538 | 541 | expect(presentation.blocks).toEqual([ |
539 | | - { type: "text", text: "Actions:\n- Appr" }, |
| 542 | + { type: "text", text: "Actions:\n- Approve" }, |
540 | 543 | { type: "text", text: "Target:\n- Canary" }, |
541 | 544 | { type: "text", text: "Muted details" }, |
542 | 545 | ]); |
@@ -577,6 +580,82 @@ describe("presentation capability limits", () => { |
577 | 580 | ]); |
578 | 581 | }); |
579 | 582 |
|
| 583 | + it("splits unsupported button fallbacks without losing action labels", () => { |
| 584 | + const labels = ["Approve production", "Rollback release", "Show audit trail"]; |
| 585 | + const maxLength = 24; |
| 586 | + const presentation = adaptMessagePresentationForChannel({ |
| 587 | + presentation: { |
| 588 | + blocks: [ |
| 589 | + { |
| 590 | + type: "buttons", |
| 591 | + buttons: labels.map((label, index) => ({ label, value: `action-${index}` })), |
| 592 | + }, |
| 593 | + ], |
| 594 | + }, |
| 595 | + capabilities: { |
| 596 | + buttons: false, |
| 597 | + context: false, |
| 598 | + limits: { |
| 599 | + actions: { maxLabelLength: 4 }, |
| 600 | + text: { maxLength, encoding: "characters" }, |
| 601 | + }, |
| 602 | + }, |
| 603 | + }); |
| 604 | + |
| 605 | + const fallback = presentation.blocks.map((block) => { |
| 606 | + expect(block.type).toBe("text"); |
| 607 | + return block.type === "text" ? block.text : ""; |
| 608 | + }); |
| 609 | + expect(fallback.length).toBeGreaterThan(1); |
| 610 | + expect(fallback.every((value) => Array.from(value).length <= maxLength)).toBe(true); |
| 611 | + expect(fallback.join("")).toBe(`Actions:\n${labels.map((label) => `- ${label}`).join("\n")}`); |
| 612 | + expect(renderMessagePresentationFallbackText({ presentation })).toBe( |
| 613 | + `Actions:\n${labels.map((label) => `- ${label}`).join("\n")}`, |
| 614 | + ); |
| 615 | + }); |
| 616 | + |
| 617 | + it("splits overflow select fallbacks without losing unavailable options", () => { |
| 618 | + const maxLength = 18; |
| 619 | + const presentation = adaptMessagePresentationForChannel({ |
| 620 | + presentation: { |
| 621 | + blocks: [ |
| 622 | + { |
| 623 | + type: "select", |
| 624 | + placeholder: "Deployment target", |
| 625 | + options: [ |
| 626 | + { label: "Canary", value: "canary" }, |
| 627 | + { label: "Production cluster", value: "production" }, |
| 628 | + { label: "Rollback environment", value: "rollback" }, |
| 629 | + ], |
| 630 | + }, |
| 631 | + ], |
| 632 | + }, |
| 633 | + capabilities: { |
| 634 | + limits: { |
| 635 | + selects: { maxOptions: 1, maxLabelLength: 4 }, |
| 636 | + text: { maxLength, encoding: "characters" }, |
| 637 | + }, |
| 638 | + }, |
| 639 | + }); |
| 640 | + |
| 641 | + expect(presentation.blocks[0]).toMatchObject({ |
| 642 | + type: "select", |
| 643 | + options: [{ label: "Cana", value: "canary" }], |
| 644 | + }); |
| 645 | + const fallback = presentation.blocks.slice(1).map((block) => { |
| 646 | + expect(block.type).toBe("context"); |
| 647 | + return block.type === "context" ? block.text : ""; |
| 648 | + }); |
| 649 | + expect(fallback.length).toBeGreaterThan(1); |
| 650 | + expect(fallback.every((value) => Array.from(value).length <= maxLength)).toBe(true); |
| 651 | + expect(fallback.join("")).toBe( |
| 652 | + "Deployment target:\n- Production cluster\n- Rollback environment", |
| 653 | + ); |
| 654 | + expect(renderMessagePresentationFallbackText({ presentation })).toBe( |
| 655 | + "Depl:\n- Cana\n\nDeployment target:\n- Production cluster\n- Rollback environment", |
| 656 | + ); |
| 657 | + }); |
| 658 | + |
580 | 659 | it("applies advertised text limits to titles, text, context, and generated fallback", () => { |
581 | 660 | const presentation = adaptMessagePresentationForChannel({ |
582 | 661 | presentation: { |
@@ -609,6 +688,9 @@ describe("presentation capability limits", () => { |
609 | 688 | { type: "text", text: "hello" }, |
610 | 689 | { type: "context", text: "abcde" }, |
611 | 690 | { type: "context", text: "Actio" }, |
| 691 | + { type: "context", text: "ns:\n" }, |
| 692 | + { type: "context", text: "- Dep" }, |
| 693 | + { type: "context", text: "loy" }, |
612 | 694 | ], |
613 | 695 | }); |
614 | 696 | }); |
|
0 commit comments