import { render, screen, fireEvent } from '@testing-library/react'; import { describe, it, expect, vi } from 'vitest'; import React from 'react'; import { MapViewControl } from './map-view-control'; describe('MapViewControl', () => { const views = [ { id: 'rs', label: 'Estado', center: { lat: -30.03, lng: -51.23 }, zoom: 7 }, { id: 'metro', label: 'Região metropolitana', center: { lat: -29.99, lng: -51.15 }, zoom: 10 }, ]; it('renders one button per view', () => { render( {}} />); expect(screen.getByRole('button', { name: 'Estado' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: 'Região metropolitana' })).toBeInTheDocument(); }); it('marks the active view with aria-pressed', () => { render( {}} />); expect(screen.getByRole('button', { name: 'Região metropolitana' })).toHaveAttribute( 'aria-pressed', 'true' ); expect(screen.getByRole('button', { name: 'Estado' })).toHaveAttribute('aria-pressed', 'false'); }); it('reports the chosen view', () => { const onViewChange = vi.fn(); render(); fireEvent.click(screen.getByRole('button', { name: 'Estado' })); expect(onViewChange).toHaveBeenCalledWith('rs'); }); it('hides the reframe button when there is nothing to do', () => { render( {}} />); expect(screen.queryByRole('button', { name: 'Reframe to data' })).not.toBeInTheDocument(); }); it('exposes the reframe action when wired up', () => { const onRefit = vi.fn(); render( {}} onRefit={onRefit} />); fireEvent.click(screen.getByRole('button', { name: 'Reframe to data' })); expect(onRefit).toHaveBeenCalled(); }); it('names the control group', () => { render( {}} />); expect(screen.getByRole('group', { name: 'Map views' })).toBeInTheDocument(); }); });