Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions front-end/components/bloom.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const createBloom = (template, bloom) => {
return bloomFrag;
};

function _formatHashtags(text) {
export function _formatHashtags(text) {
if (!text) return text;
return text.replace(
/\B#[^#]+/g,
/\B#[^#\s]+/g,
(match) => `<a href="/hashtag/${match.slice(1)}">${match}</a>`
);
}
Expand Down
26 changes: 26 additions & 0 deletions front-end/tests/bloom.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { test, expect } from "@playwright/test";
import { _formatHashtags } from "../components/bloom.mjs";

test.describe("Bloom Component", () => {
test("should format a single hashtag in a bloom", () => {
const text = "Test #do";
const result = _formatHashtags(text);
expect(result).toContain('<a href="/hashtag/do">#do</a>');
});

test("should format multiple hashtags in a bloom", () => {
const text = "Tech is magic #blessed #TechLife";
const result = _formatHashtags(text);
expect(result).toContain('<a href="/hashtag/blessed">#blessed</a>');
expect(result).toContain('<a href="/hashtag/TechLife">#TechLife</a>');
});

test("should not include word after hashtag that is not a hashtag", () => {
const text = "Let's get some #SwizBiz love!!";
const result = _formatHashtags(text);
expect(result).toContain('<a href="/hashtag/SwizBiz">#SwizBiz</a>');
expect(result).not.toContain(
'<a href="/hashtag/SwizBiz">#SwizBiz love!!</a>',
);
});
});