5180 fichiers 38.5 Mo 0 téléchargements 236 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / api / mentions / mentionSegments.test.ts
mentionSegments.test.ts 1.3 Ko Télécharger le fichier
import { describe, expect, it } from 'vitest';
import { segmentMentionText } from './mentionSegments';

describe('segmentMentionText', () => {
    it('leaves a line without mentions as one plain segment', () => {
        expect(segmentMentionText('hello there', 'Bob')).toEqual([{ text: 'hello there', kind: '' }]);
    });

    it('tags a mention and keeps the spacing around it', () => {
        expect(segmentMentionText('hi @Alice  and bye', 'Bob')).toEqual([
            { text: 'hi ', kind: '' },
            { text: '@Alice', kind: 'tag' },
            { text: '  and bye', kind: '' }
        ]);
    });

    it('stops the tag before the punctuation that follows it', () => {
        expect(segmentMentionText('thanks @Bob, @all!', 'Bob')).toEqual([
            { text: 'thanks ', kind: '' },
            { text: '@Bob', kind: 'self' },
            { text: ', ', kind: '' },
            { text: '@all', kind: 'self' },
            { text: '!', kind: '' }
        ]);
    });

    it('treats a lone at sign and an at sign inside a word as plain text', () => {
        expect(segmentMentionText('mail @ me, a@b', 'Bob')).toEqual([{ text: 'mail @ me, a@b', kind: '' }]);
    });

    it('reads every alias as addressed to the viewer', () => {
        expect(segmentMentionText('@stanza', 'Bob')[0].kind).toBe('self');
    });
});
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser