test: tighten shared text normalization coverage

This commit is contained in:
Peter Steinberger 2026-03-13 21:26:15 +00:00
parent 0c79c86b40
commit 090c0c4b5d
2 changed files with 23 additions and 0 deletions

View File

@ -29,10 +29,20 @@ describe("shared/string-normalization", () => {
expect(normalizeHyphenSlug(null)).toBe(""); expect(normalizeHyphenSlug(null)).toBe("");
}); });
it("collapses repeated separators and trims leading/trailing punctuation", () => {
expect(normalizeHyphenSlug(" ...Hello / World--- ")).toBe("hello-world");
expect(normalizeHyphenSlug(" ###Team@@@Room### ")).toBe("###team@@@room###");
});
it("normalizes @/# prefixed slugs used by channel allowlists", () => { it("normalizes @/# prefixed slugs used by channel allowlists", () => {
expect(normalizeAtHashSlug(" #My_Channel + Alerts ")).toBe("my-channel-alerts"); expect(normalizeAtHashSlug(" #My_Channel + Alerts ")).toBe("my-channel-alerts");
expect(normalizeAtHashSlug("@@Room___Name")).toBe("room-name"); expect(normalizeAtHashSlug("@@Room___Name")).toBe("room-name");
expect(normalizeAtHashSlug(undefined)).toBe(""); expect(normalizeAtHashSlug(undefined)).toBe("");
expect(normalizeAtHashSlug(null)).toBe(""); expect(normalizeAtHashSlug(null)).toBe("");
}); });
it("strips repeated prefixes and collapses separator-only results", () => {
expect(normalizeAtHashSlug("###__Room Name__")).toBe("room-name");
expect(normalizeAtHashSlug("@@@___")).toBe("");
});
}); });

View File

@ -9,6 +9,12 @@ describe("concatOptionalTextSegments", () => {
it("keeps explicit empty-string right value", () => { it("keeps explicit empty-string right value", () => {
expect(concatOptionalTextSegments({ left: "A", right: "" })).toBe(""); expect(concatOptionalTextSegments({ left: "A", right: "" })).toBe("");
}); });
it("falls back to whichever side is present and honors custom separators", () => {
expect(concatOptionalTextSegments({ left: "A" })).toBe("A");
expect(concatOptionalTextSegments({ right: "B" })).toBe("B");
expect(concatOptionalTextSegments({ left: "A", right: "B", separator: " | " })).toBe("A | B");
});
}); });
describe("joinPresentTextSegments", () => { describe("joinPresentTextSegments", () => {
@ -23,4 +29,11 @@ describe("joinPresentTextSegments", () => {
it("trims segments when requested", () => { it("trims segments when requested", () => {
expect(joinPresentTextSegments([" A ", " B "], { trim: true })).toBe("A\n\nB"); expect(joinPresentTextSegments([" A ", " B "], { trim: true })).toBe("A\n\nB");
}); });
it("keeps whitespace-only segments unless trim is enabled and supports custom separators", () => {
expect(joinPresentTextSegments(["A", " ", "B"], { separator: " | " })).toBe("A | | B");
expect(joinPresentTextSegments(["A", " ", "B"], { trim: true, separator: " | " })).toBe(
"A | B",
);
});
}); });