/ opencodehub / tests / unit / mentions.test.ts
Swadhin Biswas Feature/ai code reviewer (#79) · 8/16/2026
cfd400d
37 lines · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { describe, expect, it } from "vitest";
import { extractMentions } from "@/lib/mentions";

describe("mention extraction", () => {
  it("extracts simple usernames", () => {
    expect(extractMentions("Hi @alice, please review")).toEqual(["alice"]);
  });

  it("extracts multiple distinct usernames", () => {
    expect(extractMentions("@alice and @bob and @alice")).toEqual([
      "alice",
      "bob",
    ]);
  });

  it("supports usernames with hyphens and underscores", () => {
    expect(extractMentions("cc @dev-team @jane_doe")).toEqual([
      "dev-team",
      "jane_doe",
    ]);
  });

  it("ignores email addresses and plain text without @", () => {
    expect(extractMentions("contact [email protected] for help")).toEqual([]);
    expect(extractMentions("no mentions here")).toEqual([]);
  });

  it("returns empty for empty input", () => {
    expect(extractMentions("")).toEqual([]);
    expect(extractMentions(undefined as unknown as string)).toEqual([]);
  });

  it("does not match bare @ at end of text", () => {
    expect(extractMentions("ping @")).toEqual([]);
  });
});