| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { mentionSuggestions } from "./mention.ts"; |
| 5 | |
| 6 | const TEAMS = ["@acme/backend", "@acme/backend-oncall", "@acme/web", "@acme/design", "@acme/docs", "@acme/data"]; |
| 7 | |
| 8 | test("with no handles nothing is offered", () => { |
| 9 | assert.equal(mentionSuggestions("thanks @g1", 10), null); |
| 10 | assert.equal(mentionSuggestions("@", 1), null); |
| 11 | }); |
| 12 | |
| 13 | test("teams complete from the workspace or from their own name", () => { |
| 14 | assert.deepEqual(mentionSuggestions("cc @acme/b", 10, TEAMS), { start: 3, options: ["@acme/backend", "@acme/backend-oncall"] }); |
| 15 | assert.deepEqual(mentionSuggestions("@back", 5, TEAMS), { start: 0, options: ["@acme/backend", "@acme/backend-oncall"] }); |
| 16 | assert.deepEqual(mentionSuggestions("(@ACME/W", 8, TEAMS), { start: 1, options: ["@acme/web"] }); |
| 17 | // Handles given without their @ work the same. |
| 18 | assert.deepEqual(mentionSuggestions("@we", 3, ["acme/web"]), { start: 0, options: ["@acme/web"] }); |
| 19 | // An email address, and a caret not at the end of it, are not mentions. |
| 20 | assert.equal(mentionSuggestions("me@acme/w", 9, TEAMS), null); |
| 21 | assert.equal(mentionSuggestions("@acme/w later", 13, TEAMS), null); |
| 22 | }); |
| 23 | |
| 24 | test("at most five, and nothing once one is typed in full", () => { |
| 25 | const all = mentionSuggestions("@", 1, TEAMS); |
| 26 | assert.equal(all?.options.length, 5); |
| 27 | assert.equal(all?.options[0], "@acme/backend"); |
| 28 | assert.equal(mentionSuggestions("@acme/web", 9, TEAMS), null); |
| 29 | assert.equal(mentionSuggestions("@acme/x", 7, TEAMS), null); |
| 30 | assert.equal(mentionSuggestions("@acme/web later", 15, TEAMS), null); |
| 31 | }); |