5180 fichiers 38.5 Mo 0 téléchargements 283 vues mis à jour il y a 6 heures ui
nitro-v36-with-renderer-v36 / src / hooks / rooms / widgets / useChatCommandSelector.helpers.test.ts
useChatCommandSelector.helpers.test.ts 1.7 Ko Télécharger le fichier
import { describe, expect, it } from 'vitest';
import { CommandDefinition } from '../../../api';
import { getChatCommandQuery, getRankedCommandSuggestions } from './useChatCommandSelector.helpers';

const commands: CommandDefinition[] = [
    { key: 'commands', description: 'Mostra tutti i comandi' },
    { key: 'empty', description: 'Svuota la stanza' },
    { key: 'emptybots', description: 'Svuota inventario bot' },
    { key: 'xempty', description: 'Comando di test' },
    { key: 'ejectall', description: 'Espelli tutti i furni' },
    { key: 'togglefps', description: 'Mostra o nasconde FPS' }
];

describe('getChatCommandQuery', () => {
    it('returns null when the input is not a command prefix', () => {
        expect(getChatCommandQuery('ciao')).toBeNull();
        expect(getChatCommandQuery(':empty ')).toBeNull();
    });

    it('returns the normalized command query', () => {
        expect(getChatCommandQuery(':Em')).toBe('em');
    });
});

describe('getRankedCommandSuggestions', () => {
    it('ranks prefix matches before contains and description matches', () => {
        const result = getRankedCommandSuggestions(commands, 'em', 10);

        expect(result.map((command) => command.key)).toEqual(['empty', 'emptybots', 'xempty']);
    });

    it('matches command descriptions when the key does not match', () => {
        const result = getRankedCommandSuggestions(commands, 'furni', 10);

        expect(result.map((command) => command.key)).toEqual(['ejectall']);
        expect(result[0].matchType).toBe('description');
    });

    it('limits the visible suggestions', () => {
        const result = getRankedCommandSuggestions(commands, '', 2);

        expect(result).toHaveLength(2);
    });
});
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