From 16654b67b32bd312f8ea02075ca87139ce5402ee Mon Sep 17 00:00:00 2001 From: QQ Date: Sat, 14 Nov 2026 14:23:19 +0800 Subject: [PATCH] Import apps/android/tests/bot-mentions.test.ts --- apps/android/tests/bot-mentions.test.ts | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 apps/android/tests/bot-mentions.test.ts diff --git a/apps/android/tests/bot-mentions.test.ts b/apps/android/tests/bot-mentions.test.ts new file mode 100644 index 0000000..8ed5def --- /dev/null +++ b/apps/android/tests/bot-mentions.test.ts @@ -0,0 +1,37 @@ +import { describe, expect, it } from 'vitest' +import { botMentionSpans, linkBotMentions } from '../src/screens/bot/mentions' +import type { BotEntry } from '../src/services/bot-catalog' + +const bot = (id: string, name: string) => ({ id, name } as BotEntry) +const roster = [bot('probe', 'Probe'), bot('chief', 'Chief'), bot('chief-of-staff', 'Chief of Staff')] + +describe('where a message mentions a Bot', () => { + it('finds the name and keeps the text around it', () => { + const spans = botMentionSpans('@Probe 1+1 is 2.', roster) + expect(spans).toHaveLength(1) + expect(spans[0]!.start).toBe(0) + expect(spans[0]!.end).toBe(6) + expect(spans[0]!.bot.id).toBe('probe') + }) + + it('prefers the longest name that fits', () => { + const spans = botMentionSpans('@Chief of Staff please', roster) + expect(spans[0]!.bot.id).toBe('chief-of-staff') + expect(spans[0]!.end).toBe(15) + }) + + it('leaves code, links and addresses alone', () => { + expect(botMentionSpans('`@Probe`', roster)).toHaveLength(0) + expect(botMentionSpans('mail me@Probe.example', roster)).toHaveLength(0) + expect(botMentionSpans('[@Probe](https://example.com)', roster)).toHaveLength(0) + }) + + it('skips the sender itself', () => { + expect(botMentionSpans('@Probe hi', roster, 'probe')).toHaveLength(0) + expect(botMentionSpans('@Chief hi', roster, 'probe')).toHaveLength(1) + }) + + it('links the same spans it hands to the renderer', () => { + expect(linkBotMentions('@Probe 1+1 is 2.', roster)).toBe('[@Probe](https://bots.local/probe) 1+1 is 2.') + }) +})