5180 fichiers 38.5 Mo 0 téléchargements 252 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / components / soundboard / SoundboardPadView.test.tsx
SoundboardPadView.test.tsx 2.1 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 { DisplaySoundboardSound } from '../../hooks/soundboard/soundboardPresentation';
import { SoundboardPadView } from './SoundboardPadView';

const sound: DisplaySoundboardSound = {
    id: 1,
    name: 'Campanella',
    url: '/sounds/campanella.mp3', classname: '',
    categoryId: 'effects',
    tone: 'gold',
    keywords: []
};

describe('SoundboardPadView', () => {
    afterEach(cleanup);

    test('renders a tone pad named after the sound and plays it', () => {
        const onPlay = vi.fn();
        render(<SoundboardPadView sound={sound} disabled={false} onPlay={onPlay} hotkey="3" />);

        const button = screen.getByRole('button', { name: 'Campanella' });
        expect(button.textContent).toContain('Campanella');
        expect(button.textContent).toContain('3');
        expect(button).toHaveAttribute('data-tone', 'gold');

        fireEvent.click(button);
        expect(onPlay).toHaveBeenCalledWith(sound);
    });

    test('does not play while disabled', () => {
        const onPlay = vi.fn();
        render(<SoundboardPadView sound={sound} disabled onPlay={onPlay} />);

        const button = screen.getByRole('button', { name: 'Campanella' });
        expect(button).not.toBeDisabled();
        expect(button).toHaveAttribute('aria-disabled', 'true');
        fireEvent.click(button);
        expect(onPlay).not.toHaveBeenCalled();
    });

    test('toggles the favourite on right click and marks favourite and playing pads', () => {
        const onToggleFavorite = vi.fn();
        render(<SoundboardPadView sound={sound} disabled={false} onPlay={vi.fn()} favorite playing onToggleFavorite={onToggleFavorite} />);

        const button = screen.getByRole('button', { name: 'Campanella' });
        expect(button).toHaveAttribute('data-favorite', 'true');
        expect(button).toHaveAttribute('data-playing', 'true');

        fireEvent.contextMenu(button);
        expect(onToggleFavorite).toHaveBeenCalledWith(sound);
    });
});
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