5180 fichiers 38.5 Mo 0 téléchargements 259 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / components / soundboard / SoundboardFeedView.test.tsx
SoundboardFeedView.test.tsx 1.7 Ko Télécharger le fichier
/* @vitest-environment jsdom */

import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, test, vi } from 'vitest';
import { useSoundboardFeedStore } from '../../hooks/soundboard/soundboardFeedStore';
import { SoundboardFeedItemView } from './SoundboardFeedView';

vi.mock('@octane/renderer', () => ({ GetSessionDataManager: () => ({ userId: 1 }) }));

vi.mock('../../api', () => ({
    LocalizeText: (key: string, _keys?: string[], values?: string[]) => `${key}${values?.length ? ` ${values.join(' ')}` : ''}`
}));

vi.mock('../../hooks', () => ({ useSoundboard: vi.fn() }));

const pushEntry = () => {
    const key = useSoundboardFeedStore.getState().push({ username: 'tester', userId: 7, soundName: 'Bell', soundId: 3 });

    return useSoundboardFeedStore.getState().entries.find((entry) => entry.key === key)!;
};

describe('SoundboardFeedItemView', () => {
    afterEach(() => {
        cleanup();
        useSoundboardFeedStore.getState().clear();
    });

    test('mutes the user of the entry and takes the entry off the feed', () => {
        const entry = pushEntry();
        const onSilence = vi.fn();
        render(<SoundboardFeedItemView entry={entry} canSilence onSilence={onSilence} />);

        fireEvent.click(screen.getByRole('button', { name: 'soundboard.feed.silence tester' }));

        expect(onSilence).toHaveBeenCalledWith(7);
        expect(useSoundboardFeedStore.getState().entries).toEqual([]);
    });

    test('offers no mute button for a player who cannot be muted', () => {
        render(<SoundboardFeedItemView entry={pushEntry()} canSilence={false} onSilence={vi.fn()} />);

        expect(screen.queryByRole('button')).toBeNull();
    });
});
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