|
1 | 1 | // Slack tests cover outbound adapter plugin behavior. |
| 2 | +import { presentationToInteractiveControlsReply } from "openclaw/plugin-sdk/interactive-runtime"; |
2 | 3 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 4 |
|
4 | 5 | const sendMessageSlackMock = vi.hoisted(() => vi.fn()); |
@@ -28,6 +29,45 @@ describe("slackOutbound", () => { |
28 | 29 | sendMessageSlackMock.mockReset(); |
29 | 30 | }); |
30 | 31 |
|
| 32 | + it("sends mirrored question controls once at the Slack message block limit", async () => { |
| 33 | + sendMessageSlackMock.mockResolvedValue({ messageId: "171.001", channelId: "C123" }); |
| 34 | + const questionId = "ask_0123456789abcdef0123456789abcdef"; |
| 35 | + const presentation = { |
| 36 | + blocks: [ |
| 37 | + { |
| 38 | + type: "buttons" as const, |
| 39 | + buttons: [ |
| 40 | + { |
| 41 | + label: "Continue", |
| 42 | + action: { type: "question" as const, questionId, optionValue: "Continue" }, |
| 43 | + }, |
| 44 | + ], |
| 45 | + }, |
| 46 | + ], |
| 47 | + }; |
| 48 | + const payload = { |
| 49 | + channelData: { |
| 50 | + askUser: { questionId }, |
| 51 | + slack: { blocks: Array.from({ length: 49 }, () => ({ type: "divider" as const })) }, |
| 52 | + }, |
| 53 | + presentation, |
| 54 | + interactive: presentationToInteractiveControlsReply(presentation), |
| 55 | + }; |
| 56 | + const rendered = await slackOutbound.renderPresentation!({ |
| 57 | + payload, |
| 58 | + presentation, |
| 59 | + ctx: { cfg, to: "C123", text: "", payload }, |
| 60 | + }); |
| 61 | + |
| 62 | + await slackOutbound.sendPayload!({ cfg, to: "C123", text: "", payload: rendered! }); |
| 63 | + |
| 64 | + expect(sendMessageSlackMock).toHaveBeenCalledOnce(); |
| 65 | + expect(sendMessageSlackMock.mock.calls[0]?.[2]?.blocks).toHaveLength(50); |
| 66 | + expect(sendMessageSlackMock.mock.calls[0]?.[2]?.blocks.at(-1)).toMatchObject({ |
| 67 | + elements: [{ action_id: "openclaw:question_button:1:1" }], |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
31 | 71 | it("sends payload media first, then finalizes with blocks", async () => { |
32 | 72 | sendMessageSlackMock |
33 | 73 | .mockResolvedValueOnce({ messageId: "m-media-1" }) |
|
0 commit comments