Files
reply-end-controls/tests/runtime-helper.test.mjs

59 lines
1.8 KiB
JavaScript

import test from "node:test"
import assert from "node:assert/strict"
import {
applyStopStateToInboundText,
buildDefaultReplyEndButtons,
buildReplyEndAcknowledgement,
buildResolvedReplyEndButtons,
} from "../src/runtime/openclaw-telegram-poc.ts"
test("default reply-end buttons contain continue and stop", () => {
const buttons = buildDefaultReplyEndButtons()
assert.equal(buttons[0][0].callback_data, "rec:continue")
assert.equal(buttons[0][1].callback_data, "rec:stop")
})
test("resolved buttons mark continue selection", () => {
const buttons = buildResolvedReplyEndButtons("continue")
assert.match(buttons[0][0].text, /^✅/)
assert.doesNotMatch(buttons[0][1].text, /^⏹/)
})
test("resolved buttons mark stop selection", () => {
const buttons = buildResolvedReplyEndButtons("stop")
assert.match(buttons[0][1].text, /^⏹/)
assert.doesNotMatch(buttons[0][0].text, /^✅/)
})
test("acknowledgement text matches choice", () => {
assert.equal(buildReplyEndAcknowledgement("continue"), "reply-end-controls: continue received")
assert.equal(buildReplyEndAcknowledgement("stop"), "reply-end-controls: stop received")
})
test("stop state injects control text into inbound message", () => {
const result = applyStopStateToInboundText("我先這樣", {
lastChoice: "stop",
lastChoiceAt: "2026-05-13T00:00:00Z",
sourceMessageId: "1",
sourceCallbackId: "cb-1",
active: true,
})
assert.match(result, /reply-end-controls Stop/)
})
test("continue or null state leaves inbound text unchanged", () => {
const base = "我先這樣"
assert.equal(applyStopStateToInboundText(base, null), base)
assert.equal(
applyStopStateToInboundText(base, {
lastChoice: "continue",
lastChoiceAt: "2026-05-13T00:00:00Z",
sourceMessageId: "1",
sourceCallbackId: "cb-1",
active: true,
}),
base
)
})