5180 fichiers 38.5 Mo 0 téléchargements 294 vues mis à jour il y a 6 heures ui
nitro-v36-with-renderer-v36 / src / components / floorplan-editor / views / FloorplanHeightPicker.test.tsx
FloorplanHeightPicker.test.tsx 2.4 Ko Télécharger le fichier
/* @vitest-environment jsdom */

import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { FloorplanHeightPicker } from './FloorplanHeightPicker';

describe('FloorplanHeightPicker', () => {
    afterEach(() => {
        cleanup();
    });

    it('renders the track + thumb with the current value', () => {
        render(<FloorplanHeightPicker selectedH={12} onSelect={() => undefined} />);

        expect(screen.getByTestId('height-track')).toBeInTheDocument();
        expect(screen.getByTestId('height-thumb').getAttribute('data-value')).toBe('12');
        expect(screen.getByRole('slider', { name: 'Brush height' }).getAttribute('aria-valuenow')).toBe('12');
    });

    it('arrow keys step the brush height by one, Home / End jump to the ends', () => {
        const onSelect = vi.fn();

        render(<FloorplanHeightPicker selectedH={5} onSelect={onSelect} />);

        const slider = screen.getByRole('slider', { name: 'Brush height' });

        fireEvent.keyDown(slider, { key: 'ArrowUp' });
        expect(onSelect).toHaveBeenLastCalledWith(6);

        fireEvent.keyDown(slider, { key: 'ArrowDown' });
        expect(onSelect).toHaveBeenLastCalledWith(4);

        fireEvent.keyDown(slider, { key: 'End' });
        expect(onSelect).toHaveBeenLastCalledWith(26);

        fireEvent.keyDown(slider, { key: 'Home' });
        expect(onSelect).toHaveBeenLastCalledWith(0);
    });

    it('does not fire onSelect when the key press keeps the current height', () => {
        const onSelect = vi.fn();

        render(<FloorplanHeightPicker selectedH={26} onSelect={onSelect} />);

        fireEvent.keyDown(screen.getByRole('slider', { name: 'Brush height' }), { key: 'ArrowUp' });

        expect(onSelect).not.toHaveBeenCalled();
    });

    it('thumb fill matches the tile colour at the picked height', () => {
        const { rerender } = render(<FloorplanHeightPicker selectedH={0} onSelect={() => undefined} />);

        const colourAtZero = screen.getByTestId('height-thumb').getAttribute('data-thumb-color');

        rerender(<FloorplanHeightPicker selectedH={13} onSelect={() => undefined} />);

        const colourAtThirteen = screen.getByTestId('height-thumb').getAttribute('data-thumb-color');

        expect(colourAtZero).toBeTruthy();
        expect(colourAtThirteen).toBeTruthy();
        expect(colourAtZero).not.toBe(colourAtThirteen);
    });
});
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