From f580b683805cdfdf2d02c9b193cf69eeb71363a8 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 22 Mar 2026 18:30:07 -0700 Subject: [PATCH] test(mattermost): cover onchar parsing --- .../src/mattermost/monitor-onchar.test.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 extensions/mattermost/src/mattermost/monitor-onchar.test.ts diff --git a/extensions/mattermost/src/mattermost/monitor-onchar.test.ts b/extensions/mattermost/src/mattermost/monitor-onchar.test.ts new file mode 100644 index 00000000000..b2e43e6ba33 --- /dev/null +++ b/extensions/mattermost/src/mattermost/monitor-onchar.test.ts @@ -0,0 +1,32 @@ +import { describe, expect, it } from "vitest"; +import { resolveOncharPrefixes, stripOncharPrefix } from "./monitor-onchar.js"; + +describe("mattermost monitor onchar", () => { + it("uses defaults when prefixes are missing or empty after trimming", () => { + expect(resolveOncharPrefixes(undefined)).toEqual([">", "!"]); + expect(resolveOncharPrefixes([" ", ""])).toEqual([">", "!"]); + }); + + it("trims configured prefixes and preserves order", () => { + expect(resolveOncharPrefixes([" ?? ", " !", " /bot "] )).toEqual(["??", "!", "/bot"]); + }); + + it("strips the first matching prefix after leading whitespace", () => { + expect(stripOncharPrefix(" ! hello world", ["!", ">"])).toEqual({ + triggered: true, + stripped: "hello world", + }); + + expect(stripOncharPrefix("??multi prefix", ["??", "?"])).toEqual({ + triggered: true, + stripped: "multi prefix", + }); + }); + + it("returns the original text when no prefix matches", () => { + expect(stripOncharPrefix("hello world", ["!", ">"])).toEqual({ + triggered: false, + stripped: "hello world", + }); + }); +});