5180 fichiers 38.5 Mo 0 téléchargements 277 vues mis à jour il y a 6 heures ui
nitro-v36-with-renderer-v36 / src / components / mod-tools / views / chatlogFilter.test.ts
chatlogFilter.test.ts 2.3 Ko Télécharger le fichier
import { describe, expect, it } from 'vitest';
import { ChatlogRecord, chatlineMatches, filterChatlogRecords } from './chatlogFilter';

const room = (roomId: number, roomName: string): ChatlogRecord => ({ isRoomInfo: true, roomId, roomName });

const line = (username: string, message: string): ChatlogRecord => ({
    isRoomInfo: false,
    timestamp: '12:00',
    habboId: 1,
    username,
    hasHighlighting: false,
    message
});

describe('filterChatlogRecords', () => {
    const records = [
        room(1, 'Lobby'),
        line('alice', 'hello there'),
        line('bob', 'selling furni'),
        room(2, 'Cafe'),
        line('carol', 'good morning')
    ];

    it('returns everything when nothing is typed', () => {
        expect(filterChatlogRecords(records, '   ')).toBe(records);
    });

    it('keeps the room heading above a surviving line', () => {
        expect(filterChatlogRecords(records, 'furni')).toEqual([room(1, 'Lobby'), line('bob', 'selling furni')]);
    });

    it('drops the heading of a room where nothing matched', () => {
        const result = filterChatlogRecords(records, 'morning');

        expect(result).toEqual([room(2, 'Cafe'), line('carol', 'good morning')]);
        expect(result.some((r) => r.isRoomInfo && r.roomName === 'Lobby')).toBe(false);
    });

    it('matches the speaker as well as what was said', () => {
        expect(filterChatlogRecords(records, 'alice')).toEqual([room(1, 'Lobby'), line('alice', 'hello there')]);
    });

    it('ignores case', () => {
        expect(filterChatlogRecords(records, 'HELLO')).toHaveLength(2);
    });

    it('emits a heading once, however many lines match under it', () => {
        const result = filterChatlogRecords(records, 'e');

        expect(result.filter((r) => r.isRoomInfo && r.roomId === 1)).toHaveLength(1);
    });

    it('returns nothing when a room heading is the only thing that would match', () => {
        expect(filterChatlogRecords(records, 'Lobby')).toEqual([]);
    });

    it('matches a single line the way the evidence list filters it', () => {
        expect(chatlineMatches('alice', 'hello there', 'ALI')).toBe(true);
        expect(chatlineMatches('alice', 'hello there', 'there')).toBe(true);
        expect(chatlineMatches('alice', 'hello there', 'bob')).toBe(false);
        expect(chatlineMatches('alice', 'hello there', '  ')).toBe(true);
    });
});
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