// @vitest-environment jsdom import { afterEach, describe, expect, it, vi } from 'vitest'; import { cleanup, fireEvent, render, screen } from '@testing-library/react'; import ScannerDestinationPicker from '../../components/ScannerDestinationPicker.js'; const COLLECTIONS = [ { id: 1, name: 'Modern Staples', tcg: 'MTG' }, { id: 2, name: 'Pokémon Binder', tcg: 'Pokemon' }, ]; const DECKS = [ { id: 10, name: 'Commander', game: 'mtg' }, { id: 11, name: 'Standard', game: 'pokemon' }, ]; describe('ScannerDestinationPicker', () => { afterEach(() => cleanup()); it('shows the active destination type with aria-pressed', () => { render( ); expect(screen.getByRole('button', { name: /my collection/i }).getAttribute('aria-pressed')).toBe('true'); expect(screen.getByRole('button', { name: /list/i }).getAttribute('aria-pressed')).toBe('false'); }); it('calls onDestinationChange when switching to a collection', () => { const onDestinationChange = vi.fn(); render( ); fireEvent.click(screen.getByRole('button', { name: /^📚 list$/i })); expect(onDestinationChange).toHaveBeenCalledWith({ type: 'collection', id: 1, label: 'Modern Staples', }); }); it('filters decks by game and disables deck toggle when none match', () => { render( ); expect(screen.getByRole('button', { name: /deck/i }).disabled).toBe(false); expect(screen.queryByText(/Standard/)).toBeNull(); }); it('calls onGameFilterChange when the game select changes', () => { const onGameFilterChange = vi.fn(); render( ); fireEvent.change(screen.getByRole('combobox', { name: /game filter/i }), { target: { value: 'Lorcana' }, }); expect(onGameFilterChange).toHaveBeenCalledWith('Lorcana'); }); });